Exemplo n.º 1
0
        public void GetCarrierVehicles_works_Properly()
        {
            string errorMessagePrefix = "CarriersService GetCarrierDrivers() method does not work properly.";

            var context = OilsProDbContextInMemoryFactory.InitializeContext();

            this.carriersService = new CarriersService(context);

            var carrier = new Carrier
            {
                Name     = "Carrier1",
                Vehicles = new List <Vehicle>
                {
                    new Vehicle()
                    {
                        RegNumber = "RegNumber1"
                    },
                    new Vehicle()
                    {
                        RegNumber = "RegNumber2"
                    },
                }
            };

            context.Carriers.Add(carrier);
            context.SaveChanges();

            var result = carriersService.GetCarrierVehicles(carrier.Name);

            Assert.True(result.Count == 2);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        public void GetCarrierByDriverId_works_Properly()
        {
            string errorMessagePrefix = "CarriersService GetCarrierByDriverId() method does not work properly.";

            var context = OilsProDbContextInMemoryFactory.InitializeContext();

            this.carriersService = new CarriersService(context);

            var carrier = new Carrier
            {
                Name    = "Carrier1",
                Drivers = new List <Driver>
                {
                    new Driver
                    {
                        FullName = "Driver1"
                    },
                }
            };

            context.Carriers.Add(carrier);
            context.SaveChanges();

            var driverId = context.Drivers.First().Id;

            var result   = carriersService.GetCarrierByDriverId(driverId);
            var expected = carrier;

            Assert.AreEqual(expected, result, errorMessagePrefix);
        }
Exemplo n.º 4
0
        public void GetCarrierByVehicleId_works_Properly()
        {
            string errorMessagePrefix = "CarriersService GetCarrierByVehicleId() method does not work properly.";

            var context = OilsProDbContextInMemoryFactory.InitializeContext();

            this.carriersService = new CarriersService(context);

            var carrier = new Carrier
            {
                Name     = "Carrier1",
                Vehicles = new List <Vehicle>
                {
                    new Vehicle()
                    {
                        RegNumber = "RegNumber1"
                    },
                }
            };

            context.Carriers.Add(carrier);
            context.SaveChanges();

            var vehicleId = context.Vehicles.First().Id;

            var result   = carriersService.GetCarrierByVehicleId(vehicleId);
            var expected = carrier;

            Assert.AreEqual(expected, result, errorMessagePrefix);
        }
Exemplo n.º 5
0
        public void GetAllCompleted_works_Properly()
        {
            string errorMessagePrefix = "OrdersService GetAllCompleted() method does not work properly.";

            var context = OilsProDbContextInMemoryFactory.InitializeContext();

            this.ordersService = new OrdersService(context);

            var receiver = new Receiver
            {
                Name = "Receiver1"
            };

            context.Receivers.Add(receiver);

            var carrier = new Carrier
            {
                Name = "Carrier1"
            };

            context.Carriers.Add(carrier);

            var driver = new Driver
            {
                FullName = "Driver1"
            };

            context.Drivers.Add(driver);

            var vehicle = new Vehicle
            {
                RegNumber = "RegNumber1"
            };

            context.Vehicles.Add(vehicle);

            var address = new DeliveryAddress()
            {
                Town   = "Town1",
                Street = "Street1"
            };

            context.DeliveryAddresses.Add(address);

            context.SaveChanges();

            for (int i = 0; i < 10; i++)
            {
                var order = ordersService.Create("UserId", "Ropa", "Town1, Street1", "Receiver1", "Carrier1", "Driver1",
                                                 "RegNumber1");
            }

            context.Orders.First().Status = OrderStatus.Completed;
            context.Orders.Last().Status  = OrderStatus.Completed;
            context.SaveChanges();

            var result = ordersService.GetAllCompleted();

            Assert.True(result.Count == 2, errorMessagePrefix);
        }
Exemplo n.º 6
0
        public void EditIncludedVehicle_works_Properly()
        {
            string errorMessagePrefix = "CarriersService EditIncludedVehicle() method does not work properly.";

            var context = OilsProDbContextInMemoryFactory.InitializeContext();

            this.carriersService = new CarriersService(context);

            var carrier = new Carrier
            {
                Name     = "Carrier1",
                Vehicles = new List <Vehicle>
                {
                    new Vehicle()
                    {
                        RegNumber = "RegNumber1"
                    },
                }
            };

            context.Carriers.Add(carrier);
            context.SaveChanges();

            var vehicleId = context.Vehicles.First().Id;

            var result = carriersService.EditIncludedVehicle(vehicleId, "RegNumber2");

            Assert.True(context.Vehicles.First().RegNumber == "RegNumber2");
        }
Exemplo n.º 7
0
        public void Delete_Should_Delete_Product()
        {
            string errorMessagePrefix = "ProductsService Delete() method does not work properly.";

            var context = OilsProDbContextInMemoryFactory.InitializeContext();

            this.productsService = new ProductsService(context);

            var product = new Product
            {
                Id              = "Id1",
                Name            = "Product1",
                ProductCode     = "01010101",
                Viscosity       = "10/10",
                PackageCapacity = 180,
                isDeleted       = false,
            };

            context.Products.Add(product);
            context.SaveChanges();

            var result = productsService.Delete("Id1");

            Assert.True(result.isDeleted);
        }
Exemplo n.º 8
0
        public void GetReceiverById_works_Properly()
        {
            string errorMessagePrefix = "ReceiverService GetReceiverById() method does not work properly.";

            var context = OilsProDbContextInMemoryFactory.InitializeContext();

            this.receiverService = new ReceiverService(context);
            var receiver = new Receiver
            {
                Name = "Receiver1",
                DeliveryAddresses = new List <DeliveryAddress>
                {
                    new DeliveryAddress
                    {
                        Town   = "Town1",
                        Street = "Street1",
                    },
                    new DeliveryAddress
                    {
                        Town   = "Town2",
                        Street = "Street2",
                    },
                }
            };

            context.Receivers.Add(receiver);
            context.SaveChanges();

            var result = receiverService.GetReceiverById(receiver.Id);

            var expected = receiver;

            Assert.AreEqual(expected, result, errorMessagePrefix);
        }
Exemplo n.º 9
0
        public void EditIncludedDriver_works_Properly()
        {
            string errorMessagePrefix = "CarriersService EditIncludedDriver() method does not work properly.";

            var context = OilsProDbContextInMemoryFactory.InitializeContext();

            this.carriersService = new CarriersService(context);

            var carrier = new Carrier
            {
                Name    = "Carrier1",
                Drivers = new List <Driver>
                {
                    new Driver
                    {
                        FullName = "Driver1"
                    },
                }
            };

            context.Carriers.Add(carrier);
            context.SaveChanges();

            var driverId = context.Drivers.First().Id;

            var result = carriersService.EditIncludedDriver(driverId, "Driver2");

            Assert.True(context.Drivers.First().FullName == "Driver2");
        }
Exemplo n.º 10
0
        public void GetAllLots_works_Properly()
        {
            string errorMessagePrefix = "DeliveriesService GetAllLots() method does not work properly.";

            var context = OilsProDbContextInMemoryFactory.InitializeContext();

            this.deliveriesService = new DeliveriesService(context);

            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 result = deliveriesService.GetAllLots();

            Assert.True(result.Count == 2);
        }
Exemplo n.º 11
0
        public void GetVehiclesByCarrierName_works_Properly()
        {
            string errorMessagePrefix = "OrdersService GetVehiclesByCarrierName() method does not work properly.";

            var context = OilsProDbContextInMemoryFactory.InitializeContext();

            this.ordersService = new OrdersService(context);

            var receiver = new Receiver
            {
                Name = "Receiver1"
            };

            context.Receivers.Add(receiver);

            var carrier = new Carrier
            {
                Name    = "Carrier1",
                Drivers = new List <Driver>()
                {
                    new Driver()
                    {
                        FullName = "Driver1"
                    }
                },
                Vehicles = new List <Vehicle>
                {
                    new Vehicle()
                    {
                        RegNumber = "RegNumber1"
                    }
                }
            };

            context.Carriers.Add(carrier);

            var address = new DeliveryAddress()
            {
                Town   = "Town1",
                Street = "Street1"
            };

            context.DeliveryAddresses.Add(address);

            context.SaveChanges();

            var order = ordersService.Create("UserId", "Ropa", "Town1, Street1", "Receiver1", "Carrier1", "Driver1",
                                             "RegNumber1");

            var result   = ordersService.GetVehiclesByCarrierName("Carrier1").First().RegNumber;
            var expected = "RegNumber1";

            Assert.AreEqual(expected, result, errorMessagePrefix);
        }
Exemplo n.º 12
0
        public void Release_works_Properly()
        {
            string errorMessagePrefix = "OrdersService Release() method does not work properly.";

            var context = OilsProDbContextInMemoryFactory.InitializeContext();

            this.ordersService = new OrdersService(context);

            var receiver = new Receiver
            {
                Name = "Receiver1"
            };

            context.Receivers.Add(receiver);
            var carrier = new Carrier
            {
                Name = "Carrier1"
            };

            context.Carriers.Add(carrier);

            var driver = new Driver
            {
                FullName = "Driver1"
            };

            context.Drivers.Add(driver);

            var vehicle = new Vehicle
            {
                RegNumber = "RegNumber1"
            };

            context.Vehicles.Add(vehicle);

            var address = new DeliveryAddress()
            {
                Town   = "Town1",
                Street = "Street1"
            };

            context.DeliveryAddresses.Add(address);

            context.SaveChanges();

            var order = ordersService.Create("UserId", "Ropa", "Town1, Street1", "Receiver1", "Carrier1", "Driver1",
                                             "RegNumber1");


            var result = ordersService.Release(order.Id);

            Assert.True(result.Status == OrderStatus.Completed);
            Assert.True(result.ReleaseDate != null);
        }
Exemplo n.º 13
0
        public void GetAllLots_works_Properly()
        {
            string errorMessagePrefix = "NomenclaturesServices GetAllLots() method does not work properly.";

            var mapper = new Mock <IMapper>();

            var context = OilsProDbContextInMemoryFactory.InitializeContext();

            this.nomenclaturesService = new NomenclaturesServices(context, mapper.Object);

            //var result = nomenclaturesService.All();
        }
Exemplo n.º 14
0
        public void Method_Create_Works_Properly()
        {
            string errorMessagePrefix = "ProductsService Create() method does not work properly.";

            var context = OilsProDbContextInMemoryFactory.InitializeContext();

            this.productsService = new ProductsService(context);

            var product1 = this.productsService.Create("Prod1", "01010101", "20/50", 180, 1800);
            var product2 = this.productsService.Create("Prod2", "02020202", "20/80", 190, 1900);

            Assert.True(context.Products.Count() == 2);
        }
Exemplo n.º 15
0
        public void Create_works_Properly()
        {
            string errorMessagePrefix = "ProductsService Create() method does not work properly.";

            var context = OilsProDbContextInMemoryFactory.InitializeContext();

            this.productsService = new ProductsService(context);

            var result   = productsService.Create("Product1", "01010101", "10/10", 110, 1800);
            var expected = context.Products.First();

            Assert.AreEqual(expected, result, errorMessagePrefix);
        }
Exemplo n.º 16
0
        public void Create_works_Properly()
        {
            string errorMessagePrefix = "OrdersService Create() method does not work properly.";

            var context = OilsProDbContextInMemoryFactory.InitializeContext();

            this.ordersService = new OrdersService(context);

            var receiver = new Receiver
            {
                Name = "Receiver1"
            };

            context.Receivers.Add(receiver);

            var carrier = new Carrier
            {
                Name = "Carrier1"
            };

            context.Carriers.Add(carrier);

            var driver = new Driver
            {
                FullName = "Driver1"
            };

            context.Drivers.Add(driver);

            var vehicle = new Vehicle
            {
                RegNumber = "RegNumber1"
            };

            context.Vehicles.Add(vehicle);

            context.SaveChanges();

            var result = ordersService.Create("UserId", "Ropa", "Town1, Street1", "Receiver1", "Carrier1", "Driver1",
                                              "RegNumber1");

            var expected = context.Orders.First();

            Assert.AreEqual(expected, result, errorMessagePrefix);
        }
Exemplo n.º 17
0
        public void GetProductsByOrderId_Return_Correct_Result()
        {
            string errorMessagePrefix = "ProductsService GetProductsByOrderId() method does not work properly.";

            var context = OilsProDbContextInMemoryFactory.InitializeContext();

            this.productsService = new ProductsService(context);

            Order order = new Order
            {
                Id       = "Order111",
                Products = new List <OrderedProducts>
                {
                    new OrderedProducts
                    {
                        Product = new Product
                        {
                            Name        = "Product1",
                            ProductCode = "01010101",
                        }
                    },
                    new OrderedProducts
                    {
                        Product = new Product
                        {
                            Name        = "Product2",
                            ProductCode = "02020202",
                        }
                    },
                }
            };

            context.SaveChanges();

            var result = productsService.GetProductsByOrderId("Order111").ToList();

            var expected = order.Products.ToList();

            for (int i = 0; i < result.Count; i++)
            {
                Assert.AreEqual(result[i], expected[i], errorMessagePrefix);
            }
        }
Exemplo n.º 18
0
        public void RemoveVehicle_works_Properly()
        {
            string errorMessagePrefix = "CarriersService RemoveDriver() method does not work properly.";

            var context = OilsProDbContextInMemoryFactory.InitializeContext();

            this.carriersService = new CarriersService(context);

            var vehicle = new Vehicle
            {
                RegNumber = "RegNumber1"
            };

            context.Vehicles.Add(vehicle);
            context.SaveChanges();

            var result = carriersService.RemoveVehicle(vehicle.Id);

            Assert.True(result.isDeleted);
        }
Exemplo n.º 19
0
        public void CreateNewAddress_works_Properly()
        {
            string errorMessagePrefix = "ReceiverService CreateNewAddress() method does not work properly.";

            var context = OilsProDbContextInMemoryFactory.InitializeContext();

            this.receiverService = new ReceiverService(context);

            var receiver = new Receiver
            {
                Name = "Receiver1",
            };

            context.Receivers.Add(receiver);
            context.SaveChanges();

            var result = receiverService.CreateNewAddress("Town1", "Street1", "Receiver1");

            Assert.True(context.DeliveryAddresses.Contains(result));
        }
Exemplo n.º 20
0
        public void DeleteAddress_works_Properly()
        {
            string errorMessagePrefix = "ReceiverService DeleteAddress() method does not work properly.";

            var context = OilsProDbContextInMemoryFactory.InitializeContext();

            this.receiverService = new ReceiverService(context);

            var address = new DeliveryAddress()
            {
                Town = "Town1",
            };

            context.DeliveryAddresses.Add(address);
            context.SaveChanges();

            var result = receiverService.DeleteAddress(address.Id);

            Assert.True(result.isDeleted);
        }
Exemplo n.º 21
0
        public void Delete_works_Properly()
        {
            string errorMessagePrefix = "CarriersService Delete() method does not work properly.";

            var context = OilsProDbContextInMemoryFactory.InitializeContext();

            this.carriersService = new CarriersService(context);

            var carrier = new Carrier
            {
                Name = "Carrier1"
            };

            context.Carriers.Add(carrier);
            context.SaveChanges();

            var result = carriersService.Delete(carrier.Id);

            Assert.True(result.isDeleted);
        }
Exemplo n.º 22
0
        public void Edit_Return_Correct_Result()
        {
            string errorMessagePrefix = "ProductsService Edit() method does not work properly.";

            var context = OilsProDbContextInMemoryFactory.InitializeContext();

            this.productsService = new ProductsService(context);

            var product = new Product
            {
                Id              = "Id1",
                Name            = "Product1",
                ProductCode     = "01010101",
                Viscosity       = "10/10",
                PackageCapacity = 180,
                isDeleted       = false,
            };

            context.Products.Add(product);
            context.SaveChanges();

            var editedProduct = new Product
            {
                Id              = "Id1",
                Name            = "Product2",
                ProductCode     = "02020202",
                Viscosity       = "20/20",
                PackageCapacity = 220,
                isDeleted       = false,
            };

            productsService.Edit(editedProduct);

            var resultProperties   = context.Products.First().GetType().GetProperties();
            var expectedProperties = editedProduct.GetType().GetProperties();

            for (int i = 0; i < resultProperties.Length; i++)
            {
                Assert.AreEqual(expectedProperties[i], resultProperties[i]);
            }
        }
Exemplo n.º 23
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");
        }
