Esempio n. 1
0
        public async Task Orders_CreateForExistingProductWithChoasEnabled_ShouldReturnHttpInternalServerError()
        {
            // Arrange
            const string ordersUrl            = "api/v1/order";
            const string customerFirstName    = "Tom";
            const string customerLastName     = "Kerkhove";
            var          selloService         = new SelloService(unleashChaosMonkeys: true);
            var          customerEmailAddress = $"{Guid.NewGuid().ToString()}@codit.eu";
            var          productToBuy         = await GetProductFromCatalogAsync();

            var customer = new CustomerContract
            {
                FirstName    = customerFirstName,
                LastName     = customerLastName,
                EmailAddress = customerEmailAddress
            };
            var order = new OrderContract
            {
                Customer = customer,
                Product  = productToBuy
            };

            // Act
            var response = await selloService.PostResponseAsync(ordersUrl, order);

            // Assert
            Assert.AreEqual(HttpStatusCode.InternalServerError, response.StatusCode);
        }
Esempio n. 2
0
        public async Task Orders_CreateWithoutProduct_ShouldReturnHttpBadRequest()
        {
            // Arrange
            const string ordersUrl            = "api/v1/order";
            const string customerFirstName    = "Tom";
            const string customerLastName     = "Kerkhove";
            const string customerEmailAddress = "*****@*****.**";
            var          selloService         = new SelloService();

            var customer = new CustomerContract
            {
                FirstName    = customerFirstName,
                LastName     = customerLastName,
                EmailAddress = customerEmailAddress
            };
            var order = new OrderContract
            {
                Customer = customer,
                Product  = null
            };

            // Act
            var response = await selloService.PostResponseAsync(ordersUrl, order);

            // Assert
            Assert.NotNull(response);
            Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode);
        }
Esempio n. 3
0
        public async Task Orders_CreateForExistingProductWithoutCustomer_ShouldReturnHttpBadRequest()
        {
            // Arrange
            const string ordersUrl    = "api/v1/order";
            var          selloService = new SelloService();
            var          productToBuy = await GetProductFromCatalogAsync();

            var order = new OrderContract
            {
                Customer = null,
                Product  = productToBuy
            };

            // Act
            var response = await selloService.PostResponseAsync(ordersUrl, order);

            // Assert
            Assert.NotNull(response);
            Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
            Assert.NotNull(response.Content);
            var rawResponse = await response.Content.ReadAsStringAsync();

            var validationMessages = JsonConvert.DeserializeObject <List <string> >(rawResponse);

            Assert.IsTrue(validationMessages.Any(
                              validationMessage => validationMessage == ValidationMessages.Customer_IsRequired));
        }
Esempio n. 4
0
        public async Task Products_GetProductDetailsForExistingProduct_ShouldReturnHttpOk()
        {
            // Arrange
            var selloService   = new SelloService();
            var productService = new ProductService();
            var products       = await productService.GetAllAsync();

            Assert.NotNull(products);
            Assert.IsNotEmpty(products);
            var firstProduct = products.First();

            // Act
            var response = await selloService.GetResponseAsync($"{ProductService.BaseUrl}/{firstProduct.Id}");

            // Assert
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            var rawContent = await response.Content.ReadAsStringAsync();

            var productInformation = JsonConvert.DeserializeObject <ProductInformationContract>(rawContent);

            Assert.AreEqual(firstProduct.Id, productInformation.Id);
            Assert.AreEqual(firstProduct.Name, productInformation.Name);
            Assert.AreEqual(firstProduct.Description, productInformation.Description);
            Assert.AreEqual(firstProduct.Price, productInformation.Price);
        }
Esempio n. 5
0
        public async Task Health_ApiIsUnhealthyBecauseOfMonkeys_ShouldReturnHttpInternalServerError()
        {
            // Arrange
            const string healthUri    = "api/v1/health";
            var          selloService = new SelloService(unleashChaosMonkeys: true);

            // Act
            var response = await selloService.GetResponseAsync(healthUri);

            // Assert
            Assert.AreEqual(HttpStatusCode.InternalServerError, response.StatusCode);
        }
