コード例 #1
0
        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);
        }
コード例 #2
0
        public void Application_ElementsCanBeAdded_AfterCreation()
        {
            HttpContext subject = new HttpContextBuilder().Context;

            subject.Application["a"] = 1;
            Assert.That(subject.Application["a"], Is.EqualTo(1));
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        public void Items_ElementsCanBeAdded_AfterCreation()
        {
            HttpContext subject = new HttpContextBuilder().Context;

            subject.Items["a"] = 1;
            Assert.That(subject.Items["a"], Is.EqualTo(1));
        }
コード例 #5
0
        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));
        }
コード例 #6
0
        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));
        }
コード例 #7
0
        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));
        }
コード例 #8
0
        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));
        }
コード例 #9
0
        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"));
        }
コード例 #10
0
 public void Application_ElementsCanBeRemoved_WhenSetInAdvance()
 {
     HttpContext subject = new HttpContextBuilder()
         .AddToApplication("a", 1)
         .Context;
     subject.Application.Remove("a");
     Assert.That(subject.Application["a"], Is.Null);
 }
コード例 #11
0
        public void QueryString_ChangesUrl()
        {
            HttpContext subject = new HttpContextBuilder().Request
                                  .AddToQueryString("key1", "value1")
                                  .Context;

            Assert.That(subject.Request.Url.Query, Is.EqualTo("?key1=value1"));
        }
コード例 #12
0
        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"));
        }
コード例 #13
0
        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"));
        }
コード例 #14
0
        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"));
        }
コード例 #15
0
        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"));
        }
コード例 #16
0
        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"));
        }
コード例 #17
0
        public void Application_ElementsCanBeRemoved_WhenSetInAdvance()
        {
            HttpContext subject = new HttpContextBuilder()
                                  .AddToApplication("a", 1)
                                  .Context;

            subject.Application.Remove("a");
            Assert.That(subject.Application["a"], Is.Null);
        }
コード例 #18
0
        public void Items_ElementsCanBeRemoved_WhenSetInAdvance()
        {
            HttpContext subject = new HttpContextBuilder()
                                  .AddToItems("a", 1)
                                  .Context;

            subject.Items.Remove("a");
            Assert.That(subject.Items["a"], Is.Null);
        }
コード例 #19
0
        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);
        }
コード例 #20
0
        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));
        }
コード例 #21
0
        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"));
        }
コード例 #22
0
        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>();
        }
コード例 #23
0
        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"));
        }
コード例 #24
0
        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"));
        }
コード例 #25
0
        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);
        }
コード例 #26
0
    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");
    }
コード例 #27
0
        public ControllerBuilder WithHttpResponseHeaders()
        {
            var httpContext = new HttpContextBuilder()
                              .WithRequest()
                              .WithResponse()
                              .WithResponseHeaders()
                              .Build();

            _controllerContext.Setup(cc => cc.HttpContext).Returns(httpContext);

            return(this);
        }
コード例 #28
0
        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>();
        }
コード例 #29
0
        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);
        }
コード例 #30
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>();
        }
コード例 #31
0
        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>();
        }
コード例 #32
0
        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>();
        }
コード例 #33
0
        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));
        }
コード例 #34
0
        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>();
        }
コード例 #35
0
        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"));
        }
コード例 #36
0
 public void QueryString_CannotRemoveItems()
 {
     HttpContext subject = new HttpContextBuilder().Context;
     Assert.That(() => subject.Request.QueryString.Remove("something"), Throws.InstanceOf<NotSupportedException>());
 }
コード例 #37
0
        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"));
        }
コード例 #38
0
 public void QueryString_StartsEmpty()
 {
     HttpContext subject = new HttpContextBuilder().Context;
     Assert.That(subject.Request.QueryString, Is.Empty);
 }
コード例 #39
0
        public void QueryString_ChangesUrl()
        {
            HttpContext subject = new HttpContextBuilder().Request
                .AddToQueryString("key1", "value1")
                .Context;

            Assert.That(subject.Request.Url.Query, Is.EqualTo("?key1=value1"));
        }
コード例 #40
0
        public void UrlReferrer_IsNullByDefault()
        {
            HttpContext subject = new HttpContextBuilder().Context;

            Assert.That(subject.Request.UrlReferrer, Is.Null);
        }
コード例 #41
0
        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"));
        }
コード例 #42
0
 /// <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);
 }
コード例 #43
0
        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"));
        }
コード例 #44
0
        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"));
        }
コード例 #45
0
        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")));
        }
コード例 #46
0
 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"));
 }
コード例 #47
0
        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));
        }
コード例 #48
0
        public void Session_StartsEmpty()
        {
            HttpContext subject = new HttpContextBuilder().Context;

            Assert.That(subject.Session, Is.Empty);
        }
コード例 #49
0
        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));
        }
コード例 #50
0
        public void Items_DoesNotStartEmpty()
        {
            HttpContext subject = new HttpContextBuilder().Context;

            Assert.That(subject.Items, Has.Count.EqualTo(1), "There is always the session state");
        }
コード例 #51
0
        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));
        }
コード例 #52
0
        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);
        }
コード例 #53
0
 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));
 }
コード例 #54
0
        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));
        }
コード例 #55
0
 public void Items_ElementsCanBeRemoved_WhenSetInAdvance()
 {
     HttpContext subject = new HttpContextBuilder()
         .AddToItems("a", 1)
         .Context;
     subject.Items.Remove("a");
     Assert.That(subject.Items["a"], Is.Null);
 }
コード例 #56
0
 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));
 }
コード例 #57
0
 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));
 }
コード例 #58
0
        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"));
        }
コード例 #59
0
 public void HttpMethod_WhenFormItemsHaveBeenAdded_POST()
 {
     HttpContext subject = new HttpContextBuilder().Request.AddToForm("a", "b").Context;
     Assert.That(subject.Request.HttpMethod, Is.EqualTo("POST"));
 }
コード例 #60
0
 internal HttpRequestBuilder(HttpContextBuilder builder, HttpRequestModel model)
 {
     _builder = builder;
     _model = model;
 }