Exemplo n.º 24
0
        public void CreateNewVehicle_works_Properly()
        {
            string errorMessagePrefix = "CarriersService CreateNewVehicle() method does not work properly.";

            var context = OilsProDbContextInMemoryFactory.InitializeContext();

            this.carriersService = new CarriersService(context);

            var carrier = new Carrier
            {
                Name = "Carrier1"
            };

            context.Carriers.Add(carrier);
            context.SaveChanges();

            var result = carriersService.CreateNewVehicle("RegNumber1", carrier.Name);

            Assert.True(context.Vehicles.Count() == 1);
            Assert.True(context.Vehicles.First().RegNumber == "RegNumber1");
        }
Exemplo n.º 25
0
        public void Include_And_Remove_Product_To_Order_Works_Correctly()
        {
            string errorMessagePrefix = "ProductsService Include() or Remove() methods does not work properly.";

            var context = OilsProDbContextInMemoryFactory.InitializeContext();

            Order order = new Order();

            Product product = new Product
            {
                Name        = "Product1",
                ProductCode = "01010101",
            };
            Lot lot = new Lot
            {
                SerialNumber = "12/56"
            };

            context.Add(order);
            context.Add(product);
            context.Add(lot);

            context.SaveChanges();

            this.productsService = new ProductsService(context);

            var result = this.productsService.Include(order.Id, product.ProductCode, product.Name, "10", "1800", lot.SerialNumber);

            var expectedResult = context.Orders.First().Products.Count > 0;

            Assert.True(expectedResult, errorMessagePrefix);

            var innerResult = context.Orders.First().Products.First();

            Assert.AreEqual(innerResult, result, errorMessagePrefix);

            var removeProduct = productsService.Remove(result.OrderId + result.ProductId);

            Assert.True(order.Products.Count == 0, errorMessagePrefix);
        }
