Ejemplo n.º 1
0
        public async Task TestCreateOrder()
        {
            var options = new DbContextOptionsBuilder <BusinessContext>()
                          .UseInMemoryDatabase(databaseName: "test_order")
                          .Options;

            using (var bc = new BusinessContext(options)) {
                var repository = new Repository(bc);

                int customerId = 1;
                int locationId = 1;
                var customer   = new Customer {
                    CustomerId = customerId
                };
                var location = new Location {
                    LocationId = locationId
                };

                bc.Add(customer);
                bc.Add(location);
                await bc.SaveChangesAsync();

                var order = await repository.createOrderAsync(customerId, locationId);

                Assert.NotNull(order);
            }
        }
Ejemplo n.º 2
0
        public async Task TestListOrderItems()
        {
            var options = new DbContextOptionsBuilder <BusinessContext>()
                          .UseInMemoryDatabase(databaseName: "test_orderitem_list")
                          .Options;

            using (var bc = new BusinessContext(options)) {
                var repository = new Repository(bc);

                var orderItemA = new OrderItem {
                    Order = new Order {
                        Customer = new Customer(),
                        Location = new Location()
                    },
                    Product = new Product(),
                };
                var orderItemB = new OrderItem {
                    Order = new Order {
                        Customer = new Customer(),
                        Location = new Location()
                    },
                    Product = new Product()
                };
                bc.Add(orderItemA);
                bc.Add(orderItemB);
                await bc.SaveChangesAsync();

                var orderItems = await repository.listOrderItemsAsync();

                Assert.Equal(2, orderItems.Count());
            }
        }
        public async Task TestUpdateInventoryFail()
        {
            var options = new DbContextOptionsBuilder <BusinessContext>()
                          .UseInMemoryDatabase(databaseName: "test_inventory_update_fail")
                          .Options;

            using (var bc = new BusinessContext(options)) {
                var repository = new Repository(bc);

                int productId  = 1;
                int locationId = 1;
                var inventory  = new Inventory {
                    Product = new Product {
                        ProductId = productId
                    },
                    Location = new Location {
                        LocationId = locationId
                    },
                    Quantity = 3
                };
                bc.Add(inventory);
                await bc.SaveChangesAsync();

                var orderItem = new BusinessOrderItem {
                    Product = new BusinessProduct {
                        ProductId = productId
                    },
                    Quantity = 4
                };
                var result = await repository.updateInventoryAsync(locationId, orderItem);

                Assert.Null(result);
            }
        }
Ejemplo n.º 4
0
 public User CreateUser(User user)
 {
     using (var bc = new BusinessContext(new DbMode()))
     {
         return(bc.Add(user));
     }
 }
Ejemplo n.º 5
0
 public Service CreateService(Service service)
 {
     using (var bc = new BusinessContext(new DbMode()))
     {
         return(bc.Add(service));
     }
 }
Ejemplo n.º 6
0
 public Config CreateConfig(User user, Config config)
 {
     using (var bc = new BusinessContext(new AppMode()))
     {
         config.UserId = user.Id;
         return(bc.Add(config));
     }
 }
        public async Task TestListInventories()
        {
            var options = new DbContextOptionsBuilder <BusinessContext>()
                          .UseInMemoryDatabase(databaseName: "test_inventory")
                          .Options;

            using (var bc = new BusinessContext(options)) {
                var repository = new Repository(bc);

                var productA = new Product {
                    ProductId = 1
                };
                var productB = new Product {
                    ProductId = 2
                };
                var locationA = new Location {
                    LocationId = 1
                };
                var inventoryA = new Inventory {
                    Product  = productA,
                    Location = locationA
                };
                var inventoryB = new Inventory {
                    Product  = productB,
                    Location = locationA
                };
                bc.Add(productA);
                bc.Add(productB);
                bc.Add(locationA);
                bc.Add(inventoryA);
                bc.Add(inventoryB);

                await bc.SaveChangesAsync();

                var productsA = await repository.listInventoriesAsync();

                var productsB = await repository.listInventoriesAsync();

                productsA = productsA.Where(p => p.Location.LocationId == 1);
                productsB = productsB.Where(p => p.Location.LocationId == 2);

                Assert.Equal(2, productsA.Count());
                Assert.Empty(productsB);
            }
        }
 public void User_InsertEntity_Test(
     )
 {
     using (var bc = new BusinessContext(new TestMode()))
     {
         var resultObject = bc.Add(new User {
             Username = "******", Password = "******"
         });
         Assert.IsTrue(resultObject.Id > 0);
     }
 }
 public void Service_InsertEntity_Test(
     )
 {
     using (var bc = new BusinessContext(new TestMode()))
     {
         var resultObject = bc.Add(new Service {
             NameService = "AO-service-report"
         });
         Assert.IsTrue(resultObject.Id > 0);
     }
 }
