private void OnHeightAndSpeedChanged(HeightSpeedDetails details) { History.PushBack(details); _logger.Debug($"History: {string.Join ( ',' , History )}"); if (History.Size < History.Capacity) { return; } var height = History [0].Height; var allSameHeight = History.All(x => x.Height == height); if (allSameHeight) { throw new ApplicationException(HeightDidNotChange); } _logger.Debug("Good, height changed"); if (History.Count() >= MinimumNumberOfItems && History.All(x => x.Speed == 0)) { throw new ApplicationException(SpeedWasZero); } _logger.Debug("Good, speed changed"); }
public void Initialize( ) { _scheduler = new TestScheduler( ); _logger = Substitute.For <ILogger> ( ); _heightAndSpeed = Substitute.For <IDeskHeightAndSpeed> ( ); _executor = Substitute.For <IDeskCommandExecutor> ( ); _subjectFinished = new Subject <uint> ( ); _subjectHeightAndSpeed = new Subject <HeightSpeedDetails> ( ); _heightAndSpeed.HeightAndSpeedChanged .Returns(_subjectHeightAndSpeed); _heightAndSpeed.Height .Returns(SomeHeight); _details1 = new HeightSpeedDetails(DateTimeOffset.Now, 1u, 2); _details2 = new HeightSpeedDetails(DateTimeOffset.Now, 11u, 22); _detailsZeroHeight = new HeightSpeedDetails(DateTimeOffset.Now, 0u, 22); _executor.Up( ) .Returns(true); _executor.Down( ) .Returns(true); _executor.Stop( ) .Returns(true); }
public void Speed_ForInvoked_Instance( HeightSpeedDetails sut, [Freeze] int speed) { sut.Speed .Should( ) .Be(speed); }
public void Height_ForInvoked_Instance( HeightSpeedDetails sut, [Freeze] uint height) { sut.Height .Should( ) .Be(height); }
public void Timestamp_ForInvoked_Instance( HeightSpeedDetails sut, [Freeze] DateTimeOffset timestamp) { sut.Timestamp .Should( ) .Be(timestamp); }
private void OnHeightAndSpeedChanged(HeightSpeedDetails details) { var heightInCm = Convert.ToInt32(Math.Round(details.Height / 100.0)); _creator.Update(NotifyIcon, heightInCm); _logger.Debug($"Height: {heightInCm}"); }
public void Initialize( ) { _logger = Substitute.For <ILogger> ( ); _scheduler = new TestScheduler( ); _providerFactory = Substitute.For <IInitialHeightAndSpeedProviderFactory> ( ); _monitorFactory = Substitute.For <IDeskMovementMonitorFactory> ( ); _executor = Substitute.For <IDeskCommandExecutor> ( ); _heightAndSpeed = Substitute.For <IDeskHeightAndSpeed> ( ); _calculator = Substitute.For <IStoppingHeightCalculator> ( ); _subjectHeightAndSpeed = new Subject <HeightSpeedDetails> ( ); _subjectFinished = new Subject <uint> ( ); _provider = Substitute.For <IInitialHeightProvider> ( ); _heightMonitor = Substitute.For <IDeskHeightMonitor> ( ); _providerFactory.Create(Arg.Any <IDeskCommandExecutor> ( ), Arg.Any <IDeskHeightAndSpeed> ( )) .Returns(_provider); _provider.Finished .Returns(_subjectFinished); _heightAndSpeed.HeightAndSpeedChanged .Returns(_subjectHeightAndSpeed); _heightAndSpeed.Height .Returns(DefaultHeight); _heightAndSpeed.Speed .Returns(DefaultSpeed); _details1 = new HeightSpeedDetails(DateTimeOffset.Now, 123u, 321); _heightMonitor.IsHeightChanging( ) .Returns(true); _monitor = Substitute.For <IDeskMovementMonitor> ( ); _monitorFactory.Create(_heightAndSpeed) .Returns(_monitor); _finished = Substitute.For <ISubject <uint> > ( ); _disposable = Substitute.For <IDisposable> ( ); _finished.Subscribe(Arg.Any <IObserver <uint> > ( )) .Returns(_disposable); _disposableProvider = Substitute.For <IInitialHeightProvider> ( ); _disposableProvider.Finished .Returns(_finished); }
public void ToString_ForInvoked_Instance( HeightSpeedDetails sut, [Freeze] DateTimeOffset timestamp, [Freeze] uint height, [Freeze] int speed) { var expected = $"Timestamp = {timestamp:O}, " + $"Height = {height}, " + $"Speed = {speed}"; sut.ToString( ) .Should( ) .Be(expected); }
public void Initialize( ) { _logger = Substitute.For <ILogger> ( ); _scheduler = new TestScheduler( ); _deskMover = Substitute.For <IDeskMover> ( ); _executer = Substitute.For <IDeskCommandExecutor> ( ); _heightAndSpeed = Substitute.For <IDeskHeightAndSpeed> ( ); _subjectHeightAndSpeed = new Subject <HeightSpeedDetails> ( ); _heightAndSpeed.HeightAndSpeedChanged .Returns(_subjectHeightAndSpeed); _details = new HeightSpeedDetails(DateTimeOffset.Now, 123u, 321); }
private void OnHeightAndSpeedChanged(HeightSpeedDetails details) { if (!IsLocked) { return; } if (_deskMover.IsAllowedToMove) { return; } _logger.Information("Manual move detected. Calling 'Stop'!"); _logger.Debug($"{details}"); _executer.Stop( ); }
public void Initialize( ) { _logger = Substitute.For <ILogger> ( ); _scheduler = new TestScheduler( ); _heightAndSpeed = Substitute.For <IDeskHeightAndSpeed> ( ); _subjectHeightAndSpeed = new Subject <HeightSpeedDetails> ( ); _heightAndSpeed.HeightAndSpeedChanged .Returns(_subjectHeightAndSpeed); _details1 = new HeightSpeedDetails(DateTimeOffset.Now, 1u, 2); _details2 = new HeightSpeedDetails(DateTimeOffset.Now, 3u, 4); _details3 = new HeightSpeedDetails(DateTimeOffset.Now, 5u, 6); _details4SameHeightAsDetails1 = new HeightSpeedDetails(DateTimeOffset.Now, 1u, 22); _details5SameHeightAsDetails1 = new HeightSpeedDetails(DateTimeOffset.Now, 1u, 33); _details6WithSpeedZero = new HeightSpeedDetails(DateTimeOffset.Now, 1u, 0); _details7WithSpeedZero = new HeightSpeedDetails(DateTimeOffset.Now, 3u, 0); _details8WithSpeedZero = new HeightSpeedDetails(DateTimeOffset.Now, 5u, 0); }
private void OnHeightAndSpeedChanged(HeightSpeedDetails details) { Height = details.Height; if (HasReceivedHeightAndSpeed) { return; } if (details.Height <= 0) { _logger.Information("Received invalid " + $"height {details.Height} and " + $"speed {details.Speed} ..."); return; } _subjectFinished.OnNext(Height); HasReceivedHeightAndSpeed = true; _logger.Information("Received valid " + $"height {details.Height}."); }
private void OnHeightAndSpeedChanged(HeightSpeedDetails details) { Height = details.Height; Speed = details.Speed; }