PageRenderTime 14ms CodeModel.GetById 2ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/Source/Bifrost.Specs/Sagas/for_SagaState/when_in_a_state_of_begun.cs

#
C# | 43 lines | 35 code | 8 blank | 0 comment | 0 complexity | 31eea6212bbded4953b1411e9dd2c0dc MD5 | raw file
 1using System;
 2using Bifrost.Sagas;
 3using Bifrost.Sagas.Exceptions;
 4using Machine.Specifications;
 5
 6namespace Bifrost.Specs.Sagas.for_SagaState
 7{
 8    [Subject(typeof(SagaState))]
 9    public class when_in_a_state_of_begun : given.a_state_of_begun
10    {
11        static Exception exception_when_transitioning_to_an_invalid_state;
12        static Exception exception_when_transitioning_to_a_valid_state;
13        
14        static bool can_transition_to_new;
15        static bool can_transition_to_begun;
16        static bool can_transition_to_continuing;
17        static bool can_transition_to_concluded;
18
19        Because of = () =>
20                         {
21                             can_transition_to_new = state.CanTransitionTo(SagaState.NEW);
22                             can_transition_to_begun = state.CanTransitionTo(SagaState.BEGUN);
23                             can_transition_to_continuing = state.CanTransitionTo(SagaState.CONTINUING);
24                             can_transition_to_concluded = state.CanTransitionTo(SagaState.CONCLUDED);
25
26                             exception_when_transitioning_to_an_invalid_state = exception_when_transitioning_to_an_invalid_state = Catch.Exception(() => state.TransitionTo(SagaState.BEGUN));
27                             exception_when_transitioning_to_a_valid_state = exception_when_transitioning_to_a_valid_state = Catch.Exception(() => state.TransitionTo(SagaState.CONTINUING));
28                         };
29
30        It should_not_support_transitioning_to_new = () => can_transition_to_new.ShouldBeFalse();
31        It should_not_support_transitioning_to_begun = () => can_transition_to_begun.ShouldBeFalse();
32        It should_not_support_transitioning_to_continuing = () => can_transition_to_continuing.ShouldBeTrue();
33        It should_support_transitioning_to_concluded = () => can_transition_to_concluded.ShouldBeTrue();
34
35        It should_throw_an_invalid_saga_state_transition_exception_when_transitioning_to_an_invalid_state =
36            () => exception_when_transitioning_to_an_invalid_state.ShouldBeOfType<InvalidSagaStateTransitionException>();
37
38        It should_not_throw_an_invalid_saga_state_transition_exception_when_transitioning_to_a_valid_state =
39            () => exception_when_transitioning_to_a_valid_state.ShouldBeNull();
40
41        It should_have_the_new_state_after_transitioning = () => state.IsContinuing.ShouldBeTrue();
42    }
43}