Beispiel #1
0
        public void AddNew(ExtendGenreDTO genreDto)
        {
            genreDto.Id = Guid.NewGuid();
            _unitOfWork.Genres.Create(_mapper.Map <Genre>(genreDto));
            _unitOfWork.Save();

            _log.Info($"{nameof(GenreService)} - add new genre { genreDto.Id}");
        }
Beispiel #2
0
        public bool IsUniqueRuName(ExtendGenreDTO genreDto)
        {
            var genre = _unitOfWork.Genres.Get(x => x.NameRu == genreDto.NameRu).FirstOrDefault();

            if (genre == null || genreDto.Id == genre.Id)
            {
                return(true);
            }

            return(false);
        }
Beispiel #3
0
        public bool IsPossibleRelation(ExtendGenreDTO genreDto)
        {
            var reverseGenreDto = _unitOfWork.Genres.Get(g => g.Id == genreDto.ParentGenreId &&
                                                         g.ParentGenreId == genreDto.Id).FirstOrDefault();

            if (reverseGenreDto == null)
            {
                return(true);
            }

            return(false);
        }
Beispiel #4
0
        public void Update(ExtendGenreDTO genreDto)
        {
            if (GetGenreById(genreDto.Id) != null)
            {
                var genre = _mapper.Map <Genre>(genreDto);

                _unitOfWork.Genres.Update(genre);
                _unitOfWork.Save();

                _log.Info($"{nameof(GenreService)} - update genre {genreDto.Id}");
            }
        }
Beispiel #5
0
        public void IsUniqueRuName_UniqueName_True()
        {
            var genre = new ExtendGenreDTO()
            {
                Id = Guid.NewGuid(), NameRu = _fakeGenreName
            };

            _uow.Setup(uow => uow.Genres.Get(It.IsAny <Func <Genre, bool> >())).Returns(new List <Genre>());

            var res = _sut.IsUniqueRuName(genre);

            Assert.True(res);
        }
Beispiel #6
0
        public void Update_GenreName_ReturnedView()
        {
            var fakeGenre = new ExtendGenreDTO()
            {
                Id = Guid.NewGuid(), NameEn = _fakeGenreName
            };

            _genreService.Setup(service => service.GetByName(_fakeGenreName)).Returns(fakeGenre);
            _genreService.Setup(service => service.GetAll()).Returns(new List <GenreDTO>());

            var res = _sut.Update(_fakeGenreName);

            Assert.IsType <ViewResult>(res);
        }
Beispiel #7
0
        public void AddNewGenre_GenreWithUniqueName_CreateCalled()
        {
            var fakeGenreDTO = new ExtendGenreDTO()
            {
                Id = Guid.NewGuid(), NameEn = "uniqueName"
            };
            var fakeGenre = _mapper.Map <Genre>(fakeGenreDTO);

            _uow.Setup(uow => uow.Genres.Get(It.IsAny <Func <Genre, bool> >())).Returns(new List <Genre>());
            _uow.Setup(uow => uow.Genres.Create(fakeGenre));

            _sut.AddNew(fakeGenreDTO);

            _uow.Verify(uow => uow.Genres.Create(It.IsAny <Genre>()), Times.Once);
        }
Beispiel #8
0
        public void IsPossibleRelation_GenreDTOWithPossibleRelation_True()
        {
            Guid firstFakeId = Guid.NewGuid();
            var  newGenre    = new ExtendGenreDTO()
            {
                Id            = Guid.NewGuid(),
                NameEn        = _fakeGenreName,
                ParentGenreId = firstFakeId
            };

            _uow.Setup(uow => uow.Genres.Get(It.IsAny <Func <Genre, bool> >())).Returns(new List <Genre>());

            var res = _sut.IsPossibleRelation(newGenre);

            Assert.True(res);
        }