Esempio n. 1
0
        public void Should_Convert_To_Entity()
        {
            var colorCommandDto = Domain.Dtos.Color.ColorCommandDto.New("teste", StatusEnum.Enable.Value, Guid.NewGuid());
            var entity          = ColorMapper.Map(colorCommandDto);

            Assert.NotNull(entity);
        }
Esempio n. 2
0
        public void Should_Convert_To_Dto()
        {
            var color = Domain.Entities.Color.New("test", StatusEnum.Enable, TenantId.New());
            var dto   = ColorMapper.Map(color);

            Assert.NotNull(dto);
        }
Esempio n. 3
0
        public async Task <Unit> Handle(InsertColorCommandRequest request, CancellationToken cancellationToken)
        {
            var color = ColorMapper.Map(request.ColorInsertDto);

            await _colorRepository.InsertAsync(color);

            return(Unit.Value);
        }
Esempio n. 4
0
        public void Should_Convert_To_List_Of_Dto2()
        {
            var colors = new Domain.Entities.Color[] { };
            var dtos   = ColorMapper.Map(colors).ToList();

            Assert.Empty(dtos);
            Assert.NotNull(dtos);
        }
Esempio n. 5
0
        public async Task <ColorQueryDto> Handle(GetColorQueryRequest request, CancellationToken cancellationToken)
        {
            var color = await _colorRepository.GetAsync(request.ColorId);

            var colorDto = ColorMapper.Map(color);

            return(colorDto);
        }
Esempio n. 6
0
        public void Should_Convert_To_List_Of_Dto()
        {
            var colors = new Domain.Entities.Color[]
            {
                Domain.Entities.Color.New("test 1", StatusEnum.Enable, TenantId.New()),
                Domain.Entities.Color.New("test 2", StatusEnum.Enable, TenantId.New())
            };
            var dtos = ColorMapper.Map(colors).ToList();

            Assert.NotEmpty(dtos);
            Assert.NotNull(dtos);
        }
Esempio n. 7
0
        public async Task <IPagination <ColorQueryDto> > Handle(ListColorQueryRequest request, CancellationToken cancellationToken)
        {
            var pagination = await _colorRepository.ListAsync(request.Filter, request.OrderBy, request.Page, request.QtyPerPage);

            if (pagination.IsEmpty())
            {
                return(Pagination <ColorQueryDto> .Empty);
            }

            var colorDtos = ColorMapper.Map(pagination.Entities);

            var paginationDto = Pagination <ColorQueryDto> .New(colorDtos, pagination.TotalPages, pagination.ItemsPerPage, pagination.CurrentPage);

            return(paginationDto);
        }
Esempio n. 8
0
        ///// <summary>
        ///// Creates a new color.
        ///// </summary>
        ///// <param name="colorDto">Color <see cref="ColorDto"/> to be created.</param>
        ///// <returns>Returns quantity of entities affected.</returns>
        //public async Task InsertAsync(ColorCommandDto colorDto)
        //{
        //    Ensure.That(colorDto, "color").EntityIsNotNull();

        //    var entity = colorDto.ToEntity();

        //   // await _colorService.ValidateAsync(entity);

        //    entity.CreationDate = DateTime.UtcNow;

        //    await _colorRepository.InsertAsync(entity);
        //}

        ///// <summary>
        ///// Updates a color.
        ///// </summary>
        ///// <param name="id">Color's id will be update.</param>
        ///// <param name="colorDto">Color <see cref="ColorDto"/> to be updated.</param>
        ///// <returns>Returns quantity of entities affected.</returns>
        //public async Task UpdateAsync(Guid id, ColorDto colorDto)
        //{
        //    Ensure.That(id, nameof(id)).IdNotEmpty();
        //    Ensure.That(colorDto, "color").EntityIsNotNull();

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

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

        //    var color = colorDto.ToEntity();

        //    color.Id = id;

        //    await _colorService.ValidateAsync(color);

        //    current.LastModificationDate = DateTime.UtcNow;
        //    current.Name = color.Name;
        //    current.Status = color.Status;

        //    await _colorRepository.UpdateAsync(current);
        //    //await _unityOfWork.CommitAsync();
        //}

        ///// <summary>
        ///// Get all color.
        ///// </summary>
        ///// <param name="filter">Filter to define color to be returned.</param>
        ///// <param name="orderBy">Columns name to order colors.</param>
        ///// <param name="page">Current page.</param>
        ///// <param name="qtyPerPage">Quantity of registers per page.</param>
        ///// <returns>Returns a pagination list of colors <see cref="IPagination{ColorDto}"/>.</returns>
        //public async ValueTask<IPagination<ColorDto>> ListAsync(string filter = null, string orderBy = null, int page = 0, int qtyPerPage = 0)
        //{
        //    var pagination = await _colorRepository.ListAsync(filter, orderBy, page, qtyPerPage);

        //    return pagination.ToDto();
        //}

        /// <summary>
        /// Get color by id.
        /// </summary>
        /// <param name="colorId">Color id.</param>
        /// <returns>Returns color found.</returns>
        public async Task <ColorQueryDto> GetAsync(Guid colorId)
        {
            var color = await _colorRepository.GetAsync(ColorId.New(colorId));

            return(ColorMapper.Map(color));
        }