Exemple #1
0
        public void UpdateTest()
        {
            //Arange
            RateDTO projectDto = new RateDTO()
            {
                Id     = "id1",
                UserId = "userId1",
                BookId = "bookId1",
                Value  = 1
            };
            bool isUpdate = false;
            Mock <IUnitOfWork>         unitOfWorkMock = new Mock <IUnitOfWork>();
            Mock <IRepository <Rate> > repositoryMock = new Mock <IRepository <Rate> >();

            repositoryMock.Setup(repo => repo.Get(It.IsAny <Expression <Func <Rate, bool> > >()))
            .Returns <Expression <Func <Rate, bool> > >(predicate =>
                                                        _rates.Where(predicate.Compile()).AsQueryable());
            repositoryMock.Setup(repo => repo.Update(It.Is <Rate>(entity =>
                                                                  (entity.Id == projectDto.Id))))
            .Callback(() => isUpdate = true);
            unitOfWorkMock.Setup(getRepo => getRepo.GetRepository <Rate>()).Returns(repositoryMock.Object);
            RateService _rateService = new RateService(unitOfWorkMock.Object);

            //Act
            _rateService.Update(projectDto);

            //Assert
            Assert.True(isUpdate);
        }
Exemple #2
0
        public IActionResult Update(string id, Rate rateIn)
        {
            var rate = _rateService.Get(id);

            if (rate == null)
            {
                return(NotFound());
            }

            _rateService.Update(id, rateIn);

            return(NoContent());
        }
Exemple #3
0
        public IActionResult Update(string id, Rate item)
        {
            var items = _service.Get(id);

            if (items == null)
            {
                return(NotFound());
            }

            _service.Update(id, item);

            return(NoContent());
        }
Exemple #4
0
        public async void Update()
        {
            var mock  = new ServiceMockFacade <IRateRepository>();
            var model = new ApiRateRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Rate>())).Returns(Task.FromResult(new Rate()));
            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(new Rate()));
            var service = new RateService(mock.LoggerMock.Object,
                                          mock.RepositoryMock.Object,
                                          mock.ModelValidatorMockFactory.RateModelValidatorMock.Object,
                                          mock.BOLMapperMockFactory.BOLRateMapperMock,
                                          mock.DALMapperMockFactory.DALRateMapperMock);

            UpdateResponse <ApiRateResponseModel> response = await service.Update(default(int), model);

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.RateModelValidatorMock.Verify(x => x.ValidateUpdateAsync(It.IsAny <int>(), It.IsAny <ApiRateRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Update(It.IsAny <Rate>()));
        }
Exemple #5
0
        public async void Update_NoErrorsOccurred_ShouldReturnResponse()
        {
            var mock  = new ServiceMockFacade <IRateService, IRateRepository>();
            var model = new ApiRateServerRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Rate>())).Returns(Task.FromResult(new Rate()));
            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(new Rate()));
            var service = new RateService(mock.LoggerMock.Object,
                                          mock.MediatorMock.Object,
                                          mock.RepositoryMock.Object,
                                          mock.ModelValidatorMockFactory.RateModelValidatorMock.Object,
                                          mock.DALMapperMockFactory.DALRateMapperMock);

            UpdateResponse <ApiRateServerResponseModel> response = await service.Update(default(int), model);

            response.Should().NotBeNull();
            response.Success.Should().BeTrue();
            mock.ModelValidatorMockFactory.RateModelValidatorMock.Verify(x => x.ValidateUpdateAsync(It.IsAny <int>(), It.IsAny <ApiRateServerRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Update(It.IsAny <Rate>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <RateUpdatedNotification>(), It.IsAny <CancellationToken>()));
        }