Пример #1
0
        public void GetEditModelById_GivenValidId_ShouldReturnValidDriveCreateEditViewModel()
        {
            // arrange
            int id = 1;

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

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

            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 = service.GetEditModelById(id);

            // assert
            result.Should().Equals(new DriveCreateEditViewModel()
            {
                Id = id
            });
        }
Пример #2
0
        public void GetEditModelById_GivenNonExistingId_ShouldReturnNull()
        {
            // arrange
            int id = 10;

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

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

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

            // act
            var result = service.GetEditModelById(id);

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