How to implement domain method which creates another domain entity in a testable way
===

Option 1. In `ParentTest.CreateChild()` it's essentially testing `Child` constructor as well (which I don't like). 

    public class Parent
    {
        public Child Child { get; private set; }

        public void CreateChild(int param1, string param2)
        {
            Child = new Child(param1, param2);
        }
    }

    public class Child
    {
        public int Param1 { get; private set; }
        public string Param2 { get; private set; }

        public Child(int param1, string param2)
        {
            Param1 = param1;
            Param2 = param2;
        }
    }
 
    [TestFixture]
    public class ParentTest
    {
        [Test]
        public void CreateChild()
        {
            const int param1 = 23;
            const string param2 = "param2";
            var parent = new Parent();

            parent.CreateChild(param1, param2);

            Assert.That(parent.Child, Is.Not.Null);
            Assert.That(parent.Child.Param1, Is.EqualTo(param1));
            Assert.That(parent.Child.Param2, Is.EqualTo(param2));
        }
    }

    [TestFixture]
    public class ChildTest
    {
        [Test]
        public void Create()
        {
            const int param1 = 23;
            const string param2 = "param2";

            var child = new Child(param1, param2);

            Assert.That(child.Param1, Is.EqualTo(param1));
            Assert.That(child.Param2, Is.EqualTo(param2));            
        }
    }

Option 2. Uses a factory service to create `Child` instance. Here I'm not too sure about the idea of passing a service as a domain method parameter.

    public class Parent
    {
        public Child Child { get; private set; }

        public void CreateChild(int param1, string param2, IChildFactory childFactory)
        {
            Child = childFactory.Create(param1, param2);
        }
    }

    public class Child
    {
        public int Param1 { get; private set; }
        public string Param2 { get; private set; }

        protected Child() {} // to be able to generate stub

        public Child(int param1, string param2)
        {
            Param1 = param1;
            Param2 = param2;
        }
    }

    public interface IChildFactory
    {
        Child Create(int param1, string param2);
    }

    public class ChildFactory : IChildFactory
    {
        public Child Create(int param1, string param2)
        {
            return new Child(param1, param2);
        }
    }     
    
    [TestFixture]
    public class ParentTest
    {
        [Test]
        public void CreateChild()
        {
            const int param1 = 23;
            const string param2 = "param2";
            var child = MockRepository.GenerateStub<Child>();
            var childFactory = MockRepository.GenerateStub<IChildFactory>();
            childFactory.Stub(x => x.Create(param1, param2)).Return(child);
            var parent = new Parent();

            parent.CreateChild(param1, param2, childFactory);

            Assert.That(parent.Child, Is.SameAs(child));
        }    
    }

    [TestFixture]
    public class ChildTest
    {
        // empty as contructor is tested in ChildFactoryTest
    }

    [TestFixture]
    public class ChildFactoryTest
    {
        [Test]
        public void Create()
        {
            const int param1 = 23;
            const string param2 = "param2";
            var childFactory = new ChildFactory();

            var child = childFactory.Create(param1, param2);

            Assert.That(child.Param1, Is.EqualTo(param1));
            Assert.That(child.Param2, Is.EqualTo(param2));
        }
    }

I actually prefer option 2, as every time a domain method creates another domain entity, I don't have to test properties of created entity (those are tested only once in the factory test).

Anybody has better solution?