public void Same_Object_Should_Equal() { var cv = new CachedVary(); var cvSame = cv; Assert.True(cv.Equals(cvSame)); }
public void IsContentEncodingAcceptable_Should_Return_True_If_ContentEncodings_Is_Not_Null() { var httpContextMoq = new Mock <HttpContextBase>(); var ocHelper = new OutputCacheHelper(httpContextMoq.Object); var cv = new CachedVary() { ContentEncodings = DefaultEncodings }; var acceptable = ocHelper.IsContentEncodingAcceptable(cv, null); Assert.True(acceptable); cv = new CachedVary() { ContentEncodings = new string[0] }; acceptable = ocHelper.IsContentEncodingAcceptable(cv, null); Assert.True(acceptable); }
public void BinarySerializer_Can_RoundTrip_CachedVary_Type() { CachedVary obj = null; var data = BinarySerializer.Serialize(obj); var actual = BinarySerializer.Deserialize(data); Assert.NotNull(actual); Assert.Equal(typeof(object), actual.GetType()); obj = new CachedVary() { CachedVaryId = Guid.NewGuid(), ContentEncodings = new string[] { "111", "222" }, Headers = new string[] { "Get", "Put" }, Params = new string[] { "test", "test1" }, VaryByAllParams = true, VaryByCustom = "Hello" }; var actualObj = RoundTrip(obj); Assert.Equal(obj, actualObj); }
public void CreateOutputCachedItemKey_Should_Create_Correct_CacheKey_For_NonePost_Requst() { var requestMoq = new Mock <HttpRequestBase>(); requestMoq.Setup(r => r.Path).Returns("test.aspx"); requestMoq.Setup(r => r.HttpMethod).Returns(HttpMethods_GET); var srvVars = new NameValueCollection(); srvVars.Add("AUTH_TYPE", "Basic"); srvVars.Add("HTTP_HOST", "localhost"); requestMoq.Setup(r => r.ServerVariables).Returns(srvVars); var queryStrs = new NameValueCollection(); queryStrs.Add("query1", "1"); queryStrs.Add("Query2", "aB"); requestMoq.Setup(r => r.QueryString).Returns(queryStrs); var forms = new NameValueCollection(); forms.Add("form1", "1"); forms.Add("Form2", "Cd"); requestMoq.Setup(r => r.Form).Returns(forms); var headers = new NameValueCollection(); headers.Add(AcceptEncodingHeaderName, "gzip,deflate"); requestMoq.Setup(r => r.Headers).Returns(headers); var context = CreateHttpContextBase(requestMoq.Object); var cacheUtilMoq = new Mock <IOutputCacheUtility>(); cacheUtilMoq.Setup(util => util.GetVaryByCustomString(context, "CustomVary")).Returns("UtilCustomVary"); var ocHelper = new OutputCacheHelper(context, cacheUtilMoq.Object); var key = ocHelper.CreateOutputCachedItemKey(null); Assert.Equal("a2test.aspx", key); var cv = new CachedVary() { VaryByCustom = "CustomVary" }; key = ocHelper.CreateOutputCachedItemKey(cv); Assert.Equal("a2test.aspxHQFCNCustomVaryVUtilCustomVaryDE", key); cv = new CachedVary() { Headers = new string[] { "AUTH_TYPE", "HTTP_HOST" }, Params = new string[] { "form1", "Form2" }, VaryByAllParams = true }; key = ocHelper.CreateOutputCachedItemKey(cv); Assert.Equal("a2test.aspxHNAUTH_TYPEVBasicNHTTP_HOSTVlocalhostQNquery1V1Nquery2VaBFCDE", key); cv = new CachedVary() { Params = new string[] { "form1", "Form2" }, VaryByAllParams = true, ContentEncodings = new string[] { "gzip", "deflate" } }; key = ocHelper.CreateOutputCachedItemKey(cv); Assert.Equal("a2test.aspxHQNquery1V1Nquery2VaBFCDEgzip", key); }