示例#1
0
        public async Task <IEnumerable <AssetGroupDto> > GetGroupsAsync(string type)
        {
            List <AssetEntity> entities = await _assetRepo
                                          .Select
                                          .Where(c => c.IsDeleted == false)
                                          .WhereIf(type.IsNotNullOrEmpty(), c => c.Type.Equals(type))
                                          .ToListAsync();

            List <AssetEntity>   parents = entities.FindAll(c => c.ParentId == 0);
            List <AssetGroupDto> dtos    = parents
                                           .Select(c =>
            {
                var dto    = new AssetGroupDto();
                dto.Name   = c.Name;
                dto.Childs = entities
                             .FindAll(d => d.ParentId == c.Id)
                             .Select(d =>
                {
                    var s     = Mapper.Map <AssetDto>(d);
                    s.IconUrl = _fileRepo.GetFileUrl(s.IconUrl);
                    return(s);
                })
                             .ToList();
                return(dto);
            })
                                           .ToList();

            return(dtos);
        }
        public async Task AddClient__NoContentResult_Returned()
        {
            var serviceMock = CreateServiceMock();

            var         groupName = "test group";
            var         clientId  = "123";
            IAssetGroup group     = new AssetGroupDto()
            {
                Name = groupName
            };

            serviceMock
            .Setup(x => x.AddClientToGroupAsync(groupName, group))
            .Returns(Task.FromResult(false));

            serviceMock
            .Setup(x => x.GetGroupAsync(groupName))
            .Returns(Task.FromResult(group));

            var controller   = CreateController(serviceMock);
            var actionResult = await controller.AddClient(clientId, groupName);

            Assert.IsInstanceOfType(actionResult, typeof(NoContentResult));

            serviceMock
            .Verify(x => x.AddClientToGroupAsync(It.IsAny <string>(), It.IsAny <IAssetGroup>()));
        }