public void ShouldAllowGettingLoggerFactory() { var httpContextMock = HttpContextMock.Default(); httpContextMock.RealInstance.RequestServices.GetRequiredService <ILoggerFactory>() .Should().NotBeNull(); }
public void Test1() { var httpContextMock = HttpContextMock.Default(); httpContextMock.Request() .WithHeader("Accept", "text/plain") .WithHeader(new { Accept = MediaTypeNames.Text.Plain }) .Https() .AppendPathSegment("person") .AppendPathSegments("person2", "person3") .AppendPathSegments(new List <string> { "person4" }) .AppendPathSegment("person5") .WithStringBody("lolek") .WithJsonBody(new { A = 123, B = "SAA" }) .WithOAuthBearerToken("my_oauth_token") .WithBasicAuth("password") .WithQueryParams(new { a = 1, b = 2 }) .WithQueryParam("c", "x") .WithQueryParam("d", null); //todo https://flurl.dev/docs/fluent-http/ Assert.AreEqual("{\"A\":123,\"B\":\"SAA\"}", new StreamReader(httpContextMock.RealInstance.Request.Body).ReadToEnd()); }
public void ShouldAllowSettingQueryParamToStringValues() { var httpContextMock = HttpContextMock.Default(); httpContextMock.Request().WithQueryParam("lol", new StringValues(new[] { "a", "b" })); httpContextMock.RealInstance.Request.QueryString.ToString().Should().Be("?lol=a,b"); }
public void ShouldAllowSettingQueryString() { var httpContextMock = HttpContextMock.Default(); httpContextMock.Request().WithQueryString(QueryString.Create(new Dictionary <string, string>() { ["lol"] = new StringValues(new[] { "a", "b" }) })); httpContextMock.RealInstance.Request.QueryString.ToString().Should().Be("?lol=a,b"); }
public void ShouldAllowSettingQueryViaDictionary() { var httpContextMock = HttpContextMock.Default(); var name = Any.String(); var value = Any.String(); httpContextMock.Request().WithQuery(new QueryCollection(new Dictionary <string, StringValues> { [name] = value })); httpContextMock.Request().RealInstance.Query[name].Should().BeEquivalentTo(new StringValues(value)); }
public void ShouldAllowRewindingRequestBody() { var httpContextMock = HttpContextMock.Default(); httpContextMock.Request().WithStringBody(Any.String()); using var streamReader = new StreamReader(httpContextMock.Request().RealInstance.Body); using var streamReader2 = new StreamReader(httpContextMock.Request().RealInstance.Body); var content = streamReader.ReadToEnd(); httpContextMock.Request().RewindBody(); var content2 = streamReader2.ReadToEnd(); content.Should().Be(content2); }
public void ShouldAllowSettingBytesBody() { var httpContextMock = HttpContextMock.Default(); var content = Any.Array <byte>(3); httpContextMock.Request().WithBytesBody(content); var result = new List <byte> { (byte)httpContextMock.Request().RealInstance.Body.ReadByte(), (byte)httpContextMock.Request().RealInstance.Body.ReadByte(), (byte)httpContextMock.Request().RealInstance.Body.ReadByte() }; result.Should().Equal(content); httpContextMock.Request().RealInstance.Body.Length.Should().Be(3); }
public async Task <AddTodoItemAdapterResponse> AttemptToAddTodoItem(Func <HttpRequestMock, HttpRequestMock> customize) { var httpContextMock = HttpContextMock.Default(); await _adapter.AddTodoEndpoint.Handle( customize(httpContextMock.Request() .AppendPathSegment("todo") .WithHeader("Authorization", $"Bearer {TestTokens.GenerateToken()}") .WithHeader("Content-Type", MediaTypeNames.Application.Json) .WithHeader("Accept", MediaTypeNames.Application.Json) .WithQueryParam("customerId", Any.String()) .WithJsonBody(new { title = "Meeting", content = "there's a meeting you need to attend" })).RealInstance, httpContextMock.Response().RealInstance, new CancellationToken() ); var httpResponseMock = httpContextMock.Response(); return(new AddTodoItemAdapterResponse(httpResponseMock)); }
public void ShouldContainEmptyBodyInResponse() { var httpContextMock = HttpContextMock.Default(); httpContextMock.Response().BodyString().Should().BeEmpty(); }