Пример #1
0
        public void TestGetStoreLocationFromItem()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <Project1Context>()
                          .UseInMemoryDatabase(databaseName: "Test7")
                          .Options;
            StoreLocation storeLocation = new StoreLocation()
            {
                Location = "Houston"
            };
            StoreItem storeItem = new StoreItem()
            {
                itemName  = "Chicken",
                itemPrice = 5
            };
            string checkLocation;
            int    userOrderId = 1;

            //Act
            using (var db3 = new Project1Context(options))
            {
                storeItem.StoreLocation = storeLocation;
                db3.AddRange(storeLocation, storeItem);
                db3.SaveChanges();
                //retrieving the locational information from item
                checkLocation = db3.StoreItems.Include(x => x.StoreLocation)
                                .First(x => x.StoreItemId == userOrderId).StoreLocation.Location;
            }
            //Assert
            using (var db3 = new Project1Context(options))
            {
                //if relationship stands, the checkLocation should return Houston
                Assert.Equal("Houston", checkLocation);
            }
        }
Пример #2
0
 public Users Get(int id)
 {
     using (Project1Context entities = new Project1Context())
     {
         return(entities.Users.FirstOrDefault(u => u.UserID == id));
     }
 }
Пример #3
0
        public async Task <List <Accounts> > GetChecking(Project1Context c, string userId)
        {
            var             _repo = new AccountsRepo(c);
            List <Accounts> all   = await _repo.GetAll(userId);

            return(all.Where(a => a.Type.Id == _repo.GetTypeId("Checking")).ToList());
        }
        public void GetAllAddressWithNoAddressShouldReturnNull()
        {
            // arrange (use the context directly - we assume that works)
            var options = new DbContextOptionsBuilder <Project1Context>()
                          .UseInMemoryDatabase("db_customer_test_create_address_2").Options;

            using (var db = new Project1Context(options));

            // act (for act, only use the repo, to test it)
            using (var db = new Project1Context(options))
            {
                var       repo     = new CustomerRepository(db);
                Customers customer = new Customers {
                    FirstName = "First Name", LastName = "Last Name"
                };

                repo.Save(customer);
                repo.SaveChanges();
            }

            // assert (for assert, once again use the context directly for verify.)
            using (var db = new Project1Context(options))
            {
                Customers        customer  = db.Customers.Include(m => m.Addresses).First(m => m.FirstName == "First Name" && m.LastName == "Last Name");
                List <Addresses> addresses = customer.Addresses.ToList();

                Assert.Empty(addresses);
            }
        }
        public void GetAllAddress()
        {
            List <Addresses> listAddresses = new List <Addresses>();

            // arrange (use the context directly - we assume that works)
            var options = new DbContextOptionsBuilder <Project1Context>()
                          .UseInMemoryDatabase("db_customer_test_create_address").Options;

            using (var db = new Project1Context(options));

            // act (for act, only use the repo, to test it)
            using (var db = new Project1Context(options))
            {
                var       repo     = new CustomerRepository(db);
                Customers customer = new Customers {
                    FirstName = "First Name", LastName = "Last Name"
                };

                Addresses address = new Addresses {
                    CustomerId = customer.Id, Address1 = "Address 1", City = "City 1", State = "S1", Zipcode = 12345
                };
                customer.Addresses.Add(address);
                listAddresses.Add(address);

                address = new Addresses {
                    CustomerId = customer.Id, Address1 = "Address 2", City = "City 2", State = "S2", Zipcode = 12345
                };
                customer.Addresses.Add(address);
                listAddresses.Add(address);

                address = new Addresses {
                    CustomerId = customer.Id, Address1 = "Address 3", City = "City 3", State = "S3", Zipcode = 12345
                };
                customer.Addresses.Add(address);
                listAddresses.Add(address);

                repo.Save(customer);
                repo.SaveChanges();
            }

            // assert (for assert, once again use the context directly for verify.)
            using (var db = new Project1Context(options))
            {
                Customers        customer  = db.Customers.Include(m => m.Addresses).First(m => m.FirstName == "First Name" && m.LastName == "Last Name");
                List <Addresses> addresses = customer.Addresses.ToList();

                Assert.Equal(listAddresses.Count, addresses.Count);

                for (int i = 0; i < addresses.Count; i++)
                {
                    Assert.NotEqual(0, addresses[i].Id);
                    Assert.Equal(customer.Id, addresses[i].CustomerId);
                    Assert.Equal(listAddresses[i].Address1, addresses[i].Address1);
                    Assert.Equal(listAddresses[i].Address2, addresses[i].Address2);
                    Assert.Equal(listAddresses[i].City, addresses[i].City);
                    Assert.Equal(listAddresses[i].State, addresses[i].State);
                    Assert.Equal(listAddresses[i].Zipcode, addresses[i].Zipcode);
                }
            }
        }
        public void GetByIdWorks()
        {
            int id = 0;

            // arrange (use the context directly - we assume that works)
            var options = new DbContextOptionsBuilder <Project1Context>()
                          .UseInMemoryDatabase("db_customer_test_getById").Options;

            using (var db = new Project1Context(options));

            // act (for act, only use the repo, to test it)
            using (var db = new Project1Context(options))
            {
                var repo = new CustomerRepository(db);

                Customers customer = new Customers {
                    FirstName = "First Name", LastName = "Last Name"
                };
                repo.Save(customer);
                repo.SaveChanges();
                id = customer.Id;
            }

            // assert (for assert, once again use the context directly for verify.)
            using (var db = new Project1Context(options))
            {
                var       repo     = new CustomerRepository(db);
                Customers customer = (Customers)repo.GetById(id);

                Assert.Equal("First Name", customer.FirstName);
                Assert.Equal("Last Name", customer.LastName);
                Assert.NotEqual(0, customer.Id); // should get some generated ID
            }
        }
