PageRenderTime 30ms CodeModel.GetById 17ms app.highlight 8ms RepoModel.GetById 2ms app.codeStats 0ms

/Source/Bifrost.Specs/Domain/for_AggregatedRootRepository/when_getting_a_stateless_aggregated_root_that_has_events.cs

#
C# | 36 lines | 32 code | 4 blank | 0 comment | 0 complexity | 719108bedc1098146192654547023954 MD5 | raw file
 1using System;
 2using Bifrost.Events;
 3using Machine.Specifications;
 4
 5namespace Bifrost.Specs.Domain.for_AggregatedRootRepository
 6{
 7    [Subject(Subjects.getting_aggregated_root)]
 8    public class when_getting_a_stateless_aggregated_root_that_has_events : given.a_repository_for_a_stateless_aggregated_root
 9    {
10        static Guid aggregated_root_id = Guid.NewGuid();
11        static Guid event_id = Guid.NewGuid();
12        static SimpleStatelessAggregatedRoot stateless_aggregated_root;
13        static CommittedEventStream event_stream;
14        static EventSourceVersion expected_version;
15        static EventSourceVersion version_of_last_event;
16
17        Establish context = () =>
18                                {
19                                    version_of_last_event = new EventSourceVersion(1,1);
20                                    expected_version = new EventSourceVersion(2, 0);
21                                    event_store_mock.Setup(e => e.GetLastCommittedVersion(typeof(SimpleStatelessAggregatedRoot),aggregated_root_id)).Returns(version_of_last_event);
22                                };
23
24        Because of = () => stateless_aggregated_root = repository.Get(aggregated_root_id);
25
26        It should_return_an_instance = () => stateless_aggregated_root.ShouldNotBeNull();
27        It should_not_get_events_for_the_aggregated_root = () => event_store_mock.Verify(e => e.Load(typeof(SimpleStatelessAggregatedRoot), aggregated_root_id),Moq.Times.Never());
28        It should_not_re_apply_events_for_the_aggregated_root = () => stateless_aggregated_root .ReApplyCalled.ShouldBeFalse();
29        It should_ensure_the_event_source_has_the_correct_version = () =>
30                                                                        {
31                                                                            event_store_mock.Verify(e => e.GetLastCommittedVersion(typeof(SimpleStatelessAggregatedRoot), aggregated_root_id), Moq.Times.Once());
32                                                                            stateless_aggregated_root.Version.ShouldEqual(expected_version);
33                                                                        };
34        It should_register_the_aggregate_root_for_tracking_within_this_context = () => command_context_mock.Verify(cc => cc.RegisterForTracking(stateless_aggregated_root));        
35    }
36}