public void GivenEnumerableAsString_Set_SetsValueOnTargetObjectsProperIndex() { var targetObject = new TestTypeParent() { Tag57s = new string[3] }; var uut = new CompositePropertySetter(); var firstValueToSet = "12357"; var secondValueToSet = "12358"; var mappingDetails = new TagMapLeaf(targetObject.GetType().GetProperty(nameof(targetObject.Tag57s)), new StringSetter()) { IsEnumerable = true, RepeatingTagNumber = 56, InnerType = typeof(string), }; var messageContext = new FixMessageContext(); // Setting the 1st element uut.Set(firstValueToSet.AsSpan(), mappingDetails, messageContext, targetObject); // Setting the 2nd element uut.Set(secondValueToSet.AsSpan(), mappingDetails, messageContext, targetObject); Assert.Equal(firstValueToSet, targetObject.Tag57s.First()); Assert.Equal(secondValueToSet, targetObject.Tag57s.Skip(1).First()); }
public void GivenEnumeratedParents_SetTwice_ReturnsSecondElement() { var targetObject = new TestTypeParent() { Tag59s = new TestMany[3] }; var uut = new CompositePropertySetter(); var valueToSet = new byte[1].AsSpan(); var mappingDetails = new TagMapLeaf(typeof(TestMany).GetProperty("Tag60"), new MockPropertySetter()) { Parents = new List <TagMapParent> { new TagMapParent(targetObject.GetType().GetProperty(nameof(targetObject.Tag59s)), new ParentPropertySetter()) { IsEnumerable = true, InnerType = typeof(TestMany), } } }; var messageContext = new FixMessageContext(); uut.Set(valueToSet, mappingDetails, messageContext, targetObject); var result = uut.Set(valueToSet, mappingDetails, messageContext, targetObject); Assert.NotNull(targetObject.Tag59s.First()); Assert.Equal(result, targetObject.Tag59s.Skip(1).First()); }
public static void TestTypeSize() { GC.Collect(); var sizeBase = GC.GetAllocatedBytesForCurrentThread(); var testType = new TestTypeParent(); var newSize = GC.GetAllocatedBytesForCurrentThread(); Console.WriteLine($"{testType.GetType().Name}: {newSize - sizeBase}"); }
public void GivenFalseValues_Set_SetsParsedValue(string value) { var targetObject = new TestTypeParent(); var uut = new NullableBooleanSetter(); var mappingDetails = new TagMapLeaf(targetObject.GetType().GetProperty(nameof(targetObject.Tag69)), uut); var messageContext = new FixMessageContext(); uut.Set(value, mappingDetails, messageContext, targetObject); Assert.False(targetObject.Tag69); }
public void GivenNullableDateTimeOffsetAsString_Set_SetsValueOnTargetObject() { var targetObject = new TestTypeParent(); var uut = new CompositePropertySetter(); var valueToSet = "20181219-18:14:23"; var mappingDetails = new TagMapLeaf(targetObject.GetType().GetProperty(nameof(targetObject.Tag71)), new NullableDateTimeOffsetSetter()); var messageContext = new FixMessageContext(); uut.Set(valueToSet.AsSpan(), mappingDetails, messageContext, targetObject); Assert.Equal(new DateTimeOffset(2018, 12, 19, 18, 14, 23, 0, TimeSpan.Zero), targetObject.Tag71.Value); }
public void GivenBoolAsString_Set_SetsValueOnTargetObject() { var targetObject = new TestTypeParent(); var uut = new CompositePropertySetter(); var valueToSet = "Y"; var mappingDetails = new TagMapLeaf(targetObject.GetType().GetProperty(nameof(targetObject.Tag68)), new BooleanSetter()); var messageContext = new FixMessageContext(); uut.Set(valueToSet.AsSpan(), mappingDetails, messageContext, targetObject); Assert.True(targetObject.Tag68); }
public void GivenNullableBool_Set_SetsValueOnTargetObject() { var targetObject = new TestTypeParent(); var uut = new CompositePropertySetter(); var valueToSet = Encoding.ASCII.GetBytes("Y").AsSpan(); var mappingDetails = new TagMapLeaf(targetObject.GetType().GetProperty(nameof(targetObject.Tag69)), new NullableBooleanSetter()); var messageContext = new FixMessageContext(); uut.Set(valueToSet, mappingDetails, messageContext, targetObject); Assert.True(targetObject.Tag69); Assert.False(targetObject.Tag68); }
public void GivenNullableIntegerAsString_Set_SetsValueOnTargetObject() { var targetObject = new TestTypeParent(); var uut = new CompositePropertySetter(); ReadOnlySpan <char> valueToSet = "12357".AsSpan(); var mappingDetails = new TagMapLeaf(targetObject.GetType().GetProperty(nameof(targetObject.Tag63)), new IntegerSetter()); var messageContext = new FixMessageContext(); uut.Set(valueToSet, mappingDetails, messageContext, targetObject); Assert.Equal(12357, targetObject.Tag63); }
public void GivenNullable_Set_SetsValueOnTargetObject() { var targetObject = new TestTypeParent(); var uut = new CompositePropertySetter(); var valueToSet = Encoding.ASCII.GetBytes("12357").AsSpan(); var mappingDetails = new TagMapLeaf(targetObject.GetType().GetProperty(nameof(targetObject.Tag63)), new IntegerSetter()); var messageContext = new FixMessageContext(); uut.Set(valueToSet, mappingDetails, messageContext, targetObject); Assert.Equal(12357, targetObject.Tag63); }
public void GivenIEnumerablePrimitive_SetAsString_CreatesArryOfPrimitive() { var targetObject = new TestTypeParent(); var uut = new RepeatingGroupTagSetter(); var valueToSet = "3".AsSpan(); PropertyInfo propertyInfo = targetObject.GetType().GetProperty(nameof(targetObject.Tag57s)); var mappingDetails = TagMapLeaf.CreateRepeatingTag(propertyInfo, propertyInfo.PropertyType.GetGenericArguments()[0], uut); var messageContext = new FixMessageContext(); var result = uut.Set(valueToSet, mappingDetails, messageContext, targetObject); Assert.NotNull(targetObject.Tag57s); Assert.Equal(3, targetObject.Tag57s.Count()); }
public void GivenIEnumerableT_Set_CreatesArryOfT() { var targetObject = new TestTypeParent(); var uut = new RepeatingGroupTagSetter(); var valueToSet = new byte[2]; IntegerToFixConverter.Instance.Convert(15, valueToSet, 2); PropertyInfo propertyInfo = targetObject.GetType().GetProperty(nameof(targetObject.Tag59s)); var mappingDetails = TagMapLeaf.CreateRepeatingTag(propertyInfo, propertyInfo.PropertyType.GetGenericArguments()[0], uut); var messageContext = new FixMessageContext(); var result = uut.Set(valueToSet, mappingDetails, messageContext, targetObject); Assert.NotNull(targetObject.Tag59s); Assert.Equal(15, targetObject.Tag59s.Count()); }
public void GivenString_Set_SetsValueOnTargetObject() { var targetObject = new TestTypeParent(); var uut = new TypeConvertedSetter(); var valueToSet = "12358"; var property = targetObject.GetType().GetProperty(nameof(targetObject.Tag61)); var typeConverter = property.GetCustomAttribute <TypeConverterAttribute>(); var mappingDetails = new TagMapLeaf(property, uut) { TypeConverterName = typeConverter.ConverterTypeName }; var messageContext = new FixMessageContext(); uut.Set(valueToSet.AsSpan(), mappingDetails, messageContext, targetObject); Assert.Equal(12358, targetObject.Tag61.Value); }
public void GivenParentsAsString_Set_CreatesParentTypes() { var targetObject = new TestTypeParent(); var uut = new CompositePropertySetter(); var valueToSet = "test"; var mappingDetails = new TagMapLeaf(MockPropertyInfo.Get, new MockPropertySetter()) { Parents = new List <TagMapParent> { new TagMapParent(targetObject.GetType().GetProperty(nameof(targetObject.CustomType)), new ParentPropertySetter()) } }; var messageContext = new FixMessageContext(); var result = uut.Set(valueToSet.AsSpan(), mappingDetails, messageContext, targetObject); Assert.NotNull(targetObject.CustomType); Assert.Equal(result, targetObject.CustomType); }
public void GivenEnumerableValue_Set_SetsValueOnTargetObjectsProperIndex() { var targetObject = new TestTypeParent() { Tag57s = new string[3] }; var uut = new CompositePropertySetter(); var valueToSet = Encoding.ASCII.GetBytes("12357").AsSpan(); var mappingDetails = new TagMapLeaf(targetObject.GetType().GetProperty(nameof(targetObject.Tag57s)), new StringSetter()) { IsEnumerable = true, RepeatingTagNumber = 56, InnerType = typeof(string), }; var messageContext = new FixMessageContext(); uut.Set(valueToSet, mappingDetails, messageContext, targetObject); Assert.Equal("12357", targetObject.Tag57s.First()); }
public void GivenCachedSettersIEnumerablePrimitive_Set_DoesNotSetAgain() { var targetObject = new TestTypeParent(); var uut = new RepeatingGroupTagSetter(); var valueToSet = new byte[2]; IntegerToFixConverter.Instance.Convert(15, valueToSet, 2); PropertyInfo propertyInfo = targetObject.GetType().GetProperty(nameof(targetObject.Tag57s)); var mappingDetails = TagMapLeaf.CreateRepeatingTag(propertyInfo, propertyInfo.PropertyType.GetGenericArguments()[0], uut); var messageContext = new FixMessageContext(); uut.Set(valueToSet, mappingDetails, messageContext, targetObject); // Try to set a different value IntegerToFixConverter.Instance.Convert(16, valueToSet, 2); var result = uut.Set(valueToSet, mappingDetails, messageContext, targetObject); Assert.NotNull(targetObject.Tag57s); Assert.Equal(15, targetObject.Tag57s.Count()); }
public void GivenTpyeConverterOnEnumerable_Set_SetsValueOnTargetObject() { // Expect the array available for the Tag65 var targetObject = new TestTypeParent() { Tag65s = new TestConvertable[3] }; var uut = new TypeConvertedSetter(); var valueToSet = Encoding.ASCII.GetBytes("12358").AsSpan(); var property = targetObject.GetType().GetProperty(nameof(targetObject.Tag65s)); var typeConverter = property.GetCustomAttribute <TypeConverterAttribute>(); var mappingDetails = new TagMapLeaf(property, uut) { IsEnumerable = true, TypeConverterName = typeConverter.ConverterTypeName }; var messageContext = new FixMessageContext(); uut.Set(valueToSet, mappingDetails, messageContext, targetObject); Assert.Equal(12358, targetObject.Tag65s.First().Value); }