Пример #7
0
        public void TestHomeControllerLocation()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <Project1Context>()
                          .UseInMemoryDatabase(databaseName: "Test17")
                          .Options;
            StoreLocation storeLocation = new StoreLocation()
            {
                Location = "Houston"
            };
            IEnumerable <StoreLocation> locations;

            using (var db1 = new Project1Context(options))
            {
                db1.Add(storeLocation);
                db1.SaveChanges();
                locations = db1.StoreLocations;
            }
            var mock = new Mock <IRepoStoreLocation>();

            mock.Setup(x => x.GetAllStoreLocations()).Returns(locations);
            var controller = new HomeController(null, null, mock.Object, null, null, null);
            //Act
            var actual = controller.Location();
            //Assert
            var viewResult = Assert.IsAssignableFrom <ViewResult>(actual);
            var list       = Assert.IsAssignableFrom <IEnumerable <StoreLocation> >(viewResult.Model);
        }
        public void DeleteWithIdThatDoesntExistThrowsException()
        {
            int id = 1000;
            // arrange (use the context directly - we assume that works)
            var options = new DbContextOptionsBuilder <Project1Context>()
                          .UseInMemoryDatabase("db__ingredient_test_delete").Options;

            using (var db = new Project1Context(options));

            // act (for act, only use the repo, to test it)

            /*using (var db = new Project1Context(options))
             * {
             *  var repo = new IngredientRepository(db);
             *
             *  Ingredients ingredient = new Ingredients { Name = "Test Delete", Stock = 10 };
             *  repo.Save(ingredient);
             *  repo.SaveChanges();
             *  id = ingredient.Id;
             * }*/

            // assert (for assert, once again use the context directly for verify.)
            using (var db = new Project1Context(options))
            {
                var         repo       = new IngredientRepository(db);
                Ingredients ingredient = (Ingredients)repo.GetById(id);

                Assert.Null(ingredient);

                Assert.Throws <ArgumentException>(() => repo.Delete(id));
            }
        }
