Пример #1
0
        public async Task AddVideo_should_return_the_expected_video(string kindId, string genreId)
        {
            //Arrange
            string data = GenData.Create <string>();

            AddVideoRequest expectedVideo = new AddVideoRequest()
            {
                AltTitle    = data,
                Description = data,
                Duration    = 123,
                Episode     = 7,
                ReleaseYear = DateTime.Now,
                Season      = 1,
                Title       = data,
                KindId      = new Guid(kindId),
                GenreId     = new Guid(genreId)
            };

            VideoService sut = new VideoService(Repository, Mapper);

            //Act
            VideoResponse result = await sut.AddVideoAsync(expectedVideo);

            //Assert
            result.Should().BeEquivalentTo(expectedVideo);
        }
Пример #2
0
        public AddVideoResponse AddVideoToLibrary(AddVideoRequest request)
        {
            var response = new AddVideoResponse();

            try
            {
                var user = ApplicationUserRepository.FindOne(u => u.Username == request.User);
                if (user.Videos.Any(x => x.Id == request.VideoId))
                {
                    response.AddVideoStatus = AddVideoStatus.VideoAlreadyAdded;
                    return(response);
                }
                var video = VideoRepository.FindOne(v => v.Id == request.VideoId);
                if (user.Credits < video.Credits)
                {
                    response.AddVideoStatus = AddVideoStatus.InsufficientCredits;
                    return(response);
                }
                user.Credits -= video.Credits;
                user.Videos.Add(video);
                ApplicationUserRepository.Save(user);
                response.Credits        = user.Credits;
                response.AddVideoStatus = AddVideoStatus.Success;
            }
            catch (Exception ex)
            {
                response.AddVideoStatus = AddVideoStatus.Error;
                response.Message        = ex.Message;
            }
            return(response);
        }
Пример #3
0
        public void Should_not_have_error_when_Duration_is_null()
        {
            AddVideoRequest addVideoRequest = TestDataFactory.CreateAddVideoRequest();

            addVideoRequest.Duration = null;

            Validator.ShouldNotHaveValidationErrorFor(x => x.Duration, addVideoRequest);
        }
Пример #4
0
        public void Should_have_error_when_Duration_is_lower_than_0()
        {
            AddVideoRequest addVideoRequest = TestDataFactory.CreateAddVideoRequest();

            addVideoRequest.Duration = -1;

            Validator.ShouldHaveValidationErrorFor(x => x.Duration, addVideoRequest);
        }
Пример #5
0
        public void Should_have_error_when_GenreId_is_empty()
        {
            AddVideoRequest addVideoRequest = TestDataFactory.CreateAddVideoRequest();

            addVideoRequest.GenreId = Guid.Empty;

            Validator.ShouldHaveValidationErrorFor(x => x.GenreId, addVideoRequest);
        }
Пример #6
0
        public async Task <VideoResponse> AddVideoAsync(AddVideoRequest request)
        {
            Video video = await _mapper.From(request).AdaptToTypeAsync <Video>();

            Video result = _videoRepository.Add(video);

            int affected = await _videoRepository.UnitOfWork.SaveChangesAsync();

            return(_mapper.Map <VideoResponse>(result));
        }
Пример #7
0
        public void Should_have_error_when_KindId_doesnt_exist()
        {
            KindServiceMock
            .Setup(x => x.GetKindAsync(It.IsAny <GetKindRequest>()))
            .ReturnsAsync(() => null);

            AddVideoRequest addVideoRequest = new AddVideoRequest {
                KindId = Guid.NewGuid()
            };

            Validator.ShouldHaveValidationErrorFor(x => x.KindId, addVideoRequest);
        }
Пример #8
0
        public AddVideoResponse AddVideo(AddVideoRequest request, Guid idUser)
        {
            if (request == null)
            {
                AddNotification("AdicionarVideoRequest", MSG.OBJETO_X0_E_OBRIGATORIO.ToFormat("AdicionarVideoRequest"));
                return(null);
            }

            User user = _repositoryUser.Get(idUser);

            if (user == null)
            {
                AddNotification("User", MSG.X0_NAO_INFORMADO.ToFormat("Usuário"));
                return(null);
            }

            Channel channel = _repositoryChannel.Get(request.IdChannel);

            if (channel == null)
            {
                AddNotification("Canal", MSG.X0_NAO_INFORMADO.ToFormat("Canal"));
                return(null);
            }

            PlayList playList = null;

            if (request.IdPlayList != Guid.Empty)
            {
                playList = _repositoryPlayList.Get(request.IdPlayList);
                if (playList == null)
                {
                    AddNotification("PlayList", MSG.X0_NAO_INFORMADA.ToFormat("playList"));
                    return(null);
                }
            }

            var video = new Video(channel, playList, request.Title, request.Description, request.Tags, request.OrderPlayList, request.IdVideoYoutube, user);

            AddNotifications(video);

            if (this.IsInvalid())
            {
                return(null);
            }

            _repositoryVideo.Add(video);

            return(new AddVideoResponse(video.Id));
        }
