Skip to content

Commit

Permalink
add test case for interface fields
Browse files Browse the repository at this point in the history
  • Loading branch information
lofcz committed Jan 8, 2025
1 parent 1702e58 commit b3b866f
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions FastCloner.Tests/SpecialCaseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1892,4 +1892,42 @@ public T Value

public LazyRef(Func<T> initializer) => _initializer = initializer;
}

[Test]
public void CanCopyInterfaceField()
{
MyObject o = new MyObject();

MyIClass original = new MyIClass
{
Field1 = o,
Field2 = o
};

MyIClass result = original.DeepClone();

Assert.Multiple(() =>
{
Assert.That(original.Field1, Is.SameAs(original.Field2), "Original objects should be same");
Assert.That(result.Field1, Is.SameAs(result.Field2), "Cloned objects should be same");
});
}

public class MyIClass
{
public IMyInterface1 Field1;
public IMyInterface2 Field2;
}

public interface IMyInterface1
{
}

public interface IMyInterface2
{
}

public class MyObject : IMyInterface1, IMyInterface2
{
}
}

0 comments on commit b3b866f

Please sign in to comment.