public void PrivateSealedClassWithNoMembers() { var clone = BinarySerialisationCloner.Clone(new ClassWithNoMembersAndNoInheritance(), _referenceReuseStrategy); Assert.NotNull(clone); Assert.IsType <ClassWithNoMembersAndNoInheritance>(clone); }
private T AssertCloneMatchesOriginalAndReturnClone <T>(T value) { var clone = BinarySerialisationCloner.Clone(value, _referenceReuseStrategy); Assert.Equal(value, clone); return(clone); }
public static void FieldNotPresentInSerialisedDataExceptionCanBeSerialisedWithDanSerialiser() { var clone = BinarySerialisationCloner.Clone(new FieldNotPresentInSerialisedDataException("MyType", "MyField"), ReferenceReuseOptions.SupportReferenceReUseInMostlyTreeLikeStructure); Assert.IsType<FieldNotPresentInSerialisedDataException>(clone); Assert.Equal("MyType", clone.TypeName); Assert.Equal("MyField", clone.FieldName); }
private static T CloneAndSupportDynamicAssemblies <T>(T value, params Type[] dynamicTypes) { // SupportReferenceReUseInMostlyTreeLikeStructure seems to be the best general compromise so we'll use that here return(ResolveDynamicAssembliesWhilePerformingAction <T>( () => BinarySerialisationCloner.Clone(value, ReferenceReuseOptions.SupportReferenceReUseInMostlyTreeLikeStructure), dynamicTypes )); }
public static void AvoidLinkedListStackOverflow() { var value = PersistentList.Of(Enumerable.Range(0, 3000)); var typeConverters = new[] { PersistentListTypeConverter.Instance }; var clone = BinarySerialisationCloner.Clone(value, typeConverters, typeConverters, ReferenceReuseOptions.SupportReferenceReUseInMostlyTreeLikeStructure); Assert.Equal(value.ToArray(), clone.ToArray()); }
public void PrivateSealedClassWithSinglePublicReadonlyAutoProperty() { var clone = BinarySerialisationCloner.Clone(new ClassWithSinglePublicReadonlyAutoPropertyAndNoInheritance("abc"), _referenceReuseStrategy); Assert.NotNull(clone); Assert.IsType <ClassWithSinglePublicReadonlyAutoPropertyAndNoInheritance>(clone); Assert.Equal("abc", clone.Name); }
public void PropertyOnBaseClassThatIsOverriddenWithNewOnDerivedClass() { var source = new ManagerDetails(123, "abc"); var clone = BinarySerialisationCloner.Clone(new ManagerDetails(123, "abc"), _referenceReuseStrategy); Assert.IsType <ManagerDetails>(clone); Assert.Equal(123, clone.Id); Assert.Equal("abc", ((EmployeeDetails)clone).Name); }
public void NonSerializedPropertydNotSerialised() { var source = new SomethingWithNonSerialisableIdProperty { Id = 123 }; var clone = BinarySerialisationCloner.Clone(source, _referenceReuseStrategy); Assert.Equal(0, clone.Id); }
public void PropertyOnBaseClassThatIsOverriddenOnDerivedClass() { var source = new SupervisorDetails(123, "abc"); var clone = BinarySerialisationCloner.Clone(new SupervisorDetails(123, "abc"), _referenceReuseStrategy); Assert.IsType <SupervisorDetails>(clone); Assert.Equal(123, clone.Id); Assert.Equal("abc", clone.Name); }
public void PrivateStructWithSinglePublicAutoProperty() { var clone = BinarySerialisationCloner.Clone(new StructWithSinglePublicAutoProperty { Name = "abc" }, _referenceReuseStrategy); Assert.IsType <StructWithSinglePublicAutoProperty>(clone); Assert.Equal("abc", clone.Name); }
public void CircularReferenceSupported() { var source = new Node(); source.Child = source; var clone = BinarySerialisationCloner.Clone(source, _referenceReuseStrategy); Assert.Equal(clone, clone.Child); }
public void PrivateSealedClassWithSinglePublicField() { var clone = BinarySerialisationCloner.Clone(new ClassWithSinglePublicFieldAndNoInheritance { Name = "abc" }, _referenceReuseStrategy); Assert.NotNull(clone); Assert.IsType <ClassWithSinglePublicFieldAndNoInheritance>(clone); Assert.Equal("abc", clone.Name); }
public void PrivateSealedClassWithSinglePublicReadonlyAutoPropertyThatIsSerialisedToInterfaceThatIsExplicitlyImplemented() { var clone = BinarySerialisationCloner.Clone <IHaveName>( new ClassWithSinglePublicAutoPropertyToExplicitlyImplementAnInterfaceButNoInheritance { Name = "abc" }, _referenceReuseStrategy ); Assert.NotNull(clone); Assert.IsType <ClassWithSinglePublicAutoPropertyToExplicitlyImplementAnInterfaceButNoInheritance>(clone); Assert.Equal("abc", clone.Name); }
public void PrivateSealedClassWithSinglePublicReadonlyAutoPropertyThatIsSerialisedToAbstractClass() { var clone = BinarySerialisationCloner.Clone <NamedItem>( new ClassWithOwnPublicAutoPropertyAndPublicAutoPropertyInheritedFromAnAbstractClassButNoOtherInheritance { Name = "abc", OtherProperty = "xyz" }, _referenceReuseStrategy ); Assert.NotNull(clone); Assert.IsType <ClassWithOwnPublicAutoPropertyAndPublicAutoPropertyInheritedFromAnAbstractClassButNoOtherInheritance>(clone); Assert.Equal("abc", clone.Name); Assert.Equal("xyz", ((ClassWithOwnPublicAutoPropertyAndPublicAutoPropertyInheritedFromAnAbstractClassButNoOtherInheritance)clone).OtherProperty); }
public static void CanSerialiseTypeWithDictionaryIfUseSpecialisationsMayBeIgnoredWhenSerialisingAndDefaultEqualityComparerFastSerialisationTypeConverter() { var value = new SomethingWithDictionary(); value.Set(1, "One"); var clone = BinarySerialisationCloner.Clone( value, new[] { DefaultEqualityComparerFastSerialisationTypeConverter.Instance }, new IDeserialisationTypeConverter[0], ReferenceReuseOptions.SpeedyButLimited ); Assert.Equal("One", clone.TryToGet(1)); }
public static void PointPropertyMayBeSerialisedAsArray() { var value = new { Location = new Point { X = 10, Y = 20 } }; var serialisationTypeConverter = new PointToArrayTypeConverter(); var deserialisationTypeConverter = new ArrayToPointTypeConverter(); var clone = BinarySerialisationCloner.Clone(value, new[] { serialisationTypeConverter }, new[] { deserialisationTypeConverter }, ReferenceReuseOptions.SupportReferenceReUseInMostlyTreeLikeStructure); Assert.Equal(value, clone); Assert.Equal(1, serialisationTypeConverter.NumberOfValuesChanged); // Should have changed one Point into an array Assert.Equal(3, serialisationTypeConverter.NumberOfValuesNotChanged); // Should have encountered one instance of an anonymous type and X and Y values that weren't changed for serialisation Assert.Equal(1, deserialisationTypeConverter.NumberOfValuesChanged); // Should have changed one array into a Point Assert.Equal(3, deserialisationTypeConverter.NumberOfValuesNotChanged); // Should have encountered one instance of an anonymous type and X and Y values that weren't changed for deserialisation }
public void MemberSetterCacheTargetsMostSpecificTypeForArrayElementsWhereMostSpecificTypeIsEligibleForOptimisedMemberSetter() { var source = new EmptyThingBase[] { new ThingWithWrappedStringName(new WrappedString("abc")), new ThingWithWrappedStringName(new WrappedString("xyz")) }; var clone = BinarySerialisationCloner.Clone(source, _referenceReuseStrategy); Assert.NotNull(clone); Assert.Equal(2, clone.Length); Assert.IsType <ThingWithWrappedStringName>(clone[0]); Assert.Equal("abc", ((ThingWithWrappedStringName)clone[0]).Name?.Value); Assert.IsType <ThingWithWrappedStringName>(clone[1]); Assert.Equal("xyz", ((ThingWithWrappedStringName)clone[1]).Name?.Value); }
public void CircularReferencesAreSupportedWhereTheSameTypeIsEncounteredMultipleTimes() { var source = new List <Node>(); var node = new Node(); node.Child = node; source.Add(node); node = new Node(); node.Child = node; source.Add(node); var clone = BinarySerialisationCloner.Clone(source, _referenceReuseStrategy); Assert.Equal(2, clone.Count); Assert.Equal(clone[0], clone[0].Child); Assert.Equal(clone[1], clone[1].Child); }
public void WideArrayCircularReferencesDoNotThrow() { var categories = Enumerable.Range(0, 1000).Select(i => new Category { Key = 100000 + i }).ToDictionary(c => c.Key, c => c); var categoryGroups = Enumerable.Range(0, 1000).Select(i => new CategoryGroup { Key = 900000 + i, Categories = categories }).ToDictionary(g => g.Key, g => g); foreach (var category in categories.Values) { category.Groups = categoryGroups; } BinarySerialisationCloner.Clone(categories, _referenceReuseStrategy); Assert.True(true); }
public static void CircularReferenceExceptionCanBeSerialisedWithDanSerialiser() { Assert.IsType<CircularReferenceException>(BinarySerialisationCloner.Clone(new CircularReferenceException(), ReferenceReuseOptions.SupportReferenceReUseInMostlyTreeLikeStructure)); }
public void PrivateStructWithNoMembers() { var clone = BinarySerialisationCloner.Clone(new StructWithNoMembers(), _referenceReuseStrategy); Assert.IsType <StructWithNoMembers>(clone); }
public void NullPrivateSealedClassWithNoMembers() { var clone = BinarySerialisationCloner.Clone((ClassWithNoMembersAndNoInheritance)null, _referenceReuseStrategy); Assert.Null(clone); }