Example #1
0
        public void Create_works_Properly()
        {
            string errorMessagePrefix = "DeliveriesService Create() method does not work properly.";

            var context = OilsProDbContextInMemoryFactory.InitializeContext();

            this.deliveriesService = new DeliveriesService(context);

            var supplier = new Supplier
            {
                Name = "Supplier1",
            };

            context.Suppliers.Add(supplier);

            var lot = new Lot
            {
                SerialNumber = "56/566"
            };

            context.Lots.Add(lot);

            context.SaveChanges();

            var result = deliveriesService.Create("12-12-1222", supplier.Name, lot.SerialNumber);

            Assert.True(context.Deliveries.Count() == 1);
        }
Example #2
0
        public void GetById_works_Properly()
        {
            string errorMessagePrefix = "DeliveriesService GetById() method does not work properly.";

            var context = OilsProDbContextInMemoryFactory.InitializeContext();

            this.deliveriesService = new DeliveriesService(context);

            var supplier = new Supplier
            {
                Name = "Supplier1",
            };

            context.Suppliers.Add(supplier);

            var lot = new Lot
            {
                SerialNumber = "77/77"
            };

            context.Lots.Add(lot);

            var lot2 = new Lot
            {
                SerialNumber = "88/88"
            };

            context.Lots.Add(lot2);

            context.SaveChanges();

            var delivery1 = deliveriesService.Create("12-12-1222", supplier.Name, lot.SerialNumber);

            var delivery2 = deliveriesService.Create("10-10-1222", supplier.Name, lot2.SerialNumber);

            var result = deliveriesService.GetById(delivery2.Id);

            Assert.True(result.Lot.SerialNumber == "88/88");
        }
Example #3
0
        public IActionResult Create(CreateDeliveryViewModel input)
        {
            if (!ModelState.IsValid)
            {
                var model = new Delivery
                {
                    DeliveryDate = DateTime.UtcNow
                };

                ViewBag.Suppliers = SetSuppliersToSelectListItems();
                ViewBag.Lots      = SetLotsToSelectListItems();

                return(this.View(model));
            }

            var dlivery = _deliveriesService.Create(input.DeliveryDate.ToString("dd/MM/yyyy"), input.SupplierName, input.LotSerialNumber);

            return(this.Redirect($"/Deliveries/All"));
        }
Example #4
0
        public void Edit_works_Properly()
        {
            string errorMessagePrefix = "DeliveriesService Edit() method does not work properly.";

            var context = OilsProDbContextInMemoryFactory.InitializeContext();

            this.deliveriesService = new DeliveriesService(context);

            var supplier = new Supplier
            {
                Name = "Supplier1",
            };

            context.Suppliers.Add(supplier);

            var lot = new Lot
            {
                SerialNumber = "56/566"
            };

            context.Lots.Add(lot);
            var lot2 = new Lot
            {
                SerialNumber = "88/888"
            };

            context.Lots.Add(lot2);

            context.SaveChanges();

            var delivery = deliveriesService.Create("12-12-1222", supplier.Name, lot.SerialNumber);

            var editedDelivery = delivery;

            editedDelivery.Lot = lot2;

            var result = deliveriesService.Edit(editedDelivery.Id, editedDelivery.DeliveryDate.ToString(), editedDelivery.Supplier.Name,
                                                delivery.Lot.SerialNumber);

            Assert.True(result.Lot.SerialNumber == "88/888");
        }