Example #1
0
        public void EditPublisher_ValidMethodParameter_True()
        {
            //assign
            Publisher existedEntity = new Publisher()
            {
                Id = 1, Name = "Ubisoft"
            };
            EditPublisherDto newPublisher = new EditPublisherDto()
            {
                Id = 1, Name = "Sega"
            };

            publisherRepositoryMoq.Setup((p) => p.GetSingleAsync(It.IsAny <Expression <Func <Publisher, bool> > >()))
            .Returns(Task.FromResult(existedEntity));

            mapperMoq.Setup(p => p.Map(newPublisher, existedEntity))
            .Returns(new Publisher()
            {
                Id = 1, Name = "Sega"
            });

            //act
            service.EditPublisher(newPublisher);

            //assign
            unitofworkMoq.Verify(p => p.CommitAsync(), Times.Once);
            publisherRepositoryMoq.Verify(p => p.Update(It.IsAny <Publisher>()), Times.Once);
        }
Example #2
0
        public async Task <IActionResult> Put(int id, [FromBody] PublisherCreateModel value)
        {
            EditPublisherDto editedPubliisher = new EditPublisherDto()
            {
                Id   = id,
                Name = value.Name,
            };

            await publisherService.EditPublisher(editedPubliisher);

            return(StatusCode((int)HttpStatusCode.OK, "Publisher was updated"));
        }
Example #3
0
        public async Task EditPublisher(EditPublisherDto genreDto)
        {
            using (unitOfWork)
            {
                var publisher = await unitOfWork.PublisherRepository.GetSingleAsync(p => p.Id == genreDto.Id);

                if (publisher == null)
                {
                    throw new ArgumentException("Invalid publisher Id");
                }

                publisher = mapper.Map(genreDto, publisher);

                unitOfWork.PublisherRepository.Update(publisher);
                await unitOfWork.CommitAsync();
            }
        }
Example #4
0
        public void EditPublisher_EntityWithInvalidID_ThrowsArgumentException()
        {
            //assign
            Publisher        returnedNUllEntity = null;
            EditPublisherDto newPublisher       = new EditPublisherDto()
            {
                Id = 1, Name = "Sega"
            };

            publisherRepositoryMoq.Setup((p) => p.GetSingleAsync(It.IsAny <Expression <Func <Publisher, bool> > >()))
            .Returns(Task.FromResult(returnedNUllEntity));


            //act
            Assert.ThrowsAsync <ArgumentException>(async() =>
            {
                await service.EditPublisher(newPublisher);
            });

            //assign
            unitofworkMoq.Verify(p => p.CommitAsync(), Times.Never);
            publisherRepositoryMoq.Verify(p => p.Update(It.IsAny <Publisher>()), Times.Never);
        }