diff --git a/src/PinkParrot.Infrastructure.Tests/PropertiesBagTests.cs b/src/PinkParrot.Infrastructure.Tests/PropertiesBagTests.cs index 221791b01..0a0ef6567 100644 --- a/src/PinkParrot.Infrastructure.Tests/PropertiesBagTests.cs +++ b/src/PinkParrot.Infrastructure.Tests/PropertiesBagTests.cs @@ -30,6 +30,19 @@ namespace PinkParrot.Infrastructure dynamicBag = bag; } + [Fact] + public void Should_serialize_and_deserialize_empty() + { + var serializerSettings = new JsonSerializerSettings(); + + serializerSettings.Converters.Add(new PropertiesBagConverter()); + + var content = JsonConvert.SerializeObject(bag, serializerSettings); + var response = JsonConvert.DeserializeObject(content, serializerSettings); + + Assert.Equal(bag.Count, response.Count); + } + [Fact] public void Should_serialize_and_deserialize() { @@ -312,6 +325,14 @@ namespace PinkParrot.Infrastructure AssertString("Foo"); } + [Fact] + public void Should_provide_null() + { + bag.Set("Key", null); + + AssertNull(); + } + [Fact] public void Should_throw_when_converting_instant_to_number() { @@ -335,6 +356,12 @@ namespace PinkParrot.Infrastructure Assert.Equal(expected, (string)dynamicBag.Key); } + private void AssertNull() + { + Assert.Null(bag["Key"].ToString()); + Assert.Null(bag["Key"].RawValue); + } + private void AssertBoolean(bool expected) { Assert.Equal(expected, bag["Key"].ToBoolean(c)); diff --git a/src/PinkParrot.Infrastructure.Tests/TypeNameRegistryTests.cs b/src/PinkParrot.Infrastructure.Tests/TypeNameRegistryTests.cs index 0bb361784..dec1e6499 100644 --- a/src/PinkParrot.Infrastructure.Tests/TypeNameRegistryTests.cs +++ b/src/PinkParrot.Infrastructure.Tests/TypeNameRegistryTests.cs @@ -1,8 +1,13 @@ -using System; -using System.Collections.Generic; -using System.Linq; +// ========================================================================== +// TypeNameRegistryTests.cs +// PinkParrot Headless CMS +// ========================================================================== +// Copyright (c) PinkParrot Group +// All rights reserved. +// ========================================================================== + +using System; using System.Reflection; -using System.Threading.Tasks; using Xunit; namespace PinkParrot.Infrastructure diff --git a/src/PinkParrot.Infrastructure/Guard.cs b/src/PinkParrot.Infrastructure/Guard.cs index fb5cca769..b5aefcda7 100644 --- a/src/PinkParrot.Infrastructure/Guard.cs +++ b/src/PinkParrot.Infrastructure/Guard.cs @@ -9,7 +9,6 @@ using System; using System.Collections.Generic; using System.Diagnostics; -using System.Globalization; using System.IO; using System.Linq; using System.Runtime.CompilerServices; diff --git a/src/PinkParrot.Infrastructure/Reflection/PropertiesTypeAccessor.cs b/src/PinkParrot.Infrastructure/Reflection/PropertiesTypeAccessor.cs index 3e8794ddb..aa8dcfd32 100644 --- a/src/PinkParrot.Infrastructure/Reflection/PropertiesTypeAccessor.cs +++ b/src/PinkParrot.Infrastructure/Reflection/PropertiesTypeAccessor.cs @@ -9,7 +9,6 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; -using System.Linq; using System.Reflection; namespace PinkParrot.Infrastructure.Reflection diff --git a/src/pinkparrot_infrastructure/PinkParrot.Infrastructure.Tests/CQRS/EnvelopeExtensionsTest.cs b/src/pinkparrot_infrastructure/PinkParrot.Infrastructure.Tests/CQRS/EnvelopeExtensionsTest.cs new file mode 100644 index 000000000..05a650182 --- /dev/null +++ b/src/pinkparrot_infrastructure/PinkParrot.Infrastructure.Tests/CQRS/EnvelopeExtensionsTest.cs @@ -0,0 +1,75 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using NodaTime; +using NuGet.Versioning; +using Xunit; + +namespace PinkParrot.Infrastructure.CQRS +{ + public class EnvelopeExtensionsTest + { + private readonly Envelope envelope = new Envelope(1, new EnvelopeHeaders()); + + [Fact] + public void Should_set_and_get_timestamp() + { + var timestamp = SystemClock.Instance.GetCurrentInstant(); + + envelope.SetTimestamp(timestamp); + + Assert.Equal(timestamp, envelope.Headers.Timestamp()); + } + + [Fact] + public void Should_set_and_get_event_id() + { + var eventId = Guid.NewGuid(); + + envelope.SetEventId(eventId); + + Assert.Equal(eventId, envelope.Headers.EventId()); + } + + [Fact] + public void Should_set_and_get_event_number() + { + const int eventNumber = 123; + + envelope.SetEventNumber(eventNumber); + + Assert.Equal(eventNumber, envelope.Headers.EventNumber()); + } + + [Fact] + public void Should_set_and_get_aggregate_id() + { + var aggregateId = Guid.NewGuid(); + + envelope.SetAggregateId(aggregateId); + + Assert.Equal(aggregateId, envelope.Headers.AggregateId()); + } + + [Fact] + public void Should_set_and_get_tenant_id() + { + var tenantId = Guid.NewGuid(); + + envelope.SetTenantId(tenantId); + + Assert.Equal(tenantId, envelope.Headers.TenantId()); + } + + [Fact] + public void Should_set_and_get_commit_id() + { + var commitId = Guid.NewGuid(); + + envelope.SetCommitId(commitId); + + Assert.Equal(commitId, envelope.Headers.CommitId()); + } + } +}