예제 #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();
        }
예제 #2
0
        public void Create_GivenNullData_ShouldThrowNullObjectException()
        {
            // arrange
            var            model   = new DriveCreateEditViewModel();
            IDrivesService service = new DrivesService(null, null, null);

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

            // assert
            action.Should().ThrowExactly <NullObjectException>();
        }
예제 #3
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>();
        }
예제 #4
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));
        }