Esempio n. 6
0
        public async Task Health_ApiShouldBeHealthy_ShouldReturnHttpOk()
        {
            // Arrange
            const string healthUri    = "api/v1/health";
            var          selloService = new SelloService();

            // Act
            var response = await selloService.GetResponseAsync(healthUri);

            // Assert
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
        }
Esempio n. 7
0
        public async Task Products_ListAllProductsWithChaosEnabled_ShouldReturnHttpOk()
        {
            // Arrange
            const string productsUrl  = ProductService.BaseUrl;
            var          selloService = new SelloService(unleashChaosMonkeys: true);

            // Act
            var response = await selloService.GetResponseAsync(productsUrl);

            // Assert
            Assert.AreEqual(HttpStatusCode.InternalServerError, response.StatusCode);
        }
Esempio n. 8
0
        public async Task Products_GetProductDetailsForNotExistingProduct_ShouldReturnHttpNotFound()
        {
            // Arrange
            const string productId    = "I-DO-NOT-EXIST";
            var          selloService = new SelloService();

            // Act
            var response = await selloService.GetResponseAsync($"{ProductService.BaseUrl}/{productId}");

            // Assert
            Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode);
        }
Esempio n. 9
0
        public async Task Products_GetProductDetailsForExistingProductWithChaosEnabled_ShouldReturnHttpInternalServerError()
        {
            // Arrange
            var selloService   = new SelloService(unleashChaosMonkeys: true);
            var productService = new ProductService();
            var products       = await productService.GetAllAsync();

            Assert.NotNull(products);
            Assert.IsNotEmpty(products);
            var firstProduct = products.First();

            // Act
            var response = await selloService.GetResponseAsync($"{ProductService.BaseUrl}/{firstProduct.Id}");

            // Assert
            Assert.AreEqual(HttpStatusCode.InternalServerError, response.StatusCode);
        }
Esempio n. 10
0
        public async Task Products_ListAllProducts_ShouldReturnHttpOk()
        {
            // Arrange
            const string productsUrl  = ProductService.BaseUrl;
            var          selloService = new SelloService();

            // Act
            var response = await selloService.GetResponseAsync(productsUrl);

            // Assert
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            var rawContent = await response.Content.ReadAsStringAsync();

            var products = JsonConvert.DeserializeObject <List <ProductInformationContract> >(rawContent);

            Assert.NotNull(products);
        }
Esempio n. 11
0
        public async Task Orders_CreateForExistingProduct_ShouldReturnHttpOk()
        {
            // Arrange
            const string ordersUrl            = "api/v1/order";
            const string customerFirstName    = "Tom";
            const string customerLastName     = "Kerkhove";
            var          selloService         = new SelloService();
            var          customerEmailAddress = $"{Guid.NewGuid().ToString()}@codit.eu";
            var          productToBuy         = await GetProductFromCatalogAsync();

            var customer = new CustomerContract
            {
                FirstName    = customerFirstName,
                LastName     = customerLastName,
                EmailAddress = customerEmailAddress
            };
            var order = new OrderContract
            {
                Customer = customer,
                Product  = productToBuy
            };

            // Act
            var response = await selloService.PostResponseAsync(ordersUrl, order);

            // Assert
            Assert.AreEqual(HttpStatusCode.Created, response.StatusCode);
            var rawContent = await response.Content.ReadAsStringAsync();

            var orderConfirmation = JsonConvert.DeserializeObject <OrderConfirmationContract>(rawContent);

            Assert.NotNull(orderConfirmation);
            Assert.NotNull(orderConfirmation.ConfirmationId);
            Assert.IsNotEmpty(orderConfirmation.ConfirmationId);
            Assert.NotNull(orderConfirmation.Order);
            Assert.NotNull(orderConfirmation.Order.Product);
            Assert.AreEqual(productToBuy.Id, orderConfirmation.Order.Product.Id);
            Assert.AreEqual(productToBuy.Name, orderConfirmation.Order.Product.Name);
            Assert.AreEqual(productToBuy.Description, orderConfirmation.Order.Product.Description);
            Assert.AreEqual(productToBuy.Price, orderConfirmation.Order.Product.Price);
            Assert.NotNull(orderConfirmation.Order.Customer);
            Assert.AreEqual(customerFirstName, orderConfirmation.Order.Customer.FirstName);
            Assert.AreEqual(customerLastName, orderConfirmation.Order.Customer.LastName);
            Assert.AreEqual(customerEmailAddress, orderConfirmation.Order.Customer.EmailAddress);
        }
