Login Audit App
The Software Outline
User story
As a member of DTT
I want to see when a user last logged into Sitecore
So that I can manage Sitecore licences
Acceptance criteria
AC1 - Data
GIVEN I want to find out the last login date for all Sitecore users
WHEN I run the report
THEN the following information is returned for each Sitecore user as a csv file:
- Full name
- Last login date
My approach
I started by learning basic C# syntax and got the basics of .NET Core 6 using the Microsoft documentation. I then took this knowledge and used my previous coding knowledge to build an application that takes the last login dates from my API and converts the resulting data into a csv file.
This code loops over the data from the data that is returned from the API/getall endpoint and writes a line for each person:

I created a model for the data that should be returned in the CSV file:

I created an interface with methods to generate a CSV file with a unique name (using the system DateTime method), Add a title row to show what data is held in each column and a method to add a single line of data to the file:

The methods are shown below and are stored in the .services folder:

Finally I created unit tests to check my program generated the correct results/data types and various other tests:

In total I created a total of 8 tests to ensure my program works effectively and has no errors, the results of the tests can be seen below:

And the result of running the report is this CSV file which can be accessed using excel or any text editor:

Challenges I overcame:
I had to figure out how to fetch the data from my API and how to parse the JSON response into usable data for my application to run. I did this using Stack Overflow and other forums along with the Microsoft C# documentation.
I also had very little knowledge of unit testing so I used this project as a way to learn how to write basic tests to ensure my code works as it should. I learned about creating mock data using Xunit testing.
I had to also figure out how to write lines to a file using System.IO and I used what I learned to write to the file and store the result in a set location (Output Folder).
No comments yet.