コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }