Skip to content

Commit

Permalink
Merge pull request #12 from osstotalsoft/feature/RequestsAndEventsMet…
Browse files Browse the repository at this point in the history
…adata

requests and events metadata update
  • Loading branch information
fraliv13 authored Jun 5, 2019
2 parents ec36b21 + 7057ad4 commit 1c9d1f6
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/Application/NBB.Application.DataContracts/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ public abstract class Command : ICommand, IMetadataProvider<CommandMetadata>
{
public CommandMetadata Metadata { get; }

protected Command(CommandMetadata metadata)
protected Command(CommandMetadata metadata = null)
{
Metadata = metadata ?? CommandMetadata.Default();
}
}

public abstract class Command<TResponse> : Command, IRequest<TResponse>
{
protected Command(CommandMetadata metadata)
protected Command(CommandMetadata metadata = null)
: base(metadata)
{
}
Expand Down
2 changes: 1 addition & 1 deletion src/Application/NBB.Application.DataContracts/Event.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public abstract class Event : IEvent, IMetadataProvider<EventMetadata>
{
public EventMetadata Metadata { get; }

protected Event(EventMetadata metadata)
protected Event(EventMetadata metadata = null)
{
Metadata = metadata ?? EventMetadata.Default();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Application/NBB.Application.DataContracts/Query.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public abstract class Query<TResponse> : IQuery<TResponse>, IMetadataProvider<Qu
{
public QueryMetadata Metadata { get; }

protected Query(QueryMetadata metadata)
protected Query(QueryMetadata metadata = null)
{
Metadata = metadata ?? QueryMetadata.Default();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Domain/NBB.Domain/DomainEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public abstract class DomainEvent : IDomainEvent, IMetadataProvider<DomainEventM
{
public DomainEventMetadata Metadata { get; }

protected DomainEvent(DomainEventMetadata metadata)
protected DomainEvent(DomainEventMetadata metadata = null)
{
Metadata = metadata ?? DomainEventMetadata.Default();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Reflection;
using FluentAssertions;
using Moq;
using NBB.Application.DataContracts;
using NBB.Core.Abstractions;
using NBB.Messaging.DataContracts;
using Newtonsoft.Json;
Expand All @@ -12,7 +13,7 @@ namespace NBB.Messaging.Abstractions.Tests
{
public class MessageSerDesTests
{
public class TestMessage : IEvent
public class TestMessage : Event
{
public Guid EventId { get; private set; }
public DateTime CreationDate { get; private set; }
Expand All @@ -24,26 +25,16 @@ public class TestMessage : IEvent
private readonly bool _constructedWithPrivateConstructor;
public bool ConstructedWithPrivateConstructor() => _constructedWithPrivateConstructor;

[JsonConstructor]
private TestMessage(Guid eventId, DateTime creationDate, long contractId, long partnerId, string details)
public TestMessage(long partnerId, long contractId, string details, EventMetadata metadata = null) : base(metadata)
{
EventId = eventId;
CreationDate = creationDate;
ContractId = contractId;
PartnerId = partnerId;
ContractId = contractId;
Details = details;

_constructedWithPrivateConstructor = true;
}

public TestMessage(long contractId, long partnerId, string details)
:this(Guid.NewGuid(), DateTime.Now, contractId, partnerId, details)
{
}
}

[Fact]
public void Should_deserialize_messages_using_the_attributed_private_constructor()
public void Should_deserialize_messages_using_constructor_with_optional_params()
{
//Arrange
var sut = new NewtonsoftJsonMessageSerDes(Mock.Of<IMessageTypeRegistry>(x => x.ResolveType(It.IsAny<string>(), It.IsAny<IEnumerable<Assembly>>()) == typeof(TestMessage)));
Expand All @@ -56,7 +47,8 @@ public void Should_deserialize_messages_using_the_attributed_private_constructor

//Assert
deserialized.Should().NotBeNull();
deserialized.Payload.ConstructedWithPrivateConstructor().Should().BeTrue();
deserialized.Payload.Should().NotBeNull();
deserialized.Payload.Should().BeEquivalentTo(@event);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\..\src\Application\NBB.Application.DataContracts\NBB.Application.DataContracts.csproj" />
<ProjectReference Include="..\..\..\..\src\Messaging\NBB.Messaging.Abstractions\NBB.Messaging.Abstractions.csproj" />
</ItemGroup>

Expand Down

0 comments on commit 1c9d1f6

Please sign in to comment.