Browse Source

Merge branch 'master' of github.com:SebastianStehle/PinkParrot

pull/1/head
Sebastian 9 years ago
parent
commit
c49ba1dc9e
  1. 27
      src/PinkParrot.Infrastructure.Tests/PropertiesBagTests.cs
  2. 13
      src/PinkParrot.Infrastructure.Tests/TypeNameRegistryTests.cs
  3. 1
      src/PinkParrot.Infrastructure/Guard.cs
  4. 1
      src/PinkParrot.Infrastructure/Reflection/PropertiesTypeAccessor.cs
  5. 75
      src/pinkparrot_infrastructure/PinkParrot.Infrastructure.Tests/CQRS/EnvelopeExtensionsTest.cs

27
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<PropertiesBag>(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));

13
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

1
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;

1
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

75
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<object> envelope = new Envelope<object>(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());
}
}
}
Loading…
Cancel
Save