public WorkingCopyTests() { _testSetup = TestSetup.Create(); _testPlatformAbstractions = new TestPlatformAbstractions(); CommandLineUI.Platform = _testPlatformAbstractions; }
public RepositoryExtensionsTests() { _testSetup = TestSetup.Create(); _testPlatformAbstractions = new TestPlatformAbstractions(); CommandLineUI.Platform = _testPlatformAbstractions; }
public ProgramTests() { _testSetup = TestSetup.Create(); TempProject.CreateCsharpProject(_testSetup.WorkingDirectory, "1.1.0"); _testPlatformAbstractions = new TestPlatformAbstractions(); CommandLineUI.Platform = _testPlatformAbstractions; }
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()); }
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()); }
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"); }
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); }
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()); }
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()); }
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")); }
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); }