public void ShouldFailBecauseCollectionsAreNotAssigned(bool b1, bool b2) { var nested1 = new NestedTestClass(); nested1.Int = nested1.Int.WithValue(101); var nested2 = new NestedTestClass(); nested2.Int = nested2.Int.WithValue(101); var second1 = new SecondNestedTestClass(); second1.Int = second1.Int.WithValue(201); var second2 = new SecondNestedTestClass(); second2.Int = second2.Int.WithValue(201); var second3 = new SecondNestedTestClass(); second3.Int = second3.Int.WithValue(201); var second4 = new SecondNestedTestClass(); second4.Int = second4.Int.WithValue(201); nested1.SecondNestedTestClass = nested1.SecondNestedTestClass.WithValue(second1); if (b1) { nested1.SecondNestedCollection = nested1.SecondNestedCollection.WithValue(new[] { second2 }); } nested2.SecondNestedTestClass = nested2.SecondNestedTestClass.WithValue(second3); if (b2) { nested2.SecondNestedCollection = nested2.SecondNestedCollection.WithValue(new[] { second4 }); } var sut = new TestClass(); sut.NestedTestClass = sut.NestedTestClass.WithValue(nested1); if (b2) { sut.NestedTestCollection = sut.NestedTestCollection.WithValue(new[] { nested2 }); } var result = Model.Verify(sut); var failures = result.AssertFailure(); var paths = failures.Select(f => f.Path.ToString()); if (!b1) { paths.Should().Contain($"{nameof(TestClass.NestedTestClass)}.{nameof(NestedTestClass.SecondNestedCollection)}"); } if (!b2) { paths.Should().Contain($"{nameof(TestClass.NestedTestCollection)}"); } }
public void NestedElements() { var context = new ObjectQueryContext(typeof(NestedTestClass)); var test = new NestedTestClass { Attribute = new AttributeTestClass(), OmitIfNullAttribute = new OmitIfNullAttributeTestClass(), NamedAttribute = new NamedAttributeTestClass(), PrefixedAttribute = new PrefixedAttributeTestClass(), PrefixedNestedAttribute = new AttributeTestClass(), PrefixedNestedPrefixedAttribute = new PrefixedAttributeTestClass() }; Assert.IsTrue(context.PropertyExists("Attribute", test)); Assert.IsTrue(context.PropertyExists("Attribute@Foo", test)); Assert.IsTrue(context.PropertyExists("OmitIfNullAttribute", test)); Assert.IsFalse(context.PropertyExists("OmitIfNullAttribute@Foo", test)); Assert.IsTrue(context.PropertyExists("NamedAttribute", test)); Assert.IsTrue(context.PropertyExists("NamedAttribute@foo", test)); Assert.IsTrue(context.PropertyExists("PrefixedAttribute", test)); Assert.IsTrue(context.PropertyExists("PrefixedAttribute@bar:foo", test)); Assert.IsTrue(context.PropertyExists("bar:prefixedNestedAttribute", test)); Assert.IsTrue(context.PropertyExists("bar:prefixedNestedAttribute@Foo", test)); Assert.IsTrue(context.PropertyExists("bar:prefixedNestedPrefixedAttribute", test)); Assert.IsTrue(context.PropertyExists("bar:prefixedNestedPrefixedAttribute@bar:foo", test)); test.OmitIfNullAttribute.Foo = "bar"; Assert.IsTrue(context.PropertyExists("OmitIfNullAttribute@Foo", test)); var equality = false; context.VisitProperty("OmitIfNullAttribute@Foo", test, value => equality = value.Equals("bar")); Assert.IsTrue(equality); }
public void ShouldFailBecauseNestedClassNotValid(int value1, int value2) { var nested1 = new NestedTestClass(); nested1.Int = nested1.Int.WithValue(value1); var nested2 = new NestedTestClass(); nested2.Int = nested2.Int.WithValue(value2); var second1 = new SecondNestedTestClass(); second1.Int = second1.Int.WithValue(201); var second2 = new SecondNestedTestClass(); second2.Int = second2.Int.WithValue(201); var second3 = new SecondNestedTestClass(); second3.Int = second3.Int.WithValue(201); var second4 = new SecondNestedTestClass(); second4.Int = second4.Int.WithValue(201); nested1.SecondNestedTestClass = nested1.SecondNestedTestClass.WithValue(second1); nested1.SecondNestedCollection = nested1.SecondNestedCollection.WithValue(new[] { second2 }); nested2.SecondNestedTestClass = nested2.SecondNestedTestClass.WithValue(second3); nested2.SecondNestedCollection = nested2.SecondNestedCollection.WithValue(new[] { second4 }); var sut = new TestClass(); sut.NestedTestClass = sut.NestedTestClass.WithValue(nested1); sut.NestedTestCollection = sut.NestedTestCollection.WithValue(new[] { nested2 }); var result = Model.Verify(sut); var failures = result.AssertFailure(); var paths = failures.Select(f => f.Path.ToString()); if (value1 < 101) { paths.Should().Contain($"{nameof(TestClass.NestedTestClass)}.{nameof(SecondNestedTestClass.Int)}"); } if (value2 < 101) { paths.Should().Contain($"{nameof(TestClass.NestedTestCollection)}[0].{nameof(SecondNestedTestClass.Int)}"); } }
public void Component_SerializeBiggerObjectAndReadSmaller_NoError() { //Arrange NestedTestClass toSerialize = _fixture.Create <NestedTestClass>(); //Act var result = AvroConvert.Serialize(toSerialize); var deserialized = AvroConvert.Deserialize <SmallerNestedTestClass>(result); //Assert Assert.NotNull(result); Assert.NotNull(deserialized); Assert.Equal(toSerialize.justSomeProperty, deserialized.justSomeProperty); }
public void Component_SerializeAndDeserializeClassesWithDifferentPropertyCases_NoError() { //Arrange NestedTestClass toSerialize = _fixture.Create <NestedTestClass>(); //Act var result = AvroConvert.Serialize(toSerialize); var deserialized = AvroConvert.Deserialize <DifferentCaseNestedTestClass>(result); //Assert Assert.NotNull(result); Assert.NotNull(deserialized); Assert.Equal(toSerialize.justSomeProperty, deserialized.JustSomeProperty); Assert.Equal(toSerialize.andLongProperty, deserialized.AndLongProperty); }
public void ShouldSucceedBecauseEverythingIsValid() { var nested1 = new NestedTestClass(); nested1.Int = nested1.Int.WithValue(101); var nested2 = new NestedTestClass(); nested2.Int = nested2.Int.WithValue(101); var second1 = new SecondNestedTestClass(); second1.Int = second1.Int.WithValue(201); var second2 = new SecondNestedTestClass(); second2.Int = second2.Int.WithValue(201); var second3 = new SecondNestedTestClass(); second3.Int = second3.Int.WithValue(201); var second4 = new SecondNestedTestClass(); second4.Int = second4.Int.WithValue(201); nested1.SecondNestedTestClass = nested1.SecondNestedTestClass.WithValue(second1); nested1.SecondNestedCollection = nested1.SecondNestedCollection.WithValue(new[] { second2 }); nested2.SecondNestedTestClass = nested2.SecondNestedTestClass.WithValue(second3); nested2.SecondNestedCollection = nested2.SecondNestedCollection.WithValue(new[] { second4 }); var sut = new TestClass(); sut.NestedTestClass = sut.NestedTestClass.WithValue(nested1); sut.NestedTestCollection = sut.NestedTestCollection.WithValue(new[] { nested2 }); var result = Model.Verify(sut); result.AssertSuccess(); }
private void MulticodecRoundTripNested(ICodec codec) { var test = new NestedTestClass { HelloOther = new TestClass { HelloString = "Hello World", HelloInt = int.MaxValue, HelloBool = true } }; NestedTestClass result; using (var stream = new MemoryStream()) { codec.Encoder(stream).Encode(test); stream.Seek(0, SeekOrigin.Begin); result = codec.Decoder(stream).Decode <NestedTestClass>(); } Assert.Equal(result, test); }
private async Task MulticodecRoundTripNestedAsync(ICodec codec) { var test = new NestedTestClass { HelloOther = new TestClass { HelloString = "Hello World", HelloInt = int.MaxValue, HelloBool = true } }; NestedTestClass result; using (var stream = new MemoryStream()) { await codec.Encoder(stream).EncodeAsync(test, CancellationToken.None); stream.Seek(0, SeekOrigin.Begin); result = await codec.Decoder(stream).DecodeAsync <NestedTestClass>(CancellationToken.None); } Assert.Equal(result, test); }
public void ItGeneratesNestedCorrectPatchDocument() { var original = new NestedTestClass { Id = "id", Message = "message", DecimalValue = 1.43m, GuidValue = Guid.Empty, IntList = new List <int>() { 1, 2, 3 }, NestedClass = new NestedClass { NestedId = "nested-id", NestedIntValue = 465 }, NestedClassList = new List <NestedClass> { new NestedClass { NestedId = "1", NestedIntValue = 1 }, new NestedClass { NestedId = "2", NestedIntValue = 2 }, new NestedClass { NestedId = "3", NestedIntValue = 3 } } }; var modified = new NestedTestClass { Id = "new-id", Message = "new-message", DecimalValue = 1.40m, GuidValue = Guid.Parse("64362fd9-a24a-4b4b-97cd-8ba9df24a1b5"), IntList = new List <int>() { 1, 2, 3, 4 }, NestedClass = new NestedClass { NestedId = "new-nested-id", NestedIntValue = 465 }, NestedClassList = new List <NestedClass> { new NestedClass { NestedId = "1", NestedIntValue = 1 }, new NestedClass { NestedId = "2", NestedIntValue = 2 }, new NestedClass { NestedId = "345", NestedIntValue = 345 } } }; var generator = new JsonPatchDocumentGenerator(); var patch = generator.Generate(original, modified); // Modify original with patch. patch.ApplyTo(original); Assert.NotNull(patch); Assert.Equal(7, patch.Operations.Count); Assert.All(patch.Operations, op => Assert.Equal(OperationType.Replace, op.OperationType)); Assert.Contains(patch.Operations, op => op.path.Equals("/NestedClass/NestedId")); Assert.Equal(original, modified, new GenericDeepEqualityComparer <NestedTestClass>()); }
public void NestedElements () { var context = new ObjectQueryContext (typeof (NestedTestClass)); var test = new NestedTestClass { Attribute = new AttributeTestClass (), OmitIfNullAttribute = new OmitIfNullAttributeTestClass (), NamedAttribute = new NamedAttributeTestClass (), PrefixedAttribute = new PrefixedAttributeTestClass (), PrefixedNestedAttribute = new AttributeTestClass (), PrefixedNestedPrefixedAttribute = new PrefixedAttributeTestClass () }; Assert.IsTrue (context.PropertyExists ("Attribute", test)); Assert.IsTrue (context.PropertyExists ("Attribute@Foo", test)); Assert.IsTrue (context.PropertyExists ("OmitIfNullAttribute", test)); Assert.IsFalse (context.PropertyExists ("OmitIfNullAttribute@Foo", test)); Assert.IsTrue (context.PropertyExists ("NamedAttribute", test)); Assert.IsTrue (context.PropertyExists ("NamedAttribute@foo", test)); Assert.IsTrue (context.PropertyExists ("PrefixedAttribute", test)); Assert.IsTrue (context.PropertyExists ("PrefixedAttribute@bar:foo", test)); Assert.IsTrue (context.PropertyExists ("bar:prefixedNestedAttribute", test)); Assert.IsTrue (context.PropertyExists ("bar:prefixedNestedAttribute@Foo", test)); Assert.IsTrue (context.PropertyExists ("bar:prefixedNestedPrefixedAttribute", test)); Assert.IsTrue (context.PropertyExists ("bar:prefixedNestedPrefixedAttribute@bar:foo", test)); test.OmitIfNullAttribute.Foo = "bar"; Assert.IsTrue (context.PropertyExists ("OmitIfNullAttribute@Foo", test)); var equality = false; context.VisitProperty ("OmitIfNullAttribute@Foo", test, value => equality = value.Equals ("bar")); Assert.IsTrue (equality); }
public TestData() { Counter = 0; Data = new NestedTestClass { Name = "bla", Value = 42.3f }; }
internal static TestClass Build(int testStructNestedTestClassPrivateIntValue, NestedTestClass protectedNestedTestClass) => new(RandomUtil.Randomizer.NextBool(), protectedNestedTestClass)