Exemplo n.º 1
0
        public void DeserializationWhenBusinessTransactionTypeDoesNotExist()
        {
            var property        = Guid.NewGuid().ToString();
            var anotherProperty = Guid.NewGuid().ToString();
            var transactionId   = Guid.NewGuid();
            var json            = $@"{{
	""property"": ""{property}"",
	""businessTransaction"": {{
		""doesNotExist"": {JsonSerializer.Serialize(new TestBusinessTransaction {TransactionId = transactionId, Version = 1})}
	}},
    ""anotherProperty"": ""{anotherProperty}""
}}";

            var command = JsonSerializer.Deserialize <TestCommand>(json,
                                                                   TransactoSerializerOptions.BusinessTransactions(typeof(TestBusinessTransaction)));

            Assert.Equal(property, command.Property);
            Assert.Equal(anotherProperty, command.AnotherProperty);

            Assert.Null(command.BusinessTransaction);
        }
Exemplo n.º 2
0
        public void Serialization()
        {
            var sut = TransactoSerializerOptions.BusinessTransactions(typeof(TestBusinessTransaction));

            var testBusinessTransaction = new TestBusinessTransaction {
                Version       = 1,
                TransactionId = Guid.NewGuid()
            };
            var dto = new TestCommand {
                Property            = Guid.NewGuid().ToString(),
                AnotherProperty     = Guid.NewGuid().ToString(),
                BusinessTransaction = testBusinessTransaction
            };

            var copy = JsonSerializer.Deserialize <TestCommand>(JsonSerializer.Serialize(dto, sut), sut);

            Assert.Equal(dto.Property, copy.Property);
            Assert.Equal(dto.AnotherProperty, copy.AnotherProperty);
            var transaction = Assert.IsType <TestBusinessTransaction>(dto.BusinessTransaction);

            Assert.Equal(testBusinessTransaction.TransactionId, transaction.TransactionId);
        }