Пример #9
0
        public async Task <IActionResult> Adicionar([FromBody] AddVideoRequest request)
        {
            try
            {
                string usuarioClaims = _httpContextAccessor.HttpContext.User.FindFirst("Usuario").Value;
                AutenticarUsuarioResponse usuarioResponse = JsonConvert.DeserializeObject <AutenticarUsuarioResponse>(usuarioClaims);

                var response = _serviceVideo.AddVideo(request, usuarioResponse.Id);

                return(await ResponseAsync(response, _serviceVideo));
            }
            catch (Exception ex)
            {
                return(await ResponseExceptionAsync(ex));
            }
        }
Пример #10
0
        public AddVideoResponse AddVideo(AddVideoRequest request, Guid idUsuario)
        {
            if (request == null)
            {
                AddNotification("AddVideoRequest", Msg.OBJETO_X0_E_OBRIGATORIO.ToFormat("AddVideoRequest"));
            }

            Usuario usuario = _repositoryUsuario.Obter(idUsuario);

            if (usuario == null)
            {
                AddNotification("Usuario", Msg.X0_NAO_INFORMADO.ToFormat("Usuario"));
            }
            Canal canal = _repositoryCanal.Obter(request.IdCanal);

            if (canal == null)
            {
                AddNotification("Canal", Msg.X0_NAO_INFORMADO.ToFormat("Canal"));
            }

            PlayList playList = null;

            if (request.IdPlayList != Guid.Empty)
            {
                playList = _repositoryPlayList.Obter(request.IdPlayList);
                if (playList == null)
                {
                    AddNotification("PlayList", Msg.X0_NAO_INFORMADA.ToFormat("playList"));
                    return(null);
                }
            }

            Video video = new Video(canal, playList, request.Titulo, request.Descricao, request.Tags, request.OrdemPlayList, request.IdVideoYoutube, usuario);

            AddNotifications(video);

            if (this.IsInvalid())
            {
                return(null);
            }

            _repositoryVideo.Add(video);

            return((AddVideoResponse)video);
        }
Пример #11
0
        public async Task Add_should_create_new_video()
        {
            //Arrange
            AddVideoRequest request = TestDataFactory.CreateAddVideoRequest();

            request.KindId  = new Guid("6fa1bc43-ee6c-4d60-a2c8-9eb1a0494fd5");
            request.GenreId = new Guid("2af1ad8c-60df-4d40-a6c7-d68da49d006a");

            HttpClient    client      = Factory.CreateClient();
            StringContent httpContent = new StringContent(JsonConvert.SerializeObject(request),
                                                          Encoding.UTF8, "application/json");

            //Act
            HttpResponseMessage response = await client.PostAsync($"{Url}", httpContent);

            //Assert
            response.EnsureSuccessStatusCode();
            response.Headers.Location.Should().NotBeNull();
        }
Пример #12
0
        public static AddVideoRequest CreateAddVideoRequest()
        {
            AddVideoRequest add = GenData.Create <AddVideoRequest>();

            return(add);
        }
Пример #13
0
        public async Task <IActionResult> Post(AddVideoRequest request)
        {
            VideoResponse result = await VideoService.AddVideoAsync(request);

            return(CreatedAtAction(nameof(GetById), new { id = result.Id }, null));
        }
Пример #14
0
 /// <summary>
 /// Добавляет видеозапись в список пользователя.
 /// </summary>
 /// <param name="callback">Метод, который будет вызван по завершении операции.
 /// Параметр является результатом запроса.</param>
 /// <param name="request">Объект запроса с необходимыми параметрами.</param>
 public void Add(Action <VKResponse <VKOperationIsSuccess> > callback, AddVideoRequest request)
 {
     VKHelper.GetResponse <VKOperationIsSuccess>(request, callback);
 }