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 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); }
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); }