Exemplo n.º 1
0
        public async Task ListProducts_Valid_OK()
        {
            var listRequest = new ListProductRequest {
            };

            var actual = await Fixture.Api.Products.ListProductsAsync(listRequest);

            Assert.Equal(HttpStatusCode.OK, actual.StatusCode);

            var actualContent = actual.Data;

            Assert.Equal(2, actualContent.Records.Count);

            var expectedFirst = _productRecords[0];
            var actualFirst   = actualContent.Records[0];

            AssertUtilities.NotEmpty(actualFirst.Id);
            Assert.Equal($"{expectedFirst.ProductCode} - {expectedFirst.ProductName}", actualFirst.Name);

            var expectedSecond = _productRecords[1];
            var actualSecond   = actualContent.Records[1];

            AssertUtilities.NotEmpty(actualSecond.Id);
            Assert.Equal($"{expectedSecond.ProductCode} - {expectedSecond.ProductName}", actualSecond.Name);
        }
Exemplo n.º 2
0
        public async Task CreateCustomer_Valid_Created()
        {
            var createRequest = new CreateCustomerRequest
            {
                FirstName = "First name 1",
                LastName  = "Last name 1",
            };

            var createResponse = await Fixture.Api.Customers.CreateCustomerAsync(createRequest);

            Assert.Equal(HttpStatusCode.Created, createResponse.StatusCode);

            var createResponseContent = createResponse.Data;

            AssertUtilities.NotEmpty(createResponseContent.Id);

            Assert.Equal(createRequest.FirstName, createResponseContent.FirstName);
            Assert.Equal(createRequest.LastName, createResponseContent.LastName);

            var findRequest = new FindCustomerRequest {
                Id = createResponseContent.Id
            };

            var findResponse = await Fixture.Api.Customers.FindCustomerAsync(findRequest);

            Assert.Equal(HttpStatusCode.OK, findResponse.StatusCode);

            var findResponseContent = findResponse.Data;

            Assert.Equal(createResponseContent.Id, findResponseContent.Id);
            Assert.Equal(createRequest.FirstName, findResponseContent.FirstName);
            Assert.Equal(createRequest.LastName, findResponseContent.LastName);
        }
Exemplo n.º 3
0
        public async Task ListCustomers_OK()
        {
            var listRequest = new ListCustomersRequest {
            };

            var actual = await Fixture.Api.Customers.ListCustomersAsync(listRequest);

            Assert.Equal(HttpStatusCode.OK, actual.StatusCode);

            var actualContent = actual.Data;

            Assert.Equal(2, actualContent.Records.Count);

            var expectedFirst = _customerRecords[0];
            var actualFirst   = actualContent.Records[0];

            AssertUtilities.NotEmpty(actualFirst.Id);
            Assert.Equal(expectedFirst.FirstName + " " + expectedFirst.LastName, actualFirst.Name);

            var expectedSecond = _customerRecords[1];
            var actualSecond   = actualContent.Records[1];

            AssertUtilities.NotEmpty(actualSecond.Id);
            Assert.Equal(expectedSecond.FirstName + " " + expectedSecond.LastName, actualSecond.Name);
        }
Exemplo n.º 4
0
        public async Task RelistProduct_ValidRequest_ReturnsResponse()
        {
            var record = _productRecords.Where(e => !e.IsListed).First();
            var id     = record.Id;

            var activateRequest = new RelistProductRequest
            {
                Id = id,
            };

            var activateResponse = await Fixture.Products.RelistProductAsync(activateRequest);

            AssertUtilities.NotEmpty(activateResponse.Id);
            Assert.Equal(record.Id, activateResponse.Id);
            Assert.Equal(record.ProductCode, activateResponse.Code);
            Assert.Equal(record.ProductName, activateResponse.Description);
            Assert.Equal(record.ListPrice, activateResponse.UnitPrice);
            Assert.True(activateResponse.IsListed);

            var findRequest = new FindProductRequest {
                Id = activateResponse.Id
            };

            var findResponse = await Fixture.Products.FindProductAsync(findRequest);

            Assert.Equal(activateResponse.Id, findResponse.Id);
            Assert.Equal(activateResponse.Code, findResponse.Code);
            Assert.Equal(activateResponse.Description, findResponse.Description);
            Assert.Equal(activateResponse.UnitPrice, findResponse.UnitPrice);
            Assert.Equal(activateResponse.IsListed, findResponse.IsListed);
        }