Ejemplo n.º 10
0
        public async Task <IActionResult> Create([Bind("ID,Name,Description")] Area area)
        {
            if (ModelState.IsValid)
            {
                _context.Add(area);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(area));
        }
Ejemplo n.º 11
0
        public async Task <IActionResult> Create([Bind("ClientId,Client1,Address1,Address2,City,Pr,PostalCode")] Client client)
        {
            if (ModelState.IsValid)
            {
                _context.Add(client);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(client));
        }
Ejemplo n.º 12
0
        public async Task <IActionResult> Create([Bind("MarketID,Name,Budget,StartDate,ProductGuideID,RowVersion")] Market market)
        {
            if (ModelState.IsValid)
            {
                _context.Add(market);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProductGuideID"] = new SelectList(_context.ProductGuides, "ID", "FullName", market.ProductGuideID);
            return(View(market));
        }
Ejemplo n.º 13
0
        public async Task <IActionResult> Create([Bind("ProductID,Price,MarketID,ProductName")] Product product)
        {
            if (ModelState.IsValid)
            {
                _context.Add(product);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            PopulateMarketsDropDownList(product.MarketID);
            return(View(product));
        }
 public void Sevice_GetEntity_Test()
 {
     using (var bc = new BusinessContext(new TestMode()))
     {
         var resultObject = bc.Add(new Service {
             NameService = "AO-service-report"
         });
         var result = bc.Get <Service, int>(resultObject.Id);
         Assert.IsNotNull(result);
         Assert.IsTrue(result.Id > 0);
     }
 }
 public void User_GetEntity_Test()
 {
     using (var bc = new BusinessContext(new TestMode()))
     {
         var resultObject = bc.Add(new User {
             Username = "******", Password = "******"
         });
         var result = bc.Get <User, int>(resultObject.Id);
         Assert.IsNotNull(result);
         Assert.IsTrue(result.Id > 0);
     }
 }
Ejemplo n.º 16
0
        public async Task TestListLocations()
        {
            var options = new DbContextOptionsBuilder <BusinessContext>()
                          .UseInMemoryDatabase(databaseName: "test_location_list")
                          .Options;

            using (var bc = new BusinessContext(options)) {
                var repository = new Repository(bc);

                bc.Add(new Location {
                    LocationName = "test"
                });
                bc.Add(new Location {
                    LocationName = "test2"
                });
                await bc.SaveChangesAsync();

                var locations = await repository.listLocationsAsync();

                Assert.Equal(2, locations.Count());
            }
        }
        public IActionResult GetUsers()
        {
            BusinessContext context = new BusinessContext();
            User            user    = new User();

            user.Username = "******";
            user.Password = "******";
            context.Add(user);
            context.SaveChanges();
            UserView userView = Mapper.Map <UserView>(user);

            return(Ok(userView));
        }
Ejemplo n.º 18
0
        public async Task TestSubmitOrder()
        {
            var options = new DbContextOptionsBuilder <BusinessContext>()
                          .UseInMemoryDatabase(databaseName: "test_order_submit")
                          .Options;

            using (var bc = new BusinessContext(options)) {
                var repository = new Repository(bc);

                int customerId = 1;
                int locationId = 1;
                int orderId    = 1;
                var customer   = new Customer {
                    CustomerId = customerId
                };
                var location = new Location {
                    LocationId = locationId
                };
                var order = new Order {
                    OrderId  = orderId,
                    Customer = customer,
                    Location = location
                };
                var orderItem = new OrderItem {
                    Order = order
                };


                bc.Add(customer);
                bc.Add(location);
                bc.Add(order);
                bc.Add(orderItem);
                await bc.SaveChangesAsync();

                var submit = await repository.submitOrderAsync(new BusinessOrder { OrderId = orderId });

                Assert.NotNull(submit);
            }
        }
 public void User_InsertEntity_Test()
 {
     using (var bc = new BusinessContext(new TestMode()))
     {
         var client     = new AccountServiceClient();
         var resultUser = client.CreateUser(new User()
         {
             Username = "******", Password = "******"
         });
         var config = bc.Add(new Config()
         {
             Key = "key", Value = "value", UserId = resultUser.Id
         });
         Assert.IsNotNull(config);
         Assert.IsTrue(config.Id > 0);
     }
 }
Ejemplo n.º 20
0
        public async Task <IActionResult> Create([Bind("Id,BusinessName")] Business business)
        {
            if (ModelState.IsValid)
            {
                //verification of repeated id
                foreach (Business b in _context.Business)
                {
                    if (b.Id == business.Id)
                    {
                        //In case of a repeated Id viewbag needs to be reloaded
                        ViewBag.IdAlreadyExists = "ID ya existe, porfavor intente otro ID";
                        return(View());
                    }
                }
                _context.Add(business);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(business));
        }
Ejemplo n.º 21
0
        public async Task <IActionResult> Create([Bind("LastName,FirstMidName,SubscriptionDate")] Customer customer)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(customer);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (DbUpdateException /* ex */)
            {
                //Log the error (uncomment ex variable name and write a log.
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists " +
                                         "see your system administrator.");
            }
            return(View(customer));
        }
