public async Task Handle_FilesExist_WriteNoFiles( [Frozen] Mock <IMediator> mediatorMock, [Frozen] Mock <IFileWriter> fileWriterMock, StoreProductPhotosCommandHandler sut, StoreProductPhotosCommand command, List <ProductWithPhotoDto> products ) { // Arrange mediatorMock.Setup(_ => _.Send( It.IsAny <GetAllProductsWithPhotosQuery>(), It.IsAny <CancellationToken>() ) ) .ReturnsAsync(products); fileWriterMock.Setup(_ => _.FileExists(It.IsAny <string>())) .Returns(true); //Act var result = await sut.Handle(command, CancellationToken.None); //Assert fileWriterMock.Verify(_ => _.WriteFile( It.IsAny <string>(), It.IsAny <byte[]>() ), Times.Never ); }
public async Task Handle_WriteFilesFails_NoFilesWritten( [Frozen] Mock <IMediator> mediatorMock, [Frozen] Mock <IFileWriter> fileWriterMock, StoreProductPhotosCommandHandler sut, StoreProductPhotosCommand command, List <ProductWithPhotoDto> products ) { // Arrange mediatorMock.Setup(_ => _.Send( It.IsAny <GetAllProductsWithPhotosQuery>(), It.IsAny <CancellationToken>() ) ) .ReturnsAsync(products); fileWriterMock.Setup(_ => _.WriteFile( It.IsAny <string>(), It.IsAny <byte[]>() ) ) .Throws <IOException>(); //Act var result = await sut.Handle(command, CancellationToken.None); //Assert fileWriterMock.Verify(_ => _.WriteFile( It.IsAny <string>(), It.IsAny <byte[]>() ), Times.Exactly(products.Count * 3 * 2) // 3 products * 3 photos * 2 (thumbnail + large photo) ); }