예제 #1
0
        public void ProblemDetailsRequestTest()
        {
            //Doesn't seem like we need a application/problem+x-msgpack content-type
            using (var endpoint = new MessagePackServerInfo())
            {
                var client = endpoint.Provider.GetService <IValuesClient>();

                ValidationProblemDetails errors1 = null;

                var dto = new RequiredDto()
                {
                    Id = 1
                };

                client.ProblemDetailsRequest(dto, BadRequestCallback: _ =>
                {
                    errors1 = _;
                });

                var dto2 = new RequiredDto()
                {
                    Id     = 1,
                    Field1 = "Hello"
                };

                client.ProblemDetailsRequest(dto2,
                                             OKCallback: () =>
                {
                }
                                             );
            }
        }
예제 #2
0
        public void RequestAndResponseChecks()
        {
            using (var endpoint = new MessagePackServerInfo())
            {
                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-msgpack");
                Assert.True(response.Content.Headers.ContentType.MediaType == "application/x-msgpack");



                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);
            }
        }
예제 #3
0
        public void HeaderTestInt()
        {
            using (var endpoint = new MessagePackServerInfo())
            {
                var valuesClient = endpoint.Provider.GetService <IValuesClient>();
                var value        = valuesClient.HeaderTestInt(15);


                Assert.AreEqual(15, value);
            }
        }
        public void HeaderTestInt()
        {
            using (var endpoint = new MessagePackServerInfo())
            {
                var valuesClient = endpoint.Provider.GetService <IValuesClient>();
                var value        = valuesClient.HeaderTestInt(15, cancellationToken: endpoint.TimeoutToken);


                Assert.Equal(15, value);
            }
        }
예제 #5
0
        public void GetTest()
        {
            using (var endpoint = new MessagePackServerInfo())
            {
                var valuesClient = endpoint.Provider.GetService <IValuesClient>();
                var values       = valuesClient.GetEnumerable();


                Assert.AreEqual(new List <string> {
                    "value1", "value2"
                }, values);
            }
        }
예제 #6
0
        public void DtoReturns()
        {
            using (var endpoint = new MessagePackServerInfo())
            {
                var        valuesClient = endpoint.Provider.GetService <IValuesClient>();
                MyFancyDto dto          = null;

                valuesClient.FancyDtoReturn(15,
                                            OKCallback: (_) =>
                {
                    dto = _;
                });


                Assert.AreEqual(15, dto.Id);
            }
        }
예제 #7
0
        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());
            }
        }