Using Visual Studio and C#, create a console-based app that will create a dictionary object that returns in the console the counts of employees in each department
- Copied and pasted the given CSV file to the project folder and changed the
Copy to Output Directory property to Copy always
:
- Created a class
Employee.cs
to read the CSV file (15 fields/columns to read) and insertedCsvColumn
attributes since the first line in the CSV file are the field/column names:
- Defined a method called
ReadCsvFile()
inProgram.cs
:
- Calling
ReadCsvFile()
inside theMain
method andConsole.ReadKey()
to see the output on the console:
- Output on the console:
- To see if the counts of employees get incremented correctly, I tried setting the breakpoint at the line 52:
- If I run the app with the breakpoint at the line 52, the code should've completed its iteration over the first
employee
object which is this employee:
- And if I actually run the app, we can find that that's the case and the engineering department has the count of 1:
- Now, I'd like to see if the count of engineering department gets incremented once it encounters the next employee whose department is also engineering. The next engineering employee in line is
Harper Dominguez
.
- And if I keep running the app, I can see that the department of engineering has the count of 2 at the employee
Harper Dominguez
:
Not sure how to do unit test yet, but I thought it'd be good to do something like the followings:
- Divide the
employee.csv
file into several sample csv files; - Add test data into each of them;
- Verify if the app still outputs the expected values