public void ShallowCloneToStructArrayOfDifferingLengthsWillNotWork() { var source = new CloneTestStruct[2]; var destination = new CloneTestStruct[3]; Assert.Throws <InvalidOperationException>(() => Cloneable <CloneTestStruct[]> .ShallowCloneTo(source, destination)); }
public void CloneJaggedStructArray() { var source = new CloneTestStruct[][] { new CloneTestStruct[] { new CloneTestStruct { FirstName = "John", LastName = "Doe" }, new CloneTestStruct { FirstName = "Jane", LastName = "Smith" } } }; Assert.IsTrue(Cloneable <CloneTestStruct[][]> .CanClone()); Assert.IsTrue(Cloneable <CloneTestStruct[][]> .CanShallowClone()); var clone = Cloneable <CloneTestStruct[][]> .Clone(source); var shallowClone = Cloneable <CloneTestStruct[][]> .ShallowClone(source); Assert.AreEqual(source.Length, clone.Length); Assert.AreEqual(source.Length, shallowClone.Length); Assert.AreEqual("John", clone[0][0].FirstName); Assert.AreEqual("Doe", clone[0][0].LastName); Assert.AreEqual("Jane", clone[0][1].FirstName); Assert.AreEqual("Smith", clone[0][1].LastName); Assert.AreEqual("John", shallowClone[0][0].FirstName); Assert.AreEqual("Doe", shallowClone[0][0].LastName); Assert.AreEqual("Jane", shallowClone[0][1].FirstName); Assert.AreEqual("Smith", shallowClone[0][1].LastName); }
public void CloneStructArray() { var source = new CloneTestStruct[] { new CloneTestStruct { FirstName = "John", LastName = "Doe" }, new CloneTestStruct { FirstName = "Jane", LastName = "Smith" } }; Assert.IsTrue(Cloneable <CloneTestStruct[]> .CanClone()); Assert.IsTrue(Cloneable <CloneTestStruct[]> .CanShallowClone()); var clones = Cloneable <CloneTestStruct[]> .Clone(source); var shallowClones = Cloneable <CloneTestStruct[]> .ShallowClone(source); Assert.IsFalse(object.ReferenceEquals(source, clones)); Assert.IsFalse(object.ReferenceEquals(source, shallowClones)); Assert.AreEqual(source.Length, clones.Length); Assert.AreEqual(source.Length, shallowClones.Length); Assert.AreEqual("John", clones[0].FirstName); Assert.AreEqual("Doe", clones[0].LastName); Assert.AreEqual("Jane", clones[1].FirstName); Assert.AreEqual("Smith", clones[1].LastName); }
public void CloneStruct() { var source = new CloneTestStruct { FirstName = "John", LastName = "Doe" }; Assert.IsTrue(Cloneable <CloneTestStruct> .CanClone()); Assert.IsTrue(Cloneable <CloneTestStruct> .CanShallowClone()); Assert.IsTrue(Cloneable <CloneTestStruct?> .CanClone()); Assert.IsTrue(Cloneable <CloneTestStruct?> .CanShallowClone()); var clone = Cloneable <CloneTestStruct> .Clone(source); var shallowClone = Cloneable <CloneTestStruct> .ShallowClone(source); Assert.AreEqual("John", clone.FirstName); Assert.AreEqual("Doe", clone.LastName); Assert.AreEqual("John", shallowClone.FirstName); Assert.AreEqual("Doe", shallowClone.LastName); clone = Cloneable <CloneTestStruct?> .Clone(source).Value; shallowClone = Cloneable <CloneTestStruct?> .ShallowClone(source).Value; Assert.AreEqual("John", clone.FirstName); Assert.AreEqual("Doe", clone.LastName); Assert.AreEqual("John", shallowClone.FirstName); Assert.AreEqual("Doe", shallowClone.LastName); Assert.IsNull(Cloneable <CloneTestStruct?> .Clone(null)); Assert.IsNull(Cloneable <CloneTestStruct?> .ShallowClone(null)); }
public void ShallowCloneToStructArray() { var source = new[] { new CloneTestStruct { FirstName = "John", LastName = "Doe" } }; var destination = new CloneTestStruct[1]; source.ShallowCloneTo(destination); Assert.AreEqual("John", destination[0].FirstName); Assert.AreEqual("Doe", destination[0].LastName); }
public void CloneMultidimensionalStructArray() { CloneTestStruct[,] source = new CloneTestStruct[, ] { { new CloneTestStruct { FirstName = "John", LastName = "Doe" }, new CloneTestStruct { FirstName = "Jane", LastName = "Smith" } } }; Assert.IsTrue(Cloneable <CloneTestStruct[, ]> .CanClone()); Assert.IsTrue(Cloneable <CloneTestStruct[, ]> .CanShallowClone()); var clone = Cloneable <CloneTestStruct[, ]> .Clone(source); var shallowClone = Cloneable <CloneTestStruct[, ]> .ShallowClone(source); Assert.AreEqual(source.Length, clone.Length); Assert.AreEqual(source.Length, shallowClone.Length); Assert.AreEqual("John", clone[0, 0].FirstName); Assert.AreEqual("Doe", clone[0, 0].LastName); Assert.AreEqual("Jane", clone[0, 1].FirstName); Assert.AreEqual("Smith", clone[0, 1].LastName); Assert.AreEqual("John", shallowClone[0, 0].FirstName); Assert.AreEqual("Doe", shallowClone[0, 0].LastName); Assert.AreEqual("Jane", shallowClone[0, 1].FirstName); Assert.AreEqual("Smith", shallowClone[0, 1].LastName); }
public void ShallowCloneToStructArrayOfDifferingLengthsWillNotWork() { var source = new CloneTestStruct[2]; var destination = new CloneTestStruct[3]; Assert.Throws<InvalidOperationException>(() => Cloneable<CloneTestStruct[]>.ShallowCloneTo(source, destination)); }
public void CloneJaggedStructArray() { var source = new CloneTestStruct[][] { new CloneTestStruct[] { new CloneTestStruct { FirstName = "John", LastName = "Doe" }, new CloneTestStruct { FirstName = "Jane", LastName = "Smith"} } }; Assert.IsTrue(Cloneable<CloneTestStruct[][]>.CanClone()); Assert.IsTrue(Cloneable<CloneTestStruct[][]>.CanShallowClone()); var clone = Cloneable<CloneTestStruct[][]>.Clone(source); var shallowClone = Cloneable<CloneTestStruct[][]>.ShallowClone(source); Assert.AreEqual(source.Length, clone.Length); Assert.AreEqual(source.Length, shallowClone.Length); Assert.AreEqual("John", clone[0][0].FirstName); Assert.AreEqual("Doe", clone[0][0].LastName); Assert.AreEqual("Jane", clone[0][1].FirstName); Assert.AreEqual("Smith", clone[0][1].LastName); Assert.AreEqual("John", shallowClone[0][0].FirstName); Assert.AreEqual("Doe", shallowClone[0][0].LastName); Assert.AreEqual("Jane", shallowClone[0][1].FirstName); Assert.AreEqual("Smith", shallowClone[0][1].LastName); }
public void CloneMultidimensionalStructArray() { CloneTestStruct[,] source = new CloneTestStruct[,] { { new CloneTestStruct { FirstName = "John", LastName = "Doe" }, new CloneTestStruct { FirstName = "Jane", LastName = "Smith"} } }; Assert.IsTrue(Cloneable<CloneTestStruct[,]>.CanClone()); Assert.IsTrue(Cloneable<CloneTestStruct[,]>.CanShallowClone()); var clone = Cloneable<CloneTestStruct[,]>.Clone(source); var shallowClone = Cloneable<CloneTestStruct[,]>.ShallowClone(source); Assert.AreEqual(source.Length, clone.Length); Assert.AreEqual(source.Length, shallowClone.Length); Assert.AreEqual("John", clone[0, 0].FirstName); Assert.AreEqual("Doe", clone[0, 0].LastName); Assert.AreEqual("Jane", clone[0, 1].FirstName); Assert.AreEqual("Smith", clone[0, 1].LastName); Assert.AreEqual("John", shallowClone[0, 0].FirstName); Assert.AreEqual("Doe", shallowClone[0, 0].LastName); Assert.AreEqual("Jane", shallowClone[0, 1].FirstName); Assert.AreEqual("Smith", shallowClone[0, 1].LastName); }
public void CloneStructArray() { var source = new CloneTestStruct[] { new CloneTestStruct { FirstName = "John", LastName = "Doe" }, new CloneTestStruct { FirstName = "Jane", LastName = "Smith"} }; Assert.IsTrue(Cloneable<CloneTestStruct[]>.CanClone()); Assert.IsTrue(Cloneable<CloneTestStruct[]>.CanShallowClone()); var clones = Cloneable<CloneTestStruct[]>.Clone(source); var shallowClones = Cloneable<CloneTestStruct[]>.ShallowClone(source); Assert.IsFalse(object.ReferenceEquals(source, clones)); Assert.IsFalse(object.ReferenceEquals(source, shallowClones)); Assert.AreEqual(source.Length, clones.Length); Assert.AreEqual(source.Length, shallowClones.Length); Assert.AreEqual("John", clones[0].FirstName); Assert.AreEqual("Doe", clones[0].LastName); Assert.AreEqual("Jane", clones[1].FirstName); Assert.AreEqual("Smith", clones[1].LastName); }
public void CloneStruct() { var source = new CloneTestStruct { FirstName = "John", LastName = "Doe" }; Assert.IsTrue(Cloneable<CloneTestStruct>.CanClone()); Assert.IsTrue(Cloneable<CloneTestStruct>.CanShallowClone()); Assert.IsTrue(Cloneable<CloneTestStruct?>.CanClone()); Assert.IsTrue(Cloneable<CloneTestStruct?>.CanShallowClone()); var clone = Cloneable<CloneTestStruct>.Clone(source); var shallowClone = Cloneable<CloneTestStruct>.ShallowClone(source); Assert.AreEqual("John", clone.FirstName); Assert.AreEqual("Doe", clone.LastName); Assert.AreEqual("John", shallowClone.FirstName); Assert.AreEqual("Doe", shallowClone.LastName); clone = Cloneable<CloneTestStruct?>.Clone(source).Value; shallowClone = Cloneable<CloneTestStruct?>.ShallowClone(source).Value; Assert.AreEqual("John", clone.FirstName); Assert.AreEqual("Doe", clone.LastName); Assert.AreEqual("John", shallowClone.FirstName); Assert.AreEqual("Doe", shallowClone.LastName); Assert.IsNull(Cloneable<CloneTestStruct?>.Clone(null)); Assert.IsNull(Cloneable<CloneTestStruct?>.ShallowClone(null)); }