public Task StoreSnapshotAsync <TSnapshot>( ThingyId thingyId, int aggregateSequenceNumber, TSnapshot snapshot) where TSnapshot : ISnapshot { var snapshotDefinition = SnapshotDefinitionService.GetDefinition(typeof(TSnapshot)); var snapshotMetadata = new SnapshotMetadata { AggregateId = thingyId.Value, AggregateName = "ThingyAggregate", AggregateSequenceNumber = aggregateSequenceNumber, SnapshotName = snapshotDefinition.Name, SnapshotVersion = snapshotDefinition.Version, }; return(SnapshotPersistence.SetSnapshotAsync( typeof(ThingyAggregate), thingyId, new SerializedSnapshot( JsonConvert.SerializeObject(snapshotMetadata), JsonConvert.SerializeObject(snapshot), snapshotMetadata), CancellationToken.None)); }
public void DeleteSnapshotAsync_GetSnapshotAsync_NoneExistingSnapshotDoesNotThrow() { // Act + Assert Assert.DoesNotThrow(() => SnapshotPersistence.DeleteSnapshotAsync( typeof(ThingyAggregate), ThingyId.New, CancellationToken.None).Wait()); }
private static void Main(string[] args) { ObjectContainer.SetContainer(new AutofacContainerObject()); var applictionInitializer = new EventHandleProvider(); applictionInitializer.Initialize(Assembly.GetExecutingAssembly()); var commandInitializer = new CommandHandleProvider(); commandInitializer.Initialize(Assembly.GetExecutingAssembly()); ObjectContainer.RegisterInstance(applictionInitializer); ObjectContainer.RegisterInstance(commandInitializer); var dbConnection = new MySqlConnection(_mysqlConnection); var persistence = new SnapshotPersistence(dbConnection); var binarySerializer = new DefaultBinarySerializer(); var snapshotRepository = new SnapshotRepository(persistence, new SnapshotFactory(binarySerializer)); var eventPersistence = new EventStorePersistence(dbConnection); var eventFactory = new EventStreamFactory(binarySerializer); var eventStore = new EventStore(eventPersistence, eventFactory); IRepository repository = new EventSouringRepository(eventStore, snapshotRepository); var comamndHandler = ObjectContainer.Resolve<CommandHandleProvider>(); var changePasswordCommand = new ChangePasswordCommand("90ca0d59-65e6-403b-82c5-8df967cc8e22", "2222222", "11111"); var commandContext = new CommandContext(repository); var commandHanldeAction = comamndHandler.GetInternalCommandHandle(typeof(ChangePasswordCommand)); commandHanldeAction(commandContext, changePasswordCommand); var aggregateRoots = commandContext.AggregateRoots; IList<IEvent> unCommitEvents = null; foreach (var item in aggregateRoots) { unCommitEvents = item.Value.Commit(); } var aggregateRoot = aggregateRoots.FirstOrDefault().Value; eventStore.AppendToStream(aggregateRoot.AggregateRootId, new EventStream(aggregateRoot.Version, unCommitEvents)); snapshotRepository.Create(aggregateRoot); Console.WriteLine("改方法执行完毕..."); }
public async Task GetSnapshotAsync_NoneExistingSnapshotReturnsNull() { // Act var committedSnapshot = await SnapshotPersistence.GetSnapshotAsync( typeof(ThingyAggregate), ThingyId.New, CancellationToken.None) .ConfigureAwait(false); // Assert committedSnapshot.Should().BeNull(); }
public void PurgeSnapshotsAsync_EmptySnapshotStoreDoesNotThrow() { // Act + Assert Assert.DoesNotThrow(() => SnapshotPersistence.PurgeSnapshotsAsync(CancellationToken.None).Wait()); }
public void PurgeSnapshotsAsync_NoneExistingSnapshotDoesNotThrow() { // Act + Assert Assert.DoesNotThrow(() => SnapshotPersistence.PurgeSnapshotsAsync(typeof(ThingyAggregate), CancellationToken.None).Wait()); }