Beispiel #1
0
        public async Task Get_Tenant_Should_Cached()
        {
            var acme = await _tenantRepository.FindByNameAsync("acme");

            acme.ShouldNotBeNull();

            (await _cache.GetAsync(TenantCacheItem.CalculateCacheKey(acme.Id, null))).ShouldBeNull();
            (await _cache.GetAsync(TenantCacheItem.CalculateCacheKey(null, acme.Name))).ShouldBeNull();

            await _tenantStore.FindAsync(acme.Id);

            (await _cache.GetAsync(TenantCacheItem.CalculateCacheKey(acme.Id, null))).ShouldNotBeNull();

            await _tenantStore.FindAsync(acme.Name);

            (await _cache.GetAsync(TenantCacheItem.CalculateCacheKey(null, acme.Name))).ShouldNotBeNull();


            var volosoft = _tenantRepository.FindByName("volosoft");

            volosoft.ShouldNotBeNull();

            (_cache.Get(TenantCacheItem.CalculateCacheKey(volosoft.Id, null))).ShouldBeNull();
            (_cache.Get(TenantCacheItem.CalculateCacheKey(null, volosoft.Name))).ShouldBeNull();

            _tenantStore.Find(volosoft.Id);
            (_cache.Get(TenantCacheItem.CalculateCacheKey(volosoft.Id, null))).ShouldNotBeNull();

            _tenantStore.Find(volosoft.Name);
            (_cache.Get(TenantCacheItem.CalculateCacheKey(null, volosoft.Name))).ShouldNotBeNull();
        }
        public TenantEditor CreateOrModify(string name)
        {
            var existing = repository.FindByName(name);

            if (existing == null)
            {
                Instance = repository.Create(new TenantResource
                {
                    Name = name,
                });
            }
            else
            {
                existing.Name = name;
                Instance      = repository.Modify(existing);
            }

            return(this);
        }
        public async Task <TenantEditor> CreateOrModify(string name)
        {
            var existing = await repository.FindByName(name).ConfigureAwait(false);

            if (existing == null)
            {
                Instance = await repository.Create(new TenantResource
                {
                    Name = name,
                }).ConfigureAwait(false);
            }
            else
            {
                existing.Name = name;
                Instance      = await repository.Modify(existing).ConfigureAwait(false);
            }

            return(this);
        }
Beispiel #4
0
        public TenantConfiguration Find(string name)
        {
            using (_currentTenant.Change(null)) //TODO: No need this if we can implement to define host side (or tenant-independent) entities!
            {
                var tenant = _tenantRepository.FindByName(name);
                if (tenant == null)
                {
                    return(null);
                }

                return(_objectMapper.Map <Tenant, TenantConfiguration>(tenant));
            }
        }
Beispiel #5
0
 public static Task <TenantResource[]> FindByNamesOrIdsOrFail(this ITenantRepository repo,
                                                              IEnumerable <string> namesOrIds)
 {
     return(repo.FindByNamesOrIdsOrFail(n => repo.FindByName(n), "Tenants", "tenant", namesOrIds));
 }
Beispiel #6
0
 public static Task <TenantResource> FindByNameOrIdOrFail(this ITenantRepository repo, string nameOrId)
 {
     return(repo.FindByNameOrIdOrFail(n => repo.FindByName(n), "Tenants", "tenant", nameOrId));
 }