Пример #1
0
        public async Task Delete_CorrectID_SuccessStatusCode()
        {
            //Setup
            Element element = InvoiceTest.GetElementSeed();

            //Act
            var response = await _internalClient.PostAsJsonAsync("Item/Delete", element.Item.ID);

            //Assert
            Assert.IsTrue(response.IsSuccessStatusCode, "Server responded with Success code");
        }
Пример #2
0
        public async Task Create_ExistingProductGroupObject_BadRequestStatusCode()
        {
            //Setup
            ProductGroup productGroup = InvoiceTest.GetElementSeed().Item.Product.ProductGroup;

            //Act
            var response = await _internalClient.PostAsJsonAsync("ProductGroup/Create", productGroup);

            //Assert
            Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode, "Server responded with bad request code");//check if internal server error
        }
Пример #3
0
        public async Task CreateOrUpdate_ExistingItemObject_SuccessStatusCode()
        {
            //Setup
            Element element = InvoiceTest.GetElementSeed();
            Item    item    = element.Item;

            //Act
            var response = await _internalClient.PostAsJsonAsync("Item/CreateOrUpdate", item);

            //Assert
            Assert.IsTrue(response.IsSuccessStatusCode, "Server responded with Success code");
        }
Пример #4
0
        public async Task GetTaxGroups_MethodCalled_SuccessStatusCodeAndTaxGroupsReturned()
        {
            //Setup
            InvoiceTest.GetElementSeed();

            //Act
            var response = await _internalClient.GetAsync("TaxGroup/GetTaxGroups");

            List <TaxGroup> taxGroups = JsonConvert.DeserializeObject <List <TaxGroup> >(await response.Content.ReadAsStringAsync());

            //Assert
            Assert.IsTrue(response.IsSuccessStatusCode, "Server responded with Success code");
            Assert.AreNotEqual(0, taxGroups.Count, "Tax groups received");
        }
Пример #5
0
        public async Task Create_ExistingProductGroupObject_IsSuccessStatusCodeAndResponseFalse()
        {
            //Setup
            ProductGroup productGroup = InvoiceTest.GetElementSeed().Item.Product.ProductGroup;

            //Act
            var response = await _client.PostAsJsonAsync("ProductGroup/Create", productGroup);

            var deserializedResponse = JsonConvert.DeserializeObject <bool>(await response.Content.ReadAsStringAsync());

            //Assert
            Assert.IsTrue(response.IsSuccessStatusCode);
            Assert.IsFalse(deserializedResponse);
        }
Пример #6
0
        public async Task GetProductGroups_MethodCalled_IsSuccessStatusCodeAndProductGroupsReturned()
        {
            //Setup
            InvoiceTest.GetElementSeed();

            //Act
            var response = await _client.GetAsync("ProductGroup/GetProductGroups");

            List <ProductGroup> productGroups = JsonConvert.DeserializeObject <List <ProductGroup> >(await response.Content.ReadAsStringAsync());

            //Assert
            Assert.IsTrue(response.IsSuccessStatusCode);
            Assert.AreNotEqual(0, productGroups.Count);
        }
Пример #7
0
        public async Task CreateOrUpdate_ExistingItemObject_IsSuccessStatusCodeAndResponseTrue()
        {
            //Setup
            Element element = InvoiceTest.GetElementSeed();
            Item    item    = element.Item;

            //Act
            var response = await _client.PostAsJsonAsync("Item/CreateOrUpdate", item);

            var deserializedResponse = JsonConvert.DeserializeObject <bool>(await response.Content.ReadAsStringAsync());

            //Assert
            Assert.IsTrue(response.IsSuccessStatusCode);
            Assert.IsTrue(deserializedResponse);
        }
