0

This question is regarding unit testing the scheduled methods.

I am using FluentScheduler to achieve the scheduled job execution.

Here is my Execute method

public void Execute()
{
   var provisioningRepo = _containerFactory.GetInstance<IProvisioningRepo>();
   var discounts = provisioningRepo.GetDiscounts();
   if (discounts.Count == 0)
     return;

   foreach (var discount in discounts)
   {
       //doing some logics
   }    
}

Here is my `app.config' entry for scheduler.

      <add key="myMinitueSchedule" value="60" />

Question 1: How do I test method executed at right time? that is every 60 seconds?

Question 2: Logic inside execute need to be tested independent to scheduler?

kudlatiger
  • 3,028
  • 8
  • 48
  • 98

1 Answers1

2

According to your question 2: The logic inside the method Execute() can be tested as follows: Just outsorce the "logic operations" on your list discounts. Then you are able to unit test the method MakeLogicThingsWithDiscount logic separately:

public void Execute()
{
   var provisioningRepo = _containerFactory.GetInstance<IProvisioningRepo>();
   var discounts = provisioningRepo.GetDiscounts();
   if (discounts.Count == 0)
     return;
   discounts = MakeLogicThingsWithDiscount(discounts);
}

private IEnumerable<Discount> MakeLogicThingsWithDiscount(IEnumerable<Discount> discounts)
{
   //make logic things here
}
CJ Thiele
  • 43
  • 8
  • How do I create mock for classes which has multiple inheritance? – kudlatiger Jul 23 '18 at 06:45
  • I don't understand your question completely. The condition for mocking is that the class is able for instantiation. Therefor you have to implement a constructor. Multiple inheritance doesn't prohibit the instantiation of a class. So whats your problem exactly? – CJ Thiele Jul 23 '18 at 08:50
  • https://stackoverflow.com/questions/51473303/how-do-i-unit-test-the-method-which-has-dependency-on-base-classes – kudlatiger Jul 23 '18 at 08:56
  • I can't comment your other post because of reputation. Please write the code of the base class in your post too. – CJ Thiele Jul 23 '18 at 09:45
  • Like Nkosi said: Show your current version of UnitTest too, so that the context is more understandable. – CJ Thiele Jul 23 '18 at 12:41
  • updated here: https://stackoverflow.com/questions/51473303/how-do-i-unit-test-the-method-which-has-dependency-on-base-classes – kudlatiger Jul 23 '18 at 14:06