public void GetOrAddNamedOptionForCurrentTenantOnly(string name) { var ti = new TenantInfo("test-id-123", null, null, null, null); var tc = new MultiTenantContext(); tc.TenantInfo = ti; var tca = new TestMultiTenantContextAccessor(tc); var cache = new MultiTenantOptionsCache <CookieAuthenticationOptions>(tca); var options = new CookieAuthenticationOptions(); options.Cookie.Name = "a_name"; var options2 = new CookieAuthenticationOptions(); options2.Cookie.Name = "diff_name"; // Add new options. var result = cache.GetOrAdd(name, () => options); Assert.Same(options, result); // Get the existing options if exists. result = cache.GetOrAdd(name, () => options2); Assert.NotSame(options2, result); // Confirm different tenant on same object is an add (ie it didn't exist there). ti.Id = "diff_id"; result = cache.GetOrAdd(name, () => options2); Assert.Same(options2, result); }
public void GetOrAddNamedOptionForCurrentTenantOnly(string name) { var ti = new TenantInfo { Id = "test-id-123" }; var tc = new MultiTenantContext <TenantInfo>(); tc.TenantInfo = ti; var tca = new MultiTenantContextAccessor <TenantInfo>(); tca.MultiTenantContext = tc; var cache = new MultiTenantOptionsCache <TestOptions, TenantInfo>(tca); var options = new TestOptions(); var options2 = new TestOptions(); // Add new options. var result = cache.GetOrAdd(name, () => options); Assert.Same(options, result); // Get the existing options if exists. result = cache.GetOrAdd(name, () => options2); Assert.NotSame(options2, result); // Confirm different tenant on same object is an add (ie it didn't exist there). ti.Id = "diff_id"; result = cache.GetOrAdd(name, () => options2); Assert.Same(options2, result); }
public void AdjustOptionsNameOnGetOrAdd(string name) { var tc = new TenantContext("test-id-123", null, null, null, null, null); var tca = new TestTenantContextAccessor(tc); var cache = new MultiTenantOptionsCache <CookieAuthenticationOptions>(tca, (o, context) => { o.Cookie.Name = context.Id; }); var options = new CookieAuthenticationOptions(); options.Cookie.Name = "a_name"; var options2 = new CookieAuthenticationOptions(); options2.Cookie.Name = "diff_name"; // Add new options. var result = cache.GetOrAdd(name, () => options); Assert.Equal(options.Cookie.Name, result.Cookie.Name); // Get the existing object. result = cache.GetOrAdd(name, () => options2); Assert.NotEqual(options2.Cookie.Name, result.Cookie.Name); // Confirm different tenant on same object is an add. tc.GetType().GetProperty("Id").SetValue(tc, "diff_id"); result = cache.GetOrAdd(name, () => options2); Assert.Equal(options2.Cookie.Name, result.Cookie.Name); }
public void AdjustOptionsNameOnGetOrAdd(string name) { var ti = new TenantInfo("test-id-123", null, null, null, null); var tc = new MultiTenantContext(); tc.TenantInfo = ti; var tca = new TestMultiTenantContextAccessor(tc); var cache = new MultiTenantOptionsCache <CookieAuthenticationOptions>(tca); var options = new CookieAuthenticationOptions(); options.Cookie.Name = "a_name"; var options2 = new CookieAuthenticationOptions(); options2.Cookie.Name = "diff_name"; // Add new options. var result = cache.GetOrAdd(name, () => options); Assert.Equal(options.Cookie.Name, result.Cookie.Name); // Get the existing object. result = cache.GetOrAdd(name, () => options2); Assert.NotEqual(options2.Cookie.Name, result.Cookie.Name); // Confirm different tenant on same object is an add. ti.Id = "diff_id"; result = cache.GetOrAdd(name, () => options2); Assert.Equal(options2.Cookie.Name, result.Cookie.Name); }
public void ThrowsIfGetOrAddFactoryIsNull() { var tc = new MultiTenantContext(); var tca = new TestMultiTenantContextAccessor(tc); var cache = new MultiTenantOptionsCache <CookieAuthenticationOptions>(tca); Assert.Throws <ArgumentNullException>(() => cache.GetOrAdd("", null)); }
public void ThrowsIfGetOrAddFactoryIsNull() { var tc = new MultiTenantContext <TenantInfo>(); var tca = new MultiTenantContextAccessor <TenantInfo>(); tca.MultiTenantContext = tc; var cache = new MultiTenantOptionsCache <TestOptions, TenantInfo>(tca); Assert.Throws <ArgumentNullException>(() => cache.GetOrAdd("", null)); }
public void ThrowsIfGetOtAddFactoryIsNull() { var tc = new TenantContext("test-id-123", null, null, null, null, null); var tca = new TestTenantContextAccessor(tc); var cache = new MultiTenantOptionsCache <CookieAuthenticationOptions>(tca, (o, context) => { o.Cookie.Name = context.Id; }); Assert.Throws <ArgumentNullException>(() => cache.GetOrAdd("", null)); }
public void HandleNullMultiTenantContextOnGetOrAdd() { var tca = new MultiTenantContextAccessor <TenantInfo>(); var cache = new MultiTenantOptionsCache <TestOptions, TenantInfo>(tca); var options = new TestOptions(); // Add new options, ensure no exception caused by null MultiTenantContext. var result = cache.GetOrAdd("", () => options); Assert.NotNull(result); }
public void HandleNullMultiTenantContextWhenAdjustedOptionsNameOnGetOrAdd() { var tca = new TestMultiTenantContextAccessor(null); var cache = new MultiTenantOptionsCache <CookieAuthenticationOptions>(tca); var options = new CookieAuthenticationOptions(); // Add new options, ensure no exception caused by null MultiTenantContext. var result = cache.GetOrAdd("", () => options); Assert.NotNull(result); }