Esempio n. 12
0
        public async Task Orders_CreateForExistingProductWithChangedDescription_ShouldReturnHttpBadRequest()
        {
            // Arrange
            const string ordersUrl            = "api/v1/order";
            const string customerFirstName    = "Tom";
            const string customerLastName     = "Kerkhove";
            const string customerEmailAddress = "*****@*****.**";
            var          selloService         = new SelloService();
            var          productToBuy         = await GetProductFromCatalogAsync();

            productToBuy.Description = "Altered description";

            var customer = new CustomerContract
            {
                FirstName    = customerFirstName,
                LastName     = customerLastName,
                EmailAddress = customerEmailAddress
            };
            var order = new OrderContract
            {
                Customer = customer,
                Product  = productToBuy
            };

            // Act
            var response = await selloService.PostResponseAsync(ordersUrl, order);

            // Assert
            Assert.NotNull(response);
            Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
            Assert.NotNull(response.Content);
            var rawResponse = await response.Content.ReadAsStringAsync();

            var validationMessages = JsonConvert.DeserializeObject <List <string> >(rawResponse);

            Assert.IsTrue(validationMessages.Any(
                              validationMessage => validationMessage == ValidationMessages.Product_DescriptionIsNotCorrect));
        }
Esempio n. 13
0
        public async Task Orders_CreateForNotExistingProduct_ShouldReturnHttpNotFound()
        {
            // Arrange
            const string ordersUrl            = "api/v1/order";
            const string productId            = "I-DO-NOT-EXIST";
            const string productName          = "Validation Product";
            const string productDescription   = "Product created by Integration Test, however it should never make it in";
            const double productPrice         = 100;
            const string customerFirstName    = "Tom";
            const string customerLastName     = "Tom";
            const string customerEmailAddress = "*****@*****.**";
            var          selloService         = new SelloService();

            var customer = new CustomerContract
            {
                FirstName    = customerFirstName,
                LastName     = customerLastName,
                EmailAddress = customerEmailAddress
            };
            var product = new ProductInformationContract
            {
                Id          = productId,
                Name        = productName,
                Description = productDescription,
                Price       = productPrice
            };
            var order = new OrderContract
            {
                Customer = customer,
                Product  = product
            };

            // Act
            var response = await selloService.PostResponseAsync(ordersUrl, order);

            // Assert
            Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode);
        }
Esempio n. 14
0
        public async Task Products_AddNewProductToCatalogWithChaosEnabled_ShouldReturnHttpInternalServerError()
        {
            // Arrange
            const string productsUrl        = ProductService.BaseUrl;
            var          selloService       = new SelloService(unleashChaosMonkeys: true);
            var          integrationTestId  = Guid.NewGuid().ToString();
            var          productName        = $"Integration Product ({integrationTestId})";
            var          productDescription = $"Product created by Integration Test - {integrationTestId}";
            const double productPrice       = 100;

            var newProduct = new NewProductContract
            {
                Name        = productName,
                Description = productDescription,
                Price       = productPrice
            };

            // Act
            var response = await selloService.PostResponseAsync(productsUrl, newProduct);

            // Assert
            Assert.AreEqual(HttpStatusCode.InternalServerError, response.StatusCode);
        }