Exemplo n.º 1
0
        public async Task Update_GivenDataWithNullCar_ShouldReturnFalse()
        {
            // arrange
            DriveCreateEditViewModel model = new DriveCreateEditViewModel();
            ParsedDriveUpdateData    data  = new ParsedDriveUpdateData()
            {
                From = new City(),
                To   = new City(),
                Car  = null,
                Date = new DateTime()
            };
            int driveId = 1;

            Mock <IDbRepository <Drive> > mockRepository = new Mock <IDbRepository <Drive> >();

            mockRepository.Setup(m => m.GetById(It.Is <int>(i => i == driveId)))
            .Returns(new Drive()
            {
                Id = driveId
            });

            IDrivesService service = new DrivesService(mockRepository.Object, null, null);

            // act
            var result = await service.UpdateAsync(model, data, driveId);

            // assert
            result.Should().BeFalse();
        }
Exemplo n.º 2
0
        public void Update_GivenNegativeDriveId_ShouldThrowNegativeIntException()
        {
            // arrange
            var model   = new DriveCreateEditViewModel();
            var data    = new ParsedDriveUpdateData();
            int driveId = -1;

            IDrivesService service = new DrivesService(null, null, null);

            // act
            Func <Task> action = async() => await service.UpdateAsync(model, data, driveId);

            // assert
            action.Should().ThrowExactly <NegativeIntException>();
        }
Exemplo n.º 3
0
        public async Task Update_GivenNonExistingDriveId_ShouldReturnFalse()
        {
            // arrange
            var model   = new DriveCreateEditViewModel();
            var data    = new ParsedDriveUpdateData();
            int driveId = 10;

            Mock <IDbRepository <Drive> > mockRepository = new Mock <IDbRepository <Drive> >();

            mockRepository.Setup(m => m.GetById(It.Is <int>(i => i == driveId)))
            .Returns <Drive>(null);

            IDrivesService service = new DrivesService(mockRepository.Object, null, null);

            // act
            bool result = await service.UpdateAsync(model, data, driveId);

            // assert
            result.Should().BeFalse();
        }
Exemplo n.º 4
0
        public async Task Update_GivenValidModelDataAndDriveId_ShouldReturnTrue()
        {
            // arrange
            DriveCreateEditViewModel model = new DriveCreateEditViewModel();
            ParsedDriveUpdateData    data  = new ParsedDriveUpdateData()
            {
                From = new City(),
                To   = new City(),
                Car  = new Car(),
                Date = new DateTime()
            };
            int driveId = 1;

            Mock <IDbRepository <Drive> > mockRepository = new Mock <IDbRepository <Drive> >();

            mockRepository.Setup(m => m.GetById(It.Is <int>(i => i == driveId)))
            .Returns(new Drive()
            {
                Id = driveId
            });

            IMapper mapper = new Mapper(new MapperConfiguration(cfg =>
                                                                cfg.CreateMap <Drive, DriveCreateEditViewModel>()
                                                                .ForMember(dest => dest.From, opt => opt.MapFrom(source => source.From.Name))
                                                                .ForMember(dest => dest.To, opt => opt.MapFrom(source => source.To.Name))
                                                                .ForMember(dest => dest.Cars, opt => opt.Ignore())
                                                                .ForMember(dest => dest.DateTime, opt => opt.MapFrom(source => source.DateTime.ToString("o")))));

            IDrivesService service = new DrivesService(mockRepository.Object, mapper, null);

            // act
            var result = await service.UpdateAsync(model, data, driveId);

            // assert
            result.Should().BeTrue();
        }