Example #1
0
        public void When_execute_DoSomething_it_should_saved_one_SomethingHappend_event_in_the_eventstore()
        {
            var testCommand = new TestCommand
            {
                Id = "TestAggr"
            };

            _aggregates.Provide<TestAggregate>().With(testCommand)
                .Do(aggregate => aggregate.DoSomething());

            var aggregateEvents = _eventStore.RetrieveFor(testCommand.Id);

            aggregateEvents.OfType<SomethingHappend>().Count().Should().Be(1);
        }
Example #2
0
        public void When_instantiate_an_Aggregate_it_should_do_only_once()
        {
            var testCommand = new TestCommand
            {
                Id = "TestAggr"
            };

            _aggregates.Provide<EmptyTestAggregate>().With(testCommand)
                .Try(aggregate => aggregate.DoNothing());

            _aggregates.Provide<EmptyTestAggregate>().With(testCommand)
                .Try(aggregate => aggregate.DoNothing());

            _eventStore.RetrieveFor(testCommand.Id).OfType<InstanceCreated>().Count().Should().Be(1);
        }
Example #3
0
        public void When_execute_DoSomethingOnce_twice_it_should_saved_one_SomethingHappend_event_in_the_eventstore_an_publish_twice()
        {
            var testCommand = new TestCommand
            {
                Id = "TestAggr"
            };

            _aggregates.PublishNewStateTo(_eventHandler);

            _aggregates.Provide<TestAggregate>().With(testCommand)
                .Do(aggregate => aggregate.DoSomethingOnce());

            _aggregates.Provide<TestAggregate>().With(testCommand)
                .Do(aggregate => aggregate.DoSomethingOnce());

            var aggregateEvents = _eventStore.RetrieveFor(testCommand.Id);

            aggregateEvents.OfType<SomethingHappendOnce>().Count().Should().Be(1);

            _eventHandler.RecievedEvents.OfType<SomethingHappendOnce>().Count().Should().Be(2);
        }
Example #4
0
        public void When_throw_an_Exception_within_the_aggregate_it_should_catched_in_CatchException_method()
        {
            var testCommand = new TestCommand
            {
                Id = "TestAggr"
            };

            _aggregates.Provide<TestAggregate>().With(testCommand)
                .Try(aggregate => aggregate.ThrowException())
                .CatchException(exception =>
                {
                    throw exception;
                });
        }
Example #5
0
        public void When_throw_a_Fault_within_the_aggregate_it_should_returnes_by_execution_result()
        {
            var testCommand = new TestCommand
            {
                Id = "TestAggr"
            };

            var executionResult = _aggregates.Provide<TestAggregate>().With(testCommand)
                .Try(aggregate => aggregate.ThrowFault());

            executionResult.Fault.Should().BeOfType<BusinessFault>();
            executionResult.Fault.Message.Should().Be("My BusinessFault");
        }
Example #6
0
        public void When_throw_a_Fault_within_the_aggregate_it_should_not_catched_by_default()
        {
            var testCommand = new TestCommand
            {
                Id = "TestAggr"
            };

            _aggregates.Provide<TestAggregate>().With(testCommand)
                .Do(aggregate => aggregate.ThrowFault());
        }
Example #7
0
        public void When_throw_a_Fault_within_the_aggregate_it_should_catched_in_CatchFault_method()
        {
            var testCommand = new TestCommand
            {
                Id = "TestAggr"
            };

            _aggregates.Provide<TestAggregate>().With(testCommand)
                .Try(aggregate => aggregate.ThrowFault())
                .CatchFault(fault =>
                {
                    throw fault;
                });
        }
Example #8
0
        public void When_throw_an_Fault_within_the_aggregate_it_should_not_saved_any_changes()
        {
            var testCommand = new TestCommand
            {
                Id = "TestAggr"
            };

            _aggregates.Provide<TestAggregate>().With(testCommand)
                .Try(aggregate => aggregate.ThrowException());

            _eventStore
                .RetrieveFor(testCommand.Id)
                .OfType<SomethingHappend>()
                .Count().Should().Be(0);
        }
Example #9
0
        public void When_throw_an_Fault_within_the_aggregate_it_should_not_published_any_event()
        {
            var testCommand = new TestCommand
            {
                Id = "TestAggr"
            };

            _aggregates.PublishNewStateTo(_eventHandler);

            _aggregates.Provide<TestAggregate>().With(testCommand)
                .Try(aggregate => aggregate.ThrowException());

            _eventHandler.RecievedEvents.Count.Should().Be(0);
        }
Example #10
0
        public void When_throw_an_Exception_within_the_aggregate_it_should_returned_by_execution_result()
        {
            var testCommand = new TestCommand
            {
                Id = "TestAggr"
            };

            var executionResult = _aggregates.Provide<TestAggregate>().With(testCommand)
                .Try(aggregate => aggregate.ThrowException());

            executionResult.Exception.Should().BeOfType<ApplicationException>();
            executionResult.Exception.Message.Should().Be("This is a intentionally Exception");
        }