public async Task NDFirstOrTimeOutShouldReturnCorrectNullOnCancel() { // ARRANGE await InitializeFakeDaemon().ConfigureAwait(false); (EntityState Old, EntityState New)? result = null; using CancellationTokenSource _cancelSource = new(10); // ACT DefaultDaemonRxApp.Entity("binary_sensor.pir") .StateChanges .Subscribe(_ => result = DefaultDaemonRxApp.Entity("binary_sensor.pir2").StateChanges.NDFirstOrTimeout(TimeSpan.FromMilliseconds(300), _cancelSource.Token)); DefaultHassClientMock.AddChangedEvent("binary_sensor.pir", "off", "on"); await RunFakeDaemonUntilTimeout().ConfigureAwait(false); // ASSERT Assert.Null(result); }
public async Task UsingEntityNewEventShouldNotCallFunction() { // ARRANGE await InitializeFakeDaemon().ConfigureAwait(false); var called = false; // ACT DefaultDaemonRxApp.Entity("binary_sensor.other_pir") .StateChanges .Subscribe(_ => called = true); DefaultHassClientMock.AddChangedEvent("binary_sensor.pir", "off", "on"); await RunFakeDaemonUntilTimeout().ConfigureAwait(false); // ASSERT Assert.False(called); }
public async Task NDFirstOrTimeOutShouldReturnCorrectStateChange() { // ARRANGE using var waitFor = new CancellationTokenSource(300); await InitializeFakeDaemon().ConfigureAwait(false); var task = Task.Run(async() => { await Task.Delay(20).ConfigureAwait(false); DefaultHassClientMock.AddChangedEvent("binary_sensor.pir2", "on", "off"); }); var result = DefaultDaemonRxApp.Entity("binary_sensor.pir2").StateChanges.NDFirstOrTimeout(TimeSpan.FromMilliseconds(300)); await RunFakeDaemonUntilTimeout().ConfigureAwait(false); // ASSERT Assert.NotNull(result); }