Exemplo n.º 5
0
        public async Task UnlistProduct_ValidRequest_ReturnsResponse()
        {
            var record = _productRecords.Where(e => e.IsListed).First();
            var id     = record.Id;

            var dectivateRequest = new UnlistProductRequest
            {
                Id = id,
            };

            var deactivateResponse = await Fixture.Products.UnlistProductAsync(dectivateRequest);

            AssertUtilities.NotEmpty(deactivateResponse.Id);
            Assert.Equal(record.Id, deactivateResponse.Id);
            Assert.Equal(record.ProductCode, deactivateResponse.Code);
            Assert.Equal(record.ProductName, deactivateResponse.Description);
            Assert.Equal(record.ListPrice, deactivateResponse.UnitPrice);
            Assert.False(deactivateResponse.IsActive);

            var findRequest = new FindProductRequest {
                Id = deactivateResponse.Id
            };

            var findResponse = await Fixture.Products.FindProductAsync(findRequest);

            Assert.Equal(deactivateResponse.Id, findResponse.Id);
            Assert.Equal(deactivateResponse.Code, findResponse.Code);
            Assert.Equal(deactivateResponse.Description, findResponse.Description);
            Assert.Equal(deactivateResponse.UnitPrice, findResponse.UnitPrice);
            Assert.Equal(deactivateResponse.IsActive, findResponse.IsListed);
        }
Exemplo n.º 6
0
        public async Task CreateProduct_ValidRequest_ReturnsResponse()
        {
            var createRequest = new CreateProductRequest
            {
                Code        = "ABC",
                Description = "My desc",
                UnitPrice   = 123.56m,
            };

            var createResponse = await Fixture.Products.CreateProductAsync(createRequest);

            AssertUtilities.NotEmpty(createResponse.Id);
            Assert.Equal(createRequest.Code, createResponse.Code);
            Assert.Equal(createRequest.Description, createResponse.Description);
            Assert.Equal(createRequest.UnitPrice, createResponse.UnitPrice);
            Assert.True(createResponse.IsListed);

            var findRequest = new FindProductRequest {
                Id = createResponse.Id
            };

            var findResponse = await Fixture.Products.FindProductAsync(findRequest);

            Assert.Equal(findRequest.Id, findResponse.Id);
            Assert.Equal(createRequest.Code, findResponse.Code);
            Assert.Equal(createRequest.Description, findResponse.Description);
            Assert.Equal(createRequest.UnitPrice, findResponse.UnitPrice);
            Assert.True(findResponse.IsListed);
        }
Exemplo n.º 7
0
        public async Task CreateCustomer_ValidRequest_ReturnsResponse()
        {
            var createRequest = new CreateCustomerRequest
            {
                FirstName = "First name 1",
                LastName  = "Last name 1",
            };

            var createResponse = await Fixture.Customers.CreateCustomerAsync(createRequest);

            AssertUtilities.NotEmpty(createResponse.Id);
            Assert.Equal(createRequest.FirstName, createResponse.FirstName);
            Assert.Equal(createRequest.LastName, createResponse.LastName);

            var findRequest = new FindCustomerRequest {
                Id = createResponse.Id
            };

            var findResponse = await Fixture.Customers.FindCustomerAsync(findRequest);

            Assert.Equal(findRequest.Id, findResponse.Id);
            Assert.Equal(createRequest.FirstName, findResponse.FirstName);
            Assert.Equal(createRequest.LastName, findResponse.LastName);
        }
