Exemplo n.º 1
0
        public async Task GetAsync_FunctionWithoutParameters_ShouldReturnCached()
        {
            var key = _distributedCacheService.GetKey(() => _testFunctions.FunctionWithoutParameters());

            var beforeSet = await _distributedCacheService.GetAsync(() => _testFunctions.FunctionWithoutParameters());

            _memoryDistributedCache.SetString(key, JsonConvert.SerializeObject(Value));
            var afterSet = await _distributedCacheService.GetAsync(() => _testFunctions.FunctionWithoutParameters());

            beforeSet.ShouldBeNull();
            afterSet.ShouldBe(Value);
        }
        public async Task <TenantProfileModel> GetTenantByTenantIdAsync(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                throw new ForbiddenException();
            }

            try
            {
                var tenant = await _distributedCache.GetAsync <TenantProfileModel>(id);

                if (tenant == null)
                {
                    throw new BadRequestException($"Not found tenant {id}");
                }

                return(tenant);
            }
            catch
            {
                return(await GetTenantByHttpAsync(id));
            }
        }