コード例 #1
0
        public void CreatingNewInventorySucceedsWithValidLocationAndIngredient()
        {
            // Arrange
            RepoTesting repo = new RepoTesting();

            repo.ResetDatabase("Inventory_Test_3");
            dbm.Location dbLocation = new dbm.Location {
                Id = 2, Name = "a"
            };
            dbm.Ingredient dbIngredient = new dbm.Ingredient {
                Id = 2, Name = "pepperoni", Price = 2.0m
            };
            repo.locationRepo.Create(dbLocation);
            repo.ingredientRepo.Create(dbIngredient);
            repo.SaveChanges();

            // Ensure the required entities exist
            Assert.NotNull(repo.locationRepo.GetById(dbLocation.Id));
            Assert.NotNull(repo.ingredientRepo.GetById(dbIngredient.Id));

            dbm.InventoryJunction dbInventory = new dbm.InventoryJunction
            {
                LocationId = dbLocation.Id, IngredientId = dbIngredient.Id, Count = 1
            };

            // Act
            // Create the new inventory
            repo.inventoryRepo.Create(dbInventory);

            // Assert
            // Searching for this inventory should now succeed
            Assert.NotNull(repo.inventoryRepo.GetById(dbLocation.Id, dbIngredient.Id));
        }
コード例 #2
0
        public void OrderDeleteRemovesFromOrderJunction()
        {
            // Arrange
            RepoTesting repo = new RepoTesting();

            repo.ResetDatabase("Order_Test_1");
            int orderId      = repo.dbOrder.Id;
            int pizzaId      = repo.dbPizza.PizzaId;
            int ingredientId = repo.dbIngredient.Id;

            // Ensure the entities exist
            Assert.NotNull(repo.orderRepo.GetById(orderId));
            Assert.NotNull(repo.pizzaRepo.GetById(pizzaId, ingredientId));
            Assert.NotNull(repo.orderJunctionRepo.GetById(orderId, pizzaId));

            // Act

            repo.orderRepo.Delete(repo.dbOrder);
            repo.SaveChanges();


            // Assert
            // Order junction was removed
            Assert.Throws <e.InvalidIdException>(() => repo.orderJunctionRepo.GetById(orderId, pizzaId));
            // Order was removed
            Assert.Throws <e.InvalidIdException>(() => repo.orderRepo.GetById(orderId));
        }
コード例 #3
0
        public void PizzaJunctionDeleteRemovesFromOrderTable()
        {
            // Arrange
            RepoTesting repo = new RepoTesting();

            repo.ResetDatabase("PizzaJuntion_Test_3");
            db.Models.OrderJunction dbOrderJunction = repo.dbOrderJunction;
            int orderId      = dbOrderJunction.OrderId;
            int pizzaId      = dbOrderJunction.PizzaId;
            int ingredientId = repo.dbIngredient.Id;

            // Ensure the entities exist
            // order junction
            Assert.NotNull(repo.orderJunctionRepo.GetById(dbOrderJunction.OrderId, dbOrderJunction.PizzaId));
            // Pizza junction
            Assert.NotNull(repo.pizzaRepo.GetById(pizzaId, ingredientId));

            // Act
            repo.pizzaRepo.Delete(repo.dbPizza);
            repo.SaveChanges();


            // Assert
            // Order junction was removed
            Assert.Throws <e.InvalidIdException>(() => repo.orderJunctionRepo.GetById(dbOrderJunction.OrderId, dbOrderJunction.PizzaId));
            // Pizza junction was removed
            Assert.Throws <e.InvalidIdException>(() => repo.pizzaRepo.GetById(pizzaId, ingredientId));
        }
コード例 #4
0
        public void CreatingNewInventoryFailsWithInvalidIngredient()
        {
            // Arrange
            RepoTesting repo = new RepoTesting();

            repo.ResetDatabase("Inventory_Test_2");
            int locationId          = repo.dbLocation.Id;
            int invalidIngredientId = -1;

            // Ensure the entities exist
            Assert.NotNull(repo.locationRepo.GetById(locationId));
            // Searching for this inventory should fail since we
            //  are passing in an invalid ingredient id
            Assert.Throws <e.InvalidIdException>(() => repo.inventoryRepo.GetById(locationId, invalidIngredientId));

            db.Models.InventoryJunction dbInventory = new db.Models.InventoryJunction
            {
                LocationId = locationId, IngredientId = invalidIngredientId, Count = 1
            };


            // Act
            // Assert
            Assert.Throws <e.InvalidIdException>(() => repo.inventoryRepo.Create(dbInventory));
        }
