/// <summary> /// Main entry point of console application /// </summary> /// <param name="args">Arguments list</param> static void Main(string[] args) { var filePath = Path.Combine(Environment.CurrentDirectory, "Enrollments.csv"); // Create the classes needed to read, validate and import the Enrollment data var fileReader = new FileReader(); var enrollmentCSVReader = new EnrollmentReaderCSV(); var enrollmentValidator = new EnrollmentValidator(); var enrollmentImporter = new EnrollmentImporter(); // Read in and validate the Enrollment data from the file var savedEnrollmentRecords = enrollmentImporter.Import(filePath, fileReader, enrollmentCSVReader, enrollmentValidator); // If there are no records then processing was stopped due to some invalid formatting of data in the file. if (savedEnrollmentRecords.IsNullOrEmpty()) { Console.WriteLine("A record in the file failed validation. Processing has stopped."); } else { // The records were read in so display them. Some records still may be invalid. foreach (var enrollment in savedEnrollmentRecords) { Console.WriteLine("\"{0},{1},{2},{3},{4},{5}\"", enrollment.Status, enrollment.FirstName, enrollment.LastName, enrollment.DateOfBirth.ToShortDateString(), enrollment.PlanType, enrollment.EffectiveDate.ToShortDateString()); } } Console.WriteLine("Press Enter to quit"); Console.ReadLine(); }
public void WhenValidParametersAndOneRecordHasMissingFirstName_ThenReturnNull() { string filePath = "enrollments.csv"; var fileReader = new FileReader(); var enrollmentReader = new Mock <IEnrollmentReader>(MockBehavior.Strict); var enrollmentValidator = new EnrollmentValidator(); var enrollmentWithMissingFirstName = new List <Enrollment> { new Enrollment { FirstName = String.Empty, LastName = "Doe", DateOfBirth = new DateTime(1970, 8, 16), PlanType = EnrollmentPlanType.FSA, EffectiveDate = DateTime.Today.AddDays(3) } }; enrollmentReader.Setup(x => x.ReadFromFile(It.IsAny <IFileReader>(), It.IsAny <string>())).Returns(enrollmentWithMissingFirstName); var enrollmentImporter = new EnrollmentImporter(); var savedEnrollmentRecords = enrollmentImporter.Import(filePath, fileReader, enrollmentReader.Object, enrollmentValidator); Assert.IsTrue(savedEnrollmentRecords.IsNullOrEmpty()); }
public void WhenValidParametersAndOneRecordHasOneValidRecord_ThenReturnOneRecord() { string filePath = "enrollments.csv"; var fileReader = new FileReader(); var enrollmentReader = new Mock <IEnrollmentReader>(MockBehavior.Strict); var enrollmentValidator = new EnrollmentValidator(); var enrollmentWithOneValidRecord = new List <Enrollment> { new Enrollment { FirstName = "Jane", LastName = "Doe", DateOfBirth = new DateTime(1970, 8, 16), PlanType = EnrollmentPlanType.FSA, EffectiveDate = DateTime.Today.AddDays(3) } }; enrollmentReader.Setup(x => x.ReadFromFile(It.IsAny <IFileReader>(), It.IsAny <string>())).Returns(enrollmentWithOneValidRecord); var enrollmentImporter = new EnrollmentImporter(); var savedEnrollmentRecords = enrollmentImporter.Import(filePath, fileReader, enrollmentReader.Object, enrollmentValidator); Assert.IsTrue(savedEnrollmentRecords.Count == 1); Assert.IsTrue(savedEnrollmentRecords[0].Status == EnrollmentStatus.Accepted); }
public void WhenValidatorIsNull_ThenExceptionIsThrown() { string filePath = "enrollments.csv"; var fileReader = new FileReader(); var enrollmentReader = new EnrollmentReaderCSV(); var enrollmentImporter = new EnrollmentImporter(); enrollmentImporter.Import(filePath, fileReader, enrollmentReader, null); }
public void WhenFilePathIsNull_ThenExceptionIsThrown() { string filePath = null; var fileReader = new FileReader(); var enrollmentReader = new EnrollmentReaderCSV(); var enrollmentValidator = new EnrollmentValidator(); var enrollmentImporter = new EnrollmentImporter(); enrollmentImporter.Import(filePath, fileReader, enrollmentReader, enrollmentValidator); }
public void WhenFilePathIsEmpty_ThenExceptionIsThrown() { var filePath = String.Empty; var fileReader = new FileReader(); var enrollmentReader = new EnrollmentReaderCSV(); var enrollmentValidator = new EnrollmentValidator(); var enrollmentImporter = new EnrollmentImporter(); enrollmentImporter.Import(filePath, fileReader, enrollmentReader, enrollmentValidator); }