Exemplo n.º 8
0
        public async Task CreateProduct_Valid_Created()
        {
            var createRequest = new CreateProductRequest
            {
                Code        = "My code 1",
                Description = "My name 1",
                UnitPrice   = 100.56m,
            };

            var createResponse = await Fixture.Api.Products.CreateProductAsync(createRequest);

            Assert.Equal(HttpStatusCode.Created, createResponse.StatusCode);

            var createResponseContent = createResponse.Data;

            AssertUtilities.NotEmpty(createResponseContent.Id);

            Assert.Equal(createRequest.Code, createResponseContent.Code);
            Assert.Equal(createRequest.Description, createResponseContent.Description);
            Assert.Equal(createRequest.UnitPrice, createResponseContent.UnitPrice);

            var findRequest = new FindProductRequest {
                Id = createResponseContent.Id
            };

            var findResponse = await Fixture.Api.Products.FindProductAsync(findRequest);

            Assert.Equal(HttpStatusCode.OK, findResponse.StatusCode);

            var findResponseContent = findResponse.Data;

            Assert.Equal(createResponseContent.Id, findResponseContent.Id);
            Assert.Equal(createRequest.Code, findResponseContent.Code);
            Assert.Equal(createRequest.Description, findResponseContent.Description);
            Assert.Equal(createRequest.UnitPrice, findResponseContent.UnitPrice);
        }
Exemplo n.º 9
0
        public async Task UpdateOrder_ValidRequest_ReturnsResponse()
        {
            var product1Record = _productRecords[2];
            var product2Record = _productRecords[3];

            var orderRecord = _orderRecords[1];

            var orderStatusId = orderRecord.OrderStatusId;

            var updateRequest = new UpdateOrderRequest
            {
                Id         = orderRecord.Id,
                OrderItems = new List <UpdateOrderItemRequest>
                {
                    new UpdateOrderItemRequest
                    {
                        Id        = orderRecord.OrderItems.ElementAt(0).Id,
                        ProductId = product1Record.Id,
                        Quantity  = 72,
                    },

                    new UpdateOrderItemRequest
                    {
                        Id        = null,
                        ProductId = product2Record.Id,
                        Quantity  = 84,
                    }
                },
            };

            var updateResponse = await Fixture.Orders.UpdateOrderAsync(updateRequest);

            Assert.Equal(updateRequest.Id, updateResponse.Id);
            Assert.Equal(orderRecord.CustomerId, updateResponse.CustomerId);
            Assert.Equal((OrderStatus)orderStatusId, updateResponse.Status);

            Assert.NotNull(updateResponse.OrderItems);

            Assert.Equal(updateRequest.OrderItems.Count, updateResponse.OrderItems.Count);

            for (int i = 0; i < updateRequest.OrderItems.Count; i++)
            {
                var updateRequestOrderDetail  = updateRequest.OrderItems[i];
                var updateResponseOrderDetail = updateResponse.OrderItems[i];

                if (updateRequestOrderDetail.Id != null)
                {
                    Assert.Equal(updateRequestOrderDetail.Id, updateResponseOrderDetail.Id);
                }
                else
                {
                    AssertUtilities.NotEmpty(updateResponseOrderDetail.Id);
                }

                Assert.Equal(updateRequestOrderDetail.ProductId, updateResponseOrderDetail.ProductId);
                Assert.Equal(updateRequestOrderDetail.Quantity, updateResponseOrderDetail.Quantity);
                Assert.Equal(OrderItemStatus.Allocated, updateResponseOrderDetail.Status);
            }

            var findRequest = new FindOrderRequest {
                Id = updateResponse.Id
            };

            var findResponse = await Fixture.Orders.FindOrderAsync(findRequest);

            Assert.Equal(updateResponse.Id, findResponse.Id);
            Assert.Equal(updateResponse.CustomerId, updateResponse.CustomerId);
            Assert.Equal(updateResponse.Status, updateResponse.Status);

            Assert.NotNull(findResponse.OrderItems);

            Assert.Equal(updateResponse.OrderItems.Count, findResponse.OrderItems.Count);

            // TODO: VC: Do this later when use sequential guids

            /*
             * for (int i = 0; i < updateResponse.OrderItems.Count; i++)
             * {
             *  var updateResponseOrderDetail = updateResponse.OrderItems[i];
             *  var findResponseOrderDetail = findResponse.OrderItems[i];
             *
             *  Assert.Equal(updateResponseOrderDetail.Id, findResponseOrderDetail.Id);
             *  Assert.Equal(updateResponseOrderDetail.ProductId, findResponseOrderDetail.ProductId);
             *  Assert.Equal(updateResponseOrderDetail.Quantity, findResponseOrderDetail.Quantity);
             *  Assert.Equal(updateResponseOrderDetail.StatusId, findResponseOrderDetail.StatusId);
             * }
             */
        }
