public void Executing_it_should_create_unit_of_work_with_factory()
        {
            var factoryMock = MockRepository.GenerateMock<IUnitOfWorkFactory>();
            var contextMock = MockRepository.GenerateMock<IUnitOfWorkContext>();

            factoryMock.Expect(t => t.CreateUnitOfWork()).Repeat.Once().Return(contextMock);

            Func<ChangeMessageTextCommand, Guid> getId = (c) => new Guid();
            Action<Message, ChangeMessageTextCommand> anAction = (m, c) => c.GetType();
            var executor = new DirectActionCommandExecutor<ChangeMessageTextCommand, Message>(getId, anAction, factoryMock);

            var cmd = new ChangeMessageTextCommand();
            executor.Execute(cmd);

            factoryMock.VerifyAllExpectations();
        }
Exemple #2
0
        public void Executing_it_should_create_unit_of_work_with_factory()
        {
            var factoryMock = MockRepository.GenerateMock <IUnitOfWorkFactory>();
            var contextMock = MockRepository.GenerateMock <IUnitOfWorkContext>();

            factoryMock.Expect(t => t.CreateUnitOfWork()).Repeat.Once().Return(contextMock);

            Func <ChangeMessageTextCommand, Guid>      getId    = (c) => new Guid();
            Action <Message, ChangeMessageTextCommand> anAction = (m, c) => c.GetType();
            var executor = new DirectActionCommandExecutor <ChangeMessageTextCommand, Message>(getId, anAction, factoryMock);

            var cmd = new ChangeMessageTextCommand();

            executor.Execute(cmd);

            factoryMock.VerifyAllExpectations();
        }
Exemple #3
0
        public void Executing_it_should_GetById_of_context_to_get_agg_root()
        {
            var id = Guid.NewGuid();

            var factoryMock = MockRepository.GenerateMock <IUnitOfWorkFactory>();
            var contextMock = MockRepository.GenerateMock <IUnitOfWorkContext>();

            factoryMock.Stub(t => t.CreateUnitOfWork()).Return(contextMock);
            contextMock.Expect(t => t.GetById <Message>(id)).Return(new Message("Hello world"));

            Func <ChangeMessageTextCommand, Guid>      getId    = (c) => id;
            Action <Message, ChangeMessageTextCommand> anAction = (m, c) => c.GetType();
            var executor = new DirectActionCommandExecutor <ChangeMessageTextCommand, Message>(getId, anAction, factoryMock);

            var cmd = new ChangeMessageTextCommand();

            executor.Execute(cmd);

            contextMock.VerifyAllExpectations();
        }
Exemple #4
0
        public void Executing_it_should_invoke_getId()
        {
            var invoked = false;

            var factoryMock = MockRepository.GenerateMock <IUnitOfWorkFactory>();
            var contextMock = MockRepository.GenerateMock <IUnitOfWorkContext>();

            factoryMock.Stub(t => t.CreateUnitOfWork()).Return(contextMock);
            contextMock.Expect(t => t.Accept()).Repeat.Once();

            Action <Message, ChangeMessageTextCommand> anAction = (m, c) => c.GetType();
            Func <ChangeMessageTextCommand, Guid>      getId    = (c) =>
            {
                invoked = true;
                return(Guid.NewGuid());
            };
            var executor = new DirectActionCommandExecutor <ChangeMessageTextCommand, Message>(getId, anAction, factoryMock);

            var cmd = new ChangeMessageTextCommand();

            executor.Execute(cmd);

            invoked.Should().BeTrue();
        }
        public void Executing_it_should_GetById_of_context_to_get_agg_root()
        {
            var id = Guid.NewGuid();

            var factoryMock = MockRepository.GenerateMock<IUnitOfWorkFactory>();
            var contextMock = MockRepository.GenerateMock<IUnitOfWorkContext>();

            factoryMock.Stub(t => t.CreateUnitOfWork()).Return(contextMock);
            contextMock.Expect(t => t.GetById<Message>(id)).Return(new Message("Hello world"));

            Func<ChangeMessageTextCommand, Guid> getId = (c) => id;
            Action<Message, ChangeMessageTextCommand> anAction = (m, c) => c.GetType();
            var executor = new DirectActionCommandExecutor<ChangeMessageTextCommand, Message>(getId, anAction, factoryMock);

            var cmd = new ChangeMessageTextCommand();
            executor.Execute(cmd);

            contextMock.VerifyAllExpectations();
        }
        public void Executing_it_should_invoke_getId()
        {
            var invoked = false;

            var factoryMock = MockRepository.GenerateMock<IUnitOfWorkFactory>();
            var contextMock = MockRepository.GenerateMock<IUnitOfWorkContext>();

            factoryMock.Stub(t => t.CreateUnitOfWork()).Return(contextMock);
            contextMock.Expect(t => t.Accept()).Repeat.Once();

            Action<Message, ChangeMessageTextCommand> anAction = (m, c) => c.GetType();
            Func<ChangeMessageTextCommand, Guid> getId = (c) =>
            {
                invoked = true;
                return Guid.NewGuid();
            };
            var executor = new DirectActionCommandExecutor<ChangeMessageTextCommand, Message>(getId, anAction, factoryMock);

            var cmd = new ChangeMessageTextCommand();
            executor.Execute(cmd);

            invoked.Should().BeTrue();
        }