public void Equals_ForTheSameTaskReturnsTrue(TodoTaskId taskId) { Assert.Equal(taskId, taskId); Assert.True(taskId == new TodoTaskId(taskId.Id)); Assert.False(taskId != new TodoTaskId(taskId.Id)); Assert.True(taskId.Equals(new TodoTaskId(taskId.Id))); }
public void Equals_ForDifferentTasksReturnsFalse(TodoTaskId task1, TodoTaskId task2) { Assert.NotEqual(task1, task2); Assert.False(task1 == task2); Assert.True(task1 != task2); Assert.False(task1.Equals(task2)); }
public async Task LoadAsync_WhenTheStateDoesNotExists_ReturnsEmptyVersion(TodoTaskId id) { // act var(version, _) = await _stateStorage.LoadAsync <TodoTask.AggregateState>(id, CancellationToken.None); // assert Assert.True(AggregateVersion.IsEmpty(version)); }
public void Equals_ForDifferentEntityIdentityTypesReturnsFalse(TodoTaskId task, ProjectId project) { var taskIdentity = task as IEntityIdentity; var projectIdentity = project as IEntityIdentity; Assert.NotEqual(taskIdentity, projectIdentity); Assert.False(taskIdentity.Equals(projectIdentity)); }
public void Constructor_FromTheValue(int id) { // arrange var taskId = new TodoTaskId(id); // act && assert Assert.Equal(id, taskId.Id); Assert.Equal(id.ToString(), taskId.Value); }
public async Task FindByIdAsync_WhenStateDoesNotExist_ReturnsNull( [Frozen] Mock <IAggregateStateStorage> stateStorageMock, TodoTaskId todoTaskId, TodoTaskRepository repository) { // arrange stateStorageMock .Setup(self => self.LoadAsync <TodoTask.AggregateState>(todoTaskId, It.IsAny <CancellationToken>())) .ReturnsAsync((AggregateVersion.Emtpy, default));
public void Create_TaskIdPropertyReturnsTheCorrectValue( [Frozen] TodoTaskId taskId, ProjectId projectId) { // act _task.Create(taskId, projectId); // assert Assert.IsType <TodoTaskId>(_task.Id); Assert.Equal(taskId, _task.Id); }
public void Equals_ForDifferentAbstractEntityIdentitySubTypesReturnsFalse(TodoTaskId task, ProjectId project) { var taskIdentity = task as AbstractEntityIdentity <int>; var projectIdentity = project as AbstractEntityIdentity <int>; Assert.NotEqual(taskIdentity, projectIdentity); Assert.False(taskIdentity == projectIdentity); Assert.True(taskIdentity != projectIdentity); Assert.False(taskIdentity.Equals(projectIdentity)); }
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); }
public void Complete_ForCompletedTask_DoesNotTriggerTaskCompletedEvent(TodoTaskId taskId, ProjectId projectId) { // arrange _task.Create(taskId, projectId); _task.Complete(); // act _task.Complete(); // assert Assert.Equal(1, _task.State.GetChanges().Count(evt => evt is TodoTaskCompleted)); }
public void MoveProject_WhenTheSameProjectIsPassed_DoesNotChangeProject(TodoTaskId taskId, ProjectId projectId) { // arrange _task.Create(taskId, projectId); // act _task.MoveToProject(projectId); // assert Assert.DoesNotContain( _task.State.GetChanges(), domainEvent => domainEvent is TodoTaskMoved); }
public void Create_TriggersTodoTaskCreated(TodoTaskId taskId, ProjectId projectId) { // act _task.Create(taskId, projectId); // assert Assert.Contains( _task.State.GetChanges(), domainEvent => domainEvent is TodoTaskCreated todoTaskCreated && todoTaskCreated.ProjectId == projectId && todoTaskCreated.TaskId == _task.Id); }
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)); }
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); }
private async Task <(DateTimeOffset, DateTimeOffset)> GetAuditDatesAsync(TodoTaskId taskId) { var getConfig = new GetItemOperationConfig { ConsistentRead = true }; var primaryKey = taskId.Tag + "_" + taskId.Value; const string headSortKeyValue = "HEAD"; var document = await _storageTable.GetItemAsync(primaryKey, headSortKeyValue, getConfig, CancellationToken.None); var createdAt1 = DateTimeOffset.FromUnixTimeMilliseconds((long)document["CreatedAt"]); var modifiedAt1 = DateTimeOffset.FromUnixTimeMilliseconds((long)document["UpdatedAt"]); return(createdAt1, modifiedAt1); }
public void MoveProject_WhenDifferentProjectIsPassed_ChangesProject( TodoTaskId taskId, ProjectId projectId, ProjectId newProjectId) { // arrange _task.Create(taskId, projectId); // act _task.MoveToProject(newProjectId); // assert Assert.Contains( _task.State.GetChanges(), domainEvent => domainEvent is TodoTaskMoved todoTaskMoved && todoTaskMoved.OldProjectId == projectId && todoTaskMoved.NewProjectId == newProjectId && todoTaskMoved.TaskId == _task.Id); }
public void Constructor_FromIdentity(Mock <IEntityIdentity> identity, int id) { // arrange identity .SetupGet(self => self.Tag) .Returns("todo_task"); identity .SetupGet(self => self.Value) .Returns(id.ToString); // act var taskId = new TodoTaskId(identity.Object); // assert Assert.Equal(id, taskId.Id); Assert.Equal(id.ToString(), taskId.Value); }
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); }
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 void Equals_WhenTheValueIsComparedWithNull_ReturnsFalse(TodoTaskId task) { Assert.False(task.Equals(null)); }
public void Equals_ForTheSameInstanceReturnsTrue(TodoTaskId task) { Assert.Equal(task, task); Assert.True(task.Equals(task)); }
public Task <TodoTask> GetByIdAsync(TodoTaskId id, CancellationToken cancellationToken) { return(null); }