Ejemplo n.º 1
0
        public async Task Update_should_modify_video()
        {
            //Arrange
            EditVideoRequest request = TestDataFactory.CreateEditVideoRequest();

            request.KindId  = new Guid("2fd37626-0b1d-4d51-a243-0bc4266a7a99");
            request.GenreId = new Guid("9dc0d6f2-a3d8-41a9-8393-d832c0b7a6e9");
            Guid Id = new Guid("eaa0B9d4-4A2d-496e-8a68-a36cd0758abb");

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

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

            //Assert
            response.EnsureSuccessStatusCode();
            string responseContent = await response.Content.ReadAsStringAsync();

            Video responseEntity = JsonConvert.DeserializeObject <Video>(responseContent);

            responseEntity.Should().BeEquivalentTo(request, o => o.Excluding(x => x.Id));
            Assert.Equal(Id, responseEntity.Id);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Put(Guid id, EditVideoRequest request)
        {
            request.Id = id;
            VideoResponse result = await VideoService.EditVideoAsync(request);

            return(Ok(result));
        }
Ejemplo n.º 3
0
        public async Task EditVideo_should_return_the_expected_video(string kindId, string genreId)
        {
            //Arrange
            string data = GenData.Create <string>();

            EditVideoRequest expectedVideo = new EditVideoRequest()
            {
                Id          = new Guid("eaa0B9d4-4A2d-496e-8a68-a36cd0758abb"),
                AltTitle    = data,
                Description = data,
                IsInactive  = false,
                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.EditVideoAsync(expectedVideo);

            //Assert
            result.Should().BeEquivalentTo(expectedVideo, o => o.Excluding(x => x.IsInactive));
        }
Ejemplo n.º 4
0
        public void Should_not_have_error_when_Duration_is_null()
        {
            EditVideoRequest addVideoRequest = TestDataFactory.CreateEditVideoRequest();

            addVideoRequest.Duration = null;

            Validator.ShouldNotHaveValidationErrorFor(x => x.Duration, addVideoRequest);
        }
Ejemplo n.º 5
0
        public void Should_have_error_when_Duration_is_lower_than_0()
        {
            EditVideoRequest addVideoRequest = TestDataFactory.CreateEditVideoRequest();

            addVideoRequest.Duration = -1;

            Validator.ShouldHaveValidationErrorFor(x => x.Duration, addVideoRequest);
        }
Ejemplo n.º 6
0
        public void Should_have_error_when_GenreId_is_null()
        {
            EditVideoRequest addVideoRequest = TestDataFactory.CreateEditVideoRequest();

            addVideoRequest.GenreId = Guid.Empty;

            Validator.ShouldHaveValidationErrorFor(x => x.GenreId, addVideoRequest);
        }
Ejemplo n.º 7
0
        public static EditVideoRequest CreateEditVideoRequest()
        {
            EditVideoRequest edit = GenData
                                    .Build <EditVideoRequest>()
                                    .With(x => x.IsInactive, false)
                                    .Create();

            return(edit);
        }
Ejemplo n.º 8
0
        public void Should_have_error_when_KindId_doesnt_exist()
        {
            KindServiceMock
            .Setup(x => x.GetKindAsync(It.IsAny <GetKindRequest>()))
            .ReturnsAsync(() => null);

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

            Validator.ShouldHaveValidationErrorFor(x => x.KindId, addVideoRequest);
        }
Ejemplo n.º 9
0
        public async Task <VideoResponse> EditVideoAsync(EditVideoRequest request)
        {
            Video existingRecord = await _videoRepository.GetAsync(request.Id);

            if (existingRecord == null)
            {
                throw new ArgumentException($"Video entity with {request.Id} is not present");
            }

            Video entity = _mapper.Map <Video>(request);
            Video result = _videoRepository.Update(entity);

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

            return(_mapper.Map <VideoResponse>(result));
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Редактирует данные видеозаписи на странице пользователя.
 /// </summary>
 /// <param name="callback">Метод, который будет вызван по завершении операции.
 /// Параметр является результатом запроса.</param>
 /// <param name="request">Объект запроса с необходимыми параметрами.</param>
 public void Edit(Action <VKResponse <VKOperationIsSuccess> > callback, EditVideoRequest request)
 {
     VKHelper.GetResponse <VKOperationIsSuccess>(request, callback);
 }