Ejemplo n.º 1
0
        public async Task GetNotAGUID_Returns_BadRequest()
        {
            using (var client = new TestClientProvider().Client)
            {
                var response = await client.GetAsync($"/api/orders/1");

                Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
            }
        }
Ejemplo n.º 2
0
        public async Task GetUserOrders_Returns_OK()
        {
            using (var client = new TestClientProvider().Client)
            {
                var orderResponse = await client.GetAsync($"/api/orders/user/{_fixture.order.UserId}");

                Assert.Equal(HttpStatusCode.OK, orderResponse.StatusCode);
            }
        }
Ejemplo n.º 3
0
        public async Task GetEmptyGuid_Returns_NOTFOUND()
        {
            using (var client = new TestClientProvider().Client)
            {
                var response = await client.GetAsync($"/api/orders/{Guid.Empty}");

                Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
            }
        }
Ejemplo n.º 4
0
        public async Task GetAll_Returns_OK()
        {
            using (var client = new TestClientProvider().Client)
            {
                var response = await client.GetAsync("/api/orders");

                Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            }
        }
Ejemplo n.º 5
0
        public async Task GetRandomGuid_Returns_NOTFOUND()
        {
            using (var client = new TestClientProvider().Client)
            {
                Guid guid     = Guid.NewGuid();
                var  response = await client.GetAsync($"/api/orders/{guid}");

                Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
            }
        }
Ejemplo n.º 6
0
        public async Task Delete_Order_returns_Id()
        {
            var testOrder = new Order
            {
                Address    = "Testadress",
                City       = "Teststad",
                Email      = "*****@*****.**",
                FirstName  = "Testförnamn",
                LastName   = "Testefternamn",
                OrderDate  = DateTime.Now,
                Phone      = "123",
                ZipCode    = "123",
                Status     = Status.Packas,
                UserId     = Guid.NewGuid().ToString(),
                OrderItems = new List <OrderItem> {
                    new OrderItem {
                        Name = "Testprodukt2", Price = 48.00M, ProductId = Guid.NewGuid(), Quantity = 2
                    }
                }
            };

            using (var client = new TestClientProvider().Client)
            {
                var         payload = JsonConvert.SerializeObject(testOrder);
                HttpContent content = new StringContent(payload, Encoding.UTF8, "application/json");

                //post testorder
                HttpRequestMessage postrequest = new HttpRequestMessage
                {
                    Content    = content,
                    Method     = HttpMethod.Post,
                    RequestUri = new Uri($"https://localhost:44328/api/orders/")
                };
                postrequest.Headers.Authorization = new AuthenticationHeaderValue("Bearer", _fixture.token);
                var postResponse = await client.SendAsync(postrequest);

                var orderResponse = await postResponse.Content.ReadAsStringAsync();

                var order = JsonConvert.DeserializeObject <Order>(orderResponse);
                //delete testorder
                HttpRequestMessage request = new HttpRequestMessage
                {
                    Method     = HttpMethod.Delete,
                    RequestUri = new Uri($"https://localhost:44328/api/orders/{order.Id}")
                };
                request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", _fixture.token);
                var deleteResponse = await client.SendAsync(request);

                var deletedOrderResponse = await deleteResponse.Content.ReadAsStringAsync();

                var deletedOrderId = JsonConvert.DeserializeObject <Guid>(deletedOrderResponse);

                Assert.Equal(order.Id, deletedOrderId);
            }
        }
Ejemplo n.º 7
0
        public async Task Delete_Order_EmptyGuid_returns_NotFound()
        {
            var emptyGuid = Guid.Empty;

            using (var client = new TestClientProvider().Client)
            {
                var deleteresponse = await client.DeleteAsync($"/api/orders/{emptyGuid}");

                Assert.Equal(HttpStatusCode.NotFound, deleteresponse.StatusCode);
            }
        }
Ejemplo n.º 8
0
        public async Task GetUserOrders_Returns_OK()
        {
            using (var client = new TestClientProvider().Client)
            {
                HttpRequestMessage request = new HttpRequestMessage
                {
                    Method     = HttpMethod.Get,
                    RequestUri = new Uri($"https://localhost:44328/api/orders/user/{_fixture.order.UserId}")
                };
                request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", _fixture.token);
                var orderResponse = await client.SendAsync(request);

                Assert.Equal(HttpStatusCode.OK, orderResponse.StatusCode);
            }
        }
Ejemplo n.º 9
0
        public async void Dispose()
        {
            using (var client = new TestClientProvider().Client)
            {
                HttpRequestMessage request = new HttpRequestMessage
                {
                    Method     = HttpMethod.Delete,
                    RequestUri = new Uri("https://localhost:44328/api/orders/" + order.Id)
                };
                request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);
                var deleteResponse = await client.SendAsync(request);

                deleteResponse.EnsureSuccessStatusCode();
            }
        }
