Esempio n. 1
0
        /// <summary>
        /// Removes a color.
        /// </summary>
        /// <param name="id">ColorId that will be updated..</param>
        /// <returns>Returns quantity of entities affected.</returns>
        public async Task <IResponse> DeleteAsync(Guid id)
        {
            try
            {
                var notEmpty = Ensure.That(id, nameof(id)).IdNotEmpty();

                if (!notEmpty.IsValid)
                {
                    return(Response.ValidationError(notEmpty.Error).Result);
                }

                var request = DeleteColorCommandRequest.New(id);

                var result = await _mediator.Send(request);

                //if (await _colorRepository.HasUserAssociated(id))
                //{
                //    throw new DomainException("Color", DomainMessage.EntityHasRelationship("perfil", new string[] { "usuários" }));
                //}

                //var color = await _colorRepository.GetAsync(id);

                //Ensure.That(color, nameof(id)).EntityExists();

                //await _colorRepository.DeleteAsync(color.Id);
                //await _unityOfWork.CommitAsync();

                return(result ? Response.Success() : Response.Error());
            }
            catch
            {
                return(Response.Error());
            }
        }
Esempio n. 2
0
        public async Task Should_Delete_Color()
        {
            var deleteColorCommandHandler = new DeleteColorCommandHandler(_colorRepository);
            var request = DeleteColorCommandRequest.New(Guid.NewGuid());

            await deleteColorCommandHandler.Handle(request, new CancellationToken());

            Assert.True(deleted);
        }