Skip to content

lucianopereira86/NetCore-xUnit-CronJob-Simulator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NetCore-xUnit-CronJob-Simulator

Simulating a Cronjob with .Net Core and xUnit.

Technologies

Topics

Instructions

The solution contains a console application and a unit test project.
After running the app, it will be required for the user to enter a cron string composed by 5 fields separated by empty spaces: minute, hour, day of month, month and day of week. The output will display values as numbers for each field:

  • minute: 1 to 60.
  • hour: 0 to 23.
  • day of month: 1 to 31.
  • month: 1 to 12.
  • day of week: 0 to 6.

Tips

Day of week is the only field in which you must enter characters instead of numbers. Its options are: SUN, MON, TUE, WED, THU, FRI and SAT.
The characters "?" and "*" will display all the fields' values.
The character "-" is a range between two values. For example, 2-5 will display: 2 3 4 5.
The character "," can be used between multiple entries from any field to bring their respective values to output. For example: SUN,WED,FRI would display: 0 3 5.

Running the app

The console application contains this structure:

app01

Inside Program.cs, the CronJob class will be instatiated after the user enter the cron string:

app02

The Cronjob's CheckLine method is responsible for checking the user's input. The first validation occurs at the number of required fields. Then each field receives inner validations from the GetValue method:

app03

Each field has its own validation class:

app04

All of them implements the BaseValidation class, whose GeneralValidation method is responsible for validating the special characters and treating the output accordingly.

Checking "?" and "*":

app05

Checking "-":

app06

Checking ",":

app07

If none of them are used, the field's respective callback function will be executed. For example:

app08

When running the app the positive output will be displayed this way:

app09

And a negative output will be like this:

app10

Testing the app

The xUnit project contains this structure:

test01

The TheoryTest.cs will test multiple entries and expect for specific warnings to return. For example:

test02

Each warning has its own error code to be identified during unit tests.
LineTest method will wait for the warning containing "000" because it belongs to a validation inside Cronjob.cs.
The GetOutput method is the one responsible for checking the desired output:

test03

The FactTest.cs will test for positive results by sending fixed values and expecting all validations to be flawless:

test04

The Visual Studio 2019's Test Manager will show the unit tests this way after running successfully:

test05

You can see the the output of any unit test, both Fact or Theory:

test06

This is an example of a Fact after a successful execution:

test07

And this one is a Theory example with its desired warning:

test08

About

Simulating a Cronjob with .Net Core and xUnit.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages