public void RejectsHighOrderQuantities()
        {
            var options = TestUtil.GetMemDbOptions("RejectsHighOrderQuantities");

            String productName;
            Guid   customerId;
            Guid   orderId;

            using (var db = new StoreContext(options))
            {
                var(customer, location, product, inventory) = SimplePopulate(db);
                customerId         = customer.CustomerId;
                productName        = product.Name;
                inventory.Quantity = 300;

                var order = new Order(customer, location);
                orderId = order.OrderId;
                var orderLine = new OrderLineItem(order, product);
                orderLine.Quantity = 201;
                order.OrderLineItems.Add(orderLine);

                db.Add(order);
                db.SaveChanges();
            }

            Assert.Equal(PlaceOrderResult.HighQuantityRejection, options.PlaceOrder(orderId, StoreDbUtil.Config.MAX_ORDER_QUANTITY));

            using (var db = new StoreContext(options))
            {
                var inventory = (from i in db.LocationInventories where i.Product.Name == productName select i).First();
                Assert.Equal(300, inventory.Quantity);
            }
        }
        public void UpdatesSubmittedTimeWhenOrderPlaced()
        {
            var options = TestUtil.GetMemDbOptions("UpdatesSubmittedTimeWhenOrderPlaced");

            String productName;
            Guid   customerId;
            Guid   orderId;

            using (var db = new StoreContext(options))
            {
                var(customer, location, product, inventory) = SimplePopulate(db);
                customerId  = customer.CustomerId;
                productName = product.Name;

                var order = new Order(customer, location);
                orderId = order.OrderId;
                var orderLine = new OrderLineItem(order, product);
                orderLine.Quantity = 1;
                order.OrderLineItems.Add(orderLine);

                db.Add(order);
                db.SaveChanges();
            }

            Assert.Equal(PlaceOrderResult.Ok, options.PlaceOrder(orderId, StoreDbUtil.Config.MAX_ORDER_QUANTITY));

            using (var db = new StoreContext(options))
            {
                var order = db.GetOrderById(orderId);
                Assert.NotNull(order.TimeSubmitted);
            }
        }
        public void RejectsOrderWithoutGuid()
        {
            var options = TestUtil.GetMemDbOptions("RejectsOrderWithoutGuid");

            try
            {
                Assert.Equal(PlaceOrderResult.OrderNotFound, options.PlaceOrder(null, StoreDbUtil.Config.MAX_ORDER_QUANTITY));
                Assert.True(false, "Should be a NullReferenceException to place an order without an id");
            } catch (NullReferenceException) { }
        }
        public void RejectsOrderWithNonExistentInventory()
        {
            var options = TestUtil.GetMemDbOptions("RejectsOrderWithNonExistentInventory");

            String productName;
            Guid   customerId;
            Guid   orderId;

            using (var db = new StoreContext(options))
            {
                var(customer, location, product1, inventory) = SimplePopulate(db);
                customerId = customer.CustomerId;
                var product2 = new Product(Guid.NewGuid().ToString(), 2.0);
                db.Add(product2);
                productName = product1.Name;

                // Intentionally not adding product 2 to inventory
                // var inventory2 = new LocationInventory(product2, location, 20);
                // db.Add(inventory2);

                var order = new Order(customer, location);
                orderId = order.OrderId;

                var orderLine1 = new OrderLineItem(order, product1);
                orderLine1.Quantity = 9;
                order.OrderLineItems.Add(orderLine1);

                var orderLine2 = new OrderLineItem(order, product2);
                orderLine2.Quantity = 21;
                order.OrderLineItems.Add(orderLine2);

                db.Add(order);
                db.SaveChanges();
            }

            using (var db = new StoreContext(options))
            {
                var customer = (from c in db.Customers where c.CustomerId == customerId select c).First();

                var order = (from o in db.Orders
                             where o.Customer.CustomerId == customer.CustomerId
                             select o).First();

                Assert.Equal(customer.CustomerId, order.Customer.CustomerId);
            }

            Assert.Equal(PlaceOrderResult.OutOfStock, options.PlaceOrder(orderId, StoreDbUtil.Config.MAX_ORDER_QUANTITY));

            using (var db = new StoreContext(options))
            {
                var inventoryP1 = (from i in db.LocationInventories where i.Product.Name == productName select i).First();
                Assert.Equal(10, inventoryP1.Quantity);
            }
        }