Пример #9
0
        public ActionResult Login(Users account, FormCollection form, int?id, bool rememberMe = false)
        {
            Session["degrees"] = id;
            //Session["userID"] = userid;

            using (Project1Context db = new Project1Context())
            {
                //var usr = db.user.Single(u => u.userEmail = account.userEmail && u.uPassword == account.uPassword).FirstOrDefault;
                var usr = db.User.Where(Users => Users.Email == account.Email && Users.Password == account.Password).FirstOrDefault();
                if (usr != null)
                {
                    Session["UserID"]   = usr.UserID.ToString();
                    Session["username"] = usr.Email.ToString();
                    FormsAuthentication.SetAuthCookie(usr.Email, rememberMe);
                    return(RedirectToAction("Degrees", "Home", new { id = Session["degrees"], userid = Session["UserID"] }));
                    // return RedirectToAction("Index", "MissionQuestions", new { id = Session["mission"] });
                }
                else
                {
                    ModelState.AddModelError(" ", "Username or password is wrong. ");
                    // return RedirectToAction("Index");
                }
            }
            return(View());
        }
Пример #10
0
        public ActionResult Degrees(Project1Context filtercontext, string type)
        {
            ViewBag.Type = type;
            ViewBag.Form = "<div class=\"row\"> <div class=\"col-xs-2\">Post any questions here:</div><div class=\"col-xs-3\"><fieldset><div><textarea rows=\"6\" cols=\"50\">Enter Question...</textarea></div></fieldset></div><div class=\"col-xs-1\"><br><br><br><br><br><button>Post</button></div><div class=\"col-xs-2\">Post any answers here:</div><div class=\"col-xs-3\"><fieldset><div><textarea rows=\"6\" cols=\"50\">Enter Answer...</textarea></div></fieldset></div><div class=\"col-xs-1\"><br><br><br><br><br><button>Post</button></div>";
            if (type.Equals("Masters"))
            {
                ViewBag.DegreeName = "Master's In Information Systems Management";
                ViewBag.DegreeCoor = "Dr. Bonnie Anderson";
                ViewBag.Title      = "Doctor";
                ViewBag.Office     = "776 TNRB";
                ViewBag.PhD        = "Information Systems, Carnegie Mellon University, 2001";
                ViewBag.Masters    = "MAcc, Information Systems, Brigham Young University, 1995";
                ViewBag.Bachelors  = "BS, Accounting, Brigham Young University, 1995";
                ViewBag.Admit      = "60";
                ViewBag.Img        = Url.Content("../../Content/Images/Bonnie.jpg");
            }

            else if (type.Equals("Bachelors"))
            {
                ViewBag.DegreeName = "Bachelor's in Information Systems";
                ViewBag.DegreeCoor = "Dr. Conan Albrecht";
                ViewBag.Title      = "Doctor";
                ViewBag.Office     = "780 TNRB";
                ViewBag.PhD        = "HardKnox University";
                ViewBag.Masters    = "Brigham Young University";
                ViewBag.Bachelors  = "Brigham Young University";
                ViewBag.Admit      = "120";
                ViewBag.Img        = Url.Content("../../Content/Images/ConanAlbrect.jpg");
            }

            return(View(db.Responses.ToList()));
        }
        public void GetByNameThatDoesntExistsReturnsNull()
        {
            string name = "Not existing name";

            // arrange (use the context directly - we assume that works)
            var options = new DbContextOptionsBuilder <Project1Context>()
                          .UseInMemoryDatabase("db__ingredient_test_getByName").Options;

            using (var db = new Project1Context(options));

            // act (for act, only use the repo, to test it)
            using (var db = new Project1Context(options))
            {
                var repo = new IngredientRepository(db);

                Ingredients ingredient = new Ingredients {
                    Name = "Test By Name", Stock = 10
                };
                repo.Save(ingredient);
                repo.SaveChanges();
            }

            // assert (for assert, once again use the context directly for verify.)
            using (var db = new Project1Context(options))
            {
                var repo = new IngredientRepository(db);
                List <Ingredients> listIngredients = (List <Ingredients>)repo.GetByName(name);

                Assert.Empty(listIngredients);
            }
        }
