Exemple #1
0
        public async Task LoadAsync_CanReadPersistedState(TodoTaskId id, TodoTask.AggregateState state)
        {
            // arrange
            state.Mutate(new TodoTaskCompleted(id));
            await _stateStorage.PersistAsync(id, state, AggregateVersion.Emtpy, new Dictionary <string, object>(),
                                             CancellationToken.None);

            // act
            var(restoredVersion, restoredState) =
                await _stateStorage.LoadAsync <TodoTask.AggregateState>(id, CancellationToken.None);

            // assert
            Assert.Equal(state.ProjectId, restoredState.ProjectId);
            Assert.Equal(AggregateVersion.Emtpy.Increment(), restoredVersion);
        }
Exemple #2
0
        public async Task LoadAsync_WhenStateHasChanges_IncrementsVersion(
            TodoTaskId id,
            TodoTaskCreated todoTaskCreated,
            AggregateVersion originalVersion,
            TodoTask.AggregateState state)
        {
            // arrange
            state.Mutate(todoTaskCreated);

            await _stateStorage.PersistAsync(id, state, AggregateVersion.Emtpy, new Dictionary <string, object>(),
                                             CancellationToken.None);

            // act
            var(restoredVersion, restoredState) =
                await _stateStorage.LoadAsync <TodoTask.AggregateState>(id, CancellationToken.None);

            // assert
            Assert.Equal(state.ProjectId, restoredState.ProjectId);
            Assert.Equal(AggregateVersion.Emtpy.Increment(), restoredVersion);
        }
Exemple #3
0
        public async Task PersistedAsync_ShouldStoreCreatedAtAndUpdatedAt(TodoTaskId taskId, ProjectId projectId)
        {
            // arrange & act
            TodoTask.AggregateState state = new TodoTask.AggregateState();
            state.Mutate(new TodoTaskCreated(projectId, taskId));
            await _stateStorage.PersistAsync(taskId, state, AggregateVersion.Emtpy, new Dictionary <string, object>(), CancellationToken.None);

            var(createdAt1, updatedAt1) = await GetAuditDatesAsync(taskId);

            var(newVersion, newState) = await _stateStorage.LoadAsync <TodoTask.AggregateState>(taskId, CancellationToken.None);

            newState.Mutate(new TodoTaskCompleted(taskId));
            await _stateStorage.PersistAsync(taskId, newState, newVersion, new Dictionary <string, object>(), CancellationToken.None);

            var(createdAt2, updatedAt2) = await GetAuditDatesAsync(taskId);

            // assert
            Assert.Equal(createdAt1, createdAt2);
            Assert.True(updatedAt2 > updatedAt1);
            createdAt1.Should().BeCloseTo(DateTimeOffset.UtcNow, 1000);
            updatedAt2.Should().BeCloseTo(DateTimeOffset.UtcNow, 500);
        }