public void GetFailCommunicationTest() { Mock <IDeviceRepository> deviceRepo = new Mock <IDeviceRepository>(); Mock <ITelemetryRepository> telemetryRepo = new Mock <ITelemetryRepository>(); DeviceService service = new DeviceService(deviceRepo.Object, telemetryRepo.Object); deviceRepo.Setup(o => o.GetFailsCommunicationBetween(7, It.IsAny <int>())) .Returns(deviceList); IEnumerable <Device> devices = service.CheckDeviceCommunication(7, 8); Check.That(devices).ContainsOnlyElementsThatMatch(e => e.LastCommunication < DateTime.Now.AddMinutes(-(7 * 60))); //THEN deviceRepo.Verify(a => a.GetFailsCommunicationBetween(7, 8), Times.Once); }