public void CreateKeyFragment_GenerateKeyFragmentFromSpecificCookie_ReturnStringWithCookieValue(IContent content, ICacheableSettings cacheableSettings, IEnumerable <HttpCookie> cookies, HttpCookie varyByCookie, IViewDataContainer viewDataContainer) { var htmlHelper = new HtmlHelper(A.Fake <ViewContext>(), viewDataContainer); htmlHelper.AddCookies(cookies, varyByCookie); A.CallTo(() => cacheableSettings.VaryBy).Returns(new[] { VaryBy.Cookies }); A.CallTo(() => cacheableSettings.Parameters).Returns(new Dictionary <string, string> { { VaryBy.Cookies, varyByCookie.Name } }); var cookieKeyFragmentFactory = new CookieKeyFragmentFactory(); cookieKeyFragmentFactory.CreateKeyFragment(htmlHelper, content, cacheableSettings).Should().Be($"{varyByCookie.Name}:{varyByCookie.Value}", "Because the returned value should be the cookie name and value"); }
public void CreateKeyFragment_GenerateKeyFragmentFromAllCookie_ReturnStringWithCookieValue(IContent content, ICacheableSettings cacheableSettings, IEnumerable <HttpCookie> cookies, IViewDataContainer viewDataContainer) { var htmlHelper = new HtmlHelper(A.Fake <ViewContext>(), viewDataContainer); htmlHelper.AddCookies(cookies); A.CallTo(() => cacheableSettings.VaryBy).Returns(new[] { VaryBy.Cookies }); A.CallTo(() => cacheableSettings.Parameters).Returns(new Dictionary <string, string> { { VaryBy.Cookies, "*" } }); var cookieKeyFragmentFactory = new CookieKeyFragmentFactory(); var expectedResult = string.Join(",", cookies.Select(cookie => $"{cookie.Name}:{cookie.Value}")); cookieKeyFragmentFactory.CreateKeyFragment(htmlHelper, content, cacheableSettings).Should().Be(expectedResult, "Because the returned value should contain all the cookies names and values"); }