public void GetTenants_Paging_Pass() { var tenantName = $"test tenant {Guid.NewGuid()}"; //Create var ids = new List <int> { m_sut.InsertTenant(new TenantDto(0, $"{tenantName} 1")), m_sut.InsertTenant(new TenantDto(0, $"{tenantName} 2")), m_sut.InsertTenant(new TenantDto(0, $"{tenantName} 3")), }; ids.ForEach(i => m_testOutputHelper.WriteLine($"GetTenants_Paging_Pass.tenantName : {tenantName}: {i}")); try { //Get var twoTenants = m_sut.GetTenants(pageSize: 2); var allTenants = m_sut.GetTenants() .Where(x => x.Name.StartsWith(tenantName)); Assert.Equal(2, twoTenants.Count()); Assert.Equal(3, allTenants.Count()); } finally { //Cleanup ids.ForEach(m_sut.DeleteTenant); } }
public override void OnActionExecuting(ActionExecutingContext actionExecutingContext) { var fullAddress = actionExecutingContext.HttpContext?.Request? .Headers?["Host"].ToString()?.Split('.'); if (fullAddress.Length < 2) { actionExecutingContext.Result = new StatusCodeResult(404); base.OnActionExecuting(actionExecutingContext); } else { var subdomain = fullAddress[0]; //var tenant = _dbcontext.Tenants // .SingleOrDefault(t => string.Equals(t.HostName, subdomain, StringComparison.OrdinalIgnoreCase)); var tenant = _tenantProvider.GetTenants() .SingleOrDefault(t => string.Equals(t.HostName, subdomain, StringComparison.OrdinalIgnoreCase)); if (tenant != null) { actionExecutingContext.RouteData.Values.Add("tenant", tenant); base.OnActionExecuting(actionExecutingContext); } else { actionExecutingContext.Result = new StatusCodeResult(404); base.OnActionExecuting(actionExecutingContext); } } }
IEnumerable <Tenant> ITenantManager.GetTenants(int pageSize) => m_tenantProvider.GetTenants(pageSize).Select(x => x?.ToEntity());