当前位置: 首页>>代码示例>>C#>>正文


C# CommandContext.GetById方法代码示例

本文整理汇总了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);
        }
开发者ID:johnm25,项目名称:SeekU,代码行数:12,代码来源:CommandContextFixture.cs

示例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);
        }
开发者ID:johnm25,项目名称:SeekU,代码行数:16,代码来源:CommandContextFixture.cs

示例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);
        }
开发者ID:johnm25,项目名称:SeekU,代码行数:21,代码来源:CommandContextFixture.cs

示例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);
        }
开发者ID:johnm25,项目名称:SeekU,代码行数:46,代码来源:CommandContextFixture.cs

示例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);
        }
开发者ID:johnm25,项目名称:SeekU,代码行数:30,代码来源:CommandContextFixture.cs


注:本文中的CommandContext.GetById方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。