コード例 #1
0
        public async Task CarModelService_GetAllModels_ListOfModelsWithOneModel()
        {
            var modelsToReturn = new List <CarModel> {
                new CarModel {
                    Id = Guid.Empty, Title = "Test", BrandId = Guid.Empty, CategoryId = Guid.Empty
                }
            };
            var config       = new MapperConfiguration(cfg => cfg.CreateMap <CarModel, CarModelDto>());
            var repo         = A.Fake <ICarModelRepository>();
            var modelService = new CarModelService(repo, config.CreateMapper());

            A.CallTo(() => repo.GetAllAsync()).Returns(modelsToReturn);
            var result = await modelService.GetAllAsync();

            Assert.That(result, Has.Exactly(1).Items);
        }
コード例 #2
0
        public CarsControllerTests()
        {
            _mapper = new Mapper(
                new MapperConfiguration(cfg => cfg.AddProfile(new MappingProfile())));

            _carRepository       = new EfRepository <Car>(applicationDbContext, new CarValidator());
            _imageRepository     = new EfRepository <Image>(applicationDbContext, new FileDataValidator <Image>());
            _thumbnailRepository = new EfRepository <Thumbnail>(applicationDbContext, new FileDataValidator <Thumbnail>());
            _repairRepository    = new EfRepository <Repair>(applicationDbContext, new RepairValidator());

            IImageService imageService = new ImageService(
                _imageRepository,
                _thumbnailRepository,
                new ImageFormatResolver());

            _carModelService = _carModelService = new CarModelService(
                _carRepository,
                _mapper,
                imageService);

            _carsController = new CarsController(
                _carModelService,
                _imageRepository,
                _thumbnailRepository,
                _repairRepository,
                imageService,
                new CarService(_carRepository));

            _carModel = new CarModel
            {
                Description      = "Description",
                Kilometers       = 1000,
                PurchaseDate     = new DateTime(2019, 12, 10),
                PurchasePrice    = 2000,
                LotDate          = new DateTime(2019, 12, 12),
                Make             = "Make",
                Model            = "Model",
                Trim             = "Trim",
                SellingPrice     = 4000,
                Vin              = "11111111111111111",
                ShowCase         = false,
                Year             = 2005,
                TransmissionType = Core.Enums.TransmissionType.Automatic
            };
        }
コード例 #3
0
        public async Task CategoryServiceService_GetCarModelById_GetExactlyOneCarModelWithSpecifiedValues()
        {
            var modelToReturn = new CarModel {
                Id = Guid.Empty, Title = "Test", BrandId = Guid.Empty, CategoryId = Guid.Empty
            };
            var expectedOjbect = new CarModelDto {
                Id = Guid.Empty, Title = "Test", BrandId = Guid.Empty, CategoryId = Guid.Empty
            };
            var config       = new MapperConfiguration(cfg => cfg.CreateMap <CarModel, CarModelDto>());
            var repo         = A.Fake <ICarModelRepository>();
            var modelService = new CarModelService(repo, config.CreateMapper());

            A.CallTo(() => repo.GetAsync(Guid.Empty)).Returns(modelToReturn);
            var result = await modelService.GetByIdAsync(Guid.Empty);

            Assert.That(result.CategoryId, Is.EqualTo(expectedOjbect.CategoryId));
            Assert.That(result.BrandId, Is.EqualTo(expectedOjbect.BrandId));
            Assert.That(result.Title, Is.EqualTo(expectedOjbect.Title));
            Assert.That(result.Id, Is.EqualTo(expectedOjbect.Id));
        }
コード例 #4
0
        private static void DbInitialize()
        {
            Role adminRole = new Role {
                Name = "Admin", ContentManager = true, UserAdmin = true, Seller = true, Сourier = true
            };
            Role contentManager = new Role {
                Name = "ContentManager", ContentManager = true, UserAdmin = false, Seller = false, Сourier = false
            };
            RoleService roleService = new RoleService();

            roleService.Add(adminRole);
            roleService.Add(contentManager);
            roleService.Add(new Role {
                Name = "Courier", ContentManager = false, UserAdmin = false, Seller = false, Сourier = true
            });
            roleService.Add(new Role {
                Name = "Seller", ContentManager = false, UserAdmin = false, Seller = true, Сourier = false
            });
            roleService.Add(new Role {
                Name = "Customer", ContentManager = false, UserAdmin = false, Seller = false, Сourier = false
            });

            //adminRole.Id = contentManager.Id = 0;

            //RoleService roleService = new RoleService();
            //var adminRole = roleService.GetAll().FirstOrDefault(x => x.UserAdmin == true);
            //var contentManager = roleService.GetAll().FirstOrDefault(x => x.UserAdmin == false);

            User adminUser = new User {
                Login = "******", Password = "******", RoleId = adminRole.Id
            };
            User contentUser = new User {
                Login = "******", Password = "******", RoleId = contentManager.Id
            };
            AccountService accountService = new AccountService();

            accountService.Add(adminUser);
            accountService.Add(contentUser);


            CarBrand renault = new CarBrand {
                Name = "Ranault", ImagePath = "test1"
            };
            CarBrand citroen = new CarBrand {
                Name = "Citroen", ImagePath = "test2"
            };
            CarBrand peugeot = new CarBrand {
                Name = "Peugeot", ImagePath = "test3"
            };
            CarBrand bugatti = new CarBrand {
                Name = "Bugatti", ImagePath = "test4"
            };
            CarBrandService carBrandService = new CarBrandService();

            carBrandService.Add(renault);
            carBrandService.Add(citroen);
            carBrandService.Add(peugeot);
            carBrandService.Add(bugatti);

            CarModel logan = new CarModel {
                Name = "Logan", CarBrandId = renault.Id
            };
            CarModel stepway = new CarModel {
                Name = "Stepway", CarBrandId = renault.Id
            };
            CarModel kaptur = new CarModel {
                Name = "Kaptur", CarBrandId = renault.Id
            };
            CarModel koleos = new CarModel {
                Name = "Koleos", CarBrandId = renault.Id
            };
            CarModelService carModelService = new CarModelService();

            carModelService.Add(logan);
            carModelService.Add(stepway);
            carModelService.Add(kaptur);
            carModelService.Add(koleos);

            Console.WriteLine("DB has been initialized");
        }