public void ThrowsWhenMultipleCacheProfilesWithSameNameAreAdded() { // Arrange var options = new MvcCacheOptions(); options.CacheProfiles.Add("HelloWorld", new CacheProfile { Duration = 10 }); // Act & Assert var ex = Assert.Throws <ArgumentException>( () => options.CacheProfiles.Add("HelloWorld", new CacheProfile { Duration = 5 })); Assert.Equal("An item with the same key has already been added.", ex.Message); }
private IServiceProvider GetServiceProvider(Dictionary <string, CacheProfile> cacheProfiles) { var serviceProvider = new Mock <IServiceProvider>(); var optionsAccessor = new Mock <IOptions <MvcCacheOptions> >(); var options = new MvcCacheOptions(); if (cacheProfiles != null) { foreach (var p in cacheProfiles) { options.CacheProfiles.Add(p.Key, p.Value); } } optionsAccessor.SetupGet(o => o.Options).Returns(options); serviceProvider .Setup(s => s.GetService(typeof(IOptions <MvcCacheOptions>))) .Returns(optionsAccessor.Object); return(serviceProvider.Object); }