It is interesting in this case if you are looking for behavior tests. Here's a sample in Machine.Fakes with the Moq sublayer ... it allows for nesting, it seems you want, while maintaining the logical separation of the tests. Requires NuGet packages: Machine.Fakes.Moq, Machine.Specifications.Should
class IFoo_test_context : WithSubject<IFoo> { Establish context = () => Subject.bar2 = 3; } class When_fooing_with_seven : IFoo_test_context { Establish context = () => Subject.bar = 7; It bar_should_be_seven =()=> Subject.bar.ShouldEqual(7); It bar2_should_be_three =()=> Subject.bar.ShouldEqual(3); } class When_fooing_with_nine : IFoo_test_context { Establish context = () => Subject.bar = 9; It bar_should_be_nine = () => Subject.bar.ShouldEqual(9); It bar2_should_be_three = () => Subject.bar.ShouldEqual(3); }
Again, the example is somewhat stupid because it tests mocking behavior, but itโs hard to understand what you are ultimately trying to accomplish. As far as I can tell, there is no copy constructor, as you want, with a layout.
source share