Ejemplo n.º 1
0
        public async Task Send_PostWithObject_returns_201()
        {
            var request = new KRequest(HttpMethod.Post, new Uri(_uri));

            request.SetContent(new { Id = 1, Name = "Test" });
            var client = new KClient();

            var results = await client.SendAsync(request);

            Assert.True(results.First().Response.StatusCode == HttpStatusCode.Created);
        }
Ejemplo n.º 2
0
        public async Task Send_Get_returns_200()
        {
            var request = new KRequest(HttpMethod.Get, new Uri(_uri));
            var client  = new KClient(3, 2, 2); //First batch with 2 requests and a second 500ms later with 1 request, with two iterations (=> total 6 requests)

            var results = await client.SendAsync(request);

            Assert.True(results.Count() == client.RequestsPerSecond * client.Repetition);
            Assert.DoesNotContain(results, r => r.Response.StatusCode != HttpStatusCode.OK);
            Assert.DoesNotContain(results, r => r.ElapsedTime > 1000);
        }
Ejemplo n.º 3
0
        public async Task Send_GetWithReportWithResponseBody_returns_true()
        {
            var    request    = new KRequest(HttpMethod.Get, new Uri(_uri));
            var    client     = new KClient();
            string reportFile = Path.Combine(Directory.GetCurrentDirectory(), $"KReport_{DateTime.Today:yyyy-MM-dd}__{Guid.NewGuid()}.csv");

            var results = await client.SendAsync(request);

            await KLog.ReportAsync(results, reportFile);

            Assert.True(File.Exists(reportFile));
        }
Ejemplo n.º 4
0
        public async Task Send_GetWithHeader_returns_200()
        {
            var headers = new Dictionary <string, string>
            {
                { "Authorization", "Bearer xyz" }
            };
            var request = new KRequest(HttpMethod.Get, new Uri(_uri), headers);
            var client  = new KClient();

            var results = await client.SendAsync(request);

            Assert.True(results.First().Response.StatusCode == HttpStatusCode.OK);
        }
        public void Can_encode_findvalue_request()
        {
            var node    = new KNodeId32(1);
            var buffer  = new ArrayBufferWriter <byte>();
            var encoder = new KJsonMessageEncoder <KNodeId32>();
            var message = new KFindValueRequest <KNodeId32>(node);
            var request = new KRequest <KNodeId32, KFindValueRequest <KNodeId32> >(new KMessageHeader <KNodeId32>(node, 1), message);

            encoder.Encode(new KMessageContext <KNodeId32>("application/json".Yield()), buffer, new KMessageSequence <KNodeId32>(1, new IKMessage <KNodeId32>[] { request }));
            var j = JObject.Parse(Encoding.UTF8.GetString(buffer.WrittenSpan.ToArray()));
            var z = JObject.ReadFrom(new JsonTextReader(new StreamReader(typeof(KJsonMessageEncoderTests).Assembly.GetManifestResourceStream("Alethic.Kademlia.Tests.Json.Samples.findvalue_request.json"))));

            j.Should().BeEquivalentTo(z);
        }
Ejemplo n.º 6
0
        public async Task Send_PostWithByteArrays_returns_201()
        {
            var request = new KRequest(HttpMethod.Post, new Uri(_uri));

            request.SetContent(new List <byte[]>()
            {
                GetTestTextFileAsByteArray(), GetTestTextFileAsByteArray()
            });
            var client = new KClient();

            var results = await client.SendAsync(request);

            Assert.True(results.First().Response.StatusCode == HttpStatusCode.Created);
        }