Exemplo n.º 10
0
        public async Task CreateOrder_ValidRequest_ReturnsResponse()
        {
            var customerRecord = _customerRecords[0];

            var product1Record = _productRecords[0];
            var product2Record = _productRecords[1];

            var createRequest = new CreateOrderRequest
            {
                CustomerId = customerRecord.Id,
                OrderItems = new List <CreateOrderItemRequest>
                {
                    new CreateOrderItemRequest
                    {
                        ProductId = product1Record.Id,
                        Quantity  = 10,
                    },

                    new CreateOrderItemRequest
                    {
                        ProductId = product2Record.Id,
                        Quantity  = 20,
                    }
                },
            };

            var createResponse = await Fixture.Orders.CreateOrderAsync(createRequest);

            AssertUtilities.NotEmpty(createResponse.Id);
            Assert.Equal(createRequest.CustomerId, createResponse.CustomerId);
            Assert.Equal(OrderStatus.New, createResponse.Status);

            Assert.NotNull(createResponse.OrderItems);

            Assert.Equal(createRequest.OrderItems.Count, createResponse.OrderItems.Count);

            for (int i = 0; i < createRequest.OrderItems.Count; i++)
            {
                var createRequestOrderDetail  = createRequest.OrderItems[i];
                var createResponseOrderDetail = createResponse.OrderItems[i];

                AssertUtilities.NotEmpty(createResponseOrderDetail.Id);
                Assert.Equal(createRequestOrderDetail.ProductId, createResponseOrderDetail.ProductId);
                Assert.Equal(createRequestOrderDetail.Quantity, createResponseOrderDetail.Quantity);
                Assert.Equal(OrderItemStatus.Allocated, createResponseOrderDetail.Status);
            }

            var findRequest = new FindOrderRequest {
                Id = createResponse.Id
            };

            var findResponse = await Fixture.Orders.FindOrderAsync(findRequest);

            Assert.Equal(createResponse.Id, findResponse.Id);
            Assert.Equal(createResponse.CustomerId, createResponse.CustomerId);
            Assert.Equal(createResponse.Status, createResponse.Status);

            Assert.NotNull(findResponse.OrderItems);

            // TODO: VC: Check sequence

            /*
             * Assert.Equal(createResponse.OrderItems.Count, findResponse.OrderItems.Count);
             *
             * for (int i = 0; i < createResponse.OrderItems.Count; i++)
             * {
             *  var createResponseOrderDetail = createResponse.OrderItems[i];
             *  var findResponseOrderDetail = findResponse.OrderItems[i];
             *
             *
             *  Assert.Equal(createResponseOrderDetail.Id, findResponseOrderDetail.Id);
             *  Assert.Equal(createResponseOrderDetail.ProductId, findResponseOrderDetail.ProductId);
             *  Assert.Equal(createResponseOrderDetail.Quantity, findResponseOrderDetail.Quantity);
             *  Assert.Equal(createResponseOrderDetail.StatusId, findResponseOrderDetail.StatusId);
             * }
             */
        }