本文整理汇总了C#中MyAggregateRoot.InitializeFromHistory方法的典型用法代码示例。如果您正苦于以下问题:C# MyAggregateRoot.InitializeFromHistory方法的具体用法?C# MyAggregateRoot.InitializeFromHistory怎么用?C# MyAggregateRoot.InitializeFromHistory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MyAggregateRoot
的用法示例。
在下文中一共展示了MyAggregateRoot.InitializeFromHistory方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: It_could_not_be_loaded_from_history_when_it_already_contains_uncommitted_events
public void It_could_not_be_loaded_from_history_when_it_already_contains_uncommitted_events()
{
var theAggregate = new MyAggregateRoot();
theAggregate.MethodThatCausesAnEventThatHasAHandler();
theAggregate.MethodThatCausesAnEventThatHasAHandler();
var history = new[] {new HandledEvent(), new HandledEvent()};
Action act = () => theAggregate.InitializeFromHistory(history);
act.ShouldThrow<InvalidOperationException>();
}
示例2: Initiazling_from_history_with_correct_sequence_should_not_throw_exception
public void Initiazling_from_history_with_correct_sequence_should_not_throw_exception()
{
var theAggregate = new MyAggregateRoot();
var event1 = new HandledEvent(Guid.NewGuid(), theAggregate.EventSourceId, 1, DateTime.UtcNow);
var event2 = new HandledEvent(Guid.NewGuid(), theAggregate.EventSourceId, 2, DateTime.UtcNow);
var event3 = new HandledEvent(Guid.NewGuid(), theAggregate.EventSourceId, 3, DateTime.UtcNow);
var event4 = new HandledEvent(Guid.NewGuid(), theAggregate.EventSourceId, 4, DateTime.UtcNow);
var event5 = new HandledEvent(Guid.NewGuid(), theAggregate.EventSourceId, 5, DateTime.UtcNow);
IEnumerable<SourcedEvent> history = new[] { event1, event2, event3, event4, event5 };
theAggregate.InitializeFromHistory(history);
}
示例3: Initiazling_from_wrong_history_with_wrong_sequence_should_throw_exception2
public void Initiazling_from_wrong_history_with_wrong_sequence_should_throw_exception2()
{
var theAggregate = new MyAggregateRoot();
long wrongSequence = 8;
var event1 = new HandledEvent(Guid.NewGuid(), theAggregate.EventSourceId, 0, DateTime.UtcNow);
var event2 = new HandledEvent(Guid.NewGuid(), theAggregate.EventSourceId, 1, DateTime.UtcNow);
var event3 = new HandledEvent(Guid.NewGuid(), theAggregate.EventSourceId, wrongSequence, DateTime.UtcNow);
IEnumerable<SourcedEvent> history = new[] { event1, event2, event3 };
Action act = () => theAggregate.InitializeFromHistory(history);
act.ShouldThrow<InvalidOperationException>().And.Message.Should().Contain("sequence");
}
示例4: Initializing_from_history_should_not_throw_an_exception_when_the_history_was_empty
public void Initializing_from_history_should_not_throw_an_exception_when_the_history_was_empty()
{
var theAggregate = new MyAggregateRoot();
IEnumerable<SourcedEvent> history = new SourcedEvent[0];
theAggregate.InitializeFromHistory(history);
}
示例5: Initializing_from_history_should_throw_an_exception_when_the_history_was_null
public void Initializing_from_history_should_throw_an_exception_when_the_history_was_null()
{
IEnumerable<SourcedEvent> nullHistory = null;
var theAggregate = new MyAggregateRoot();
Action act = () => theAggregate.InitializeFromHistory(nullHistory);
act.ShouldThrow<ArgumentNullException>();
}
示例6: Applying_an_event_to_an_agg_root_with_history_should_call_the_event_handler_only_once
public void Applying_an_event_to_an_agg_root_with_history_should_call_the_event_handler_only_once()
{
var theAggregate = new MyAggregateRoot();
var event1 = new HandledEvent(Guid.NewGuid(), theAggregate.EventSourceId, 1, DateTime.UtcNow);
var event2 = new HandledEvent(Guid.NewGuid(), theAggregate.EventSourceId, 2, DateTime.UtcNow);
var event3 = new HandledEvent(Guid.NewGuid(), theAggregate.EventSourceId, 3, DateTime.UtcNow);
var event4 = new HandledEvent(Guid.NewGuid(), theAggregate.EventSourceId, 4, DateTime.UtcNow);
var event5 = new HandledEvent(Guid.NewGuid(), theAggregate.EventSourceId, 5, DateTime.UtcNow);
IEnumerable<SourcedEvent> history = new[] { event1, event2, event3, event4, event5 };
theAggregate.InitializeFromHistory(history);
var eventHandlerCountAfterInitialization = theAggregate.FooEventHandlerInvokeCount;
theAggregate.MethodThatCausesAnEventThatHasAHandler();
theAggregate.FooEventHandlerInvokeCount.Should().Be(eventHandlerCountAfterInitialization + 1);
}
示例7: Initiazling_from_history_with_correct_sequence_should_not_throw_exception
public void Initiazling_from_history_with_correct_sequence_should_not_throw_exception()
{
var theAggregate = new MyAggregateRoot();
var stream = new CommittedEventStream(theAggregate.EventSourceId,
new CommittedEvent(Guid.NewGuid(), Guid.NewGuid(), theAggregate.EventSourceId, 1, DateTime.UtcNow, new HandledEvent(), new Version(1, 0)),
new CommittedEvent(Guid.NewGuid(), Guid.NewGuid(), theAggregate.EventSourceId, 2, DateTime.UtcNow, new HandledEvent(), new Version(1, 0)),
new CommittedEvent(Guid.NewGuid(), Guid.NewGuid(), theAggregate.EventSourceId, 3, DateTime.UtcNow, new HandledEvent(), new Version(1, 0)),
new CommittedEvent(Guid.NewGuid(), Guid.NewGuid(), theAggregate.EventSourceId, 4, DateTime.UtcNow, new HandledEvent(), new Version(1, 0)),
new CommittedEvent(Guid.NewGuid(), Guid.NewGuid(), theAggregate.EventSourceId, 5, DateTime.UtcNow, new HandledEvent(), new Version(1, 0)));
theAggregate.InitializeFromHistory(stream);
}
示例8: Initiazling_from_wrong_history_with_wrong_sequence_should_throw_exception
public void Initiazling_from_wrong_history_with_wrong_sequence_should_throw_exception()
{
var theAggregate = new MyAggregateRoot();
const long wrongSequence = 3;
var stream = new CommittedEventStream(theAggregate.EventSourceId,
new CommittedEvent(Guid.NewGuid(), Guid.NewGuid(), theAggregate.EventSourceId, wrongSequence, DateTime.UtcNow, new HandledEvent(), new Version(1, 0)));
Action act = ()=> theAggregate.InitializeFromHistory(stream);
act.ShouldThrow<InvalidOperationException>().And.Message.Should().Contain("sequence");
}
示例9: Initializing_from_history_should_not_throw_an_exception_when_the_history_was_empty
public void Initializing_from_history_should_not_throw_an_exception_when_the_history_was_empty()
{
var theAggregate = new MyAggregateRoot();
var history = new CommittedEventStream(Guid.Empty);
theAggregate.InitializeFromHistory(history);
}
示例10: Loading_it_from_history_should_apply_all_events
public void Loading_it_from_history_should_apply_all_events()
{
var aggId = Guid.NewGuid();
var stream = Prepare.Events(new HandledEvent(), new HandledEvent(), new HandledEvent()).ForSource(aggId);
var theAggregate = new MyAggregateRoot(aggId);
theAggregate.InitializeFromHistory(stream);
theAggregate.FooEventHandlerInvokeCount.Should().Be(3);
}