public void Deserialize_restores_immutable_message_correctly() { // Arrange var sut = new JsonMessageSerializer(); var message = fixture.Create <ImmutableMessage>(); string serialized = sut.Serialize(message); TestContext.WriteLine(serialized); // Act object actual = sut.Deserialize(serialized); // Assert actual.Should().BeOfType <ImmutableMessage>(); actual.ShouldBeEquivalentTo(message); }
public void Deserialize_restores_untyped_message_to_dynamic() { // Arrange string prop = $"{Guid.NewGuid()}"; var json = $"{{ \"Prop\": \"{prop}\" }}"; var sut = new JsonMessageSerializer(); var actual = default(object); // Act Action action = () => actual = sut.Deserialize(json); // Assert action.ShouldNotThrow(); actual.Should().NotBeNull(); ((string)((dynamic)actual).Prop).Should().Be(prop); }
public void Deserialize_restores_message_of_unknown_type_to_dynamic() { // Arrange string prop = $"{Guid.NewGuid()}"; string json = $"{{ \"$type\": \"UnknownNamespace.UnknownMessage, UnknownAssembly\", \"Prop\": \"{prop}\" }}"; var sut = new JsonMessageSerializer(); object actual = default(object); // Act Action action = () => actual = sut.Deserialize(json); // Assert action.Should().NotThrow(); actual.Should().NotBeNull(); ((string)((dynamic)actual).Prop).Should().Be(prop); }
public void sut_serializes_DateTimeOffset_property_correctly() { // Arrange var message = new MessageWithDateTimeOffsetProperty { DateTimeOffsetProp = fixture.Create <DateTimeOffset>() }; var sut = new JsonMessageSerializer(); // Act string value = sut.Serialize(message); TestContext.WriteLine(value); object actual = sut.Deserialize(value); // Assert actual.Should().BeOfType <MessageWithDateTimeOffsetProperty>(); actual.ShouldBeEquivalentTo(message); }
public void sut_implements_IMessageSerializer() { var sut = new JsonMessageSerializer(); sut.Should().BeAssignableTo <IMessageSerializer>(); }