static void Main(string[] args) { // Basic test case for employee { Console.WriteLine(); String userIDString = "EMP" + "1234556789"; Bill bill = new Bill(System.Guid.NewGuid(), userIDString, 2000); IUser user = UserFactory.GiveUser(userIDString); if(user != null) { UserData userData = new UserData(userIDString, "ABC"); user.SetUserData(userData); user.SetBill(bill); DiscountResult result = user.CalculateDiscountAmount(); Console.WriteLine("User ID = " + userIDString + ", " + "Bill Amount = " + bill.BillAmount + ", " + "Discounted bill = " + result.DiscountedBillAmount); if (!result.Success) { Console.WriteLine(result.Message); } } else { Console.WriteLine("Unknown user with ID " + userIDString); } } // Basic test case for customer { Console.WriteLine(); String userIDString = "CUST" + "1234556789"; Bill bill = new Bill(System.Guid.NewGuid(), userIDString, 2000); IUser user = UserFactory.GiveUser(userIDString); if (user != null) { UserData userData = new UserData(userIDString, "ABC"); user.SetUserData(userData); user.SetAssociatedYears(4); user.SetBill(bill); DiscountResult result = user.CalculateDiscountAmount(); Console.WriteLine("User ID = " + userIDString + ", " + "Bill Amount = " + bill.BillAmount + ", " + "Discounted bill = " + result.DiscountedBillAmount); if (!result.Success) { Console.WriteLine(result.Message); } } else { Console.WriteLine("Unknown user with ID " + userIDString); } } // Basic test case for affiliate { Console.WriteLine(); String userIDString = "AFF" + "1234556789"; Bill bill = new Bill(System.Guid.NewGuid(), userIDString, 2000); IUser user = UserFactory.GiveUser(userIDString); if (user != null) { UserData userData = new UserData(userIDString, "ABC"); user.SetUserData(userData); user.SetBill(bill); DiscountResult result = user.CalculateDiscountAmount(); Console.WriteLine("User ID = " + userIDString + ", " + "Bill Amount = " + bill.BillAmount + ", " + "Discounted bill = " + result.DiscountedBillAmount); if (!result.Success) { Console.WriteLine(result.Message); } } else { Console.WriteLine("Unknown user with ID " + userIDString); } } // Test case for unknown user { Console.WriteLine(); String userIDString = "ABB" + "1234556789"; Bill bill = new Bill(System.Guid.NewGuid(), userIDString, 2000); IUser user = UserFactory.GiveUser(userIDString); if (user != null) { UserData userData = new UserData(userIDString, "ABC"); user.SetUserData(userData); user.SetBill(bill); DiscountResult result = user.CalculateDiscountAmount(); Console.WriteLine("User ID = " + userIDString + ", " + "Bill Amount = " + bill.BillAmount + ", " + "Discounted bill = " + result.DiscountedBillAmount); if (!result.Success) { Console.WriteLine(result.Message); } } else { Console.WriteLine("Unknown user with ID " + userIDString); } } // Test case for negative bill value { Console.WriteLine(); String userIDString = "EMP" + "1234556789"; Bill bill = new Bill(System.Guid.NewGuid(), userIDString, -2000); IUser user = UserFactory.GiveUser(userIDString); if (user != null) { UserData userData = new UserData(userIDString, "ABC"); user.SetUserData(userData); user.SetBill(bill); DiscountResult result = user.CalculateDiscountAmount(); Console.WriteLine("User ID = " + userIDString + ", " + "Bill Amount = " + bill.BillAmount + ", " + "Discounted bill = " + result.DiscountedBillAmount); if(!result.Success) { Console.WriteLine(result.Message); } } else { Console.WriteLine("Unknown user with ID " + userIDString); } } // Test case for customer who is associated for less than 2 years { Console.WriteLine(); String userIDString = "CUST" + "1234556789"; Bill bill = new Bill(System.Guid.NewGuid(), userIDString, 2000); IUser user = UserFactory.GiveUser(userIDString); if (user != null) { UserData userData = new UserData(userIDString, "ABC"); user.SetUserData(userData); user.SetAssociatedYears(1); user.SetBill(bill); DiscountResult result = user.CalculateDiscountAmount(); Console.WriteLine("User ID = " + userIDString + ", " + "Bill Amount = " + bill.BillAmount + ", " + "Discounted bill = " + result.DiscountedBillAmount); if (!result.Success) { Console.WriteLine(result.Message); } } else { Console.WriteLine("Unknown user with ID " + userIDString); } } Console.ReadLine(); }
/// <summary> /// Set the bill /// </summary> /// <param name="bill">Bill</param> public void SetBill(Bill bill) { this.bill = bill; }