public void CleanUp_ForOneExpiredDeviceInCollection_RemovesDeviceFromCollection( ILogger logger, IDateTimeOffset dateTimeOffset, IDeviceMonitor deviceMonitor, ISubject <IDevice> deviceExpired, ObservableTimerFactory factory, TestScheduler scheduler, IDevice device) { deviceMonitor.DiscoveredDevices .Returns(new[] { device }); var sut = new DeviceMonitorWithExpiry(logger, dateTimeOffset, deviceMonitor, deviceExpired, factory, scheduler); dateTimeOffset.Ticks .Returns(sut.TimeOut.Ticks); dateTimeOffset.Now .Returns(dateTimeOffset); device.BroadcastTime .Ticks .Returns(0); scheduler.AdvanceBy(sut.TimeOut.Ticks + 1); deviceMonitor.Received() .RemoveDevice(device); }
public void CleanUp_ForOneExpiredDeviceInCollection_NotifiesDeviceExpired( ILogger logger, IDateTimeOffset dateTimeOffset, IDeviceMonitor deviceMonitor, Subject <IDevice> deviceExpired, ObservableTimerFactory factory, TestScheduler scheduler, IDevice device) { var sut = new DeviceMonitorWithExpiry(logger, dateTimeOffset, deviceMonitor, deviceExpired, factory, scheduler); IDevice expiredDevice = null; using var disposable = sut.DeviceExpired .Subscribe(expired => expiredDevice = expired); deviceExpired.OnNext(device); scheduler.AdvanceBy(sut.TimeOut.Ticks); expiredDevice.Should() .Be(device); }
public void CleanUp_ForNotExpiredDeviceInCollection_DoesNotNotifyDeviceExpired( ILogger logger, IDateTimeOffset dateTimeOffset, IDeviceMonitor deviceMonitor, ISubject <IDevice> deviceExpired, ObservableTimerFactory factory, TestScheduler scheduler, IDevice device) { deviceMonitor.DiscoveredDevices .Returns(new[] { device }); var sut = new DeviceMonitorWithExpiry(logger, dateTimeOffset, deviceMonitor, deviceExpired, factory, scheduler); dateTimeOffset.Ticks .Returns(sut.TimeOut.Ticks); dateTimeOffset.Now .Returns(dateTimeOffset); device.BroadcastTime .Ticks .Returns(sut.TimeOut.Ticks / 2); scheduler.AdvanceBy(sut.TimeOut.Ticks); deviceExpired.DidNotReceive() .Publish(device); }
public void Create_ForInvoked_ReturnsInstance( ObservableTimerFactory sut, IScheduler scheduler) { sut.Create(TimeSpan.FromSeconds(10), scheduler) .Should() .NotBeNull(); }