Ejemplo n.º 10
0
        public async Task GetEmptyGuid_Returns_NOTFOUND()
        {
            using (var client = new TestClientProvider().Client)
            {
                HttpRequestMessage request = new HttpRequestMessage
                {
                    Method     = HttpMethod.Get,
                    RequestUri = new Uri("https://localhost:44328/api/orders/" + Guid.Empty)
                };
                request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", _fixture.token);
                var response = await client.SendAsync(request);

                Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
            }
        }
Ejemplo n.º 11
0
        public async Task Put_Empty_Order_WithexistingGuid_returns_BadRequest()
        {
            //existing guid
            var guid = _fixture.order.Id;
            //empty order
            var order = new Order();

            using (var client = new TestClientProvider().Client)
            {
                var         payload        = JsonConvert.SerializeObject(order);
                HttpContent content        = new StringContent(payload, Encoding.UTF8, "application/json");
                var         deleteresponse = await client.PutAsync($"/api/orders/{guid}", content);

                Assert.Equal(HttpStatusCode.BadRequest, deleteresponse.StatusCode);
            }
        }
Ejemplo n.º 12
0
        public async Task PutOrder_returns_Status_OK()
        {
            using (var client = new TestClientProvider().Client)
            {
                var order = _fixture.order;
                order.Phone = "123456";

                var         payload = JsonConvert.SerializeObject(order);
                HttpContent content = new StringContent(payload, Encoding.UTF8, "application/json");

                //put order
                var putresponse = await client.PutAsync($"/api/orders/{order.Id}", content);

                Assert.Equal(HttpStatusCode.OK, putresponse.StatusCode);
            }
        }
Ejemplo n.º 13
0
        public async Task Delete_Order_EmptyGuid_returns_NotFound()
        {
            var emptyGuid = Guid.Empty;

            using (var client = new TestClientProvider().Client)
            {
                HttpRequestMessage request = new HttpRequestMessage
                {
                    Method     = HttpMethod.Delete,
                    RequestUri = new Uri($"https://localhost:44328/api/orders/{emptyGuid}")
                };
                request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", _fixture.token);
                var deleteResponse = await client.SendAsync(request);

                Assert.Equal(HttpStatusCode.NotFound, deleteResponse.StatusCode);
            }
        }
Ejemplo n.º 14
0
        public async Task GetOrderById_Returns_Order()
        {
            using (var client = new TestClientProvider().Client)
            {
                var orderResponse = await client.GetAsync($"/api/orders/{_fixture.order.Id}");

                using (var responseStream = await orderResponse.Content.ReadAsStreamAsync())
                {
                    var order = await System.Text.Json.JsonSerializer.DeserializeAsync <Order>(responseStream,
                                                                                               new JsonSerializerOptions()
                    {
                        PropertyNameCaseInsensitive = true
                    });

                    Assert.Equal(_fixture.order.Id, order.Id);
                }
            }
        }
Ejemplo n.º 15
0
        public async Task GetAll_Returns_orderitems()
        {
            using (var client = new TestClientProvider().Client)
            {
                var response = await client.GetAsync("/api/orders");

                var orderResponse = await response.Content.ReadAsStringAsync();

                var orders = JsonConvert.DeserializeObject <IEnumerable <Order> >(orderResponse);

                foreach (var order in orders)
                {
                    foreach (var orderItem in order.OrderItems)
                    {
                        Assert.NotNull(orderItem);
                    }
                }
            }
        }
Ejemplo n.º 16
0
        public async Task Delete_Order_returns_Id()
        {
            var testOrder = new Order
            {
                Address    = "Testadress",
                City       = "Teststad",
                Email      = "*****@*****.**",
                FirstName  = "Testförnamn",
                LastName   = "Testefternamn",
                OrderDate  = DateTime.Now,
                Phone      = "123",
                ZipCode    = "123",
                Status     = Status.Packas,
                UserId     = Guid.NewGuid().ToString(),
                OrderItems = new List <OrderItem> {
                    new OrderItem {
                        Name = "Testprodukt2", Price = 48.00M, ProductId = Guid.NewGuid(), Quantity = 2
                    }
                }
            };

            using (var client = new TestClientProvider().Client)
            {
                var         payload = JsonConvert.SerializeObject(testOrder);
                HttpContent content = new StringContent(payload, Encoding.UTF8, "application/json");

                //post testorder
                var postresponse = await client.PostAsync($"/api/orders/", content);

                var orderResponse = await postresponse.Content.ReadAsStringAsync();

                var order = JsonConvert.DeserializeObject <Order>(orderResponse);
                //delete testorder
                var deleteresponse = await client.DeleteAsync($"/api/orders/{order.Id}");

                var deletedOrderResponse = await deleteresponse.Content.ReadAsStringAsync();

                var deletedOrderId = JsonConvert.DeserializeObject <Guid>(deletedOrderResponse);

                Assert.Equal(order.Id, deletedOrderId);
            }
        }
