Ejemplo n.º 1
0
        public void Should_Be_Valid_Command()
        {
            var _validCommand = new DeleteVideoCommand(Guid.NewGuid(), Guid.NewGuid());

            _validCommand.Validate();
            Assert.True(!_validCommand.IsInvalid);
        }
Ejemplo n.º 2
0
        public ICommandResult Handle(DeleteVideoCommand command)
        {
            command.Validate();
            if (command.IsInvalid)
            {
                return(new DefaultCommandResult(CommandResultStatus.InvalidCommand, command.Notifications));
            }

            try
            {
                var video = _videoRepository.GetByServerIdAndVideoId(command.ServerId, command.VideoId);
                if (video == null)
                {
                    return(new DefaultCommandResult(CommandResultStatus.InvalidData, "Video não foi localizado"));
                }

                _videoRepository.Delete(video);
                _videoRepository.DeleteInFileSystem(video);
                return(new DefaultCommandResult(CommandResultStatus.Success, "Video excluido com sucesso", null));
            }
            catch (Exception e)
            {
                Console.WriteLine($"Fail to execute DeleteVideoHandler. Fail stack ===> {e.ToString()}");
                return(new DefaultCommandResult(CommandResultStatus.Exception));
            }
        }
Ejemplo n.º 3
0
        public void Should_Be_Invalid_Command()
        {
            var _invalidCommand = new DeleteVideoCommand(new Guid(), new Guid());

            _invalidCommand.Validate();
            Assert.True(_invalidCommand.IsInvalid);
        }
Ejemplo n.º 4
0
        public IActionResult Delete([FromServices] VideoHandler handler, [FromRoute] Guid serverId, [FromRoute] Guid videoId)
        {
            var command  = new DeleteVideoCommand(serverId, videoId);
            var response = (DefaultCommandResult)handler.Handle(command);

            return(this.DefaultCommandResultToActionResult(response));
        }
Ejemplo n.º 5
0
        public async Task Retornar_erro_quando_servidor_nao_existir()
        {
            var command = new DeleteVideoCommand(Guid.NewGuid(), Guid.NewGuid());

            var result = await _handler.Handle(command, CancellationToken.None);

            result.IsFail.Should().BeTrue();
        }
        public Task <HttpResponseMessage> Delete(int id)
        {
            var command = new DeleteVideoCommand(
                idVideo: id
                );

            var video = _service.Delete(command);

            return(CreateResponse(HttpStatusCode.OK, video));
        }
Ejemplo n.º 7
0
        public DeleteVideoHandlerTest()
        {
            _fakeServerRepository        = new FakeServerRepository(_dataContextMock);
            _fakeVideoRepository         = new FakeVideoRepository(_dataContextMock);
            _invalidCommand              = new DeleteVideoCommand(new Guid(), new Guid());
            _validCommandWithNotExistsId = new DeleteVideoCommand(Guid.NewGuid(), Guid.NewGuid());
            var videoValid = _dataContextMock.Videos.FirstOrDefault();

            _validCommand = new DeleteVideoCommand(videoValid.ServerId, videoValid.Id);
        }
Ejemplo n.º 8
0
        public async Task Retornar_erro_quando_video_nao_existir()
        {
            var server = BuildServer();

            _serverRepositoryMock.Setup(x => x.GetAsync(It.IsAny <Guid>(), false)).ReturnsAsync(server);
            var command = new DeleteVideoCommand(Guid.NewGuid(), Guid.NewGuid());

            var result = await _handler.Handle(command, CancellationToken.None);

            result.IsFail.Should().BeTrue();
        }
Ejemplo n.º 9
0
        public async Task Remover_video()
        {
            var server = BuildServer();

            _serverRepositoryMock.Setup(x => x.GetAsync(It.IsAny <Guid>(), false)).ReturnsAsync(server);
            var command = new DeleteVideoCommand(Guid.NewGuid(), server.Videos.First().Id);

            var result = await _handler.Handle(command, CancellationToken.None);

            result.IsSuccess.Should().BeTrue();
            _videoRepositoryMock.Verify(x => x.RemoveContent(string.Empty), Times.Once());
            _serverRepositoryMock.Verify(x => x.SaveChangesAsync(), Times.Once());
        }
Ejemplo n.º 10
0
 public HttpResponseMessage Delete(int Id)
 {
     try {
         var command = new DeleteVideoCommand(Id);
         var result  = commandBus.Submit(command);
         if (!result.Success)
         {
             throw new HttpResponseException(HttpStatusCode.BadRequest);
         }
         return(Request.CreateResponse(HttpStatusCode.OK));
     } catch (Exception _excepcion) {
         log.Error(_excepcion);
         return(Request.CreateResponse(HttpStatusCode.InternalServerError, _excepcion));
     }
 }
        public Video Delete(DeleteVideoCommand command)
        {
            var video = _repository.GetById(command.IdVideo);

            video.Delete();
            _repository.Delete(video);

            //Caso o vídeo seja inativado ele também será inativado na tabela VideoEquipment
            var            listVideoEquipment          = _repositoryVideoEquipment.GetAllByVideo(command.IdVideo);
            VideoEquipment videoEquipment              = new VideoEquipment();
            var            listVideoEquipmentInativada = videoEquipment.Delete(listVideoEquipment);

            _repositoryVideoEquipment.Delete(listVideoEquipmentInativada);

            if (Commit())
            {
                return(video);
            }

            return(null);
        }