本文整理汇总了C#中CommandContext.GetById方法的典型用法代码示例。如果您正苦于以下问题:C# CommandContext.GetById方法的具体用法?C# CommandContext.GetById怎么用?C# CommandContext.GetById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CommandContext
的用法示例。
在下文中一共展示了CommandContext.GetById方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Context_Does_Not_Finds_Missing_Root_Objects
public void Context_Does_Not_Finds_Missing_Root_Objects()
{
var resolver = new Mock<IDependencyResolver>();
resolver.Setup(r => r.Resolve<ISnapshotStore>()).Returns(new InMemorySnapshotStore());
resolver.Setup(r => r.Resolve<IEventStore>()).Returns(new InMemoryEventStore());
var context = new CommandContext(resolver.Object);
var root = context.GetById<TestDomain>(SequentialGuid.NewId());
Assert.IsNull(root);
}
示例2: Context_Finds_Root_Objects
public void Context_Finds_Root_Objects()
{
var resolver = new Mock<IDependencyResolver>();
var eventStore = new Mock<IEventStore>();
eventStore.Setup(es => es.GetEvents(It.IsAny<Guid>(), It.IsAny<long>())).Returns(
new List<DomainEvent>{new AccountCreatedEvent(Guid.NewGuid(), 100)});
resolver.Setup(r => r.Resolve<IEventStore>()).Returns(eventStore.Object);
resolver.Setup(r => r.Resolve<ISnapshotStore>()).Returns(new InMemorySnapshotStore());
var context = new CommandContext(resolver.Object);
var root = context.GetById<TestDomain>(SequentialGuid.NewId());
Assert.IsNotNull(root);
}
示例3: Context_Loads_Root_From_Snapshot
public void Context_Loads_Root_From_Snapshot()
{
var eventStore = new Mock<IEventStore>();
var snapshotStore = new Mock<ISnapshotStore>();
var resolver = new Mock<IDependencyResolver>();
eventStore.Setup(e => e.GetEvents(It.IsAny<Guid>(), It.IsAny<long>()));
eventStore.Setup(e => e.Insert(It.IsAny<Guid>(), It.IsAny<List<DomainEvent>>()));
snapshotStore.Setup(s => s.GetSnapshot<TestSnapshot>(It.IsAny<Guid>()))
.Returns(new Snapshot<TestSnapshot>(Guid.NewGuid(), 3, new TestSnapshot { Value = 99 }));
resolver.Setup(r => r.Resolve<IEventStore>()).Returns(eventStore.Object);
resolver.Setup(r => r.Resolve<ISnapshotStore>()).Returns(snapshotStore.Object);
resolver.Setup(r => r.Resolve<DomainRepository>()).Returns(new DomainRepository(snapshotStore.Object, eventStore.Object));
var context = new CommandContext(resolver.Object);
var root = context.GetById<TestDomainWithSnapshot>(SequentialGuid.NewId());
Assert.AreEqual(3, root.Version);
}
示例4: Context_Upgrades_Event_Versions
public void Context_Upgrades_Event_Versions()
{
var events = new List<DomainEvent>
{
new OldEventHappened{Sequence = 1, FirstName = "First"},
new IntermediateEventHappened{Sequence = 2, FirstName = "First", LastName = "Last"},
new NewEventHappened{Sequence = 2, FirstName = "First", LastName = "Last", Age = 95},
};
var eventStore = new Mock<IEventStore>();
var snapshotStore = new Mock<ISnapshotStore>();
var resolver = new Mock<IDependencyResolver>();
eventStore.Setup(e => e.GetEvents(It.IsAny<Guid>(), It.IsAny<long>())).Returns(events);
eventStore.Setup(e => e.Insert(It.IsAny<Guid>(), It.IsAny<List<DomainEvent>>()));
snapshotStore.Setup(s => s.GetSnapshot<TestSnapshot>(It.IsAny<Guid>())).Returns(() => null);
resolver.Setup(r => r.Resolve<IEventStore>()).Returns(eventStore.Object);
resolver.Setup(r => r.Resolve<ISnapshotStore>()).Returns(snapshotStore.Object);
resolver.Setup(r => r.Resolve<DomainRepository>())
.Returns(new DomainRepository(snapshotStore.Object, eventStore.Object));
var context = new CommandContext(resolver.Object);
var root = context.GetById<TestDomain>(SequentialGuid.NewId());
Assert.AreEqual(3, root.Version);
Assert.AreEqual(0, root.AppliedEvents.Count);
var event1 = root.VersionedEvents[0];
var event2 = root.VersionedEvents[1];
var event3 = root.VersionedEvents[2];
Assert.AreEqual(event1.FirstName, "First");
Assert.AreEqual(event2.FirstName, "First");
Assert.AreEqual(event3.FirstName, "First");
Assert.AreEqual(event1.LastName, "Unknown");
Assert.AreEqual(event2.LastName, "Last");
Assert.AreEqual(event3.LastName, "Last");
Assert.AreEqual(event1.Age, -1);
Assert.AreEqual(event2.Age, -1);
Assert.AreEqual(event3.Age, 95);
}
示例5: Context_Replays_Post_Snapshot_Events
public void Context_Replays_Post_Snapshot_Events()
{
var events = new List<DomainEvent>
{
new SomethingHappenedEvent{Sequence = 3},
new SomethingHappenedEvent{Sequence = 4},
};
var eventStore = new Mock<IEventStore>();
var snapshotStore = new Mock<ISnapshotStore>();
var resolver = new Mock<IDependencyResolver>();
eventStore.Setup(e => e.GetEvents(It.IsAny<Guid>(), It.IsAny<long>())).Returns(events);
eventStore.Setup(e => e.Insert(It.IsAny<Guid>(), It.IsAny<List<DomainEvent>>()));
snapshotStore.Setup(s => s.GetSnapshot<TestSnapshot>(It.IsAny<Guid>()))
.Returns(new Snapshot<TestSnapshot>(Guid.NewGuid(), 2, new TestSnapshot { Value = 99 }));
resolver.Setup(r => r.Resolve<IEventStore>()).Returns(eventStore.Object);
resolver.Setup(r => r.Resolve<ISnapshotStore>()).Returns(snapshotStore.Object);
resolver.Setup(r => r.Resolve<DomainRepository>())
.Returns(new DomainRepository(snapshotStore.Object, eventStore.Object));
var context = new CommandContext(resolver.Object);
var root = context.GetById<TestDomainWithSnapshot>(SequentialGuid.NewId());
Assert.AreEqual(4, root.Version);
Assert.AreEqual(0, root.AppliedEvents.Count);
}