Пример #12
0
        public void GetLocationsWorks()
        {
            // arrange
            var options = new DbContextOptionsBuilder <Project1Context>().UseInMemoryDatabase("get_locations_test").Options;

            using (var db = new Project1Context(options))
            {
                db.Location.Add(new DataAccess.Location {
                    Name = "a"
                });
                db.Location.Add(new DataAccess.Location {
                    Name = "b"
                });

                db.SaveChanges();
            }

            List <Library.Location> locations = new List <Library.Location>();

            using (var db = new Project1Context(options))
            {
                //nothing
                var repo = new DataRepository(db);
                locations = repo.GetLocations();
            }
            Assert.Equal("a", locations[0].Name);
            Assert.Equal("b", locations[1].Name);
        }
        public void CreateIngredientsWorks()
        {
            // arrange (use the context directly - we assume that works)
            var options = new DbContextOptionsBuilder <Project1Context>()
                          .UseInMemoryDatabase("db__ingredient_test_create").Options;

            using (var db = new Project1Context(options));

            // act (for act, only use the repo, to test it)
            using (var db = new Project1Context(options))
            {
                var         repo       = new IngredientRepository(db);
                Ingredients ingredient = new Ingredients {
                    Name = "Test", Stock = 10
                };
                repo.Save(ingredient);
                repo.SaveChanges();
            }

            // assert (for assert, once again use the context directly for verify.)
            using (var db = new Project1Context(options))
            {
                Ingredients ingredient = db.Ingredients.First(m => m.Name == "Test");
                Assert.Equal("Test", ingredient.Name);
                Assert.Equal(10, ingredient.Stock);
                Assert.NotEqual(0, ingredient.Id); // should get some generated ID
            }
        }
        public void DeleteWithIdThatDoesntExistThrowsException()
        {
            int id = 1000;
            // arrange (use the context directly - we assume that works)
            var options = new DbContextOptionsBuilder <Project1Context>()
                          .UseInMemoryDatabase("db_pizza_test_delete").Options;

            using (var db = new Project1Context(options));

            // act (for act, only use the repo, to test it)
            //using (var db = new Project1Context(options))
            //{
            //var repo = new PizzaRepository(db);

            //Pizzas Pizza = new Pizzas { Name = "Test Delete", Stock = 10 };
            //repo.Save(Pizza);
            //repo.SaveChanges();
            //id = Pizza.Id;
            //}

            // assert (for assert, once again use the context directly for verify.)
            using (var db = new Project1Context(options))
            {
                var    repo  = new PizzaRepository(db);
                Pizzas Pizza = (Pizzas)repo.GetById(id);

                Assert.Null(Pizza);

                Assert.Throws <ArgumentException>(() => repo.Delete(id));
            }
        }
Пример #15
0
        public void GetUsersWorks()
        {
            // arrange
            var options = new DbContextOptionsBuilder <Project1Context>().UseInMemoryDatabase("get_users_test").Options;

            using (var db = new Project1Context(options))
            {
                db.User.Add(new DataAccess.User {
                    FirstName = "a", LastName = "b"
                });
                db.User.Add(new DataAccess.User {
                    FirstName = "c", LastName = "d"
                });

                db.SaveChanges();
            }

            List <Lib.User> users = new List <Lib.User>();

            using (var db = new Project1Context(options))
            {
                //nothing
                var repo = new DataRepository(db);
                users = repo.GetUsers();
            }
            Assert.Equal("a", users[0].FirstName);
            Assert.Equal("b", users[0].LastName);
            Assert.Equal("c", users[1].FirstName);
            Assert.Equal("d", users[1].LastName);
        }
Пример #16
0
 public IEnumerable <Users> Get()
 {
     using (Project1Context entities = new Project1Context())
     {
         return(entities.Users.ToList());
     }
 }
