laazyj / GeorgeCloney

DeepClone, Serialize, DeSerialize extensions useful for testing
Other
17 stars 3 forks source link

Does not clone fields from base classes. #2

Closed steenlknudsen closed 10 years ago

steenlknudsen commented 10 years ago

DeepCloneWithoutSerialization does not clone fields from base classes.

This unit test fails:

public class A
{
    public string Name { get; set; }
}

public class B : A
{
    public string Message { get; set; }
}

[TestFixture]
[Category("Unittest")]
public class ClonerTest
{
    [Test]
    public void DebetKreditTest1()
    {
        var a = new A();
        a.Name = "test1";

        var clone1 = a.DeepCloneWithoutSerialization();

        Assert.IsTrue(a.Name == clone1.Name);

        var b = new B();
        b.Name = "test2";
        b.Message = "test2a";

        var clone2 = b.DeepCloneWithoutSerialization();

        Assert.IsTrue(b.Message == clone2.Message);
        Assert.IsTrue(b.Name == clone2.Name);
    }
steenlknudsen commented 10 years ago

I have made a patch here:

https://github.com/steenlknudsen/GeorgeCloney/blob/master/GeorgeCloney/CloneExtension.cs

laazyj commented 10 years ago

Sorry for taking so long to get around to looking at this. Thanks for the patch! I've merged it and included in NuGet package 1.1.0.13