public void SerializeStateTest(TodoTask.AggregateState state)
        {
            // act
            var serializedObject = JObject.Parse(_serializer.SerializeState(state));

            // assert
            Assert.Equal(state.ProjectId.Id, (int)serializedObject["projectId"]);
            Assert.Equal(TaskState.Created.ToString("G"), (string)serializedObject["taskState"]);
        }
        public void DeserializeStateTest(TodoTask.AggregateState state)
        {
            // arrange
            var serializedString = _serializer.SerializeState(state);

            // act
            var deserializedObject = _serializer.DeserializeState <TodoTask.AggregateState>(serializedString);

            // assert
            Assert.Equal(state.ProjectId.Id, deserializedObject.ProjectId.Id);
        }
 public void RestoreFromState_UpdatesStateAndVersionOfTheAggregate(
     [Frozen] AggregateVersion version,
     [Frozen] TodoTask.AggregateState state,
     [Frozen] TodoTaskId id,
     TestableAbstractAggregateRoot entity)
 {
     // assert
     Assert.Equal(id, entity.Id);
     Assert.Equal(version, entity.Version);
     Assert.Same(state, entity.State);
 }
示例#4
0
        public async Task LoadAsync_WhenStageWasUpdatedConcurrently_Throws(
            TodoTaskId id,
            TodoTask.AggregateState state)
        {
            // arrange
            await _stateStorage.PersistAsync(id, state, AggregateVersion.Emtpy, new Dictionary <string, object>(),
                                             CancellationToken.None);

            // act && assert
            await Assert.ThrowsAsync <StateWasConcurrentlyUpdatedException>(
                () => _stateStorage.PersistAsync(id, state, AggregateVersion.Emtpy.Increment(),
                                                 new Dictionary <string, object>(), CancellationToken.None));
        }
示例#5
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);
        }
示例#6
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);
        }
示例#7
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);
        }
 public TodoTaskStateTests()
 {
     _state = new TodoTask.AggregateState();
 }