Ejemplo n.º 1
0
        //[Fact]
        public async Task Should_Return_OK_When_DeleteAsync()
        {
            HttpClientFactory client = new HttpClientFactory(MockStartup <Startup> .Instance.GetCliente());
            await client.AddAuthorizationAsync();

            var entity = new OrderDTO()
            {
                Date         = DateTime.Now,
                ExchangeId   = Guid.NewGuid(),
                BaseAssetId  = Guid.NewGuid(),
                QuoteAssetId = Guid.NewGuid(),
                OrderItems   = new List <OrderItemDTO>()
                {
                    new OrderItemDTO()
                    {
                        Price      = 1,
                        Quantity   = 1,
                        Fee        = 1,
                        FeeAssetId = Guid.NewGuid()
                    }
                }
            };
            var result = await client.PostAsync(ROUTE_PATH, entity);

            Assert.Equal(HttpStatusCode.OK, result.StatusCode);
            entity = JsonConvert.DeserializeObject <OrderDTO>(await result.Content.ReadAsStringAsync());
            result = await client.DeleteAsync($"{ROUTE_PATH}/{entity.Id}");

            Assert.Equal(HttpStatusCode.OK, result.StatusCode);
        }
Ejemplo n.º 2
0
        //[Fact]
        public async Task Should_Return_NotFound_When_Not_Exist_In_DeleteAsync()
        {
            HttpClientFactory client = new HttpClientFactory(MockStartup <Startup> .Instance.GetCliente());
            await client.AddAuthorizationAsync();

            var id     = new Guid();
            var result = await client.DeleteAsync($"{ROUTE_PATH}/{id}");

            Assert.Equal(HttpStatusCode.NotFound, result.StatusCode);
        }
Ejemplo n.º 3
0
        public async Task TestDeleteAsync()
        {
            // Setup
            var logger      = Log.Logger;
            var eventBridge = new EventBridge();
            var factory     = new HttpTunnelHandlerFactory(eventBridge, _serializer, null, logger);
            var client      = new HttpClientFactory(factory, logger).CreateClient("msft");

            var adapter     = new MethodHandlerAdapter(factory.YieldReturn());
            var chunkServer = new TestChunkServer(_serializer, 128 * 1024, (method, buffer, type) => {
                Assert.Equal(MethodNames.Response, method);
                return(adapter.InvokeAsync(method, buffer, type).Result);
            });

            var uri     = new Uri("https://test/test/test?test=test");
            var rand    = new Random();
            var fix     = new Fixture();
            var request = Mock.Of <IHttpRequest>(r =>
                                                 r.Uri == uri);
            var response = Mock.Of <IHttpResponse>(r =>
                                                   r.Content == null &&
                                                   r.StatusCode == System.Net.HttpStatusCode.OK);
            var httpclientMock = Mock.Of <IHttpClient>();

            Mock.Get(httpclientMock)
            .Setup(m => m.DeleteAsync(It.IsAny <IHttpRequest>(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(response));
            Mock.Get(httpclientMock)
            .Setup(m => m.NewRequest(It.Is <Uri>(u => u == uri), It.IsAny <string>()))
            .Returns(request);

            var server = new HttpTunnelServer(httpclientMock, chunkServer.CreateClient(), _serializer, logger);

            eventBridge.Handler = server;

            // Act

            var result = await client.DeleteAsync(uri);

            // Assert

            Assert.NotNull(result);
            Assert.Equal(System.Net.HttpStatusCode.OK, result.StatusCode);
            Assert.Null(result.Content);
            Assert.NotNull(result.Headers);
            Assert.Empty(result.Headers);
        }
Ejemplo n.º 4
0
        //[Fact]
        public async Task Should_Return_OK_When_DeleteAsync()
        {
            HttpClientFactory client = new HttpClientFactory(MockStartup <Startup> .Instance.GetCliente());
            await client.AddAuthorizationAsync();

            var entity = new AssetDTO()
            {
                Name        = "Teste",
                Description = "teste",
                Symbol      = "T"
            };
            var result = await client.PostAsync(ROUTE_PATH, entity);

            Assert.Equal(HttpStatusCode.OK, result.StatusCode);
            entity = JsonConvert.DeserializeObject <AssetDTO>(await result.Content.ReadAsStringAsync());
            result = await client.DeleteAsync($"{ROUTE_PATH}/{entity.Id}");

            Assert.Equal(HttpStatusCode.OK, result.StatusCode);
        }