Esempio n. 1
0
 private static void ExecuteSendmailNTimes(SomeService someService, int times)
 {
     for (int i = 0; i < times; i++)
     {
         someService.SendEmailIfSomethingGoneWrong();
     }
 }
Esempio n. 2
0
 private static void ExecuteSendMailNTimesParallel(SomeService someService, int times)
 {
     Parallel.For(0, times, new ParallelOptions {
         MaxDegreeOfParallelism = 10
     }, (i) =>
     {
         someService.SendEmailIfSomethingGoneWrong();
     });
 }
Esempio n. 3
0
        public void SendMailOnceAminuteMultiple()
        {
            // ARRANGE
            var someService = new SomeService();

            someService.SendMailEvery = TimeSpan.FromMinutes(1);
            // ACT
            ExecuteSendmailNTimes(someService, times: 100);
            // ASSERT
            Assert.AreEqual(1, someService.EmailsSent);
        }
Esempio n. 4
0
        public void SendMailOnceAminuteSimple()
        {
            // ARRANGE
            var someService = new SomeService();

            someService.SendMailEvery = TimeSpan.FromMinutes(1);
            // ACT
            someService.SendEmailIfSomethingGoneWrong();
            // ASSERT
            Assert.AreEqual(1, someService.EmailsSent);
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        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);
        }