public void TimeOfRelay(int milisec) { Mock <IConfigController> mockConfigController = new Mock <IConfigController>(); mockConfigController.SetupGet(cfg => cfg.Config).Returns(new DTO.ConfigDTO() { RepeatConfig = new DTO.RepeatConfigDTO() { Delay = milisec, NumberOfRepetitions = 1 } }); IRepeatController repeatController = new RepeatController(mockConfigController.Object); Stopwatch stopwatch = new Stopwatch(); repeatController.Start(() => { stopwatch.Start(); }); stopwatch.Stop(); int toleration = 50; Assert.IsTrue(milisec <= stopwatch.ElapsedMilliseconds && milisec + toleration >= stopwatch.ElapsedMilliseconds); }
public void QuantityRepeat(int quantity) { Mock <IConfigController> mockConfigController = new Mock <IConfigController>(); mockConfigController.SetupGet(cfg => cfg.Config).Returns(new DTO.ConfigDTO() { RepeatConfig = new DTO.RepeatConfigDTO() { Delay = 1, NumberOfRepetitions = quantity } }); IRepeatController repeatController = new RepeatController(mockConfigController.Object); int i = 0; repeatController.Start(() => { i++; }); Assert.AreEqual(quantity, i); }