private static void ShouldBeSerializable(SerializationFormat format) { // Arrange. var category = ApplicationEventCategory.Information; var verbosity = ApplicationEventVerbosity.Normal; var description = "description"; var environmentName = "environmentName"; var userInformation = "userInformation"; var target = new ApplicationEvent(category, verbosity, description, environmentName, userInformation); var serializer = new DynamicSerializer <ApplicationEvent>(format); // Act. var serializedTarget = serializer.Serialize(target); var deserializedResult = serializer.Deserialize(serializedTarget); // Assert. deserializedResult.Should().NotBeNull(); deserializedResult.Category.Should().Be(target.Category); deserializedResult.Description.Should().Be(target.Description); deserializedResult.EnvironmentName.Should().Be(target.EnvironmentName); deserializedResult.OccurrenceDateTime.Should().Be(target.OccurrenceDateTime); deserializedResult.Summary.Should().Be(target.Summary); deserializedResult.UserInformation.Should().Be(target.UserInformation); deserializedResult.Verbosity.Should().Be(target.Verbosity); }
/// <summary> /// Deserializes the specified message. /// </summary> /// <typeparam name="TMessage"> /// The type of the message. /// </typeparam> /// <param name="message"> /// The message to deserialize. /// </param> /// <returns> /// The deserialized result. /// </returns> /// <exception cref="SerializationException"> /// <paramref name="message" /> is invalid or an error occurred during deserialization. /// </exception> protected TMessage DeserializeMessage <TMessage>(Byte[] message) where TMessage : class { var serializer = new DynamicSerializer <TMessage>(MessageSerializationFormat); return(serializer.Deserialize(message)); }
private static void ShouldBeSerializable(SerializationFormat format) { // Arrange. Arrange. var target = new TimeOfDay(TimeZoneInfo.Utc, 15, 32, 56, 490); var serializer = new DynamicSerializer <TimeOfDay>(format); // Act. var serializedTarget = serializer.Serialize(target); var deserializedResult = serializer.Deserialize(serializedTarget); // Assert. deserializedResult.Should().Be(target); }
private static void ShouldBeSerializable(SerializationFormat format) { // Arrange. Arrange. var value = Guid.Parse("4aaadf09-0a66-41dc-bfc8-f8520f4aeaf8"); var identifier = new EnhancedReadabilityGuid(value); var target = new EnhancedReadabilityGuidContainer(identifier); var serializer = new DynamicSerializer <EnhancedReadabilityGuidContainer>(format); // Act. var serializedTarget = serializer.Serialize(target); var deserializedResult = serializer.Deserialize(serializedTarget); // Assert. deserializedResult.Identifier.Should().Be(identifier); }
public void TestDynamicObject() { var reg = new MessageRegistry(); var typeRegistry = TypeRegistry.CreateDefault(); var ser = new DefaultSerializer<SubMessage>(reg, typeRegistry); var r = new DynamicSerializer(reg, typeRegistry); using (var buf = new ThreadSafeWriteQueue(1024)) { dynamic src = new SubMessage { MessageId = ser.MessageId, A = 1, B = 2 }; r.Serialize(buf, src); dynamic a = new { }; r.Deserialize(buf, buf.ReadMessage(), a); } }
private static void ShouldBeSerializable(SerializationFormat format) { // Arrange. Arrange. var start = new DateTime(1997, 11, 6, 14, 7, 46, 482, DateTimeKind.Local); var end = new DateTime(2024, 2, 29, 17, 41, 10, 193, DateTimeKind.Local); var target = new DateTimeRange(start, end); var serializer = new DynamicSerializer <DateTimeRange>(format); // Act. var serializedTarget = serializer.Serialize(target); var deserializedResult = serializer.Deserialize(serializedTarget); // Assert. deserializedResult.Should().Be(target); }
private static void ShouldBeSerializable(SerializationFormat format) { // Arrange. Arrange. var correlationIdentifier = Guid.Parse("4aaadf09-0a66-41dc-bfc8-f8520f4aeaf8"); var dateRange = new DateTimeRange(DateTime.UtcNow, DateTime.UtcNow.AddDays(1)); var target = new SimulatedRequestMessage(correlationIdentifier, dateRange); var identifier = target.Identifier; var resultType = target.ResultType; var serializer = new DynamicSerializer <SimulatedRequestMessage>(format); // Act. var serializedTarget = serializer.Serialize(target); var deserializedResult = serializer.Deserialize(serializedTarget); // Assert. deserializedResult.Should().NotBeNull(); deserializedResult.CorrelationIdentifier.Should().Be(correlationIdentifier); deserializedResult.DateRange.Should().Be(dateRange); deserializedResult.Identifier.Should().Be(identifier); deserializedResult.ResultType.Should().Be(resultType); }
private static void ShouldBeSerializable(SerializationFormat format) { // Arrange. Arrange. var requestMessageIdentifier = Guid.Parse("fab2812e-88f4-4a03-8723-6d285a98b149"); var correlationIdentifier = Guid.Parse("4aaadf09-0a66-41dc-bfc8-f8520f4aeaf8"); var result = TimeSpan.FromMilliseconds(99999); var target = new SimulatedResponseMessage(requestMessageIdentifier, correlationIdentifier, result); var identifier = target.Identifier; var resultType = target.ResultType; var serializer = new DynamicSerializer <SimulatedResponseMessage>(format); // Act. var serializedTarget = serializer.Serialize(target); var deserializedResult = serializer.Deserialize(serializedTarget); // Assert. deserializedResult.Should().NotBeNull(); deserializedResult.CorrelationIdentifier.Should().Be(correlationIdentifier); deserializedResult.Identifier.Should().Be(identifier); deserializedResult.RequestMessageIdentifier.Should().Be(requestMessageIdentifier); deserializedResult.Result.Should().Be(result); deserializedResult.ResultType.Should().Be(resultType); }
private static void ShouldBeSerializable(SerializationFormat format) { // Arrange. var series = new Double[] { 0d, 1d, 2d, 3d, 4d }; var target = series.ComputeDescriptives(); var serializer = new DynamicSerializer <DescriptiveStatistics>(format); // Act. var serializedTarget = serializer.Serialize(target); var deserializedResult = serializer.Deserialize(serializedTarget); // Assert. deserializedResult.Should().NotBeNull(); deserializedResult.Maximum.Should().Be(target.Maximum); deserializedResult.Mean.Should().Be(target.Mean); deserializedResult.Median.Should().Be(target.Median); deserializedResult.Midrange.Should().Be(target.Midrange); deserializedResult.Minimum.Should().Be(target.Minimum); deserializedResult.Range.Should().Be(target.Range); deserializedResult.Size.Should().Be(target.Size); deserializedResult.StandardDeviation.Should().Be(target.StandardDeviation); deserializedResult.Sum.Should().Be(target.Sum); deserializedResult.Variance.Should().Be(target.Variance); }