public async Task SearchAsync_NotValidParams_ReturnsEmptyArray(string search) { var repository = GetProductReadOnlyRepository(); var handler = new ProductQueriesHandler(repository); var result = await handler.SearchAsync(search); Assert.AreEqual(0, result.Length); }
public async Task GetAsync_NotValidId_ReturnsProduct(string id) { var repository = GetProductReadOnlyRepository(); var handler = new ProductQueriesHandler(repository); var result = await handler.GetAsync(id); Assert.IsNull(result); }
public void SearchAsync_OnInnerException_ThrowsSameException(string search) { var exception = new Exception(); var repositoryMock = new Mock <IProductReadOnlyRepository>(); repositoryMock.Setup(repository => repository.SearchAsync(search)).ThrowsAsync(exception); var handler = new ProductQueriesHandler(repositoryMock.Object); var result = Assert.ThrowsAsync(exception.GetType(), async() => await handler.SearchAsync(search)); Assert.AreEqual(exception, result); }
public async Task SearchAsync_ValidParams_ReturnsProducts(string search) { var products = GetProducts(); var repositoryMock = new Mock <IProductReadOnlyRepository>(); repositoryMock.Setup(repository => repository.SearchAsync(search)).ReturnsAsync(products); var handler = new ProductQueriesHandler(repositoryMock.Object); var result = await handler.SearchAsync(search); Assert.AreEqual(products, result); }
public async Task GetAllAsync_ReturnsAllProducts() { var products = GetProducts(); var repositoryMock = new Mock <IProductReadOnlyRepository>(); repositoryMock.Setup(repository => repository.GetAllAsync()).ReturnsAsync(products); var handler = new ProductQueriesHandler(repositoryMock.Object); var result = await handler.GetAllAsync(); Assert.AreEqual(products, result); }
public async Task GetAsync_ValidId_ReturnsRepositoryResult(string id, bool repositoryReturnsProduct) { var product = repositoryReturnsProduct ? GetProduct(id) : null; var repositoryMock = new Mock <IProductReadOnlyRepository>(); repositoryMock.Setup(repository => repository.GetAsync(id)).ReturnsAsync(product); var handler = new ProductQueriesHandler(repositoryMock.Object); var result = await handler.GetAsync(id); Assert.AreEqual(product, result); }