Пример #17
0
        public void CheckAddsLocationToDbTestPersist()
        {
            //Test1
            //Arrange
            var options = new DbContextOptionsBuilder <Project1Context>()
                          .UseInMemoryDatabase(databaseName: "Test1")
                          .Options;

            //Act
            using (var db = new Project1Context(options))
            {
                // adds location to the table
                db.StoreLocations.Add(new StoreLocation {
                    Location = "Houston"
                });
                db.StoreLocations.Add(new StoreLocation {
                    Location = "Dallas"
                });
                db.SaveChanges();
            }
            //Assert
            using (var db = new Project1Context(options))
            {
                //counts the total locations in the location table
                Assert.Equal(2, db.StoreLocations.Count());
                //select the first location in table
                Assert.Equal("Houston", db.StoreLocations.First(x => x.StoreLocationId == 1).Location);
            }
        }
        public void GetByIdWorks()
        {
            int id = 0;

            // arrange (use the context directly - we assume that works)
            var options = new DbContextOptionsBuilder <Project1Context>()
                          .UseInMemoryDatabase("db__ingredient_test_getById").Options;

            using (var db = new Project1Context(options));

            // act (for act, only use the repo, to test it)
            using (var db = new Project1Context(options))
            {
                var repo = new IngredientRepository(db);

                Ingredients ingredient = new Ingredients {
                    Name = "Test By Id", Stock = 10
                };
                repo.Save(ingredient);
                repo.SaveChanges();
                id = ingredient.Id;
            }

            // assert (for assert, once again use the context directly for verify.)
            using (var db = new Project1Context(options))
            {
                var         repo       = new IngredientRepository(db);
                Ingredients ingredient = (Ingredients)repo.GetById(id);

                Assert.NotEqual(0, ingredient.Id);
                Assert.Equal("Test By Id", ingredient.Name);
                Assert.Equal(10, ingredient.Stock);
            }
        }
Пример #19
0
        public AddressRepository(Project1Context db)
        {
            _db = db ?? throw new ArgumentNullException(nameof(db));

            // code-first style, make sure the database exists by now.
            db.Database.EnsureCreated();
        }
Пример #20
0
        public void GetByIdThatDoesntExistReturnsNull()
        {
            int id = 100;

            // arrange (use the context directly - we assume that works)
            var options = new DbContextOptionsBuilder <Project1Context>()
                          .UseInMemoryDatabase("db_address_test_getById").Options;

            using (var db = new Project1Context(options));

            // act (for act, only use the repo, to test it)
            //using (var db = new Project1Context(options))
            //{
            //var repo = new AddressRepository(db);

            //Addresses Address = new Addresses { Name = "Test By Id", Stock = 10 };
            //repo.Save(Address);
            //repo.SaveChanges();
            //id = Address.Id;
            //}

            // assert (for assert, once again use the context directly for verify.)
            using (var db = new Project1Context(options))
            {
                var       repo    = new AddressRepository(db);
                Addresses Address = (Addresses)repo.GetById(id);

                Assert.Null(Address);
            }
        }
