예제 #1
0
        public void ShouldSaveSound()
        {
            _soundsAvailable.Clear();

            SoundDto savedSound = null;

            _soundRepositoryMock.Setup(x => x.Save(It.IsAny <SoundDto>()))
            .Callback <SoundDto>(soundDto =>
            {
                savedSound = soundDto;
            });

            _soundService.CreateSound(_sound);

            Assert.NotNull(savedSound);
            Assert.Equal(_sound, savedSound);
        }
예제 #2
0
        public ResponseDto CreateSound(SoundDto sound)
        {
            if (sound == null)
            {
                throw new ArgumentException(nameof(sound));
            }

            ResponseDto response;

            if (_soundRepository.FindSoundByName(sound.Name) == null)
            {
                long id = _soundRepository.Save(sound);

                response = ResponseUtils.CreateResponseDto(StatusCodeEnum.Success, id);
            }
            else
            {
                response = ResponseUtils.CreateResponseDto(StatusCodeEnum.ErrorSameNameSounds);
            }

            return(response);
        }
예제 #3
0
        public DataInsertion()
        {
            #region Author definition

            _authorsAvailable = new List <Author> {
                new Author
                {
                    Id     = 1,
                    Name   = "Pearl Jam",
                    ImgUrl = "https://i.ytimg.com/vi/cs-XZ_dN4Hc/0.jpg"
                }
            };

            _author = new AuthorDto
            {
                Name   = "Pearl Jam",
                ImgUrl = "https://i.ytimg.com/vi/cs-XZ_dN4Hc/0.jpg"
            };

            #endregion

            #region Category definition

            _categoriesAvailable = new List <Category> {
                new Category
                {
                    Id     = 1,
                    Name   = "Rock",
                    ImgUrl = "https://i.ytimg.com/vi/cs-XZ_dN4Hc/0.jpg"
                }
            };

            _category = new CategoryDto
            {
                Name   = "Rock",
                ImgUrl = "https://images.vexels.com/media/users/3/145816/isolated/preview/7616b64374d1ecc318e9d638807c4d61-logotipo-de-sinal-de-m-sica-rock-by-vexels.png"
            };

            #endregion

            #region Sounds Definition

            _soundsAvailable = new List <Sound> {
                new Sound
                {
                    Id         = 1,
                    Name       = "Black",
                    IdCategory = 1,
                    ImgUrl     = "https://i.ytimg.com/vi/cs-XZ_dN4Hc/0.jpg",
                    HeardCount = 1000
                }
            };

            _sound = new SoundDto
            {
                Name       = "Black",
                HeardCount = 0,
                ImgUrl     = "https://i.ytimg.com/vi/4q9UafsiQ6k/hqdefault.jpg"
            };

            #endregion

            #region Author Repository and Service

            _authorRepositoryMock = new Mock <IAuthorRepository>();
            _authorRepositoryMock.Setup(x => x.GetAuthorByName(_author.Name))
            .Returns(_authorsAvailable);

            _authorService = new AuthorService(
                _authorRepositoryMock.Object);

            #endregion

            #region Category Repository and Service

            _categoryRepositoryMock = new Mock <ICategoryRepository>();
            _categoryRepositoryMock.Setup(x => x.GetCategoryByName(_category.Name))
            .Returns(_categoriesAvailable);

            _categoryService = new CategoryService(
                _categoryRepositoryMock.Object);

            #endregion

            #region Sound Repository and Service

            _soundRepositoryMock = new Mock <ISoundRepository>();
            _soundRepositoryMock.Setup(x => x.GetSoundByName(_sound.Name))
            .Returns(_soundsAvailable);

            _soundService = new SoundService(
                _soundRepositoryMock.Object);

            #endregion
        }