Esempio n. 1
0
        public void Create_GivenValidModelAndData_ShouldReturnCompletedTask()
        {
            // arrange
            DriveCreateEditViewModel model = new DriveCreateEditViewModel();
            ParsedDriveCreateData    data  = new ParsedDriveCreateData()
            {
                From   = new City(),
                To     = new City(),
                Car    = new Car(),
                Date   = new DateTime(),
                Driver = new ApplicationUser()
            };

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

            mockRepository.Setup(m => m.CreateAsync(It.IsAny <Drive>()))
            .Returns(Task.FromResult(new Drive()));

            IMapper mapper = new Mapper(new MapperConfiguration(cfg =>
                                                                cfg.CreateMap <DriveCreateEditViewModel, Drive>()
                                                                .ForMember(dest => dest.From, opt => opt.Ignore())
                                                                .ForMember(dest => dest.To, opt => opt.Ignore())
                                                                .ForMember(dest => dest.Car, opt => opt.Ignore())
                                                                .ForMember(dest => dest.Driver, opt => opt.Ignore())
                                                                .ForMember(dest => dest.DateTime, opt => opt.Ignore())));

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

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

            // assert
            action.Should().NotThrow();
        }
Esempio n. 2
0
        public async Task CreateAsync(DriveCreateEditViewModel model, ParsedDriveCreateData data)
        {
            Require.ThatObjectIsNotNull(model);
            Require.ThatObjectIsNotNull(data);

            Drive drive = this.MapDriveCreate(model, data);

            await this.drives.CreateAsync(drive);
        }
Esempio n. 3
0
        private async Task <ParsedDriveCreateData> ParseModelDataCreate(string from, string to, int carId, string dateAsString, int driverId)
        {
            ParsedDriveUpdateData data = await this.ParseModelData(from, to, carId, dateAsString);

            ParsedDriveCreateData parsedData = this.mapper.Map <ParsedDriveCreateData>(data);

            parsedData.Driver = this.GetDriver(driverId);

            return(parsedData);
        }
Esempio n. 4
0
        private Drive MapDriveCreate(DriveCreateEditViewModel model, ParsedDriveCreateData data)
        {
            Drive drive = this.MapDrive(model, data);

            if (drive != null && data.Driver != null)
            {
                drive.Driver = data.Driver;
                return(drive);
            }

            return(null);
        }
Esempio n. 5
0
        public void Create_GivenNullModel_ShouldThrowNullObjectException()
        {
            // arrange
            var            data    = new ParsedDriveCreateData();
            IDrivesService service = new DrivesService(null, null, null);

            // act
            Func <Task> action = async() => await service.CreateAsync(null, data);

            // assert
            action.Should().ThrowExactly <NullObjectException>();
        }
Esempio n. 6
0
        public void Create_GivenDataWithNullFrom_ShouldReturnNull()
        {
            // arrange
            DriveCreateEditViewModel model = new DriveCreateEditViewModel();
            ParsedDriveCreateData    data  = new ParsedDriveCreateData()
            {
                From = null,
                To   = new City(),
                Car  = new Car(),
                Date = new DateTime()
            };

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

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

            // assert
            action.Should().Equals(Task.FromResult <Drive>(null));
        }