Пример #21
0
 public BaseController(Project1Context context = null)
 {
     if (context != null)
     {
         _context = new Project1Context();
     }
 }
        public void GetByNameWorks()
        {
            List <Customers> inserted  = new List <Customers>();
            string           name      = "Test";
            string           nameWrong = "Name";
            int id = 0;

            // arrange (use the context directly - we assume that works)
            var options = new DbContextOptionsBuilder <Project1Context>()
                          .UseInMemoryDatabase("db_customer_test_getByName_List").Options;

            using (var db = new Project1Context(options));

            // act (for act, only use the repo, to test it)
            using (var db = new Project1Context(options))
            {
                var repo = new CustomerRepository(db);

                Customers customer = new Customers {
                    FirstName = "First Test", LastName = "Last"
                };
                repo.Save(customer);
                inserted.Add(customer);

                customer = new Customers {
                    FirstName = "First", LastName = "Last Test"
                };
                repo.Save(customer);
                inserted.Add(customer);

                customer = new Customers {
                    FirstName = "First Name", LastName = "Last Name"
                };
                repo.Save(customer);
                inserted.Add(customer);

                repo.SaveChanges();
            }

            // assert (for assert, once again use the context directly for verify.)
            using (var db = new Project1Context(options))
            {
                var repo = new CustomerRepository(db);
                List <Customers> list = (List <Customers>)repo.GetByName(name);

                Assert.Equal(2, list.Count);

                foreach (Customers customer in list)
                {
                    Assert.NotEqual(0, customer.Id);
                    Assert.DoesNotContain(nameWrong, customer.FirstName);
                    Assert.DoesNotContain(nameWrong, customer.LastName);

                    //Assert if the string searched is contained in FirstName OR LastName
                    bool contains = customer.FirstName.Contains(name) || customer.LastName.Contains(name);
                    Assert.True(contains);
                }
            }
        }
Пример #23
0
        public void UpdateWithWorngIdShouldReturnException()
        {
            int id      = 0;
            int idWrong = 1000;

            // arrange (use the context directly - we assume that works)
            var options = new DbContextOptionsBuilder <Project1Context>()
                          .UseInMemoryDatabase("db_address_test_delete").Options;

            using (var db = new Project1Context(options));

            // act (for act, only use the repo, to test it)
            using (var db = new Project1Context(options))
            {
                var customerRepo = new CustomerRepository(db);
                var repo         = new AddressRepository(db);

                //Create customer
                Customers customer = new Customers {
                    FirstName = "First Name", LastName = "Last Name"
                };
                customerRepo.Save(customer);
                customerRepo.SaveChanges();

                Addresses address = new Addresses
                {
                    CustomerId = customer.Id,
                    Address1   = "Ad1 Test",
                    City       = "City",
                    State      = "ST",
                    Zipcode    = 12345
                };
                repo.Save(address);
                customerRepo.SaveChanges();
                id = address.Id;
            }

            // assert (for assert, once again use the context directly for verify.)
            using (var db = new Project1Context(options))
            {
                var       repo    = new AddressRepository(db);
                Addresses address = (Addresses)repo.GetById(id);

                Assert.Equal(id, address.Id);
                Assert.Equal("Ad1 Test", address.Address1);
                Assert.Equal("City", address.City);
                Assert.Equal("ST", address.State);
                Assert.Equal(12345, address.Zipcode);

                address.Address1 = "Ad1 Test alt";
                address.City     = "City alt";
                address.State    = "AL";
                address.Zipcode  = 98765;

                Assert.Throws <ArgumentException>(() => repo.Save(address, idWrong));
            }
        }
Пример #24
0
 public AccountsController(Project1Context context, UserManager <YABUser> userManager, ILogger <AccountsController> logger)
 {
     _userManager = userManager;
     _logger      = logger;
     _context     = context;
     _arepo       = new AccountsRepo(context);     //TODO Remove
     _trepo       = new TransactionsRepo(context); //TODO Remove
     _bl          = new BL(context);
 }
