Exemplo n.º 1
0
        public async Task EditVignetteAsyncShouldEditCorrectly()
        {
            //Arrange
            var editVignetteFormServiceModel = new VignetteFormServiceModel
            {
                StartDate = DateTime.UtcNow.AddDays((int)TimesPeriod.Dayly),
                EndDate   = DateTime.UtcNow.AddDays((int)TimesPeriod.YearDays + (int)TimesPeriod.Dayly),
                Expired   = false
            };

            var newVignette = this.fixture.Mapper
                              .Map <VignetteFormServiceModel, Data.Models.Vignette>(editVignetteFormServiceModel, opt =>
                                                                                    opt.ConfigureMap()
                                                                                    .ForMember(m => m.Id, opt => opt.Ignore())
                                                                                    .ForMember(m => m.Vehicle, opt => opt.Ignore()));

            //Act
            await this.vignetteServise.EditAsync(2, editVignetteFormServiceModel);

            var vignetteModel = await this.vignetteServise.GetByIdAsync <VignetteFormServiceModel>(2);

            //Assert
            Assert.Equal(vignetteModel.StartDate, editVignetteFormServiceModel.StartDate);
            Assert.Equal(vignetteModel.EndDate, editVignetteFormServiceModel.EndDate);
            Assert.Equal(vignetteModel.Expired, editVignetteFormServiceModel.Expired);
        }
Exemplo n.º 2
0
        public async Task AddVignetteAsync(int vehicleId, VignetteFormServiceModel vignetteFormModel)
        {
            var existVehicle = await this.db.Vehicles.AnyAsync(v => v.Id == vehicleId);

            if (!existVehicle)
            {
                throw new ArgumentException(NotExistItemExceptionMessage);
            }

            var existVignette = await this.DoesVehicleHaveActiveVignetteAsync(vehicleId);

            if (existVignette)
            {
                throw new ArgumentException(ExistItemExceptionMessage);
            }

            if (vignetteFormModel.StartDate > vignetteFormModel.EndDate)
            {
                throw new ArgumentException(WrongDateExceptionMessage);
            }

            var newVignette = this.mapper
                              .Map <VignetteFormServiceModel, Data.Models.Vignette>(vignetteFormModel, opt =>
                                                                                    opt.ConfigureMap()
                                                                                    .ForMember(m => m.Id, opt => opt.Ignore())
                                                                                    .ForMember(m => m.Vehicle, opt => opt.Ignore()));

            await this.db.Vignettes.AddAsync(newVignette);

            await this.db.SaveChangesAsync();
        }
Exemplo n.º 3
0
        public async Task AddPostMethod_WithValidVignette_ShouldCAddSuccessMessageTempData()
        {
            VignetteFormViewModel    newVignette  = GetVignetteFormViewMode();
            VignetteFormServiceModel newVignette2 = GetVignetteFormServiceModel();

            var mockVignettesService = new Mock <IVignettesService>();
            var mockVehiclesService  = new Mock <IVehicleService>();
            var mockImapper          = new Mock <IMapper>();

            TempDataDictionary tempData = TempDataDictionary();

            var controller = new VignettesController(
                mockVignettesService.Object,
                mockVehiclesService.Object,
                mockImapper.Object)
            {
                TempData = tempData
            };

            MockGetVignetteByVehicleId(mockVignettesService);
            MockIMapper(newVignette2, mockImapper);
            MockAddVignette(mockVignettesService);

            //Act
            await controller.Add(newVignette);

            //Assert
            Assert.True(controller.TempData.ContainsKey(TempDataSuccessMessageKey));
        }
Exemplo n.º 4
0
        //Callback не се инициализира защото, трябва да има съществуващ VehicleId
        public async Task AddPostMethod_WithValidVignette_ShouldCallServiceMethod()
        {
            //Arrange
            bool serviceMethodCall = false;
            VignetteFormViewModel    newVignette  = GetVignetteFormViewMode();
            VignetteFormServiceModel newVignette2 = GetVignetteFormServiceModel();

            var mockVignettesService = new Mock <IVignettesService>();
            var mockVehiclesService  = new Mock <IVehicleService>();
            var mockImapper          = new Mock <IMapper>();

            TempDataDictionary tempData = TempDataDictionary();

            var controller = new VignettesController(
                mockVignettesService.Object,
                mockVehiclesService.Object,
                mockImapper.Object)
            {
                TempData = tempData
            };

            MockGetVignetteByVehicleId(mockVignettesService);
            MockIMapper(newVignette2, mockImapper);


            mockVignettesService.Verify(srv => srv.AddVignetteAsync(It.IsAny <int>(), It.IsAny <VignetteFormServiceModel>()), Times.Once());
            //mockVignettesService.Setup(srv => srv.AddVignetteAsync(vehicleIdConst, newVignette2))
            //    .Callback(() => serviceMethodCall = true);

            //Act
            var result = await controller.Add(newVignette);

            //Assert
            //Assert.True(serviceMethodCall);
        }
Exemplo n.º 5
0
        public async Task AddVignetteAsyncShouldReturnErrorMessageWhenVehicleNotExist()
        {
            //Arrange
            var model = new VignetteFormServiceModel();

            //Act
            var exceptionMessage = await Assert.ThrowsAsync <ArgumentException>(() => this.vignetteServise.AddVignetteAsync(int.MaxValue, model));

            //Assert
            Assert.Equal(NotExistItemExceptionMessage, exceptionMessage.Message);
        }
Exemplo n.º 6
0
        public async Task EditAsync(int vignetteId, VignetteFormServiceModel vignetteFormModel)
        {
            var editVignette =
                await this.db.Vignettes.FirstOrDefaultAsync(v => v.Id == vignetteId);

            if (editVignette == null)
            {
                throw new ArgumentException(NotExistItemExceptionMessage);
            }

            this.mapper.Map(vignetteFormModel, editVignette, opt =>
                            opt.ConfigureMap()
                            .ForMember(m => m.Id, opt => opt.Ignore())
                            .ForMember(m => m.Vehicle, opt => opt.Ignore()));

            await this.db.SaveChangesAsync();
        }
Exemplo n.º 7
0
        public async Task AddVignetteAsyncShouldReturnErrorIfStartDateIsBiggerOrEqualEndDate(DateTime startDate, DateTime endDate)
        {
            //Arrange
            var newVignetteModel = new VignetteFormServiceModel
            {
                Expired   = false,
                StartDate = startDate,
                EndDate   = endDate
            };

            //Act
            var exceptionMessage = await Assert.ThrowsAsync <ArgumentException>(()
                                                                                => this.vignetteServise.AddVignetteAsync(10, newVignetteModel));

            //Assert
            Assert.Equal(WrongDateExceptionMessage, exceptionMessage.Message);
        }
Exemplo n.º 8
0
 private static void MockIMapper(VignetteFormServiceModel newVignette2, Mock <IMapper> mockImapper)
 {
     mockImapper.Setup(m => m.Map <VignetteFormServiceModel>(It.IsAny <VignetteFormViewModel>()))
     .Returns(newVignette2);
 }