private static void ExecuteSendmailNTimes(SomeService someService, int times) { for (int i = 0; i < times; i++) { someService.SendEmailIfSomethingGoneWrong(); } }
private static void ExecuteSendMailNTimesParallel(SomeService someService, int times) { Parallel.For(0, times, new ParallelOptions { MaxDegreeOfParallelism = 10 }, (i) => { someService.SendEmailIfSomethingGoneWrong(); }); }
public void SendMailOnceAminuteMultiple() { // ARRANGE var someService = new SomeService(); someService.SendMailEvery = TimeSpan.FromMinutes(1); // ACT ExecuteSendmailNTimes(someService, times: 100); // ASSERT Assert.AreEqual(1, someService.EmailsSent); }
public void SendMailOnceAminuteSimple() { // ARRANGE var someService = new SomeService(); someService.SendMailEvery = TimeSpan.FromMinutes(1); // ACT someService.SendEmailIfSomethingGoneWrong(); // ASSERT Assert.AreEqual(1, someService.EmailsSent); }
public void SendMailOnce10SecondsAndThenWaitForElapsedMultipleParallel() { // ARRANGE var someService = new SomeService(); someService.SendMailEvery = TimeSpan.FromSeconds(10); // ACT ExecuteSendMailNTimesParallel(someService, times: 10); Thread.Sleep(TimeSpan.FromSeconds(10)); ExecuteSendMailNTimesParallel(someService, times: 4); // ASSERT Assert.AreEqual(2, someService.EmailsSent); }
public void SendMailOnce10SecondsAndThenWaitForElapsed() { // ARRANGE var someService = new SomeService(); someService.SendMailEvery = TimeSpan.FromSeconds(10); // ACT ExecuteSendmailNTimes(someService, times: 10); Thread.Sleep(TimeSpan.FromSeconds(10)); someService.SendEmailIfSomethingGoneWrong(); // ASSERT Assert.AreEqual(2, someService.EmailsSent); }