コード例 #5
0
        public void CreatingNewOrderJunctionSucceedsWithValidOrderIdandPizzaId()
        {
            // Arrange
            RepoTesting repo = new RepoTesting();

            repo.ResetDatabase("OrderJunction_Test_1");
            dbm.PizzaJunction dbPizza = new dbm.PizzaJunction {
                PizzaId = dbm.PizzaJunction.GetNewId(), Count = 1, IngredientId = repo.dbIngredient.Id
            };
            repo.pizzaRepo.Create(dbPizza);
            repo.SaveChanges();

            // Ensure the required entities exist
            Assert.NotNull(repo.pizzaRepo.GetById(dbPizza.PizzaId, dbPizza.IngredientId));

            dbm.OrderJunction dbOrderJunction = new dbm.OrderJunction
            {
                OrderId = repo.dbOrder.Id, PizzaId = dbPizza.PizzaId
            };

            // Act
            // Create the new order junction
            repo.orderJunctionRepo.Create(dbOrderJunction);

            // Assert
            // Searching for this orderJunction should now succeed
            Assert.NotNull(repo.orderJunctionRepo.GetById(repo.dbOrder.Id, dbPizza.PizzaId));
        }
コード例 #6
0
        public void IngredientDeleteRemovesFromPizzaJunctionTable()
        {
            // Arrange
            RepoTesting repo = new RepoTesting();

            repo.ResetDatabase("Ingredient_Test_2");
            int ingredientId = repo.ingredientRepo.GetById(repo.dbIngredient.Id).Id;
            int pizzaId      = repo.pizzaRepo.GetById(repo.dbPizza.PizzaId, ingredientId).PizzaId;

            // Ensure the entities exist
            Assert.NotNull(repo.ingredientRepo.GetById(ingredientId));
            Assert.NotNull(repo.pizzaRepo.GetById(pizzaId, ingredientId));

            // Act

            repo.ingredientRepo.Delete(repo.dbIngredient);
            repo.SaveChanges();


            // Assert
            // Pizza junction was removed
            Assert.Throws <e.InvalidIdException>(() => repo.pizzaRepo.GetById(pizzaId, ingredientId));
            // Ingredient was removed
            Assert.Throws <e.InvalidIdException>(() => repo.ingredientRepo.GetById(ingredientId));
        }
コード例 #7
0
        public void LocationDeleteRemovesFromInventoryJunctionTable()
        {
            // Arrange
            RepoTesting repo = new RepoTesting();

            repo.ResetDatabase("Location_Test_3");
            int locationId   = repo.dbLocation.Id;
            int ingredientId = repo.dbIngredient.Id;

            // Ensure the entities exist
            Assert.NotNull(repo.locationRepo.GetById(locationId));
            Assert.NotNull(repo.ingredientRepo.GetById(ingredientId));
            Assert.NotNull(repo.inventoryRepo.GetById(locationId, ingredientId));

            // Act
            repo.locationRepo.Delete(repo.dbLocation);
            repo.SaveChanges();


            // Assert
            // InventoryJunction was removed
            Assert.Throws <e.InvalidIdException>(() => repo.inventoryRepo.GetById(locationId, ingredientId));
            // Location was removed
            Assert.Throws <e.InvalidIdException>(() => repo.locationRepo.GetById(locationId));
        }
コード例 #8
0
        public void UserCreateFailsWithInvalidDefaultLocationId()
        {
            // Arrange
            RepoTesting repo = new RepoTesting();

            repo.ResetDatabase("User_Test_3");

            int invalidLocationId = -1;

            // Ensure the locationId is invalid
            Assert.Throws <e.InvalidIdException>(() => repo.locationRepo.GetById(invalidLocationId));

            dbm.User dbUser = new dbm.User
            {
                Id                = 2,
                FirstName         = "John",
                LastName          = "Pot",
                DefaultLocationId = invalidLocationId
            };

            // Act
            // Create should throw exception
            Assert.Throws <e.InvalidIdException>(() => repo.userRepo.Create(dbUser));

            // Assert
            // User should not be findable
            Assert.Throws <e.InvalidIdException>(() => repo.userRepo.GetById(dbUser.Id));
        }