Пример #8
0
        public async Task Delete_CorrectID_IsSuccessStatusCodeAndItemDeleted()
        {
            //Setup
            Element element = InvoiceTest.GetElementSeed();
            Item    item    = element.Item;
            int     id      = item.ID;

            //Act
            var response = await _client.PostAsJsonAsync("Item/Delete", id);

            var deserializedResponse = JsonConvert.DeserializeObject <bool>(await response.Content.ReadAsStringAsync());

            //Assert
            Assert.IsTrue(response.IsSuccessStatusCode);
            Assert.IsTrue(deserializedResponse);
        }
Пример #9
0
        public async Task GetItem_CorrectItemId_SuccessStatusCodeAndItemReturned()
        {
            //Setup
            Element element    = InvoiceTest.GetElementSeed();
            var     parameters = HttpUtility.ParseQueryString(string.Empty);

            parameters["id"] = element.Item.ID.ToString();

            //Act
            var response = await _internalClient.GetAsync("Item/GetItem?" + parameters);

            Item item = JsonConvert.DeserializeObject <Item>(await response.Content.ReadAsStringAsync());

            //Assert
            Assert.IsTrue(response.IsSuccessStatusCode, "Server responded with Success code");
            Assert.IsTrue(AreItemsEqual(element.Item, item), "Items are equal");//check if object received is the same
        }
Пример #10
0
        public async Task GetProduct_CorrectBarcode_SuccessStatusCodeAndSameObjectReturned()
        {
            //Setup
            Product testProduct = InvoiceTest.GetElementSeed().Item.Product;
            var     parameters  = HttpUtility.ParseQueryString(string.Empty);

            parameters["barcode"] = testProduct.Barcode.ToString();

            //Act
            var response = await _internalClient.GetAsync("Product/GetProduct?" + parameters);

            Product product = JsonConvert.DeserializeObject <Product>(await response.Content.ReadAsStringAsync());

            //Assert
            Assert.IsTrue(response.IsSuccessStatusCode, "Server responded with Success code");
            Assert.IsTrue(AreProductsEqual(product, product), "Products are equal");
        }
Пример #11
0
        public async Task GetInvoiceElements_CorrectInvoiceId_IsSuccessStatusCodeAndElementsReturned()
        {
            //Setup
            Element element    = InvoiceTest.GetElementSeed();
            Invoice invoice    = element.Invoice;
            var     parameters = HttpUtility.ParseQueryString(string.Empty);

            parameters["id"] = invoice.ID.ToString();

            //Act
            var response = await _client.GetAsync("Element/GetInvoiceElements?" + parameters);

            List <Element> invoiceElements = JsonConvert.DeserializeObject <List <Element> >(await response.Content.ReadAsStringAsync());

            //Assert
            Assert.IsTrue(response.IsSuccessStatusCode);
            Assert.AreNotEqual(0, invoiceElements.Count);
        }
Пример #12
0
        public async Task GetCompany_CorrectID_IsSuccessStatusCodeAndSameObjectReturned()
        {
            //Setup
            Element element    = InvoiceTest.GetElementSeed();
            Invoice invoice    = element.Invoice;
            var     parameters = HttpUtility.ParseQueryString(string.Empty);

            parameters["id"] = invoice.Sender.Company.ID.ToString();

            //Act
            var response = await _client.GetAsync("Company/GetCompany?" + parameters);

            Company company = JsonConvert.DeserializeObject <Company>(await response.Content.ReadAsStringAsync());

            //Assert
            Assert.IsTrue(response.IsSuccessStatusCode);
            Assert.AreEqual(true, AreCompaniesEqual(company, invoice.Sender.Company));//check if object received is the same
        }
