public void TestReadClaim() { // Arrange (Create and initialize variables) var lossDate = new DateTime(2019, 08, 12); var claimDate = new DateTime(2019, 09, 09); var claimExpiration = new TimeSpan(30, 0, 0, 0); bool isValid = claimDate <= lossDate + claimExpiration; var claim = new Claim(1, ClaimType.Home, "House fire", 150000.00m, lossDate, claimDate, isValid); var claimTester = new ClaimCRUD(); // Act (Add claim to queue) claimTester.CreateClaim(claim); // Assert (List of claims should not be null) Assert.IsNotNull(claimTester.GetAllClaims(), "Read was not successful"); }
public void TestDeleteClaim() { // Arrange (Create and initialize variables) var lossDate = new DateTime(2020, 08, 11); var claimDate = new DateTime(2020, 09, 01); var claimExpiration = new TimeSpan(30, 0, 0, 0); bool isValid = claimDate <= lossDate + claimExpiration; var claim = new Claim(1, ClaimType.Theft, "Stolen TV and laptop", 2500.00m, lossDate, claimDate, isValid); var claimTester = new ClaimCRUD(); claimTester.CreateClaim(claim); // Act (Call DeleteClaim() method on the claim bool wasDeleted = claimTester.DeleteClaim(claim.ClaimID); // Assert (wasDeleted should return true if the delete was successful) Assert.IsTrue(wasDeleted, "Delete was not successful."); }
public void TestAddClaim() { // Arrange (Create and initialize variables) var lossDate = new DateTime(2020, 03, 14); var claimDate = new DateTime(2020, 03, 15); var claimExpiration = new TimeSpan(30, 0, 0, 0); bool isValid = claimDate <= lossDate + claimExpiration; var claim = new Claim(1, ClaimType.Vehicle, "Fender bender", 3000.00m, lossDate, claimDate, isValid); var claimTester = new ClaimCRUD(); int beginningCount = claimTester.GetAllClaims().Count; // Act (Add new claim to queue) claimTester.CreateClaim(claim); // Assert (Check the count of the claims queue to make sure it is greater than it was at the beginning) int endingCount = claimTester.GetAllClaims().Count; Assert.IsTrue(endingCount > beginningCount, "Add was not successful."); }
// Create a new claim private Claim CreateNewClaim() { Console.Clear(); Console.ForegroundColor = ConsoleColor.Green; var newClaim = new Claim(); // Set Claim ID newClaim.ClaimID = _claimQueue.Count + 1; // Select claim type SetClaimType: Console.Clear(); Console.WriteLine("What type of claim is this?\n"); int typeCounter = 0; foreach (var type in Enum.GetNames(typeof(ClaimType))) { typeCounter++; Console.WriteLine($"{typeCounter}. {Enum.GetName(typeof(ClaimType), typeCounter)}"); } string inputType = Console.ReadLine(); bool parseType = int.TryParse(inputType, out int whichType); if (parseType) { switch (whichType) { case 1: newClaim.ClaimType = ClaimType.Vehicle; goto SetClaimDescription; case 2: newClaim.ClaimType = ClaimType.Home; goto SetClaimDescription; case 3: newClaim.ClaimType = ClaimType.Theft; goto SetClaimDescription; default: PressAnyKey(); goto SetClaimType; } } else { PressAnyKey(); goto SetClaimType; } // Enter claim description SetClaimDescription: Console.Clear(); Console.WriteLine("Briefly describe what happened:\n"); newClaim.ClaimDescription = Console.ReadLine(); // Enter claim amount SetClaimAmount: Console.Clear(); Console.WriteLine("Enter the amount of the claim:\n"); string inputAmount = Console.ReadLine(); bool parseAmount = decimal.TryParse(inputAmount, out decimal claimAmount); if (parseAmount) { newClaim.ClaimAmount = decimal.Round(claimAmount, 2); } else { PressAnyKey(); goto SetClaimAmount; } // Enter loss date SetLossDate: Console.Clear(); Console.WriteLine("Enter the date of the loss (mm/dd/yyyy format)"); string inputFullLossDate = Console.ReadLine(); bool parseLossDate = DateTime.TryParseExact(inputFullLossDate, "MM/dd/yyyy", CultureInfo.InstalledUICulture, DateTimeStyles.AssumeLocal, out DateTime lossDate); if (parseLossDate) { newClaim.LossDate = lossDate; } else { PressAnyKey(); goto SetLossDate; } // Enter claim date SetClaimDate: Console.Clear(); Console.WriteLine("Enter the date the claim was reported (mm/dd/yyyy format)"); string inputFullClaimDate = Console.ReadLine(); bool parseClaimDate = DateTime.TryParseExact(inputFullClaimDate, "MM/dd/yyyy", CultureInfo.InstalledUICulture, DateTimeStyles.AssumeLocal, out DateTime claimDate); if (parseClaimDate) { newClaim.ClaimDate = claimDate; } else { PressAnyKey(); goto SetClaimDate; } // Check claim date vs. loss date to verify if claim is valid bool isValid = claimDate <= lossDate + thirtyDays && claimDate >= lossDate; newClaim.IsValid = isValid; claimManipulator.CreateClaim(newClaim); return(newClaim); }