Example #1
0
        public async Task DeleteShouldSucceed()
        {
            // Arrange
            var id                  = Guid.NewGuid();
            var name                = "Kalo";
            var description         = "SourceDescription";
            var businessUnit1Name   = "BSG";
            var businessUnit2Name   = "BSG1";
            var source              = new Source(id, name, description);
            var sourceBusinessUnit1 = new SourceBusinessUnit(businessUnit1Name);
            var sourceBusinessUnit2 = new SourceBusinessUnit(businessUnit2Name);
            var sourceBusinessUnits = new List <SourceBusinessUnit>()
            {
                sourceBusinessUnit1, sourceBusinessUnit2
            };

            RepositoryHelper.ForSource.CreateSource(id, name, description, sourceBusinessUnits);

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

            // Assert
            var data = RepositoryHelper.ForSource.GetSources();

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

            try
            {
                await _sourceWriteRepository.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, "Source"),
                        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.DeleteSourceFailure);
            }

            return(result);
        }