コード例 #1
0
        public void TestThatForeignKeyModifyCallsPublishOnCommandBus()
        {
            var fixture = new Fixture();

            var foodGroupMock = DomainObjectMockBuilder.BuildFoodGroupMock();
            // ReSharper disable PossibleInvalidOperationException
            var foreignKeyMock = DomainObjectMockBuilder.BuildForeignKeyMock(foodGroupMock.Identifier.Value, foodGroupMock.GetType());
            // ReSharper restore PossibleInvalidOperationException

            var commandBusMock = MockRepository.GenerateMock <ICommandBus>();

            commandBusMock.Stub(m => m.Publish <ForeignKeyModifyCommand, ServiceReceiptResponse>(Arg <ForeignKeyModifyCommand> .Is.NotNull))
            .WhenCalled(e =>
            {
                var command = (ForeignKeyModifyCommand)e.Arguments.ElementAt(0);
                // ReSharper disable PossibleInvalidOperationException
                Assert.That(command.ForeignKeyIdentifier, Is.EqualTo(foreignKeyMock.Identifier.Value));
                // ReSharper restore PossibleInvalidOperationException
                Assert.That(command.ForeignKeyValue, Is.Not.Null);
                Assert.That(command.ForeignKeyValue, Is.Not.Empty);
                Assert.That(command.ForeignKeyValue, Is.EqualTo(foreignKeyMock.ForeignKeyValue));
            })
            .Return(fixture.Create <ServiceReceiptResponse>())
            .Repeat.Any();

            var logicExecutor = new LogicExecutor(commandBusMock);

            Assert.That(logicExecutor, Is.Not.Null);

            logicExecutor.ForeignKeyModify(foreignKeyMock);

            commandBusMock.AssertWasCalled(m => m.Publish <ForeignKeyModifyCommand, ServiceReceiptResponse>(Arg <ForeignKeyModifyCommand> .Is.NotNull));
        }
コード例 #2
0
        public void TestThatForeignKeyModifyThrowsArgumentNullExceptionWhenForeignKeyIsNull()
        {
            var commandBusMock = MockRepository.GenerateMock <ICommandBus>();

            var logicExecutor = new LogicExecutor(commandBusMock);

            Assert.That(logicExecutor, Is.Not.Null);

            var exception = Assert.Throws <ArgumentNullException>(() => logicExecutor.ForeignKeyModify(null));

            Assert.That(exception, Is.Not.Null);
            Assert.That(exception.ParamName, Is.Not.Null);
            Assert.That(exception.ParamName, Is.Not.Empty);
            Assert.That(exception.ParamName, Is.EqualTo("foreignKey"));
            Assert.That(exception.InnerException, Is.Null);
        }
コード例 #3
0
        public void TestThatForeignKeyModifyThrowsIntranetSystemExceptionWhenIdentifierOnForeignKeyIsNull()
        {
            var commandBusMock = MockRepository.GenerateMock <ICommandBus>();

            var foreignKeyMock = MockRepository.GenerateMock <IForeignKey>();

            foreignKeyMock.Stub(m => m.Identifier)
            .Return(null)
            .Repeat.Any();

            var logicExecutor = new LogicExecutor(commandBusMock);

            Assert.That(logicExecutor, Is.Not.Null);

            var exception = Assert.Throws <IntranetSystemException>(() => logicExecutor.ForeignKeyModify(foreignKeyMock));

            Assert.That(exception, Is.Not.Null);
            Assert.That(exception.Message, Is.Not.Null);
            Assert.That(exception.Message, Is.Not.Empty);
            Assert.That(exception.Message, Is.EqualTo(Resource.GetExceptionMessage(ExceptionMessage.IllegalValue, foreignKeyMock.Identifier, "Identifier")));
            Assert.That(exception.InnerException, Is.Null);
        }
コード例 #4
0
        public void TestThatForeignKeyModifyReturnsIdentifierFromServiceReceiptResponse()
        {
            var fixture = new Fixture();

            var foodGroupMock = DomainObjectMockBuilder.BuildFoodGroupMock();
            // ReSharper disable PossibleInvalidOperationException
            var foreignKeyMock = DomainObjectMockBuilder.BuildForeignKeyMock(foodGroupMock.Identifier.Value, foodGroupMock.GetType());
            // ReSharper restore PossibleInvalidOperationException

            var serviceReceipt = fixture.Create <ServiceReceiptResponse>();
            var commandBusMock = MockRepository.GenerateMock <ICommandBus>();

            commandBusMock.Stub(m => m.Publish <ForeignKeyModifyCommand, ServiceReceiptResponse>(Arg <ForeignKeyModifyCommand> .Is.Anything))
            .Return(serviceReceipt)
            .Repeat.Any();

            var logicExecutor = new LogicExecutor(commandBusMock);

            Assert.That(logicExecutor, Is.Not.Null);

            var result = logicExecutor.ForeignKeyModify(foreignKeyMock);

            Assert.That(result, Is.EqualTo(serviceReceipt.Identifier));
        }