public void CanCopyImmutableThrows(ReferenceHandling?referenceHandling) { var expected = "Cannot copy the members of an immutable object"; var exception = referenceHandling != null ? Assert.Throws <NotSupportedException>(() => this.VerifyMethod <Immutable>(referenceHandling.Value)) : Assert.Throws <NotSupportedException>(this.VerifyMethod <Immutable>); Assert.AreEqual(expected, exception.Message); }
public void CanCopyEnumerableOfIntsThrows(ReferenceHandling?referenceHandling) { var expected = "Can only copy the members of collections implementing IList or IDictionary"; var exception = referenceHandling != null ? Assert.Throws <NotSupportedException>(() => this.VerifyMethod <IEnumerable <int> >(referenceHandling.Value)) : Assert.Throws <NotSupportedException>(this.VerifyMethod <IEnumerable <int> >); Assert.AreEqual(expected, exception.Message); }
public void CanCopyImmutable(ReferenceHandling?referenceHandling) { var expected = "Cannot copy the members of an immutable object"; var x = new Immutable(1); var y = new Immutable(1); var exception = referenceHandling != null ? Assert.Throws <NotSupportedException>(() => this.CopyMethod(x, y, referenceHandling.Value)) : Assert.Throws <NotSupportedException>(() => this.CopyMethod(x, y)); Assert.AreEqual(expected, exception.Message); }
public void CanCopyListOfComplexTypeThrows(ReferenceHandling?referenceHandling) { if (referenceHandling != null) { Assert.Throws <NotSupportedException>(() => this.VerifyMethod <List <ComplexType> >(referenceHandling.Value)); } else { Assert.Throws <NotSupportedException>(this.VerifyMethod <List <ComplexType> >); } }
public void CanCopyEnumerableOfIntsThrows(ReferenceHandling?referenceHandling) { var expected = "Can only copy the members of collections implementing IList or IDictionary"; var x = Enumerable.Repeat(1, 2); var y = Enumerable.Repeat(1, 2); var exception = referenceHandling != null ? Assert.Throws <NotSupportedException>(() => this.CopyMethod(x, y, referenceHandling.Value)) : Assert.Throws <NotSupportedException>(() => this.CopyMethod(x, y)); Assert.AreEqual(expected, exception.Message); }
public void WithReadonlyIntHappyPath(int xv, int yv, ReferenceHandling?referenceHandling, bool expected) { var x = new WithReadonlyProperty <int>(xv); var y = new WithReadonlyProperty <int>(yv); if (referenceHandling == null) { var result = this.EqualMethod(x, y); Assert.AreEqual(expected, result); } else { var result = this.EqualMethod(x, y, referenceHandling.Value); Assert.AreEqual(expected, result); } }
public void WithComplexThrows(ReferenceHandling?referenceHandling) { var expected = this is FieldValues.Throws ? "Copy.FieldValues(x, y) failed.\r\n" + "The field WithComplexProperty.<ComplexType>k__BackingField of type ComplexType is not supported.\r\n" + "Solve the problem by any of:\r\n" + "* Make ComplexType immutable or use an immutable type.\r\n" + " - For immutable types the following must hold:\r\n" + " - Must be a sealed class or a struct.\r\n" + " - All fields and properties must be readonly.\r\n" + " - All field and property types must be immutable.\r\n" + " - All indexers must be readonly.\r\n" + " - Event fields are ignored.\r\n" + "* Use FieldsSettings and specify how copying is performed:\r\n" + " - ReferenceHandling.Structural means that a the entire graph is traversed and immutable property values are copied.\r\n" + " - For structural Activator.CreateInstance is used to create instances so a parameterless constructor may be needed, can be private.\r\n" + " - ReferenceHandling.References means that references are copied.\r\n" + " - Exclude a combination of the following:\r\n" + " - The field WithComplexProperty.<ComplexType>k__BackingField.\r\n" + " - The type ComplexType.\r\n" : "Copy.PropertyValues(x, y) failed.\r\n" + "The property WithComplexProperty.ComplexType of type ComplexType is not supported.\r\n" + "Solve the problem by any of:\r\n" + "* Make ComplexType immutable or use an immutable type.\r\n" + " - For immutable types the following must hold:\r\n" + " - Must be a sealed class or a struct.\r\n" + " - All fields and properties must be readonly.\r\n" + " - All field and property types must be immutable.\r\n" + " - All indexers must be readonly.\r\n" + " - Event fields are ignored.\r\n" + "* Use PropertiesSettings and specify how copying is performed:\r\n" + " - ReferenceHandling.Structural means that a the entire graph is traversed and immutable property values are copied.\r\n" + " - For structural Activator.CreateInstance is used to create instances so a parameterless constructor may be needed, can be private.\r\n" + " - ReferenceHandling.References means that references are copied.\r\n" + " - Exclude a combination of the following:\r\n" + " - The property WithComplexProperty.ComplexType.\r\n" + " - The type ComplexType.\r\n"; var source = new WithComplexProperty(); var target = new WithComplexProperty(); var exception = referenceHandling == null ? Assert.Throws <NotSupportedException>(() => this.CopyMethod(source, target)) : Assert.Throws <NotSupportedException>(() => this.CopyMethod(source, target, referenceHandling.Value)); Assert.AreEqual(expected, exception.Message); }
public void WithImmutableStructural(ReferenceHandling?referenceHandling) { var source = new With <Immutable>(new Immutable(1)); var target = new With <Immutable>(new Immutable(2)); if (referenceHandling == null) { this.CopyMethod(source, target); } else { this.CopyMethod(source, target, referenceHandling.Value); } Assert.AreEqual(1, source.Value.Value); Assert.AreEqual(1, target.Value.Value); Assert.AreSame(source.Value, target.Value); }
public void IgnoresMember(int xv, int yv, ReferenceHandling?referenceHandling, bool expected) { var x = new WithSimpleProperties(xv, null, "3", StringSplitOptions.RemoveEmptyEntries); var y = new WithSimpleProperties(yv, 2, "3", StringSplitOptions.RemoveEmptyEntries); var excluded = this is FieldValues.Classes ? "nullableIntValue" : nameof(WithSimpleProperties.NullableIntValue); if (referenceHandling == null) { var result = this.EqualMethod(x, y, excludedMembers: excluded); Assert.AreEqual(expected, result); } else { var result = this.EqualMethod(x, y, referenceHandling.Value, excluded); Assert.AreEqual(expected, result); } }
public void WithReadonlyIntHappyPath(int xv, int yv, ReferenceHandling?referenceHandling, string expected) { expected = expected?.Replace( "<member>", this is FieldValues.Classes ? "<Value>k__BackingField" : "Value"); var x = new WithReadonlyProperty <int>(xv); var y = new WithReadonlyProperty <int>(yv); if (referenceHandling == null) { var result = this.DiffMethod(x, y); Assert.AreEqual(expected, result.ToString(string.Empty, " ")); } else { var result = this.DiffMethod(x, y, referenceHandling.Value); Assert.AreEqual(expected, result.ToString(string.Empty, " ")); } }