static public async Task testing_PostJSON(TestClientBase client) { using (HttpResponseMessage m = await client.PostJSON("/rewriteJSON", @"{ ""a"" : null, ""b"" : {} }")) { m.Content.ReadAsStringAsync().Result.Should().Be(@"JSON: '{""a"":null,""b"":{}}'"); } }
static public async Task testing_PostXml(TestClientBase client) { using (HttpResponseMessage m = await client.PostXml("/rewriteXElement", "<a > <b/> </a>")) { m.Content.ReadAsStringAsync().Result.Should().Be("XElement: '<a><b /></a>'"); } }
static public async Task authorization_token_works(TestClientBase client) { client.Token = "my token"; using (HttpResponseMessage m = await client.Get($"/readHeader?name={client.AuthorizationHeaderName}")) { m.Content.ReadAsStringAsync().Result.Should().Be($"header '{client.AuthorizationHeaderName}': 'Bearer my token'"); } }
static public async Task setting_cookie_and_delete_without_path(TestClientBase client) { var setCookieUri = new Uri(client.BaseAddress, "/setCookie"); using (HttpResponseMessage m = await client.Get("/setCookie?name=Gateau&value=V")) { var text = await m.Content.ReadAsStringAsync(); text.Should().Be("Cookie set: Gateau Path: Value: V"); var rootCookies = client.Cookies.GetCookies(client.BaseAddress); rootCookies.Should().HaveCount(0); var cookies = client.Cookies.GetCookies(setCookieUri); cookies.Should().HaveCount(1); cookies[0].Name.Should().Be("Gateau"); cookies[0].Path.Should().Be("/setCookie"); } using (HttpResponseMessage m = await client.Get("/deleteCookie?name=Gateau")) { var text = await m.Content.ReadAsStringAsync(); text.Should().Be("Cookie delete: Gateau Path: "); var cookies = client.Cookies.GetCookies(setCookieUri); cookies.Should().HaveCount(1); } using (HttpResponseMessage m = await client.Get("setCookie/sub/path/?readCookies")) { var text = await m.Content.ReadAsStringAsync(); text.Should().Be("Gateau:V\r\n"); } using (HttpResponseMessage m = await client.Get("setCookie/?readCookies")) { var text = await m.Content.ReadAsStringAsync(); text.Should().Be("Gateau:V\r\n"); } using (HttpResponseMessage m = await client.Get("setCookie?readCookies")) { var text = await m.Content.ReadAsStringAsync(); text.Should().Be("Gateau:V\r\n"); } using (HttpResponseMessage m = await client.Get("?readCookies")) { var text = await m.Content.ReadAsStringAsync(); text.Should().BeEmpty(); } using (HttpResponseMessage m = await client.Get("/deleteCookie?name=Gateau&path=/setCookie")) { var text = await m.Content.ReadAsStringAsync(); text.Should().Be("Cookie delete: Gateau Path: /setCookie"); var cookies = client.Cookies.GetCookies(setCookieUri); cookies.Should().BeEmpty(); } }
public void SendMessage_Should_Write_Message_To_Channel() { var messageDto = Substitute.For <IMessageDto <ProtocolMessage> >(); var channelFactory = Substitute.For <ITcpClientChannelFactory>(); var logger = Substitute.For <ILogger>(); var eventLoopGroupFactory = Substitute.For <IEventLoopGroupFactory>(); var testClientBase = new TestClientBase(channelFactory, logger, eventLoopGroupFactory); testClientBase.SendMessage(messageDto); testClientBase.Channel.Received(1)?.WriteAsync(messageDto); }
static public async Task hello_world_and_notfound(TestClientBase client) { using (HttpResponseMessage notFound = await client.Get("/other")) { notFound.StatusCode.Should().Be(HttpStatusCode.NotFound); } using (HttpResponseMessage hello = await client.Get("/sayHello")) { hello.StatusCode.Should().Be(HttpStatusCode.OK); var content = hello.Content.ReadAsStringAsync().Result; content.Should().StartWith("Hello! "); } }
static public async Task setting_cookie_and_delete_on_sub_path(TestClientBase client) { var cookiePath = new Uri(client.BaseAddress, "/COOKIEPATH"); using (HttpResponseMessage m = await client.Get("/setCookie?name=Gateau&path=%2FCOOKIEPATH")) { var text = await m.Content.ReadAsStringAsync(); text.Should().StartWith("Cookie set: Gateau Path: /COOKIEPATH Value: CookieValue"); var cookies = client.Cookies.GetCookies(cookiePath); cookies.Should().HaveCount(1); cookies[0].Name.Should().Be("Gateau"); cookies[0].Path.Should().Be("/COOKIEPATH"); } using (HttpResponseMessage m = await client.Get("?readCookies")) { var text = await m.Content.ReadAsStringAsync(); text.Should().BeEmpty(); } using (HttpResponseMessage m = await client.Get("/COOKIEPATH/sub/path/?readCookies")) { var text = await m.Content.ReadAsStringAsync(); text.Should().Be("Gateau:CookieValue\r\n"); } using (HttpResponseMessage m = await client.Get("/deleteCookie?name=Gateau&path=%2FCOOKIEPATH")) { var text = await m.Content.ReadAsStringAsync(); text.Should().Be("Cookie delete: Gateau Path: /COOKIEPATH"); var cookies = client.Cookies.GetCookies(cookiePath); cookies.Should().BeEmpty(); } using (HttpResponseMessage m = await client.Get("/COOKIEPATH/sub/path/?readCookies")) { var text = await m.Content.ReadAsStringAsync(); text.Should().BeEmpty(); } }
/// <summary> /// Initializes a new instance of the <see cref="XUnitTestRunner"/> class. /// </summary> /// <param name="client">Test client to use.</param> /// <param name="replyTimeout">The timeout for waiting for replies (in miliseconds). Default is 180000.</param> /// <param name="thinkTime">The timeout think time before sending messages to the bot (in miliseconds). Default is 0.</param> /// <param name="logger">Optional. Instance of <see cref="ILogger"/> to use.</param> public XUnitTestRunner(TestClientBase client, int replyTimeout = 180000, int thinkTime = 0, ILogger logger = null) : base(client, replyTimeout, thinkTime, logger) { }
/// <summary> /// Initializes a new instance of the <see cref="XUnitTestRunner"/> class. /// </summary> /// <param name="client">Test client to use.</param> /// <param name="logger">Optional. Instance of <see cref="ILogger"/> to use.</param> public XUnitTestRunner(TestClientBase client, ILogger logger = null) : base(client, logger) { }