Ejemplo n.º 22
0
        public async Task TestSubmitOrderFail()
        {
            var options = new DbContextOptionsBuilder <BusinessContext>()
                          .UseInMemoryDatabase(databaseName: "test_order_submit_fail")
                          .Options;

            using (var bc = new BusinessContext(options)) {
                var repository = new Repository(bc);

                int orderId = 1;
                var order   = new Order {
                    OrderId   = orderId,
                    OrderDate = "not-null"
                };

                bc.Add(order);
                await bc.SaveChangesAsync();

                var submitA = await repository.submitOrderAsync(new BusinessOrder { OrderId = orderId });

                Assert.Null(submitA);
            }
        }
        public async Task <IActionResult> Create([Bind("Id,CommercialName,LegalName,Country,Region,City,CreationDate,BusinessId")] LocalBusiness localBusiness)
        {
            if (ModelState.IsValid)
            {
                //verification of repeated id
                foreach (LocalBusiness l in _context.LocalBusiness)
                {
                    if (l.Id == localBusiness.Id)
                    {
                        //In case of a repeated Id viewbag needs to be reloaded
                        ViewBag.LocalBusinessId = GetBusinessIds();
                        ViewBag.IdAlreadyExists = "ID ya existe, porfavor intente otro ID";
                        return(View());
                    }
                }
                _context.Add(localBusiness);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            return(View(localBusiness));
        }
Ejemplo n.º 24
0
        public async Task <IActionResult> Create([Bind("CountryAssignment,LastName,FirstMidName,HireDate")] ProductGuide productGuide, string[] selectedProducts)
        {
            if (selectedProducts != null)
            {
                productGuide.ProductAssignments = new List <ProductAssignment>();
                foreach (var product in selectedProducts)
                {
                    var productToAdd = new ProductAssignment {
                        ProductGuideID = productGuide.ID, ProductID = int.Parse(product)
                    };
                    productGuide.ProductAssignments.Add(productToAdd);
                }
            }
            if (ModelState.IsValid)
            {
                _context.Add(productGuide);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            PopulateAssignedProductData(productGuide);

            return(View(productGuide));
        }
Ejemplo n.º 25
0
        public async Task <IActionResult> Create([Bind("ID,Name,City,Adress,CreationDate,LocalBusinessId")] Campus campus)
        {
            if (ModelState.IsValid)
            {
                //verification of repeated id
                foreach (Campus c in _context.Campus)
                {
                    if (c.ID == campus.ID)
                    {
                        //In case of a repeated Id viewbag needs to be reloaded
                        ViewBag.LocalBusinessId = GetLocalBusinessIds();
                        ViewBag.IdAlreadyExists = "ID ya existe, porfavor intente otro ID";
                        return(View());
                    }
                }
                //no repeated id and model is valid
                ViewBag.IdAlreadyExists = "";
                _context.Add(campus);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(campus));
        }