Exemplo n.º 1
0
        public async Task Returns_Required_YearManufacture()
        {
            var mockServices  = new Mock <ITruckService>();
            var modelServices = new Mock <IModelService>();
            var unitOfWork    = new Mock <IUnitOfWork>();

            var truck = new SaveTruckDTO
            {
                ModelId         = new Guid("2c63c0ee-8290-4726-b505-b8ca6d9017dd"),
                ModelYear       = 2021,
                YearManufacture = 2020,
                Name            = "test"
            };

            var returns = new TruckDTO {
                Id = Guid.NewGuid()
            };

            mockServices.Setup(x => x.CreateTruck(truck)).ReturnsAsync(returns);

            Assert.Equal(DateTime.Now.Year, truck.YearManufacture);

            Assert.True(truck.YearManufacture >= DateTime.Now.Year);

            var controller = new TruckController(unitOfWork.Object, mockServices.Object, modelServices.Object);

            var result = await controller.Save(truck);

            Assert.IsType <RedirectToActionResult>(result);
        }
Exemplo n.º 2
0
        public void Initialization()
        {
            var items = new List <TruckDTO>();
            var item1 = new TruckDTO
            {
                name  = "goods1",
                goods = new List <string>()
                {
                    "Goods A", "Goods B", "Goods C"
                }
            };

            items.Add(item1);
            var item2 = new TruckDTO
            {
                name  = "goods1",
                goods = new List <string>()
                {
                    "Goods A", "Goods B", "Goods C"
                }
            };

            items.Add(item2);
            var truckJson = JsonConvert.SerializeObject(items);

            System.IO.File.WriteAllText(truckPath, truckJson);
        }
Exemplo n.º 3
0
        public async Task Returns_Required_ModelYear()
        {
            var mockServices  = new Mock <ITruckService>();
            var modelServices = new Mock <IModelService>();
            var unitOfWork    = new Mock <IUnitOfWork>();

            var truck = new SaveTruckDTO
            {
                ModelId         = new Guid("2c63c0ee-8290-4726-b505-b8ca6d9017dd"),
                YearManufacture = 2020,
                ModelYear       = 2020,
                Name            = "test"
            };

            var returns = new TruckDTO {
                Id = Guid.NewGuid()
            };

            mockServices.Setup(x => x.CreateTruck(truck)).ReturnsAsync(returns);

            var controller = new TruckController(unitOfWork.Object, mockServices.Object, modelServices.Object);

            Assert.False(truck.ModelYear == 0);

            Assert.True(truck.ModelYear >= DateTime.Now.Day);

            var result = await controller.Save(truck);

            var viewResult = Assert.IsType <RedirectToActionResult>(result);

            Assert.IsAssignableFrom <RedirectToActionResult>(viewResult);

            Assert.True(truck.Id != Guid.Empty && truck != null);
        }
Exemplo n.º 4
0
        public async Task Save_CreateTruck()
        {
            var mockServices  = new Mock <ITruckService>();
            var modelServices = new Mock <IModelService>();
            var unitOfWork    = new Mock <IUnitOfWork>();

            var truck = new SaveTruckDTO
            {
                ModelId         = new Guid("2c63c0ee-8290-4726-b505-b8ca6d9017dd"),
                ModelYear       = 2020,
                YearManufacture = 2020,
                Name            = "test"
            };

            var returns = new TruckDTO {
                Id = Guid.NewGuid()
            };

            mockServices.Setup(x => x.CreateTruck(truck)).ReturnsAsync(returns);

            var controller = new TruckController(unitOfWork.Object, mockServices.Object, modelServices.Object);

            var result = await controller.Save(truck);

            var viewResult = Assert.IsType <RedirectToActionResult>(result);

            Assert.IsAssignableFrom <RedirectToActionResult>(viewResult);

            Assert.NotNull(returns);
        }
        public void Get_warehouse_hierarchy_should_return_warehouse()
        {
            var warehouses = new List <WarehouseDTO>();
            var root       = new WarehouseDTO()
            {
                Code = "ROOT", Description = "Root WH", Duration = 0.5m, Parent = null
            };

            warehouses.Add(root);
            var truck = new TruckDTO()
            {
                Code = "TMOC", Parent = null, Duration = 0.5m, Latitude = 14, Longitude = 40, NumberPlate = "MOCKTRK-1", Radius = 10m
            };
            var trucks = new List <TruckDTO>();

            trucks.Add(truck);
            warehouseRepMock.Setup(input => input.FindByParent(null)).Returns(warehouses);
            truckRepMock.Setup(input => input.FindByParent(It.IsAny <WarehouseDTO>())).Returns(trucks);

            // Act
            var result = warehouse.GetWarehouseHierarchy();

            // Assert
            Assert.IsInstanceOfType(result, typeof(WarehouseModel));
        }
        public void Get_truck_by_code_should_return_truck()
        {
            var truckdto = new TruckDTO {
                Code        = "TMOC",
                Parent      = null,
                Duration    = 0.5m,
                Latitude    = 14,
                Longitude   = 40,
                NumberPlate = "MOCKTRK-1",
                Radius      = 10m
            };

            //warehouseRepository????
            warehouseRepMock.Setup(input => input.GetByCode(It.IsAny <string>())).Returns(truckdto);
            // Arrange
            //   TruckModel truck = new TruckModel() { Code = "TMOC", Parent = null, Duration = 0.5m, Latitude = 14, Longitude = 40, NumberPlate = "MOCKTRK-1", Radius = 10m };
            //  WarehouseModel root = new WarehouseModel() { Code = "ROOT", Description = "Root WH", Duration = 0.5m, Parent = null, Trucks = new List<TruckModel>() { truck } };
            // _wl.AddWarehouseRoot(root);

            // Act
            var result = warehouse.GetTruckByCode("TMOC");

            // Assert
            Assert.IsInstanceOfType(result, typeof(TruckModel));
        }
