public void PrivateSealedClassWithNoMembers()
        {
            var clone = BinarySerialisationCloner.Clone(new ClassWithNoMembersAndNoInheritance(), _referenceReuseStrategy);

            Assert.NotNull(clone);
            Assert.IsType <ClassWithNoMembersAndNoInheritance>(clone);
        }
        public void PrivateSealedClassWithSinglePublicReadonlyAutoProperty()
        {
            var clone = BinarySerialisationCloner.Clone(new ClassWithSinglePublicReadonlyAutoPropertyAndNoInheritance("abc"), _referenceReuseStrategy);

            Assert.NotNull(clone);
            Assert.IsType <ClassWithSinglePublicReadonlyAutoPropertyAndNoInheritance>(clone);
            Assert.Equal("abc", clone.Name);
        }
 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 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);
        }
Exemplo n.º 6
0
        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 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 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 NullPrivateSealedClassWithNoMembers()
        {
            var clone = BinarySerialisationCloner.Clone((ClassWithNoMembersAndNoInheritance)null, _referenceReuseStrategy);

            Assert.Null(clone);
        }