Пример #5
0
        public void CreatesUserAccount()
        {
            var options  = TestUtil.GetMemDbOptions("CreatesUserAccount");
            var customer = new Customer();

            Assert.Equal(CreateUserAccountResult.MissingLogin, options.CreateUserAccount(customer));

            customer.Login = Guid.NewGuid().ToString();
            Assert.Equal(CreateUserAccountResult.MissingPassword, options.CreateUserAccount(customer));

            customer.Password = "******";
            Assert.Equal(CreateUserAccountResult.Ok, options.CreateUserAccount(customer));

            Assert.Equal(CreateUserAccountResult.AccountNameExists, options.CreateUserAccount(customer));
        }
        public void PlacesOrderWithSingleLineItem()
        {
            var options = TestUtil.GetMemDbOptions("PlacesOrderWithSingleLineItem");

            String productName;
            Guid   customerId;
            Guid   orderId;

            using (var db = new StoreContext(options))
            {
                var(customer, location, product, inventory) = SimplePopulate(db);
                customerId  = customer.CustomerId;
                productName = product.Name;

                var order = new Order(customer, location);
                orderId = order.OrderId;
                var orderLine = new OrderLineItem(order, product);
                orderLine.Quantity = 8;
                order.OrderLineItems.Add(orderLine);

                db.Add(order);
                db.SaveChanges();
            }

            using (var db = new StoreContext(options))
            {
                var customer = (from c in db.Customers where c.CustomerId == customerId select c).First();

                var order = (from o in db.Orders
                             where o.Customer.CustomerId == customer.CustomerId
                             select o).First();

                Assert.Equal(customer.CustomerId, order.Customer.CustomerId);
                Assert.Equal(8, order.OrderLineItems[0].Quantity);
            }

            Assert.Equal(PlaceOrderResult.Ok, options.PlaceOrder(orderId, StoreDbUtil.Config.MAX_ORDER_QUANTITY));

            using (var db = new StoreContext(options))
            {
                var inventory = (from i in db.LocationInventories where i.Product.Name == productName select i).First();
                Assert.Equal(2, inventory.Quantity);
            }
        }
Пример #7
0
        public void VerifiesCredentials()
        {
            var options = TestUtil.GetMemDbOptions("VerifiesCredentials");

            string customerLogin = Guid.NewGuid().ToString();
            string password      = "******";

            using (var db = new StoreContext(options))
            {
                var customer = new Customer(Guid.NewGuid().ToString());
                customer.Password = password;
                customer.Login    = customerLogin;
                db.Add(customer);

                db.SaveChanges();
            }

            {
                // Login and password are both valid.
                var customerId = options.VerifyCredentials(customerLogin, password);
                Assert.NotNull(customerId);
            }

            {
                // Login is ok, but password is wrong.
                var customerId = options.VerifyCredentials(customerLogin, Guid.NewGuid().ToString());
                Assert.Null(customerId);
            }

            {
                // Login is wrong, but password is ok.
                var customerId = options.VerifyCredentials(Guid.NewGuid().ToString(), password);
                Assert.Null(customerId);
            }

            {
                // Both login and password are wrong.
                var customerId = options.VerifyCredentials(Guid.NewGuid().ToString(), Guid.NewGuid().ToString());
                Assert.Null(customerId);
            }
        }
Пример #8
0
        public void SearchesForCustomerByName()
        {
            var options = TestUtil.GetMemDbOptions("SearchesForCustomerByName");

            using (var db = new StoreContext(options))
            {
                var customer1 = new Customer("7/Yf" + Guid.NewGuid().ToString());
                customer1.LastName = "q/wB" + Guid.NewGuid().ToString();
                db.Add(customer1);

                var customer2 = new Customer("nNg63" + Guid.NewGuid().ToString());
                customer2.LastName = "ZQVkE" + Guid.NewGuid().ToString();
                db.Add(customer2);

                var customer3 = new Customer("w6Ntm" + Guid.NewGuid().ToString());
                customer3.LastName = "I7/v2ZN" + Guid.NewGuid().ToString();
                db.Add(customer3);
                db.SaveChanges();

                var findCustomer1 = db.FindCustomerByName("wb");
                Assert.Equal(1, findCustomer1.Count());
                Assert.Equal(customer1.LastName, findCustomer1.First().LastName);

                var findCustomer2 = db.FindCustomerByName("Vk");
                Assert.Equal(1, findCustomer2.Count());
                Assert.Equal(customer2.LastName, findCustomer2.First().LastName);

                var findCustomers = db.FindCustomerByName("7/");
                Assert.Equal(2, findCustomers.Count());
                Assert.Equal(customer1.LastName, findCustomers
                             .Where(c => c.LastName == customer1.LastName)
                             .First()
                             .LastName);
                Assert.Equal(customer3.LastName, findCustomers
                             .Where(c => c.LastName == customer3.LastName)
                             .First()
                             .LastName);
            }
        }
