本文整理汇总了C#中System.Web.HttpCookieCollection.Add方法的典型用法代码示例。如果您正苦于以下问题:C# HttpCookieCollection.Add方法的具体用法?C# HttpCookieCollection.Add怎么用?C# HttpCookieCollection.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.HttpCookieCollection
的用法示例。
在下文中一共展示了HttpCookieCollection.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DuplicateNames
public void DuplicateNames ()
{
HttpCookieCollection col = new HttpCookieCollection ();
HttpCookie cookie1 = new HttpCookie ("cookie", "value1");
HttpCookie cookie2 = new HttpCookie ("cookie", "value2");
col.Add (cookie1);
col.Add (cookie2);
Assert.AreEqual ("value1", col["cookie"].Value, "add should use first used cookie");
col.Set (cookie2);
Assert.AreEqual ("value2", col["cookie"].Value, "set should use last used cookie");
col.Clear ();
col.Add (cookie1);
col.Add (cookie2);
// Bug #553150
HttpCookie tmp = col.Get (0);
Assert.AreEqual ("cookie", tmp.Name, "#A1");
Assert.AreEqual ("value1", tmp.Value, "#A1-1");
tmp = col.Get (1);
Assert.AreEqual ("cookie", tmp.Name, "#A2");
Assert.AreEqual ("value2", tmp.Value, "#A2-1");
}
示例2: SetCurrentProjectId
public virtual void SetCurrentProjectId(HttpCookieCollection cookies, Project project)
{
if (cookies["CurrentProjectId"] == null)
cookies.Add(new HttpCookie("CurrentProjectId"));
if (cookies["CurrentProjectName"] == null)
cookies.Add(new HttpCookie("CurrentProjectName"));
cookies["CurrentProjectId"].Value = project.Id.ToString();
cookies["CurrentProjectName"].Value = project.Name;
cookies["CurrentProjectId"].Expires = DateTime.Now.AddYears(2);
cookies["CurrentProjectName"].Expires = DateTime.Now.AddYears(2);
}
示例3: CreateContext
/// <summary>
/// Mocks the http context to test against
/// </summary>
/// <param name="fullUrl"></param>
/// <param name="routeData"></param>
/// <returns></returns>
private void CreateContext(Uri fullUrl, RouteData routeData = null)
{
//Request context
var requestContextMock = new Mock<RequestContext>();
RequestContext = requestContextMock.Object;
//Cookie collection
var cookieCollection = new HttpCookieCollection();
cookieCollection.Add(new HttpCookie("UMB_UCONTEXT", "FBA996E7-D6BE-489B-B199-2B0F3D2DD826"));
//Request
var requestMock = new Mock<HttpRequestBase>();
requestMock.Setup(x => x.AppRelativeCurrentExecutionFilePath).Returns("~" + fullUrl.AbsolutePath);
requestMock.Setup(x => x.PathInfo).Returns(string.Empty);
requestMock.Setup(x => x.RawUrl).Returns(VirtualPathUtility.ToAbsolute("~" + fullUrl.AbsolutePath, "/"));
requestMock.Setup(x => x.RequestContext).Returns(RequestContext);
requestMock.Setup(x => x.Url).Returns(fullUrl);
requestMock.Setup(x => x.ApplicationPath).Returns("/");
requestMock.Setup(x => x.Cookies).Returns(cookieCollection);
requestMock.Setup(x => x.ServerVariables).Returns(new NameValueCollection());
var queryStrings = HttpUtility.ParseQueryString(fullUrl.Query);
requestMock.Setup(x => x.QueryString).Returns(queryStrings);
requestMock.Setup(x => x.Form).Returns(new NameValueCollection());
//Cache
var cacheMock = new Mock<HttpCachePolicyBase>();
//Response
//var response = new FakeHttpResponse();
var responseMock = new Mock<HttpResponseBase>();
responseMock.Setup(x => x.ApplyAppPathModifier(It.IsAny<string>())).Returns((string s) => s);
responseMock.Setup(x => x.Cache).Returns(cacheMock.Object);
//Server
var serverMock = new Mock<HttpServerUtilityBase>();
serverMock.Setup(x => x.MapPath(It.IsAny<string>())).Returns(Environment.CurrentDirectory);
//HTTP Context
var httpContextMock = new Mock<HttpContextBase>();
httpContextMock.Setup(x => x.Cache).Returns(HttpRuntime.Cache);
httpContextMock.Setup(x => x.Items).Returns(new Dictionary<object, object>());
httpContextMock.Setup(x => x.Request).Returns(requestMock.Object);
httpContextMock.Setup(x => x.Server).Returns(serverMock.Object);
httpContextMock.Setup(x => x.Response).Returns(responseMock.Object);
HttpContext = httpContextMock.Object;
requestContextMock.Setup(x => x.HttpContext).Returns(httpContextMock.Object);
if (routeData != null)
{
requestContextMock.Setup(x => x.RouteData).Returns(routeData);
}
}
示例4: GetMockUmbracoContext
public static UmbracoContext GetMockUmbracoContext(Uri requestUri, HttpCookie mockCookie = null)
{
//var mockHttpContext = MockRepository.GenerateStub<HttpContextBase>();
//var mockHttpRequest = MockRepository.GenerateStub<HttpRequestBase>();
//var mockHttpResponse = MockRepository.GenerateStub<HttpResponseBase>();
//SetupResult.For(mockHttpContext.Request).Return(mockHttpRequest);
//SetupResult.For(mockHttpRequest.Url).Return(requestUri);
//SetupResult.For(mockHttpRequest.Cookies).Return(cookieCollection);
//SetupResult.For(mockHttpContext.Response).Return(mockHttpResponse);
//SetupResult.For(mockHttpResponse.Cookies).ReturncookieCollection);
var umbracoContext = MockRepository.GenerateStrictMock<UmbracoContext>();
var cookieCollection = new HttpCookieCollection();
SetupResult.For(umbracoContext.HttpContext.Request.Cookies).Return(cookieCollection);
if (mockCookie != null)
{
cookieCollection.Add(mockCookie);
umbracoContext.Expect(c => c.HttpContext.Response.Cookies.Add(mockCookie));
}
SetupResult.For(umbracoContext.HttpContext.Request.Url).Return(requestUri);
return umbracoContext;
}
示例5: JoinCallsAddUserIfValidUserIdInCookieAndUserList
public void JoinCallsAddUserIfValidUserIdInCookieAndUserList()
{
var repository = new ChatRepository();
var user = new ChatUser
{
Id = "1234",
Name = "John",
Hash = "Hash"
};
repository.Users.Add(user);
var chat = new ChatHub(repository);
var connection = new Mock<IConnection>();
var prinicipal = new Mock<IPrincipal>();
var cookies = new HttpCookieCollection();
cookies.Add(new HttpCookie("userid", "1234"));
var clientState = new TrackingDictionary();
string clientId = "20";
chat.Agent = new ClientAgent(connection.Object, "Chat");
chat.Caller = new SignalAgent(connection.Object, clientId, "Chat", clientState);
chat.Context = new HubContext(clientId, cookies, prinicipal.Object);
chat.Join();
Assert.Equal("1234", clientState["id"]);
Assert.Equal("John", clientState["name"]);
Assert.Equal("Hash", clientState["hash"]);
Assert.Equal("20", user.ClientId);
// Need a better way to verify method name and arguments
connection.Verify(m => m.Broadcast("Chat.20", It.IsAny<object>()), Times.Once());
}
示例6: WhenRequestingMobileProfile_ThenJavascriptIsReturned
public void WhenRequestingMobileProfile_ThenJavascriptIsReturned()
{
_profileManifestRepository.Setup(p => p.GetProfile("generic"))
.Returns(new ProfileManifest
{
Id = "Generic-1.0",
Title = "Generic",
Features = new Feature[] {},
Version = "1.0"
});
_profileCookieEncoder.Setup(p => p.GetDeviceCapabilities(It.IsAny<HttpCookie>()))
.Returns(new Dictionary<string, string>{ {"id", "generic-1.0"} });
var controller = GetTestableMobileProfileController();
var response = Mock.Get(controller.Response);
var cookies = new HttpCookieCollection();
cookies.Add(new System.Web.HttpCookie("profile"));
controller.Request.SetHttpCookies(cookies);
var result = controller.ProfileScript();
Assert.IsType<PartialViewResult>(result);
response.VerifySet((r) => { r.ContentType = "text/javascript"; });
}
示例7: Set
private void Set(HttpCookieCollection cookieCollection, HttpCookie cookie)
{
if (cookieCollection.AllKeys.Contains(cookie.Name))
{
cookieCollection.Remove(cookie.Name);
}
cookieCollection.Add(cookie);
}
示例8: GetCookie
private static HttpCookie GetCookie(HttpCookieCollection cookies)
{
HttpCookie ddi = cookies["DDI"];
if (ddi == null)
{
ddi = new HttpCookie("DDI", false.ToString());
cookies.Add(ddi);
}
return ddi;
}
示例9: TestPostRequest
public void TestPostRequest()
{
var helper = new SettingsClassHelper(new TestSettings());
var cookies = new HttpCookieCollection();
cookies.Add(new HttpCookie("easysettings-token", "6d5f6e66bf0e4a638490abfb073d0e68"));
byte[] byteArray = Encoding.UTF8.GetBytes(@"{""settings"":[{""type"":0,""name"":""IntegerValue"",""value"":""0"",""desc"":""This is an integer value with a really long description that should wrap eventually"",""possibleValues"":null},{""type"":1,""name"":""MiniProfiler"",""value"":true,""desc"":""Allow MiniProfiler to run"",""possibleValues"":null},{""type"":1,""name"":""MyTest"",""value"":false,""desc"":"""",""possibleValues"":null},{""type"":2,""name"":""MyTestEnum"",""value"":""ThisIs0"",""desc"":"""",""possibleValues"":[""ThisIs0"",""ThisIs1""]}],""token"":""6d5f6e66bf0e4a638490abfb073d0e68""}");
var stream = new MemoryStream(byteArray);
var response = new EasySettingsHandler().ProcessPost(stream, helper, cookies);
}
示例10: GetOrAddCookie
private static HttpCookie GetOrAddCookie(HttpCookieCollection cookies, string defaultValue)
{
HttpCookie ddi = cookies["TH"];
if (ddi == null)
{
ddi = new HttpCookie("TH", defaultValue);
cookies.Add(ddi);
}
return ddi;
}
示例11: GetSavedCookieCollection
internal static HttpCookieCollection GetSavedCookieCollection()
{
HttpCookieCollection cookieCollection = new HttpCookieCollection();
foreach (string key in Cookiekeys())
{
cookieCollection.Add(HttpContext.Current.Request.Cookies[key]);
}
return cookieCollection;
}
示例12: GetCookieCollection
internal static HttpCookieCollection GetCookieCollection()
{
HttpCookieCollection cookieCollection = new HttpCookieCollection();
foreach (string key in Cookiekeys())
{
cookieCollection.Add( new HttpCookie(key));
}
return cookieCollection;
}
示例13: CreateContext
/// <summary>
/// Mocks the http context to test against
/// </summary>
/// <param name="fullUrl"></param>
/// <param name="routeData"></param>
/// <returns></returns>
private void CreateContext(Uri fullUrl, RouteData routeData = null)
{
//Request context
RequestContext = MockRepository.GenerateMock<RequestContext>();
//Cookie collection
var cookieCollection = new HttpCookieCollection();
cookieCollection.Add(new HttpCookie("UMB_UCONTEXT", "FBA996E7-D6BE-489B-B199-2B0F3D2DD826"));
//Request
var request = MockRepository.GenerateMock<HttpRequestBase>();
request.Stub(x => x.AppRelativeCurrentExecutionFilePath).Return("~" + fullUrl.AbsolutePath);
request.Stub(x => x.PathInfo).Return(string.Empty);
request.Stub(x => x.RawUrl).Return(VirtualPathUtility.ToAbsolute("~" + fullUrl.AbsolutePath, "/"));
request.Stub(x => x.RequestContext).Return(RequestContext);
request.Stub(x => x.Url).Return(fullUrl);
request.Stub(x => x.ApplicationPath).Return("/");
request.Stub(x => x.Cookies).Return(cookieCollection);
request.Stub(x => x.ServerVariables).Return(new NameValueCollection());
var queryStrings = HttpUtility.ParseQueryString(fullUrl.Query);
request.Stub(x => x.QueryString).Return(queryStrings);
request.Stub(x => x.Form).Return(new NameValueCollection());
//Cache
var cache = MockRepository.GenerateMock<HttpCachePolicyBase>();
//Response
//var response = new FakeHttpResponse();
var response = MockRepository.GenerateMock<HttpResponseBase>();
response.Stub(x => x.ApplyAppPathModifier(null)).IgnoreArguments().Do(new Func<string, string>(appPath => appPath));
response.Stub(x => x.Cache).Return(cache);
//Server
var server = MockRepository.GenerateStub<HttpServerUtilityBase>();
server.Stub(x => x.MapPath(Arg<string>.Is.Anything)).Return(Environment.CurrentDirectory);
//HTTP Context
HttpContext = MockRepository.GenerateMock<HttpContextBase>();
HttpContext.Stub(x => x.Cache).Return(HttpRuntime.Cache);
HttpContext.Stub(x => x.Items).Return(new Dictionary<object, object>());
HttpContext.Stub(x => x.Request).Return(request);
HttpContext.Stub(x => x.Server).Return(server);
HttpContext.Stub(x => x.Response).Return(response);
RequestContext.Stub(x => x.HttpContext).Return(HttpContext);
if (routeData != null)
{
RequestContext.Stub(x => x.RouteData).Return(routeData);
}
}
示例14: TestCollection
public void TestCollection ()
{
HttpCookieCollection col = new HttpCookieCollection ();
HttpCookie cookie = new HttpCookie ("cookie", "value");
col.Add (cookie);
Assert.AreEqual ("cookie", col["cookie"].Name, "Name is the key");
col.Remove (cookie.Name);
Assert.IsNull (col["cookie"], "removal using name");
}
示例15: GivenALoggdInUser_WhenILogout_ThenTheCookieIsExpired
public void GivenALoggdInUser_WhenILogout_ThenTheCookieIsExpired()
{
var cookies = new HttpCookieCollection();
string cookieName = "USER";
cookies.Add(new HttpCookie(cookieName));
MockRequest.Setup(r => r.Cookies).Returns(cookies);
_sessionController.Delete();
HttpCookie cookie = FakeResponse.Cookies[GetCookieUserFilterAttribute.UserCookieName];
Assert.That(cookie.Expires, Is.EqualTo(new DateTime(1970, 1, 1)));
}