I am trying to create a cookie wrap so that I can get it set in my works in MVC and get a cookie value . . We already have HttpContextWrapper, which have requests and response properties.
HttpContextWrapper:
public class HttpContextWrapper: IHttpContext {private Reedonli HttpContext _httpContext; Private Readonly HttpContextBase _httpContextBase; Public HTTP ContactWorker (HTTPPontontex httpcontestex) {_httpContext = httpContext; _httpContextBase = New system. Web.HttpContextWrapper (httpContext); } Public HttpRequest request {get {return _httpContext.Request; }} Public HttpContextBase Base {get {return _httpContextBase; }} Public HTTP Response Response {Get _httpContext.Response; }}}
IHttpContext:
Public Interface IHttpContext {HttpRequest Request} {get; } HttpContextBase Base {get; } HTTP Response Response {Receive; }}
1) How can I reuse this wrapper to set up and get cookie arts? 2) The purpose of lifting cookie values is to enable the unit to test. I am establishing and receiving the cookie values directly in my methodologies. Instead I want to make it reusable, and the unit is testable.
Any help on this is greatly appreciated.
Thanks
David Tensi Thank You for.
The following code was implemented and able to copy the response. Cookies Although this is not a reference cover which I was expecting, but at least I am able to move forward with it.
unit test files:
public class http Kantantmok: Actiteepitinteksbajh {private http Uttrprernabej response;
Get public override Actiteepiarpispointbej Response {(if (null Thiskresponse ==) {this.response = new Actiteepiarpispok ();} The return. Feedback;}}} public class HttpResponseMock Download: HttpResponseBase {private HttpCookieCollection cookies; public override Actiteepikyukiacloleshn cookies {(if (null Thiskcookies ==) {this.cookies = new HttpCookieCollection ();} this. Records Return;}}}
Test.cs:
Public Zero Testing Law () {Var _controller = new HomeContoller (); Var httpContext = new HttpContextMock (); _controller.ControllerContext = new Niyntrksngeet (httpContext, New Rutadeta () _ controller); Var Results = _controller.Welcome (userId); Aswasnkare Akwll ( "welcome", _kantrolr. response. cookies [titled "Message"]. value);}
Home controller:
public jsonresult welcome ( Int userid) {.................. .. var cookie = new HTTPQQ ("title message") {value = "welcome"}; Response.Cookies.Add (cookie); }
No comments:
Post a Comment