Пример #1
0
        public void UpdateBikeModel_Updates_BikeModel()
        {
            var testId     = 1;
            var testString = "test";
            var bike       = new BikeModelEntity();
            var dto        = new BikeModelDto
            {
                ModelName      = testString,
                ManufacturerId = testId,
                BikeTypeId     = testId,
                Description    = testString,
                ImageUrl       = testString,
                IsBikeForMales = true,
                IsChildBike    = true
            };

            mockRepo.Setup(r => r.GetById(It.IsAny <Guid>())).Returns(bike);
            bikeModelService.UpdateBikeModel(dto);

            mockRepo.Verify(r => r.Update(
                                It.Is <BikeModelEntity>(b =>
                                                        b.ModelName == testString &&
                                                        b.ManufacturerId == testId &&
                                                        b.BikeTypeId == testId &&
                                                        b.Description == testString &&
                                                        b.ImageUrl == testString &&
                                                        b.IsBikeForMales == true &&
                                                        b.IsChildBike == true)),
                            Times.Once);
        }
Пример #2
0
        public void CreateBikeModel_Calls_Create_In_Repo()
        {
            var dto = new BikeModelDto();

            bikeModelService.CreateBikeModel(dto);
            mockRepo.Verify(r => r.Insert(It.IsAny <BikeModelEntity>()), Times.Once);
        }
Пример #3
0
        public void DeleteBikeModel_Deletes_Model()
        {
            var bike = new BikeModelEntity();
            var dto  = new BikeModelDto();

            mockRepo.Setup(r => r.GetById(It.IsAny <Guid>())).Returns(bike);
            bikeModelService.DeleteBikeModel(bike.Id);

            mockRepo.Verify(r => r.Delete(It.IsAny <BikeModelEntity>()), Times.Once);
        }
Пример #4
0
        public void CreateBikeModel_Inserts_BikeModel()
        {
            var model = new BikeModelEntity();
            var dto   = new BikeModelDto();

            mockMapper.Setup(m => m.Map <BikeModelEntity>(dto)).Returns(model);
            bikeModelService.CreateBikeModel(dto);

            mockRepo.Verify(r => r.Insert(model), Times.Once);
        }
Пример #5
0
        public void CreateBikeModel_Returns_BikeModelDto()
        {
            var model = new BikeModelEntity();
            var dto   = new BikeModelDto();

            mockRepo.Setup(r => r.Insert(It.IsAny <BikeModelEntity>())).Returns(model);
            mockMapper.Setup(m => m.Map <BikeModelDto>(model)).Returns(dto);
            var actual = bikeModelService.CreateBikeModel(dto);

            Assert.AreEqual(dto, actual);
        }
Пример #6
0
        public void CreateBike_Returns_BikeModelResource()
        {
            var expected = new BikeModelDto();
            var request  = new CreateBikeModelRequest();

            mockMapper.Setup(m => m.Map <BikeModelDto>(It.IsAny <CreateBikeModelRequest>())).Returns(new BikeModelDto());
            mockService.Setup(r => r.CreateBikeModel(It.IsAny <BikeModelDto>())).Returns(expected);
            mockService.Setup(r => r.GetModelById(It.IsAny <Guid>())).Returns(expected);
            var result = bikeModelController.CreateBikeModel(request) as CreatedAtActionResult;
            var actual = result.Value as BikeModelDto;

            Assert.AreEqual(expected, actual);
        }
Пример #7
0
        public void CreateBike_Returns_Ok_Result()
        {
            var expected = new BikeModelDto();
            var request  = new CreateBikeModelRequest();

            mockMapper.Setup(m => m.Map <BikeModelDto>(It.IsAny <CreateBikeModelRequest>())).Returns(new BikeModelDto());
            mockService.Setup(r => r.CreateBikeModel(It.IsAny <BikeModelDto>())).Returns(expected);
            mockService.Setup(r => r.GetModelById(It.IsAny <Guid>())).Returns(expected);
            var result = bikeModelController.CreateBikeModel(request) as CreatedAtActionResult;

            Assert.NotNull(result);
            Assert.AreEqual(201, result.StatusCode);
        }
Пример #8
0
        public void UpdateBikeModel(BikeModelDto bikeModelDto)
        {
            var bike = _bikeModelRepository.GetById(bikeModelDto.Id);

            bike.IsActive       = bikeModelDto.IsActive;
            bike.ModelName      = bikeModelDto.ModelName;
            bike.ManufacturerId = bikeModelDto.ManufacturerId;
            bike.BikeTypeId     = bikeModelDto.BikeTypeId;
            bike.Description    = bikeModelDto.Description;
            bike.ImageUrl       = bikeModelDto.ImageUrl;
            bike.IsBikeForMales = bikeModelDto.IsBikeForMales;
            bike.IsChildBike    = bikeModelDto.IsChildBike;
            _bikeModelRepository.Update(bike);
        }
Пример #9
0
        public BikeModelDto CreateBikeModel(BikeModelDto bikeModelDto)
        {
            bikeModelDto.Slug = _slugService.CreateSlug(bikeModelDto.ModelName);

            if (_bikeModelRepository.GetBySlug(bikeModelDto.Slug) == null)
            {
                var modelToInsert = _mapper.Map <BikeModelEntity>(bikeModelDto);
                var model         = _bikeModelRepository.Insert(modelToInsert);
                return(_mapper.Map <BikeModelDto>(model));
            }
            else
            {
                throw new Exception();
            }
        }
Пример #10
0
        public void EditBike_Sends_BikeModelDto_To_Service()
        {
            var testId = 1;
            var dto    = new BikeModelDto
            {
                Id             = Guid.NewGuid(),
                BikeTypeId     = testId,
                Description    = "Test",
                ImageUrl       = "Test",
                IsBikeForMales = true,
                IsChildBike    = true,
                ManufacturerId = testId,
                ModelName      = "Test",
                Slug           = "Test"
            };

            mockMapper.Setup(m => m.Map <BikeModelDto>(It.IsAny <EditBikeModelRequest>())).Returns(dto);
            bikeModelController.EditBikeModel(new EditBikeModelRequest());

            mockService.Verify(s => s.UpdateBikeModel(dto), Times.Once);
        }
Пример #11
0
        public void EditBike_Returns_Ok_Result()
        {
            var testId = 1;
            var dto    = new BikeModelDto
            {
                Id             = Guid.NewGuid(),
                BikeTypeId     = testId,
                Description    = "Test",
                ImageUrl       = "Test",
                IsBikeForMales = true,
                IsChildBike    = true,
                ManufacturerId = testId,
                ModelName      = "Test",
                Slug           = "Test"
            };

            mockMapper.Setup(m => m.Map <BikeModelDto>(It.IsAny <EditBikeModelRequest>())).Returns(dto);
            var result = bikeModelController.EditBikeModel(new EditBikeModelRequest()) as OkResult;

            Assert.NotNull(result);
            Assert.AreEqual(200, result.StatusCode);
        }