Esempio n. 1
0
 public async Task <ActionResult <IEnumerable <CustomerModel> > > Search([FromQuery] string searchPhrase)
 {
     try
     {
         return(Ok(await _customerBusinessLayer.SearchCustomersAsync(searchPhrase)));
     }
     catch (Exception ex)
     {
         _logger.LogInformation(ex, $"Error occured for search term '{searchPhrase}'");
         return(BadRequest());
     }
 }
        public void SearchCustomersAsync_CustomerNonExistant_ReturnsEmptyEnumerable()
        {
            CustomerBusinessLayer businessLayer = _fixture.CustomerBusinessLayer;
            string searchTerm = "John";
            IEnumerable <CustomerModel> customerModels       = _fixture.CustomerModels;
            IEnumerable <CustomerModel> customerModelsResult = Enumerable.Empty <CustomerModel>();

            Func <Task> test = async() =>
            {
                customerModelsResult = await businessLayer.SearchCustomersAsync(searchTerm);
            };

            test.Should()
            .NotThrow();

            customerModelsResult.Should()
            .BeEmpty();
        }
        public void SearchCustomersAsync_CustomerExistsForSearchTerm_ReturnsEnumerableOfCustomerModels()
        {
            CustomerBusinessLayer businessLayer = _fixture.CustomerBusinessLayer;
            string searchTerm = CustomerBusinessLayerTestFixture.SearchTerm;
            IEnumerable <CustomerModel> customerModels       = _fixture.CustomerModels;
            IEnumerable <CustomerModel> customerModelsResult = Enumerable.Empty <CustomerModel>();

            Func <Task> test = async() =>
            {
                customerModelsResult = await businessLayer.SearchCustomersAsync(searchTerm);
            };

            test.Should()
            .NotThrow();

            customerModelsResult.Should()
            .NotBeNullOrEmpty()
            .And
            .BeEquivalentTo(customerModels);
        }