public void Equality_ReturnsTrue_WhenVaryByCultureIsTrue_AndCultureIsSame() { // Arrange var tagHelperContext = GetTagHelperContext(); var cacheTagHelper = new CacheTagHelper(new CacheTagHelperMemoryCacheFactory(Mock.Of <IMemoryCache>()), new HtmlTestEncoder()) { ViewContext = GetViewContext(), VaryByCulture = true, }; // Act CacheTagKey key1; CacheTagKey key2; using (new CultureReplacer("fr-FR", "fr-FR")) { key1 = new CacheTagKey(cacheTagHelper, tagHelperContext); } using (new CultureReplacer("fr-fr", "fr-fr")) { key2 = new CacheTagKey(cacheTagHelper, tagHelperContext); } var equals = key1.Equals(key2); var hashCode1 = key1.GetHashCode(); var hashCode2 = key2.GetHashCode(); // Assert Assert.True(equals, "CacheTagKeys must be equal"); Assert.Equal(hashCode1, hashCode2); }
public void GetHashCode_IsSameForSimilarCacheTagHelper() { // Arrange var tagHelperContext1 = GetTagHelperContext("some-id"); var cacheTagHelper1 = new CacheTagHelper(new CacheTagHelperMemoryCacheFactory(Mock.Of <IMemoryCache>()), new HtmlTestEncoder()) { ViewContext = GetViewContext() }; var tagHelperContext2 = GetTagHelperContext("some-id"); var cacheTagHelper2 = new CacheTagHelper(new CacheTagHelperMemoryCacheFactory(Mock.Of <IMemoryCache>()), new HtmlTestEncoder()) { ViewContext = GetViewContext() }; var cacheKey1 = new CacheTagKey(cacheTagHelper1, tagHelperContext1); var cacheKey2 = new CacheTagKey(cacheTagHelper2, tagHelperContext2); // Act var hashcode1 = cacheKey1.GetHashCode(); var hashcode2 = cacheKey2.GetHashCode(); // Assert Assert.Equal(hashcode1, hashcode2); }
public void GetHashCode_VariesByUniqueId() { // Arrange var tagHelperContext1 = GetTagHelperContext("some-id"); var cacheTagHelper1 = new CacheTagHelper(Mock.Of <IMemoryCache>(), new HtmlTestEncoder()) { ViewContext = GetViewContext() }; var tagHelperContext2 = GetTagHelperContext("some-other-id"); var cacheTagHelper2 = new CacheTagHelper(Mock.Of <IMemoryCache>(), new HtmlTestEncoder()) { ViewContext = GetViewContext() }; var cacheKey1 = new CacheTagKey(cacheTagHelper1, tagHelperContext1); var cacheKey2 = new CacheTagKey(cacheTagHelper2, tagHelperContext2); // Act var hashcode1 = cacheKey1.GetHashCode(); var hashcode2 = cacheKey2.GetHashCode(); // Assert Assert.NotEqual(hashcode1, hashcode2); }
public void GetHashCode_VariesByUniqueId() { // Arrange var tagHelperContext1 = GetTagHelperContext("some-id"); var cacheTagHelper1 = new CacheTagHelper(Mock.Of<IMemoryCache>(), new HtmlTestEncoder()) { ViewContext = GetViewContext() }; var tagHelperContext2 = GetTagHelperContext("some-other-id"); var cacheTagHelper2 = new CacheTagHelper(Mock.Of<IMemoryCache>(), new HtmlTestEncoder()) { ViewContext = GetViewContext() }; var cacheKey1 = new CacheTagKey(cacheTagHelper1, tagHelperContext1); var cacheKey2 = new CacheTagKey(cacheTagHelper2, tagHelperContext2); // Act var hashcode1 = cacheKey1.GetHashCode(); var hashcode2 = cacheKey2.GetHashCode(); // Assert Assert.NotEqual(hashcode1, hashcode2); }