public void ComplexPostCheck() { using (var endpoint = new JsonServerInfo()) { var valuesClient = endpoint.Provider.GetService <IValuesClient>(); MyFancyDto returnedDto = null; var dto = new MyFancyDto { Collision = Guid.NewGuid(), Description = "Test", Id = 12, When = DateTime.Now }; valuesClient.ComplexPost(dto, Guid.NewGuid(), OKCallback: (_) => { returnedDto = _; }, ExceptionCallback: ex => { throw ex; }, cancellationToken: endpoint.TimeoutToken); Assert.Equal(dto.Collision, returnedDto.Collision); } }
public void RequestAndResponseChecks() { using (var endpoint = new ProtobufServerInfo()) { var valuesClient = endpoint.Provider.GetService <IValuesClient>(); var dto = new MyFancyDto { Id = 1, Collision = Guid.NewGuid(), Description = "Helo", When = DateTime.UtcNow }; var response = valuesClient.DtoForDtoRaw(dto); Assert.True(response.RequestMessage.Content.Headers?.ContentType?.MediaType == "application/x-protobuf"); Assert.True(response.Content.Headers.ContentType.MediaType == "application/x-protobuf"); var actual = valuesClient.DtoForDto(dto); Assert.AreEqual(dto.Collision, actual.Collision); Assert.AreEqual(dto.Description, actual.Description); Assert.AreEqual(dto.Id, actual.Id); Assert.AreEqual(dto.When, actual.When); } }
public static void Main() { IServiceCollection services = new ServiceCollection(); services.AddTestWebClients(config => { config.UseJsonClientSerializer(); config.WithJsonBody(); config.UseHttpClientFactory(); //config.WithBaseAddress(_ => "http://localhost:62152"); config.WithBaseAddress("http://localhost:62152"); }); var provider = services.BuildServiceProvider(); var client = provider.GetService <IValuesClient>(); MyFancyDto dto = null; client.FancyDtoReturn(50, OKCallback: _ => { dto = _; }); if (dto == null) { throw new Exception("Client did not work!"); } }
public void DuplicateMethodReturnAndResponseTypeAttributeTest() { using (var endpoint = new JsonServerInfo()) { var client = endpoint.Provider.GetService <IValuesClient>(); string responseVal = null; MyFancyDto val = client.DuplicateMethodReturnAndResponse(ResponseCallback: msg => { responseVal = msg.Content.ReadAsStringAsync().ConfigureAwait(false).GetAwaiter().GetResult(); }, cancellationToken: endpoint.TimeoutToken); Assert.Equal(100, val.Id); Assert.Equal(DateTime.Now.Date, val.When); Assert.Equal("Hello", val.Description); var responseJson = JsonSerializer.Deserialize <MyFancyDto>(responseVal, new JsonSerializerOptions { PropertyNameCaseInsensitive = true }); Assert.Equal(val.Id, responseJson.Id); Assert.Equal(val.When, responseJson.When); Assert.Equal(val.Description, responseJson.Description); } }
public void ComplexPostCheck() { var endpoint = new JsonServerInfo(); var valuesClient = endpoint.Provider.GetService <IValuesClient>(); MyFancyDto returnedDto = null; var dto = new MyFancyDto { Collision = Guid.NewGuid(), Description = "Test", Id = 12, When = DateTime.Now }; valuesClient.ComplexPost(dto, Guid.NewGuid(), OKCallback: (_) => { returnedDto = _; }); Assert.AreEqual(dto.Collision, returnedDto.Collision); }
public void DtoReturns() { var endpoint = new ProtobufServerInfo(); var valuesClient = endpoint.Provider.GetService <IValuesClient>(); MyFancyDto dto = null; valuesClient.FancyDtoReturn(15, OKCallback: (_) => { dto = _; }); Assert.AreEqual(15, dto.Id); }
public void DtoReturns() { using (var endpoint = new JsonServerInfo()) { var valuesClient = endpoint.Provider.GetService <IValuesClient>(); MyFancyDto dto = null; valuesClient.FancyDtoReturn(15, OKCallback: (_) => { dto = _; }, cancellationToken: endpoint.TimeoutToken); Assert.Equal(15, dto.Id); } }
public static void Main() { IServiceCollection services = new ServiceCollection(); services.AddTestWebClients(config => { config.UseJsonClientSerializer(); config.UseJsonClientDeserializer(); config.WithJsonBody(); config.UseHttpClientFactory <ITestWebAppClient>(); config.WithBaseAddress(_ => "http://localhost:62154"); //config.WithBaseAddress("http://localhost:62154"); }); var provider = services.BuildServiceProvider(); var client = provider.GetService <IValuesClient>(); HttpResponseMessage msg = null; MyFancyDto val = client.MultiReturnParse(BadRequestCallback: () => { throw new Exception("Client did not work!"); }, InternalServerErrorCallback: () => { throw new Exception("Client did not work!"); }, CreatedCallback: dto => { }, ResponseCallback: response => { msg = response; }); if (val.Id != 5) { throw new Exception("Client did not work!"); } if (!msg.IsSuccessStatusCode) { throw new Exception("Client did not work!"); } }
public void QueryObjectTest() { var endpoint = new JsonServerInfo(); var valuesClient = endpoint.Provider.GetService <IFullClient>(); MyFancyDto expected = new MyFancyDto { Id = 1, Collision = Guid.NewGuid(), Description = "Hello", When = DateTime.Now.Date }; MyFancyDto actual = valuesClient.GetQueryObject(expected); Assert.AreEqual(expected.Collision, actual.Collision); }
public async Task MessagePackTest() { using (var endpoint = new MessagePackServerInfo()) { var hub = new ChatHubConnectionBuilder(endpoint.Server.BaseAddress, null, config => { config.HttpMessageHandlerFactory = _ => endpoint.Server.CreateHandler(); }) .AddMessagePackProtocol() .Build(); MyFancyDto actual = null; MyFancyDto expected = new MyFancyDto { Collision = Guid.NewGuid(), Description = "I am a test", Id = 15, When = DateTime.Now }; CancellationTokenSource tokenSource = new CancellationTokenSource(2000); var token = tokenSource.Token; hub.OnReceiveMessage2((dto) => { actual = dto; tokenSource.Cancel(); }); await hub.StartAsync(); await hub.DtoMessageAsync(expected); await token.WhenCanceled(); await hub.StopAsync(); Assert.AreEqual(expected.Collision, actual.Collision); Assert.AreEqual(expected.Description, actual.Description); Assert.AreEqual(expected.Id, actual.Id); Assert.AreEqual(expected.When.ToLocalTime(), actual.When.ToLocalTime()); } }
public MyFancyDto GetQueryObject([FromQuery] MyFancyDto dto) { return(dto); }
public async Task DtoMessage(MyFancyDto dto) { await Clients.All.SendAsync("ReceiveMessage2", dto); }
public IActionResult ComplexPost([FromRoute(Name = "testId")] Guid id, MyFancyDto dto) { return(Ok(dto)); }
public MyFancyDto DtoForDto(MyFancyDto dto) { return(dto); }
public async ValueTask <IActionResult> TaskReturn(MyFancyDto dto) { await Task.CompletedTask; return(Ok()); }