TESTS Code
TESTS Code
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ICT711_Day5_classes;
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
namespace ICT711_Day5_classes.Tests
{
[TestClass()]
public class InventoryTests
{
[TestMethod()]
public void AddProductTest()
{
// After creating your class, Remove the next line and uncomment the below test code.
[TestMethod()]
public void IndexProductIdTest()
{
// After creating your class, Remove the next line and uncomment the below test code.
[TestMethod()]
public void IndexProductNameTest()
{
// After creating your class, Remove the next line and uncomment the below test code.
[TestMethod()]
public void RemoveProductTest()
{
// After creating your class, Remove the next line and uncomment the below test code.
[TestMethod()]
public void RemoveProductNotInInventoryTest()
{
// After creating your class, Remove the next line and uncomment the below test code.
[TestMethod()]
public void RemoveProductNotEnoughTest()
{
// After creating your class, Remove the next line and uncomment the below test code.
[TestMethod()]
public void PlusOperatorTest()
{
// After creating your class, Remove the next line and uncomment the below test code.
[TestMethod()]
public void MinusOperatorTest()
{
// After creating your class, Remove the next line and uncomment the below test code.
[TestMethod()]
public void RemoveProductGarmentTest()
{
// After creating your class, Remove the next line and uncomment the below test code.
// You must do this test after we finish the Polymorphism and do the ProductGarment class
}
}
}
SALE
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ICT711_Day5_classes;
using System;
using System.Collections.Generic;
using System.Text;
namespace ICT711_Day5_classes.Tests
{
[TestClass()]
public class SaleTests
{
[TestMethod()]
public void SaleConstructorTest()
{
// After creating your class, Remove the next line and uncomment the below test code.
[TestMethod()]
public void SaleConstructorParametrizedTest()
{
// After creating your class, Remove the next line and uncomment the below test code.
}
[TestMethod()]
public void SaleConstructorParametrizedWithIdTest()
{
// After creating your class, Remove the next line and uncomment the below test code.
// Set Sale Id
ISale sale = new Sale(550, new DateTime(2020, 10, 1), 4, 1, SaleStatus.Returned);
// Check Sale Id
Assert.IsInstanceOfType(sale.Id, typeof(int));
Assert.IsTrue(sale.Id == 550);
Assert.AreEqual(0, new DateTime(2020, 10, 1).CompareTo(sale.Date)); // Date
Assert.AreEqual(4, sale.CustomerId); // CustomerId
Assert.AreEqual(1, sale.AssociateId); // AssociateId
Assert.AreEqual(SaleStatus.Returned, sale.Status); // Status
[TestMethod()]
public void AddProductTest()
{
// After creating your class, Remove the next line and uncomment the below test code.
[TestMethod()]
public void GetTotalTest()
{
// After creating your class, Remove the next line and uncomment the below test code.
[TestMethod()]
public void RemoveProductTest()
{
// After creating your class, Remove the next line and uncomment the below test code.
}
[TestMethod()]
public void RemoveProductGarmentTest()
{
// After creating your class, Remove the next line and uncomment the below test code.
// You must do this test after we finish the Polymorphism and do the ProductGarment class
sale.AddProduct(product3, inventory);
Assert.AreEqual(1, sale.ProductsList.Count);
Assert.AreEqual(24, sale.ProductsList[0].ProductId);
Assert.AreEqual(10, ((ProductGarment)sale.ProductsList[0]).SizePriceQuantity["S"].quantity);
sale.AddProduct(product3, inventory);
Assert.AreEqual(1, sale.ProductsList.Count);
Assert.AreEqual(20, ((ProductGarment)sale.ProductsList[0]).SizePriceQuantity["S"].quantity);
ProductGarment product5 = new ProductGarment(24, "M Shirt S", "Men Shirt Small");
product5.AddQuantity("S", 5, 15.0m);
sale.RemoveProduct(product5, inventory);
Assert.AreEqual(15, ((ProductGarment)sale.ProductsList[0]).SizePriceQuantity["S"].quantity);
}
}
}
STORE
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ICT711_Day5_classes;
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace ICT711_Day5_classes.Tests
[TestClass()]
[TestMethod()]
// After creating your class, Remove the next line and uncomment the below test code.
//Assert.Fail();
IAssociate associate1 = (IAssociate)new Associate(1, "John", "Smith", "40300000", "[email protected]", "Manager", "Store
manager");
IAssociate associate2 = (IAssociate)new Associate(78, "Mike", "M", "40377777", "[email protected]", "Finance", "Finance
associate", 1);
IAssociate associate3 = (IAssociate)new Associate(4786, "Sam", "T", "40344444", "[email protected]", "Sales", "Store
sales", 1);
IAssociate associate4 = (IAssociate)new Associate(47851, "Jim", "W", "40388888", "[email protected]", "Marketing",
"Marketing associate", 1);
IStore store = new Store() { Associates = new List<IAssociate>() { associate1, associate2, associate3,
associate4 } };
store.SaveAssociates();
[TestMethod()]
// After creating your class, Remove the next line and uncomment the below test code.
//Assert.Fail();
IStore store = new Store() { Customers = new List<ICustomer>() { customer1, customer2, customer3, customer4 }
};
store.SaveCustomers();
}
[TestMethod()]
// After creating your class, Remove the next line and uncomment the below test code.
Product product1 = new Product(22, "M Shirt", "Men Shirt", 14.47m, 78);
Product product2 = new Product(23, "L Shirt", "Ladies Shirt", 17.47m, 12);
Product product3 = new Product(24, "M Shirt S", "Men Shirt Small", 14.37m, 10);
product5.AddQuantity("S", 5, 15.0m);
product5.AddQuantity("M", 7, 19.0m);
inventory.AddProduct(product1);
inventory.AddProduct(product2);
inventory.AddProduct(product3);
inventory.AddProduct(product4);
inventory.AddProduct(product5);
prod1.SizePriceQuantity.Clear();
prod1.AddQuantity("S", 2, 15.0m);
prod1.AddQuantity("M", 1, 20.0m);
sale2.AddProduct(prod1, inventory);
prod2.SizePriceQuantity.Clear();
prod2.AddQuantity("S", 3, 15.0m);
prod2.AddQuantity("M", 4, 19.0m);
sale2.AddProduct(prod2, inventory);
store.SaveSales();
[TestMethod()]
// After creating your class, Remove the next line and uncomment the below test code.
Product product1 = new Product(22, "M Shirt", "Men Shirt", 14.47m, 78);
Product product2 = new Product(23, "L Shirt", "Ladies Shirt", 17.47m, 12);
Product product3 = new Product(24, "M Shirt S", "Men Shirt Small", 14.37m, 10);
product5.AddQuantity("S", 5, 15.0m);
product5.AddQuantity("M", 7, 19.0m);
inventory.AddProduct(product1);
inventory.AddProduct(product2);
inventory.AddProduct(product3);
inventory.AddProduct(product4);
inventory.AddProduct(product5);
store.SaveInventory();
[TestMethod()]
// After creating your class, Remove the next line and uncomment the below test code.
Product product1 = new Product(22, "M Shirt", "Men Shirt", 14.47m, 78);
inventory.AddProduct(product1);
IStore store = new Store() { Inventory = inventory, StoreName = "New Store Name", Address = "Somewhere
address" };
store.SaveStoreInfo();
string stringContents = File.ReadAllText(Store.StoreFileName);
Assert.IsTrue(stringContents.Contains("Somewhere address"));
[TestMethod()]
// After creating your class, Remove the next line and uncomment the below test code.
//Assert.Fail();
store.LoadAssociates();
Assert.AreEqual(4, store.Associates.Count);
Assert.AreEqual(1, store.Associates[0].AssociateId);
Assert.AreEqual(78, store.Associates[1].AssociateId);
Assert.AreEqual("Sam", store.Associates[2].FName);
Assert.AreEqual("40388888", store.Associates[3].Tel);
Assert.AreEqual("Marketing", store.Associates[3].Department);
Assert.AreEqual(1, store.Associates[2].ManagerId);
[TestMethod()]
// After creating your class, Remove the next line and uncomment the below test code.
//Assert.Fail();
store.LoadCustomers();
Assert.AreEqual(4, store.Customers.Count);
Assert.AreEqual(100, store.Customers[0].CustomerId);
Assert.AreEqual(110, store.Customers[1].CustomerId);
Assert.AreEqual("Eddy", store.Customers[2].FName);
Assert.AreEqual("40399999", store.Customers[3].Tel);
[TestMethod()]
// After creating your class, Remove the next line and uncomment the below test code.
//Assert.Fail();
store.LoadSales();
Assert.AreEqual(2, store.Sales.Count);
Assert.AreEqual(4, store.Sales[0].CustomerId);
Assert.AreEqual(1, store.Sales[0].AssociateId);
Assert.AreEqual(3, store.Sales[0].ProductsList.Count);
Assert.AreEqual(4, store.Sales[1].ProductsList.Count);
Assert.AreEqual(17.47m, store.Sales[1].ProductsList[1].Price);
Assert.IsInstanceOfType(store.Sales[1].ProductsList[2], typeof(ProductGarment));
[TestMethod()]
// After creating your class, Remove the next line and uncomment the below test code.
store.LoadInventory();
Assert.AreEqual(5, store.Inventory.Products.Count);
Assert.AreEqual(17.47m, store.Inventory[23].Price);
Assert.AreEqual(10, store.Inventory[24].Quantity);
Assert.IsInstanceOfType(store.Inventory[25], typeof(ProductGarment));
Assert.IsInstanceOfType(store.Inventory[26], typeof(ProductGarment));
Assert.AreEqual(2, ((ProductGarment)store.Inventory[26]).SizePriceQuantity.Count);
Assert.AreEqual(358.0m, ((ProductGarment)store.Inventory[26]).GetSubTotal());
[TestMethod()]
Assert.AreEqual(Expect_StoreName, store.StoreName);
Assert.AreEqual(Expect_Address, store.Address);