Exemplo n.º 26
0
        public void GetProductByCode_Return_Correct_Result()
        {
            string errorMessagePrefix = "ProductsService GetProductByCode() method does not work properly.";

            var context = OilsProDbContextInMemoryFactory.InitializeContext();

            this.productsService = new ProductsService(context);

            var product = new Product
            {
                Name        = "Product1",
                ProductCode = "01010101"
            };

            context.Products.Add(product);
            context.SaveChanges();

            var result   = productsService.GetProductByCode("01010101");
            var expected = product;

            Assert.AreEqual(expected, result, errorMessagePrefix);
        }
Exemplo n.º 27
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");
        }
Exemplo n.º 28
0
        public void EditIncludedAddress_works_Properly()
        {
            string errorMessagePrefix = "ReceiverService EditIncludedAddress() method does not work properly.";

            var context = OilsProDbContextInMemoryFactory.InitializeContext();

            this.receiverService = new ReceiverService(context);

            var address = new DeliveryAddress()
            {
                Town   = "Town1",
                Street = "Street1",
            };

            context.DeliveryAddresses.Add(address);
            context.SaveChanges();

            var result = receiverService.EditIncludedAddress(address.Id, "Town2", "Street2");

            Assert.True(context.DeliveryAddresses.First().Town == "Town2");
            Assert.True(context.DeliveryAddresses.First().Street == "Street2");
        }
Exemplo n.º 29
0
        public void CreateNewLot_works_Properly()
        {
            string errorMessagePrefix = "DeliveriesService CreateNewLot() method does not work properly.";

            var context = OilsProDbContextInMemoryFactory.InitializeContext();

            this.deliveriesService = new DeliveriesService(context);

            var product = new Product
            {
                Name            = "Product1",
                ProductCode     = "01010101",
                PackageCapacity = 10,
            };

            context.Products.Add(product);

            context.SaveChanges();

            var result = deliveriesService.CreateNewLot("88/88", 10, 1800, "Product1 - 01010101");

            Assert.True(context.Lots.Count() == 1);
        }