Пример #9
0
        public void SearchesForCustomerByLastName()
        {
            var options = TestUtil.GetMemDbOptions("SearchesForCustomerByLastName");

            using (var db = new StoreContext(options))
            {
                var customer1 = new Customer("" + Guid.NewGuid().ToString());
                customer1.LastName = "z--bfS/qc" + Guid.NewGuid().ToString();
                db.Add(customer1);

                var customer2 = new Customer("" + Guid.NewGuid().ToString());
                customer2.LastName = "1XfcnY" + Guid.NewGuid().ToString();
                db.Add(customer2);

                var customer3 = new Customer("" + Guid.NewGuid().ToString());
                customer3.LastName = "z--zB8tkm" + Guid.NewGuid().ToString();
                db.Add(customer3);
                db.SaveChanges();

                var findCustomer1 = db.FindCustomerByLastName("bfs");
                Assert.Equal(1, findCustomer1.Count());
                Assert.Equal(customer1.LastName, findCustomer1.First().LastName);

                var findCustomer2 = db.FindCustomerByLastName("cn");
                Assert.Equal(1, findCustomer2.Count());
                Assert.Equal(customer2.LastName, findCustomer2.First().LastName);

                var findCustomers = db.FindCustomerByLastName("z--");
                Assert.Equal(2, findCustomers.Count());
                Assert.Equal(customer1.LastName, findCustomers
                             .Where(c => c.LastName == customer1.LastName)
                             .First()
                             .LastName);
                Assert.Equal(customer3.LastName, findCustomers
                             .Where(c => c.LastName == customer3.LastName)
                             .First()
                             .LastName);
            }
        }
Пример #10
0
        public void SearchesForCustomerByFirstName()
        {
            var options = TestUtil.GetMemDbOptions("SearchesForCustomerByFirstName");

            using (var db = new StoreContext(options))
            {
                var customer1 = new Customer("--z6HkRe" + Guid.NewGuid().ToString());
                db.Add(customer1);

                var customer2 = new Customer("dPmth" + Guid.NewGuid().ToString());
                db.Add(customer2);

                var customer3 = new Customer("--za/tvV" + Guid.NewGuid().ToString());
                db.Add(customer3);
                db.SaveChanges();

                var findCustomer1 = db.FindCustomerByFirstName("6HkRe");
                Assert.Equal(1, findCustomer1.Count());
                Assert.Equal(customer1.FirstName, findCustomer1.First().FirstName);

                var findCustomer2 = db.FindCustomerByFirstName("Pmth");
                Assert.Equal(1, findCustomer2.Count());
                Assert.Equal(customer2.FirstName, findCustomer2.First().FirstName);

                var findCustomers = db.FindCustomerByFirstName("--z");
                Assert.Equal(2, findCustomers.Count());
                Assert.Equal(customer1.FirstName, findCustomers
                             .Where(c => c.FirstName == customer1.FirstName)
                             .First()
                             .FirstName);
                Assert.Equal(customer3.FirstName, findCustomers
                             .Where(c => c.FirstName == customer3.FirstName)
                             .First()
                             .FirstName);
            }
        }
        public void PlacesOrderWithMultipleLineItems()
        {
            var options = TestUtil.GetMemDbOptions("PlacesOrderWithMultipleLineItems");

            Guid product1Id, product2Id;
            Guid customerId;
            Guid orderId;

            using (var db = new StoreContext(options))
            {
                var customer = new Customer(Guid.NewGuid().ToString());
                var location = new Location(Guid.NewGuid().ToString());
                db.Add(customer);
                db.Add(location);
                customerId = customer.CustomerId;

                var product1   = new Product(Guid.NewGuid().ToString(), 1.0);
                var inventory1 = new LocationInventory(product1, location, 10);
                db.Add(product1);
                db.Add(inventory1);
                product1Id = product1.ProductId;

                var product2   = new Product(Guid.NewGuid().ToString(), 1.0);
                var inventory2 = new LocationInventory(product2, location, 20);
                db.Add(product2);
                db.Add(inventory2);
                product2Id = product2.ProductId;

                var order = new Order(customer, location);
                orderId = order.OrderId;
                var orderLine1 = new OrderLineItem(order, product1);
                orderLine1.Quantity = 5;
                var orderLine2 = new OrderLineItem(order, product2);
                orderLine2.Quantity = 7;
                order.OrderLineItems.Add(orderLine1);
                order.OrderLineItems.Add(orderLine2);

                db.Add(order);
                db.SaveChanges();
            }

            using (var db = new StoreContext(options))
            {
                var customer = (from c in db.Customers where c.CustomerId == customerId select c).First();

                var order =
                    (from o in db.Orders
                     where o.Customer.CustomerId == customer.CustomerId
                     select o).First();

                Assert.Equal(2, order.OrderLineItems.Count());
            }

            Assert.Equal(PlaceOrderResult.Ok, options.PlaceOrder(orderId, StoreDbUtil.Config.MAX_ORDER_QUANTITY));

            using (var db = new StoreContext(options))
            {
                var invProduct1 =
                    (from i in db.LocationInventories where i.Product.ProductId == product1Id select i).First();
                Assert.Equal(5, invProduct1.Quantity);

                var invProduct2 =
                    (from i in db.LocationInventories where i.Product.ProductId == product2Id select i).First();
                Assert.Equal(13, invProduct2.Quantity);
            }
        }
        public void RejectsInvalidOrderId()
        {
            var options = TestUtil.GetMemDbOptions("RejectsInvalidOrderId");

            Assert.Equal(PlaceOrderResult.OrderNotFound, options.PlaceOrder(Guid.NewGuid(), StoreDbUtil.Config.MAX_ORDER_QUANTITY));
        }