示例#1
0
        public async Task DeleteShouldSucceed()
        {
            // Arrange
            var id          = Guid.NewGuid();
            var name        = "nameOne";
            var description = "description";
            var icon        = Guid.NewGuid();
            var instruction = "instruction";

            RepositoryHelper.ForInput.CreateInput(id, name, description, icon, instruction);

            // Act
            await _repository.DeleteAsync(id, 0);

            // Assert
            var data = RepositoryHelper.ForInput.GetInputs();

            data.Should().HaveCount(0);
        }
        public async Task <Result> Handle(DeleteInputCommand request, CancellationToken cancellationToken)
        {
            Result result;

            try
            {
                await _inputWriteRepository.DeleteAsync(request.Id, request.Version);

                result = Result.Ok();
            }
            catch (EntityNotFoundDbException)
            {
                result = Result.Fail(new System.Collections.Generic.List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.NotFound.Name,
                        Message = string.Format(HandlerFailures.NotFound, "Input"),
                        Target  = "id"
                    }
                }
                                     );
            }
            catch (EntityVersionDbException)
            {
                result = Result.Fail(new System.Collections.Generic.List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.NotMet.Name,
                        Message = HandlerFailures.NotMet,
                        Target  = "version"
                    }
                }
                                     );
            }
            catch
            {
                result = Result.Fail(CustomFailures.DeleteInputFailure);
            }

            return(result);
        }