コード例 #9
0
        public void UserCreateSucceedsWithValidDefaultLocation()
        {
            // Arrange
            RepoTesting repo = new RepoTesting();

            repo.ResetDatabase("User_Test_2");

            dbm.Location dbLocation = new dbm.Location {
                Name = "a"
            };
            repo.locationRepo.Create(dbLocation);
            repo.SaveChanges();

            // Ensure the location exists
            Assert.NotNull(repo.locationRepo.GetById(dbLocation.Id));

            dbm.User dbUser = new dbm.User
            {
                Id                = 2,
                FirstName         = "John",
                LastName          = "Pot",
                DefaultLocationId = dbLocation.Id
            };

            // Act
            repo.userRepo.Create(dbUser);

            // Assert
            // User should now exist within the database
            Assert.NotNull(repo.userRepo.GetById(dbUser.Id));
        }
コード例 #10
0
        public void OrderCreateSucceedsWithValidLocationIdAndUserId()
        {
            // Arrange
            RepoTesting repo = new RepoTesting();

            repo.ResetDatabase("Order_Test_2");
            dbm.Location dbLocation = new dbm.Location {
                Name = "a"
            };
            repo.locationRepo.Create(dbLocation);
            repo.SaveChanges();
            dbm.User dbUser = new dbm.User {
                Id = 2, FirstName = "John", LastName = "Pot", DefaultLocationId = dbLocation.Id
            };
            repo.userRepo.Create(dbUser);
            repo.SaveChanges();
            // Ensure the entities exist
            Assert.NotNull(repo.locationRepo.GetById(dbLocation.Id));
            Assert.NotNull(repo.userRepo.GetById(dbUser.Id));

            dbm.Order dbOrder = new dbm.Order
            {
                Id         = 2,
                LocationId = dbLocation.Id,
                UserId     = dbUser.Id,
                TimePlaced = DateTime.Now,
                TotalPrice = 20.50m
            };

            // Act

            repo.orderRepo.Create(dbOrder);
            repo.SaveChanges();


            // Assert
            // New order should be findable
            Assert.NotNull(repo.orderRepo.GetById(dbOrder.Id));
        }
コード例 #11
0
        public void LocationDeleteRemovesFromUserTable()
        {
            // Arrange
            RepoTesting repo = new RepoTesting();

            repo.ResetDatabase("Location_Test_2");
            int?userDefaultLocationId = repo.dbUser.DefaultLocationId;
            int locationId            = repo.dbLocation.Id;

            // Act

            repo.locationRepo.Delete(repo.dbLocation);
            repo.SaveChanges();


            // Assert
            // User was updated
            Assert.NotNull(userDefaultLocationId);
            Assert.Null(repo.dbUser.DefaultLocationId);
            // Location was removed
            Assert.Throws <e.InvalidIdException>(() => repo.locationRepo.GetById(locationId));
        }
コード例 #12
0
        public void CreatingNewPizzaJunctionFailsWithInvalidIngredientId()
        {
            // Arrange
            RepoTesting repo = new RepoTesting();

            repo.ResetDatabase("PizzaJunction_Test_2");
            int invalidIngredientId = -1;

            dbm.PizzaJunction dbPizza = new dbm.PizzaJunction {
                IngredientId = invalidIngredientId, Count = 1
            };

            // Ensure the invalid ingredientId is in fact invalid
            Assert.Throws <e.InvalidIdException>(() => repo.ingredientRepo.GetById(invalidIngredientId));

            // Act
            // Creating the PizzaJunction should not work.
            Assert.Throws <e.InvalidIdException>(() => repo.pizzaRepo.Create(dbPizza));

            // Assert
            // Searching for this PizzaJunction should fail
            Assert.Throws <e.InvalidIdException>(() => repo.pizzaRepo.GetById(dbPizza.PizzaId, repo.dbIngredient.Id));
        }
