Day 4 - Person
Day 4 - Person
using System.Collections.Generic;
using System.Text;
namespace ICT711_Day4_classes
{
public class Person : IPerson
{
public string FName { get ; set ; }
public string LName { get ; set ; }
public string Tel { get ; set ; }
public string Email { get ; set ; }
namespace ICT711_Day4_classes
{
public interface IPerson
{
public string FName { get; set; }
public string LName { get; set; }
public string Tel { get; set; }
public string Email { get; set; }
public string GetFullName();
}
}
--
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
namespace ICT711_Day5_classes
{
public class Sale : ISale
{
public int Id { get; set; }
public DateTime Date { get; set; }
public int CustomerId { get; set; }
public int AssociateId { get; set; }
public Sale()
{
this.Id = new Random().Next();
}
public Sale(int id, DateTime date, int customerId, int associateId, SaleStatus status)
{
this.Id = id;
this.Date = date;
this.CustomerId = customerId;
this.AssociateId = associateId;
this.Status = status;
}
inventory.RemoveProduct(product);
p.Add(product);
return 1;
};
}
inventory.RemoveProduct(product);
ProductsList.Add(product);
return 1;
}
public decimal GetTotal()
{
decimal total = 0;
return total;
}
saleProduct.Remove(product);
inventory.AddProduct(product);
return 1;
}
}
}
}
--
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
ISale sale = new Sale(550, new DateTime(2020, 10, 1), 4, 1, SaleStatus.Returned);
ProductGarment product3 = new ProductGarment(24, "M Shirt S", "Men Shirt Small");
product3.AddQuantity("S", 10, 15.0m);
ProductGarment product4 = new ProductGarment(24, "M Shirt S", "Men Shirt Small");
product4.AddQuantity("S", 30, 15.0m);
product4.AddQuantity("L", 30, 41.0m);
Inventory inventory = new Inventory();
inventory.AddProduct(product4);
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);
}
}
}
--
using System;
using System.Collections.Generic;
using System.IO;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using Newtonsoft.Json;
//using Newtonsoft.Json.Serialization;
namespace ICT711_Day5_classes
{
public class Store : IStore
{
public string StoreName { get; set; }
public string Address { get; set; }
[JsonIgnore] // Don't store this data inside the store file. Will be stored in a separate file
public List<ICustomer> Customers { get; set; }
[JsonIgnore] // Don't store this data inside the store file. Will be stored in a separate file
public List<IAssociate> Associates { get; set; }
[JsonIgnore] // Don't store this data inside the store file. Will be stored in a separate file
public Inventory Inventory { get; set; }
[JsonIgnore] // Don't store this data inside the store file. Will be stored in a separate file
public List<ISale> Sales { get; set; }
[JsonProperty]
public static string AssociatesFileName { get; set; } = "associates.json";
[JsonProperty]
public static string CustomersFileName { get; set; } = "customers.json";
[JsonProperty]
public static string InventoryFileName { get; set; } = "inventory.json";
[JsonProperty]
public static string SalesFileName { get; set; } = "sales.json";
public static string StoreFileName { get; set; } = "store.json";
public Store()
{
this.StoreName = "New Store Name";
this.Address = "Somewhere address";
}
public void LoadAssociates()
{
string jsonString = File.ReadAllText(AssociatesFileName);
var ss = JsonConvert.DeserializeObject<List<Associate>>(jsonString, new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.Auto
});
Associates = ss.ConvertAll(s => (IAssociate)s); // Typecasting for each element
//throw new NotImplementedException();
}
}
}
}
--
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();
store.SaveAssociates();
[TestMethod()]
// After creating your class, Remove the next line and uncomment the below test code.
//Assert.Fail();
store.SaveCustomers();
int expected = 1125; // 1072
[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);
ISale sale1 = new Sale(550, new DateTime(2020, 10, 1), 4, 1, SaleStatus.Returned);
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();
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);