Exemplo n.º 1
0
        public WorkingCopyTests()
        {
            _testSetup = TestSetup.Create();

            _testPlatformAbstractions = new TestPlatformAbstractions();
            CommandLineUI.Platform    = _testPlatformAbstractions;
        }
Exemplo n.º 2
0
        public RepositoryExtensionsTests()
        {
            _testSetup = TestSetup.Create();

            _testPlatformAbstractions = new TestPlatformAbstractions();
            CommandLineUI.Platform    = _testPlatformAbstractions;
        }
Exemplo n.º 3
0
    public ProgramTests()
    {
        _testSetup = TestSetup.Create();
        TempProject.CreateCsharpProject(_testSetup.WorkingDirectory, "1.1.0");

        _testPlatformAbstractions = new TestPlatformAbstractions();
        CommandLineUI.Platform    = _testPlatformAbstractions;
    }
Exemplo n.º 4
0
        public void TestBasics()
        {
            using var setup = TestSetup.Create((r) =>
            {
                return(r.Respond().Content("Hello World!"));
            });

            var runner = setup.Runner;

            using var response = runner.GetResponse();
            Assert.Equal("Hello World!", response.GetContent());
        }
Exemplo n.º 5
0
        public void TestQuerySpecialChars()
        {
            using var setup = TestSetup.Create((r) =>
            {
                var result = string.Join('|', r.Query.Select(kv => $"{kv.Key}={kv.Value}"));
                return(r.Respond().Content(result));
            });

            var runner = setup.Runner;

            using var r = runner.GetResponse("/?key=%20%3C+");
            Assert.Equal("key= <+", r.GetContent());
        }
Exemplo n.º 6
0
        public void TestRedirection()
        {
            using var setup = TestSetup.Create((r) =>
            {
                return(r.Respond().Header("Location", $"http://localhost:{r.EndPoint.Port}/target").Status(ResponseStatus.TemporaryRedirect));
            });

            var runner = setup.Runner;

            using var redirected = runner.GetResponse("/");

            Assert.Equal(redirected.Headers["Location"], $"http://localhost:{runner.Port}/target");
        }
Exemplo n.º 7
0
        public void TestHead()
        {
            using var setup = TestSetup.Create((r) =>
            {
                return(r.Respond().Content("Hello World!"));
            });

            var runner = setup.Runner;

            var headRequest = runner.GetRequest();

            headRequest.Method = "HEAD";

            using var headed = headRequest.GetSafeResponse();

            Assert.Equal(HttpStatusCode.OK, headed.StatusCode);
        }
Exemplo n.º 8
0
        public void TestPathing()
        {
            using var setup = TestSetup.Create((r) =>
            {
                return(r.Respond().Content(r.Target.Path.ToString()));
            });

            var runner = setup.Runner;

            using var r1 = runner.GetResponse("/");
            Assert.Equal("/", r1.GetContent());

            using var r2 = runner.GetResponse("/login/");
            Assert.Equal("/login/", r2.GetContent());

            using var r3 = runner.GetResponse("/login");
            Assert.Equal("/login", r3.GetContent());
        }
Exemplo n.º 9
0
        public void TestQuery()
        {
            using var setup = TestSetup.Create((r) =>
            {
                var result = string.Join('|', r.Query.Select(kv => $"{kv.Key}={kv.Value}"));
                return(r.Respond().Content(result));
            });

            var runner = setup.Runner;

            using var r2 = runner.GetResponse("/?one=two");
            Assert.Equal("one=two", r2.GetContent());

            using var r3 = runner.GetResponse("/?one=two&three=four");
            Assert.Equal("one=two|three=four", r3.GetContent());

            using var r1 = runner.GetResponse("/");
            Assert.Equal("", r1.GetContent());
        }
Exemplo n.º 10
0
        public void TestHeaders()
        {
            using var setup = TestSetup.Create((r) =>
            {
                return(r.Respond()
                       .Content("Hello World")
                       .Header("X-Custom-Header", r.Headers["X-Custom-Header"]));
            });

            var runner = setup.Runner;

            var request = runner.GetRequest();

            request.Headers.Add("X-Custom-Header", "Custom Value");

            using var response = request.GetResponse();

            Assert.Equal("Custom Value", response.Headers.Get("X-Custom-Header"));
        }
Exemplo n.º 11
0
        public void TestCookies()
        {
            using var setup = TestSetup.Create((r) =>
            {
                Assert.Equal("World", r.Cookies["Hello"].Value);

                return(r.Respond().Content("Hello World!")
                       .Cookie(new Cookie("One", "1"))
                       .Cookie(new Cookie("Two", "2")));
            });

            var runner = setup.Runner;

            var cookieRequest = runner.GetRequest();

            cookieRequest.CookieContainer = new CookieContainer();
            cookieRequest.CookieContainer.Add(new System.Net.Cookie("Hello", "World", "/", "localhost"));

            using var cookied = cookieRequest.GetSafeResponse();

            Assert.Equal("1", cookied.Cookies["One"].Value);
            Assert.Equal("2", cookied.Cookies["Two"].Value);
        }