コード例 #13
0
        public void CreatingNewPizzaJunctionSucceedsWithValidPizzaIdAndIngredientId()
        {
            // Arrange
            RepoTesting repo = new RepoTesting();

            repo.ResetDatabase("PizzaJunction_Test_1");
            dbm.PizzaJunction dbPizza = new dbm.PizzaJunction {
                IngredientId = repo.dbIngredient.Id, Count = 1
            };
            repo.pizzaRepo.Create(dbPizza);

            // Ensure the required entities exist
            Assert.NotNull(repo.pizzaRepo.GetById(dbPizza.PizzaId, dbPizza.IngredientId));
            Assert.NotNull(repo.ingredientRepo.GetById(repo.dbIngredient.Id));

            // Act
            // Create the PizzaJuncton
            repo.pizzaRepo.Create(dbPizza);

            // Assert
            // Searching for this PizzaJunction should now succeed
            Assert.NotNull(repo.pizzaRepo.GetById(dbPizza.PizzaId, repo.dbIngredient.Id));
        }
コード例 #14
0
        public void OrderCreateFailsWithInvalidLocationId()
        {
            // Arrange
            RepoTesting repo = new RepoTesting();

            repo.ResetDatabase("Order_Test_3");
            dbm.User dbUser = new dbm.User {
                Id = 2, FirstName = "John", LastName = "Pot"
            };
            repo.userRepo.Create(dbUser);
            repo.SaveChanges();
            int invalidLocationId = -1;

            // Ensure the user is valid
            Assert.NotNull(repo.userRepo.GetById(dbUser.Id));
            // Ensure the invalidLocationId is in fact invalid
            Assert.Throws <e.InvalidIdException>(() => repo.locationRepo.GetById(invalidLocationId));

            dbm.Order dbOrder = new dbm.Order
            {
                Id         = 2,
                LocationId = invalidLocationId,
                UserId     = dbUser.Id,
                TimePlaced = DateTime.Now,
                TotalPrice = 20.50m
            };

            // Act

            Assert.Throws <e.InvalidIdException>(() => repo.orderRepo.Create(dbOrder));


            // Assert
            // New order should not have been added to the database
            Assert.Throws <e.InvalidIdException>(() => repo.orderRepo.GetById(dbOrder.Id));
        }
コード例 #15
0
        public void OrderCreateFailsWithInvalidUserId()
        {
            // Arrange
            RepoTesting repo = new RepoTesting();

            repo.ResetDatabase("Order_Test_4");
            dbm.Location dbLocation = new dbm.Location {
                Id = 2, Name = "a"
            };
            repo.locationRepo.Create(dbLocation);
            repo.SaveChanges();
            int invalidUserId = -1;

            // Ensure the location is valid
            Assert.NotNull(repo.locationRepo.GetById(dbLocation.Id));
            // Ensure the user is invalid
            Assert.Throws <e.InvalidIdException>(() => repo.userRepo.GetById(invalidUserId));

            dbm.Order dbOrder = new dbm.Order
            {
                Id         = 2,
                LocationId = dbLocation.Id,
                UserId     = invalidUserId,
                TimePlaced = DateTime.Now,
                TotalPrice = 20.50m
            };

            // Act
            // Create should throw an exception
            Assert.Throws <e.InvalidIdException>(() => repo.orderRepo.Create(dbOrder));


            // Assert
            // New order should not be searchable
            Assert.Throws <e.InvalidIdException>(() => repo.orderRepo.GetById(dbOrder.Id));
        }
コード例 #16
0
        public void CreatingNewOrderJunctionFailsWithInvalidPizzaId()
        {
            // Arrange
            RepoTesting repo = new RepoTesting();

            repo.ResetDatabase("OrderJunction_Test_3");
            int invalidPizzaId = -1;

            // Ensure the required entities exist
            Assert.NotNull(repo.orderRepo.GetById(repo.dbOrder.Id));

            dbm.OrderJunction dbOrderJunction = new dbm.OrderJunction
            {
                OrderId = repo.dbOrder.Id, PizzaId = invalidPizzaId
            };

            // Act
            // Create the new order junction
            Assert.Throws <e.InvalidIdException>(() => repo.orderJunctionRepo.Create(dbOrderJunction));

            // Assert
            // Searching for this orderJunction should fail
            Assert.Throws <e.InvalidIdException>(() => repo.orderJunctionRepo.GetById(repo.dbOrder.Id, invalidPizzaId));
        }