public void CandidateFirstVisit(bool showSearchTourPreference) { var candidateId = Guid.NewGuid(); var candidateService = new Mock <ICandidateService>(); var helpPreferences = new HelpPreferences { ShowSearchTour = showSearchTourPreference }; candidateService.Setup(cs => cs.GetCandidate(candidateId)).Returns(new CandidateBuilder(candidateId).With(helpPreferences).Build); var provider = new HelpCookieProviderBuilder().With(candidateService).Build(); var httpResponse = new Mock <HttpResponseBase>(); var responseCookies = new HttpCookieCollection(); httpResponse.Setup(m => m.Cookies).Returns(responseCookies); var httpContext = new HttpContextBuilder().With(httpResponse).Build(); var showSearchTour = provider.ShowSearchTour(httpContext, candidateId); showSearchTour.Should().Be(showSearchTourPreference); var cookie = responseCookies.Get(HelpCookieProvider.CookieName); cookie.Should().NotBeNull(); var cookieValue = cookie[HelpCookieProvider.CookieKeys.ShowSearchTour.ToString()]; cookieValue.Should().Be(candidateId.ToString()); candidateService.Verify(cs => cs.GetCandidate(It.IsAny <Guid>()), Times.Once); }
public void Application_ElementsCanBeAdded_AfterCreation() { HttpContext subject = new HttpContextBuilder().Context; subject.Application["a"] = 1; Assert.That(subject.Application["a"], Is.EqualTo(1)); }
public void CandidateSubsequentVisit() { var candidateId = Guid.NewGuid(); var candidateService = new Mock <ICandidateService>(); var provider = new HelpCookieProviderBuilder().With(candidateService).Build(); var httpRequest = new Mock <HttpRequestBase>(); var requestCookies = new HttpCookieCollection(); var existingCookie = new HttpCookie(HelpCookieProvider.CookieName); existingCookie[HelpCookieProvider.CookieKeys.ShowSearchTour.ToString()] = candidateId.ToString(); requestCookies.Add(existingCookie); httpRequest.Setup(m => m.Cookies).Returns(requestCookies); var httpResponse = new Mock <HttpResponseBase>(); var responseCookies = new HttpCookieCollection(); httpResponse.Setup(m => m.Cookies).Returns(responseCookies); var httpContext = new HttpContextBuilder().With(httpRequest).With(httpResponse).Build(); var showSearchTour = provider.ShowSearchTour(httpContext, candidateId); showSearchTour.Should().BeFalse(); var cookie = responseCookies.Get(HelpCookieProvider.CookieName); cookie.Should().BeNull(); candidateService.Verify(cs => cs.GetCandidate(It.IsAny <Guid>()), Times.Never); }
public void Items_ElementsCanBeAdded_AfterCreation() { HttpContext subject = new HttpContextBuilder().Context; subject.Items["a"] = 1; Assert.That(subject.Items["a"], Is.EqualTo(1)); }
public void Requests_NotSecure_ByDefault() { HttpContext subject = new HttpContextBuilder().Context; Assert.That(subject.Request.IsSecureConnection, Is.False); Assert.That(subject.Request.Url.Scheme, Is.EqualTo(Uri.UriSchemeHttp)); }
public void UrlReferrer_CanBeSet_InAdvance() { Uri referrer = new Uri("http://www.google.com"); HttpContext subject = new HttpContextBuilder().Request.WithReferrer(referrer).Context; Assert.That(subject.Request.UrlReferrer, Is.EqualTo(referrer)); }
public void Requests_CanBeMade_Secure() { HttpContext subject = new HttpContextBuilder().Request.MakeSecure().Context; Assert.That(subject.Request.IsSecureConnection, Is.True); Assert.That(subject.Request.Url.Scheme, Is.EqualTo(Uri.UriSchemeHttps)); }
public void Requests_CanBeMade_Secure_ByPassingSecureUrl() { HttpContext subject = new HttpContextBuilder().Request.WithUrl(new Uri("https://www.secure.org")).Context; Assert.That(subject.Request.IsSecureConnection, Is.True); Assert.That(subject.Request.Url.Scheme, Is.EqualTo(Uri.UriSchemeHttps)); }
public void Cookies_ElementsCanBeAdded_AfterCreation() { HttpContext subject = new HttpContextBuilder().Context; subject.Request.Cookies.Add(new HttpCookie("a", "1")); Assert.That(subject.Request.Cookies["a"].Value, Is.EqualTo("1")); }
public void Application_ElementsCanBeRemoved_WhenSetInAdvance() { HttpContext subject = new HttpContextBuilder() .AddToApplication("a", 1) .Context; subject.Application.Remove("a"); Assert.That(subject.Application["a"], Is.Null); }
public void QueryString_ChangesUrl() { HttpContext subject = new HttpContextBuilder().Request .AddToQueryString("key1", "value1") .Context; Assert.That(subject.Request.Url.Query, Is.EqualTo("?key1=value1")); }
public void Application_ElementsCanBeRemoved_WhenSetAfterCreation() { HttpContext subject = new HttpContextBuilder().Context; subject.Application.Add("b", 2); subject.Application.Remove("b"); Assert.That(subject.Application, Has.No.Contains("b")); }
public void Cookies_ElementsCanBeRemoved_WhenSetAfterCreation() { HttpContext subject = new HttpContextBuilder().Context; subject.Request.Cookies.Add(new HttpCookie("b", "2")); subject.Request.Cookies.Remove("b"); Assert.That(subject.Request.Cookies, Has.No.Contains("b")); }
public void Session_ElementsCanBeRemoved_WhenSetAfterCreation() { HttpContext subject = new HttpContextBuilder().Context; subject.Session["b"] = 2; subject.Session.Remove("b"); Assert.That(subject.Session, Has.No.Member("b")); }
public void Session_ElementsCanBeRemoved_WhenSetInAdvance() { HttpContext subject = new HttpContextBuilder() .AddToSession("a", 1) .Context; subject.Session.Remove("a"); Assert.That(subject.Session, Has.No.Member("a")); }
public void Items_ElementsCanBeRemoved_WhenSetInAdvance() { HttpContext subject = new HttpContextBuilder() .AddToItems("a", 1) .Context; subject.Items.Remove("a"); Assert.That(subject.Items["a"], Is.Null); }
public void Cookies_ElementsCanBeRemoved_WhenSetInAdvance() { HttpContext subject = new HttpContextBuilder().Request .AddToCookies("a", "1") .Context; subject.Request.Cookies.Remove("a"); Assert.That(subject.Request.Cookies["a"], Is.Null); }
public void Session_ElementsCanBeSet_InAdvance() { HttpContext subject = new HttpContextBuilder() .AddToSession("a", 1) .AddToSession("b", 2) .Context; Assert.That(subject.Session["a"], Is.EqualTo(1)); Assert.That(subject.Session["b"], Is.EqualTo(2)); }
public void Cookies_ElementsCanBeSet_InAdvance() { HttpContext subject = new HttpContextBuilder().Request .AddToCookies("1", "1") .AddToCookies(new HttpCookie("2", "2")) .Context; Assert.That(subject.Request.Cookies["1"].Value, Is.EqualTo("1")); Assert.That(subject.Request.Cookies["2"].Value, Is.EqualTo("2")); }
public void ShouldNotGetErrorIfDontHaveAnyCustomer() { var controller = new DemoCleanArchitecture.WebApi.UseCases.Customer.GetAll.CustomerController(presenter, customerGetAllUseCase); controller.ControllerContext.HttpContext = HttpContextBuilder.New().Build(); var output = controller.GetAllCustomers(); output.Should().BeOfType <OkObjectResult>(); }
public void Application_ElementsCanBeSet_InAdvance() { HttpContext subject = new HttpContextBuilder() .AddToApplication("1", 1) .AddToApplication("2", "2") .Context; Assert.That(subject.Application["1"], Is.EqualTo(1)); Assert.That(subject.Application["2"], Is.EqualTo("2")); }
public void Url_CanBeSet_ButQueryIsIgnored() { Uri url = new Uri("https://www.myweb.com:8080/ajax/entity/id?p=3"); HttpContext subject = new HttpContextBuilder().Request.WithUrl(url).Context; Assert.That(subject.Request.Url.AbsolutePath, Is.EqualTo("/ajax/entity/id")); Assert.That(subject.Request.Url.Host, Is.EqualTo("www.myweb.com")); Assert.That(subject.Request.Url.Scheme, Is.EqualTo("https")); Assert.That(subject.Request.Url.Query, Is.Empty); }
public void StartSentryTransaction_CreatesValidTransaction() { // Arrange var context = HttpContextBuilder.Build(); // Act var transaction = context.StartSentryTransaction(); // Assert transaction.Name.Should().Be("GET /the/path"); transaction.Operation.Should().Be("http.server"); }
public ControllerBuilder WithHttpResponseHeaders() { var httpContext = new HttpContextBuilder() .WithRequest() .WithResponse() .WithResponseHeaders() .Build(); _controllerContext.Setup(cc => cc.HttpContext).Returns(httpContext); return(this); }
public void ShouldGetCustomer() { var input = new InputCustomer() { CustomerId = CustomerId }; var controller = new CustomerController(presenter, customerGetUseCase); controller.ControllerContext.HttpContext = HttpContextBuilder.New().Build(); var output = controller.GetCustomer(input); output.Should().BeOfType <OkObjectResult>(); }
public void InncorrectUsername() { var provider = new CookieAuthorizationDataProvider(null); var claim = new Claim("TestType", "TestValue"); var httpContext = new HttpContextBuilder().Build(); provider.AddClaim(claim, httpContext, "*****@*****.**"); var claims = provider.GetClaims(httpContext, "*****@*****.**"); claims.Length.Should().Be(0); }
public void ShouldUpdateCustomer() { var input = new InputCustomer() { Id = CustomerId, Name = "CustomerTest", Age = 50, Email = "*****@*****.**" }; var controller = new CustomerController(presenter, customerSaveUseCase); controller.ControllerContext.HttpContext = HttpContextBuilder.New().Build(); var output = controller.UpdateCustomer(input); output.Should().BeOfType <OkObjectResult>(); }
public void ShouldNotGetCustomerAndReturnNotFound() { var input = new InputCustomer() { CustomerId = Guid.NewGuid() }; var controller = new CustomerController(presenter, customerGetUseCase); controller.ControllerContext.HttpContext = HttpContextBuilder.New().Build(); var output = controller.GetCustomer(input); output.Should().BeOfType <NotFoundObjectResult>(); }
public void ShouldNotCreateAndGetError() { var input = new InputCustomer() { Name = "", Age = 50, Email = "*****@*****.**" }; var controller = new CustomerController(presenter, customerSaveUseCase); controller.ControllerContext.HttpContext = HttpContextBuilder.New().Build(); var output = controller.CreateCustomer(input); output.Should().BeOfType <BadRequestObjectResult>(); }
public void Output_CanBeAccessed_AfterResponseEnd() { string written = "written"; StringBuilder sb = new StringBuilder(); HttpContext context = new HttpContextBuilder() .OuputWrittenTo(sb) .Context; context.Response.Write(written); context.Response.Flush(); Assert.That(sb.ToString(), Is.EqualTo(written)); }
public void ShouldNotDeleteAndGetError() { var input = new InputCustomer() { CustomerId = CustomerId }; var controller = new CustomerController(presenter, customerDeleteUseCase); controller.ControllerContext.HttpContext = HttpContextBuilder.New().Build(); var output = controller.DeleteCustomer(input); output.Should().BeOfType <BadRequestObjectResult>(); }
public void HttpContextBuilder_CanBeUsedToTest_HttpHandlers() { StringBuilder sb = new StringBuilder(); var subject = new MessageHandler(); HttpContext context = new HttpContextBuilder() .OuputWrittenTo(sb) .Request .AddToForm("language", "es-ES") .AddToForm("resourceName", "Message_1") .Context; subject.ProcessRequest(context); context.Response.Flush(); Assert.That(sb.ToString(), Is.EqualTo("Mensaje Uno")); }
public void QueryString_CannotRemoveItems() { HttpContext subject = new HttpContextBuilder().Context; Assert.That(() => subject.Request.QueryString.Remove("something"), Throws.InstanceOf<NotSupportedException>()); }
public void QueryString_CanBeInitialized() { NameValueCollection massInitialization = new NameValueCollection() { {"key3", "value3"}, {"key4", "value4"} }; HttpContext subject = new HttpContextBuilder().Request .AddToQueryString("key1", "value1") .AddToQueryString("key2", "value2") .AddToQueryString(massInitialization) .Context; Assert.That(subject.Request.QueryString["key1"], Is.EqualTo("value1")); Assert.That(subject.Request.QueryString["key2"], Is.EqualTo("value2")); Assert.That(subject.Request.QueryString["key3"], Is.EqualTo("value3")); Assert.That(subject.Request.QueryString["key4"], Is.EqualTo("value4")); }
public void QueryString_StartsEmpty() { HttpContext subject = new HttpContextBuilder().Context; Assert.That(subject.Request.QueryString, Is.Empty); }
public void UrlReferrer_IsNullByDefault() { HttpContext subject = new HttpContextBuilder().Context; Assert.That(subject.Request.UrlReferrer, Is.Null); }
public void QueryString_UrlEncodableKey_AccesibleByDecodedKey() { HttpContext subject = new HttpContextBuilder().Request.AddToQueryString("a&b", "value").Context; Assert.That(subject.Request.QueryString["a&b"], Is.EqualTo("value")); }
/// <summary> /// Sets the instance built by the <paramref name="builder"/> /// </summary> /// <param name="builder">Builder of the <see cref="HttpContext"/> instance.</param> /// <returns>A scope object that resets the <see cref="HttpContext.Current"/> after is disposed.</returns> public static HttpContextReseter Set(HttpContextBuilder builder) { return new HttpContextReseter(builder.Context); }
public void Items_ElementsCanBeSet_InAdvance() { var massInit = new Hashtable { { "3", 3 }, { 4, "4" } }; HttpContext subject = new HttpContextBuilder() .AddToItems("1", 1) .AddToItems(2, "2") .AddToItems(massInit) .Context; Assert.That(subject.Items["1"], Is.EqualTo(1)); Assert.That(subject.Items[2], Is.EqualTo("2")); Assert.That(subject.Items["3"], Is.EqualTo(3)); Assert.That(subject.Items[4], Is.EqualTo("4")); }
public void Url_ByDefault_PointingToLocalhost() { HttpContext subject = new HttpContextBuilder().Context; Assert.That(subject.Request.Url, Is.EqualTo(new Uri("http://127.0.0.01/webapp/default.aspx"))); }
public void Session_StartsEmpty() { HttpContext subject = new HttpContextBuilder().Context; Assert.That(subject.Session, Is.Empty); }
public void Items_DoesNotStartEmpty() { HttpContext subject = new HttpContextBuilder().Context; Assert.That(subject.Items, Has.Count.EqualTo(1), "There is always the session state"); }
public void Complex_Building() { StringBuilder sb = new StringBuilder(); Uri google = new Uri("http://www.google.com"), url = new Uri("http://dgondotnet.blogspot.com/2011/09/configure-reality.html"); var complexContext = new HttpContextBuilder() .AddToSession("session", 1) .AddToItems(2, "item") .AddToApplication("application", 3) .OuputWrittenTo(sb) .Request .MakeSecure() .WithReferrer(google) .AddToQueryString("query", "4") .AddToForm("form", "5") .AddToHeaders("header", "6") .AddToCookies("cookie", "7") .WithUrl(url) .Context; Assert.That(complexContext.Session["session"], Is.EqualTo(1)); Assert.That(complexContext.Items[2], Is.EqualTo("item")); Assert.That(complexContext.Application["application"], Is.EqualTo(3)); Assert.That(complexContext.Request.IsSecureConnection, Is.True); Assert.That(complexContext.Request.Url.Scheme, Is.EqualTo("https")); Assert.That(complexContext.Request.UrlReferrer, Is.EqualTo(google)); Assert.That(complexContext.Request.QueryString["query"], Is.EqualTo("4")); Assert.That(complexContext.Request.Form["form"], Is.EqualTo("5")); Assert.That(complexContext.Request.Headers["header"], Is.EqualTo("6")); Assert.That(complexContext.Request.Cookies["cookie"].Value, Is.EqualTo("7")); Assert.That(complexContext.Request.Cookies["cookie"].Value, Is.EqualTo("7")); Assert.That(complexContext.Request.Url, Is.EqualTo(new UriBuilder(url){Scheme = "https", Query = "query=4"}.Uri)); }
public void QueryString_UrlEncodableValue_ValueIsDecoded() { HttpContext subject = new HttpContextBuilder().Request.AddToQueryString("key", "b b").Context; Assert.That(subject.Request.QueryString["key"], Is.EqualTo("b b")); }
public void HttpMethod_WhenFormItemsHaveBeenAdded_POST() { HttpContext subject = new HttpContextBuilder().Request.AddToForm("a", "b").Context; Assert.That(subject.Request.HttpMethod, Is.EqualTo("POST")); }
internal HttpRequestBuilder(HttpContextBuilder builder, HttpRequestModel model) { _builder = builder; _model = model; }