public void SearchCustomerReturnsListOfCustomers()
        {
            var options = new DbContextOptionsBuilder <SGDB2Context>()
                          .UseInMemoryDatabase(databaseName: "SGDB2")
                          .Options;

            using (var context = new SGDB2Context(options))
            {
                var result = StoreMethods.GetSearchResults("a", context);
                Assert.IsType <List <Customers> >(result);
            }
        }//4
        public void SearchCustomerReturnsEmptyListOfCustomers()
        {
            var options = new DbContextOptionsBuilder <SGDB2Context>()
                          .UseInMemoryDatabase(databaseName: "SGDB2")
                          .Options;

            using (var context = new SGDB2Context(options))
            {
                List <Customers> result = StoreMethods.GetSearchResults("", context);
                int isEmpty             = result.Count;
                Assert.True(isEmpty == 0);
            }
        }//2
예제 #3
0
        /// <summary>
        /// Returns the results of the user search
        /// </summary>
        /// <returns>List of search results ordered by last name</returns>
        public IActionResult _ListSearchResults(string name)
        {
            //TODO Add an alert if the search results are EMPTY (no matches)

            //Find all the matches, order by last name
            var result = StoreMethods.GetSearchResults(name, _db);

            if (result.Count == 0)
            {
                _logger.LogInformation("No results were found");
                return(View(result));
            }
            else
            {
                _logger.LogInformation("Results were found");
                return(View(result));
            }
        }
        public void SearchCustomerReturnsPopulatedListOfCustomers()
        {
            var options = new DbContextOptionsBuilder <SGDB2Context>()
                          .UseInMemoryDatabase(databaseName: "SGDB2")
                          .Options;

            using (var context = new SGDB2Context(options))
            {
                Customers customer = new Customers {
                    FirstName = "aaron", LastName = "aaronson"
                };
                context.Customers.Add(customer);
                context.SaveChanges();

                List <Customers> result = StoreMethods.GetSearchResults("a", context);
                int isEmpty             = result.Count;
                Assert.False(isEmpty == 0);
            }
        }//3