Пример #25
0
        public void TestServSearchUserByName()
        {
            var options = new DbContextOptionsBuilder <Project1Context>()
                          .UseInMemoryDatabase(databaseName: "Test16")
                          .Options;
            UserInfo newUser = new UserInfo()
            {
                fName    = "david",
                lName    = "leblanc",
                userName = "******",
                password = "******"
            };
            UserInfo newUser1 = new UserInfo()
            {
                fName    = "james",
                lName    = "jones",
                userName = "******",
                password = "******"
            };
            string firstName = "James";
            string lastName  = "Jones";
            IEnumerable <UserInfo> name;
            SearchUserByNameModel  userOrder = new SearchUserByNameModel();

            //Act
            using (var db1 = new Project1Context(options))
            {
                //adds user to the table
                db1.Add(newUser);
                db1.Add(newUser1);
                db1.SaveChanges();
                name = db1.UserInfos;
                //if both first name and last name is empty display no name
                if (string.IsNullOrEmpty(firstName) && string.IsNullOrEmpty(lastName))
                {
                    name = name.Where(x => x.fName.Contains("0"));
                    userOrder.userInfos = name.ToList();
                }
                //if something is entered into first name search any first name that contain that letter
                else if (!string.IsNullOrEmpty(firstName))
                {
                    name = name.Where(x => x.fName.Contains(firstName.ToLower()));
                }
                //if something is entered into last name search any last name that contain that letter
                else if (!string.IsNullOrEmpty(lastName))
                {
                    name = name.Where(x => x.lName.Contains(lastName.ToLower()));
                }
                //store the list of names that match into a list
                userOrder.userInfos = name.ToList();
            }
            var selectedName = userOrder.userInfos.First().fName;

            //Assert
            Assert.Equal("james", selectedName);
        }
        public void GetByNameWorks()
        {
            List <Ingredients> inserted  = new List <Ingredients>();
            string             name      = "Test";
            string             nameWrong = "Name 3";
            int id = 0;

            // arrange (use the context directly - we assume that works)
            var options = new DbContextOptionsBuilder <Project1Context>()
                          .UseInMemoryDatabase("db__ingredient_test_getByName_List").Options;

            using (var db = new Project1Context(options));

            // act (for act, only use the repo, to test it)
            using (var db = new Project1Context(options))
            {
                var repo = new IngredientRepository(db);

                Ingredients ingredient = new Ingredients {
                    Name = "Test By Name", Stock = 10
                };
                repo.Save(ingredient);
                inserted.Add(ingredient);

                ingredient = new Ingredients {
                    Name = "Test By Name 2", Stock = 10
                };
                repo.Save(ingredient);
                inserted.Add(ingredient);

                ingredient = new Ingredients {
                    Name = "Name 3", Stock = 10
                };
                repo.Save(ingredient);
                inserted.Add(ingredient);

                repo.SaveChanges();
            }

            // assert (for assert, once again use the context directly for verify.)
            using (var db = new Project1Context(options))
            {
                var repo = new IngredientRepository(db);
                List <Ingredients> list = (List <Ingredients>)repo.GetByName(name);

                Assert.Equal(2, list.Count);

                foreach (Ingredients ingredient in list)
                {
                    Assert.NotEqual(0, ingredient.Id);
                    Assert.NotEqual(nameWrong, ingredient.Name);
                    Assert.Contains(name, ingredient.Name);
                    Assert.Equal(10, ingredient.Stock);
                }
            }
        }
Пример #27
0
        public void DeleteWorks()
        {
            int id = 0;

            // arrange (use the context directly - we assume that works)
            var options = new DbContextOptionsBuilder <Project1Context>()
                          .UseInMemoryDatabase("db_address_test_delete").Options;

            using (var db = new Project1Context(options));

            // act (for act, only use the repo, to test it)
            using (var db = new Project1Context(options))
            {
                var customerRepo = new CustomerRepository(db);
                var repo         = new AddressRepository(db);

                //Create customer
                Customers customer = new Customers {
                    FirstName = "First Name", LastName = "Last Name"
                };
                customerRepo.Save(customer);
                customerRepo.SaveChanges();

                Addresses address = new Addresses
                {
                    CustomerId = customer.Id,
                    Address1   = "Ad1 Test Delete",
                    City       = "City Delete",
                    State      = "ST",
                    Zipcode    = 12345
                };
                repo.Save(address);
                customerRepo.SaveChanges();
                id = address.Id;
            }

            // assert (for assert, once again use the context directly for verify.)
            using (var db = new Project1Context(options))
            {
                var       repo    = new AddressRepository(db);
                Addresses address = (Addresses)repo.GetById(id);

                Assert.Equal(id, address.Id);
                Assert.Equal("Ad1 Test Delete", address.Address1);
                Assert.Equal("City Delete", address.City);
                Assert.Equal("ST", address.State);
                Assert.Equal(12345, address.Zipcode);

                repo.Delete(id);
                repo.SaveChanges();
                address = (Addresses)repo.GetById(id);

                Assert.Null(address);
            }
        }