Exemplo n.º 7
0
        public void UpdateTruck(long TruckId, [FromBody] TruckForUpdating truck)
        {
            TruckDTO truckToReturn = _logicRepository.UpdateTruck(TruckId, truck);

            _logicRepository.Save();

            //return Ok(truckToReturn);
        }
Exemplo n.º 8
0
 public void Delete(TruckDTO t)
 {
     try
     {
         _dbContext.Trucks.Remove(t);
         _dbContext.SaveChanges();
     }
     catch (Exception ex)
     {
         throw new DalException("DAL error deleting truck", ex);
     }
 }
Exemplo n.º 9
0
 public void Create(TruckDTO t)
 {
     try
     {
         _dbContext.Trucks.Add(t);
         _dbContext.SaveChanges();
     }
     catch (Exception ex)
     {
         throw new DalException("DAL error creating truck", ex);
     }
 }
        public TruckDTO UpdateTruck(long TruckId, TruckForUpdating truck)
        {
            IsPresent(TruckId);

            TruckDTO truckToReturn = GetTruckById(TruckId);

            truckToReturn.PriceUSD   = truck.PriceUSD;
            truckToReturn.Model      = truck.Model;
            truckToReturn.AmountYear = truck.YearGraduation.GetCurrentAge();



            return(truckToReturn);
        }
Exemplo n.º 11
0
        public void Report_hop_should_return_true()
        {
            var hop = new HopArrivalModel
            {
                Code       = "1234",
                DateTime   = DateTime.Now,
                TrackingId = "12345ABC"
            };

            var recipient = new RecipientDTO
            {
                FirstName  = "Rudi",
                LastName   = "Recipient",
                Street     = "Poststraße",
                PostalCode = "A-1070",
                City       = "Poststadt"
            };
            var parcel = new ParcelDTO {
                Recipient = recipient, Weight = 1.0f, TrackingCode = "MOCKCODE"
            };

            var ware = new WarehouseDTO
            {
                Code        = "1234",
                Description = "root warehouse",
                Duration    = 12,
                Id          = 3
            };

            var truck = new TruckDTO
            {
                Code        = "1234",
                Description = "root truck",
                Duration    = 42,
                Id          = 4
            };

            truckMock.Setup(input => input.GetByCode(It.IsAny <string>())).Returns(truck);
            warehouseMock.Setup(input => input.GetByCode(It.IsAny <string>())).Returns(ware);
            parcelMock.Setup(input => input.GetByTrackingCode(It.IsAny <string>())).Returns(parcel);
            var result = tracking.ReportHop(hop);

            // Assert
            Assert.IsTrue(result);
        }
 public void Delete(TruckDTO t)
 {
     _trucks.Remove(t);
 }
 public void Update(TruckDTO t)
 {
     throw new NotImplementedException();
 }
 public void Create(TruckDTO t)
 {
     t.Id = _autoinc++;
     _trucks.Add(t);
 }