public void AdjustedOptionsNameOnAdd(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(); // Add new options. var result = cache.TryAdd(name, options); Assert.True(result); // Fail adding options under same name. result = cache.TryAdd(name, options); Assert.False(result); // Change the TC id and confirm options can be added again. tc.GetType().GetProperty("Id").SetValue(tc, "diff_id"); result = cache.TryAdd(name, options); Assert.True(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 RemoveOptionsForAllTenants(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(); // Add new options. var result = cache.TryAdd(name, options); Assert.True(result); tc.GetType().GetProperty("Id").SetValue(tc, "diff_id"); result = cache.TryAdd(name, options); Assert.True(result); // Remove all options. result = cache.TryRemove(name); Assert.True(result); Assert.Empty((IEnumerable)cache.GetType().BaseType. GetField("_cache", BindingFlags.NonPublic | BindingFlags.Instance). GetValue(cache)); }