Ejemplo n.º 17
0
        public async Task PutOrder_returns_updatedOrder()
        {
            using (var client = new TestClientProvider().Client)
            {
                var order = _fixture.order;
                order.Status = Status.Bekräftad;

                var         payload = JsonConvert.SerializeObject(order);
                HttpContent content = new StringContent(payload, Encoding.UTF8, "application/json");

                //put order
                var putresponse = await client.PutAsync($"/api/orders/{order.Id}", content);

                var orderResponse = await putresponse.Content.ReadAsStringAsync();

                var changedOrder = JsonConvert.DeserializeObject <Order>(orderResponse);

                Assert.Equal(order.Status, changedOrder.Status);
            }
        }
Ejemplo n.º 18
0
        private async Task <Order> Initialize()
        {
            using (var client = new TestClientProvider().Client)
            {
                var testOrder = new Order
                {
                    Address    = "Testadress",
                    City       = "Teststad",
                    Email      = "*****@*****.**",
                    FirstName  = "Testförnamn",
                    LastName   = "Testefternamn",
                    OrderDate  = DateTime.Now,
                    Phone      = "000011111",
                    ZipCode    = "29281",
                    Status     = Status.Beställd,
                    UserId     = Guid.NewGuid().ToString(),
                    OrderItems = new List <OrderItem> {
                        new OrderItem {
                            Name = "Testprodukt", Price = 98.00M, ProductId = Guid.NewGuid(), Quantity = 3
                        }
                    }
                };
                var payload = new StringContent(JsonConvert.SerializeObject(testOrder), Encoding.UTF8, "application/json");
                HttpRequestMessage request = new HttpRequestMessage
                {
                    Content    = payload,
                    Method     = HttpMethod.Post,
                    RequestUri = new Uri("https://localhost:44328/api/orders/")
                };
                request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);

                var response = await client.SendAsync(request);

                var responseOrder = await response.Content.ReadAsStringAsync();

                var createdProduct = JsonConvert.DeserializeObject <Order>(responseOrder);
                return(createdProduct);
            }
        }
Ejemplo n.º 19
0
        public async Task GetAll_Returns_orderitems()
        {
            using (var client = new TestClientProvider().Client)
            {
                HttpRequestMessage request = new HttpRequestMessage
                {
                    Method     = HttpMethod.Get,
                    RequestUri = new Uri("https://localhost:44328/api/orders/")
                };
                request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", _fixture.token);
                var response      = client.SendAsync(request);
                var orderResponse = await response.Result.Content.ReadAsStringAsync();

                var orders = JsonConvert.DeserializeObject <IEnumerable <Order> >(orderResponse);

                foreach (var order in orders)
                {
                    foreach (var orderItem in order.OrderItems)
                    {
                        Assert.NotNull(orderItem);
                    }
                }
            }
        }
Ejemplo n.º 20
0
        public async Task Put_Empty_Order_WithexistingGuid_returns_BadRequest()
        {
            //existing guid
            var guid = _fixture.order.Id;
            //empty order
            var order = new Order();

            using (var client = new TestClientProvider().Client)
            {
                var                payload = JsonConvert.SerializeObject(order);
                HttpContent        content = new StringContent(payload, Encoding.UTF8, "application/json");
                HttpRequestMessage request = new HttpRequestMessage
                {
                    Content    = content,
                    Method     = HttpMethod.Put,
                    RequestUri = new Uri($"https://localhost:44328/api/orders/{_fixture.order.Id}")
                };
                request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", _fixture.token);
                var putResponse = await client.SendAsync(request);


                Assert.Equal(HttpStatusCode.BadRequest, putResponse.StatusCode);
            }
        }
Ejemplo n.º 21
0
        public async Task GetOrderById_Returns_Order()
        {
            using (var client = new TestClientProvider().Client)
            {
                HttpRequestMessage request = new HttpRequestMessage
                {
                    Method     = HttpMethod.Get,
                    RequestUri = new Uri($"https://localhost:44328/api/orders/{_fixture.order.Id}")
                };
                request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", _fixture.token);
                var orderResponse = await client.SendAsync(request);

                using (var responseStream = await orderResponse.Content.ReadAsStreamAsync())
                {
                    var order = await System.Text.Json.JsonSerializer.DeserializeAsync <Order>(responseStream,
                                                                                               new JsonSerializerOptions()
                    {
                        PropertyNameCaseInsensitive = true
                    });

                    Assert.Equal(_fixture.order.Id, order.Id);
                }
            }
        }
Ejemplo n.º 22
0
        public async Task PutOrder_returns_Status_OK()
        {
            using (var client = new TestClientProvider().Client)
            {
                var order = _fixture.order;
                order.Phone = "123456";

                var         payload = JsonConvert.SerializeObject(order);
                HttpContent content = new StringContent(payload, Encoding.UTF8, "application/json");

                //put order
                HttpRequestMessage request = new HttpRequestMessage
                {
                    Content    = content,
                    Method     = HttpMethod.Put,
                    RequestUri = new Uri($"https://localhost:44328/api/orders/{_fixture.order.Id}")
                };
                request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", _fixture.token);
                var putResponse = await client.SendAsync(request);


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