Пример #13
0
        public async Task Create_NewTaxGroupObject_SuccessStatusCode()
        {
            //Setup
            TaxGroup taxGroup = InvoiceTest.GetElementSeed().Item.IncomingTaxGroup;

            using (var db = new DatabaseContext())
            {
                db.TaxGroups.Attach(taxGroup);
                db.Items.RemoveRange(db.Items.Where(x => x.IncomingTaxGroup_ID == taxGroup.ID || x.OutgoingTaxGroup_ID == taxGroup.ID));
                db.TaxGroups.Remove(taxGroup);
                db.SaveChanges();
            }

            //Act
            var response = await _internalClient.PostAsJsonAsync("TaxGroup/Create", taxGroup);

            //Assert
            Assert.IsTrue(response.IsSuccessStatusCode, "Server responded with Success code");
        }
Пример #14
0
        public async Task GetItems_MethodCalled_SuccessStatusCodeAndItemsReturned()
        {
            //Setup
            InvoiceTest.GetElementSeed();
            var parameters = HttpUtility.ParseQueryString(string.Empty);

            parameters["serialNumber"] = "";
            parameters["productName"]  = "";
            parameters["barcode"]      = 0.ToString();

            //Act
            var response = await _internalClient.GetAsync("Item/GetItems?" + parameters);

            List <Item> items = JsonConvert.DeserializeObject <List <Item> >(await response.Content.ReadAsStringAsync());

            //Assert
            Assert.IsTrue(response.IsSuccessStatusCode, "Server responded with Success code");
            Assert.AreNotEqual(0, items.Count, "Gets items");
        }
Пример #15
0
        public async Task CreateOrUpdate_NewItemObject_SuccessStatusCode()
        {
            //Setup
            Element element = InvoiceTest.GetElementSeed();
            Item    item    = element.Item;

            item.IncomingTaxGroup = null;
            item.OutgoingTaxGroup = null;
            using (var db = new DatabaseContext())
            {
                db.Items.Remove(db.Items.SingleOrDefault(x => x.ID == item.ID));
                db.SaveChanges();
            }

            //Act
            var response = await _internalClient.PostAsJsonAsync("Item/CreateOrUpdate", item);

            //Assert
            Assert.IsTrue(response.IsSuccessStatusCode, "Server responded with Success code");
        }
Пример #16
0
        public async Task Create_NewTaxGroupObject_IsSuccessStatusCodeAndResponseTrue()
        {
            //Setup
            TaxGroup taxGroup = InvoiceTest.GetElementSeed().Item.IncomingTaxGroup;

            using (var db = new DatabaseContext())
            {
                db.TaxGroups.Attach(taxGroup);
                db.Items.RemoveRange(db.Items.Where(x => x.IncomingTaxGroup_ID == taxGroup.ID || x.OutgoingTaxGroup_ID == taxGroup.ID));
                db.TaxGroups.Remove(taxGroup);
                db.SaveChanges();
            }

            //Act
            var response = await _client.PostAsJsonAsync("TaxGroup/Create", taxGroup);

            var deserializedResponse = JsonConvert.DeserializeObject <bool>(await response.Content.ReadAsStringAsync());

            //Assert
            Assert.IsTrue(response.IsSuccessStatusCode);
            Assert.IsTrue(deserializedResponse);
        }
Пример #17
0
        public async Task CreateOrUpdate_NewItemObject_IsSuccessStatusCodeAndResponseTrue()
        {
            //Setup
            Element element = InvoiceTest.GetElementSeed();
            Item    item    = element.Item;

            item.IncomingTaxGroup = null;
            item.OutgoingTaxGroup = null;
            using (var db = new DatabaseContext())
            {
                db.Items.Remove(db.Items.SingleOrDefault(x => x.ID == item.ID));
                db.SaveChanges();
            }

            //Act
            var response = await _client.PostAsJsonAsync("Item/CreateOrUpdate", item);

            var deserializedResponse = JsonConvert.DeserializeObject <bool>(await response.Content.ReadAsStringAsync());

            //Assert
            Assert.IsTrue(response.IsSuccessStatusCode, "Api didn't encounter unexpected issue");
            Assert.IsTrue(deserializedResponse, "Api returned that operation has not succeeded");
        }