public async Task UsingTwiceSameImage_ForDifferentTasks_ReusesImage() { using (var connection = this._testInfrastructure.OpenDatabaseConnection()) { // Arrange var commandDispatcher = this._testInfrastructure.DiContainer.GetInstance <IMediator>(); var taskImagesRepository = new TaskImageRepository(); var newTask = await this.CreateNewTask(); var newTask2 = await this.CreateNewTask(); var fileName = "TestImage.jpg"; var filePath = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestResources", fileName); var attachImageCommand = new AttachFileToTaskCommand(newTask.TaskId, filePath); var attachImageCommand2 = new AttachFileToTaskCommand(newTask2.TaskId, filePath); // Act var resultTask1 = await commandDispatcher.Send(attachImageCommand); var resultTask2 = await commandDispatcher.Send(attachImageCommand2); // Assert var task1Images = await taskImagesRepository.GetImagesForTaskAsync(connection, newTask.TaskId); var task2Images = await taskImagesRepository.GetImagesForTaskAsync(connection, newTask2.TaskId); Assert.That(resultTask1.FileId, Is.EqualTo(resultTask2.FileId)); Assert.That(task1Images.Count, Is.EqualTo(task2Images.Count)); Assert.That(task1Images.Select(x => x.ImageId).SequenceEqual(task2Images.Select(x => x.ImageId)), Is.True); } }
public async Task AttachingImage_ToTask_ShouldCreateProjection() { // Arrange using (var connection = this._testInfrastructure.OpenDatabaseConnection()) { var commandDispatcher = this._testInfrastructure.DiContainer.GetInstance <IMediator>(); var repository = new TaskImageRepository(); var newTask = await this.CreateNewTask(); var fileName = "TestImage.jpg"; var filePath = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestResources", fileName); var attachImageCommand = new AttachFileToTaskCommand(newTask.TaskId, filePath); await commandDispatcher.Send(attachImageCommand); // Act var projection = await repository.GetImagesForTaskAsync(connection, newTask.TaskId); // Assert Assert.That(newTask.TaskId, Is.Not.EqualTo(Guid.Empty)); Assert.That(projection, Is.Not.Null); Assert.That(projection.Count, Is.EqualTo(3)); } }