Пример #28
0
        public void TestAddUserOrderToDb()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <Project1Context>()
                          .UseInMemoryDatabase(databaseName: "Test10")
                          .Options;
            UserInfo userInfo = new UserInfo()
            {
                fName    = "David",
                lName    = "Leblanc",
                userName = "******",
                password = "******"
            };
            StoreLocation storeLocation = new StoreLocation()
            {
                Location = "Houston"
            };
            StoreItem storeItem = new StoreItem()
            {
                itemName  = "Chicken",
                itemPrice = 5
            };

            storeItem.StoreLocation = storeLocation;
            int userOrderId;

            //Act
            using (var db3 = new Project1Context(options))
            {
                db3.AddRange(userInfo, storeLocation, storeItem);
                db3.SaveChanges();
                //retrieves user information from username
                var aUserInfo = db3.UserInfos.First(x => x.userName == userInfo.userName);
                //retrieves store location from store item id
                var location = db3.StoreLocations
                               .First(x => x.StoreLocationId == db3.StoreItems.Include(x => x.StoreLocation)
                                      .First(x => x.StoreItemId == 1).StoreLocation.StoreLocationId);
                var newOrder = new UserOrder
                {
                    UserInfo      = aUserInfo,
                    StoreLocation = location,
                    timeStamp     = DateTime.Now
                };
                db3.Add(newOrder);
                db3.SaveChanges();
                userOrderId = db3.UserOrders.First().UserOrderId;
            }
            //Assert
            using (var db3 = new Project1Context(options))
            {
                //checks if an order exists within the database
                Assert.Equal(1, userOrderId);
            }
        }
        public void UpdateWithWorngIdShouldReturnException()
        {
            int id      = 0;
            int idWrong = 1000;

            // arrange (use the context directly - we assume that works)
            var options = new DbContextOptionsBuilder <Project1Context>()
                          .UseInMemoryDatabase("db_pizza_test_delete").Options;

            using (var db = new Project1Context(options));

            // act (for act, only use the repo, to test it)
            using (var db = new Project1Context(options))
            {
                var repo = new PizzaRepository(db);
                var ingredientRepository = new IngredientRepository(db);

                Ingredients ingredient = new Ingredients()
                {
                    Name = "Ingredient", Stock = 10
                };
                ingredientRepository.Save(ingredient);
                ingredientRepository.SaveChanges();

                Pizzas pizza = new Pizzas
                {
                    Name  = "Pizza 1",
                    Price = 20,
                };
                pizza.PizzasIngredients.Add(new PizzasIngredients()
                {
                    IngredientId = ingredient.Id
                });
                repo.Save(pizza);
                repo.SaveChanges();
                id = pizza.Id;
            }

            // assert (for assert, once again use the context directly for verify.)
            using (var db = new Project1Context(options))
            {
                var    repo  = new PizzaRepository(db);
                Pizzas pizza = (Pizzas)repo.GetById(id);

                Assert.NotEqual(0, pizza.Id);
                Assert.Equal("Pizza 1", pizza.Name);
                Assert.Equal(20, pizza.Price);

                pizza.Name  = "Pizza 1 alt";
                pizza.Price = 40;

                Assert.Throws <ArgumentException>(() => repo.Save(pizza, idWrong));
            }
        }
Пример #30
0
 public DeletePersonalDataModel(
     UserManager <YABUser> userManager,
     SignInManager <YABUser> signInManager,
     Project1Context context,
     ILogger <DeletePersonalDataModel> logger)
 {
     _userManager   = userManager;
     _signInManager = signInManager;
     _logger        = logger;
     _custRepo      = new CustomersRepo(context);
 }