private void Bootstrap(CommandLineArguments commandLineArguments) { var server = BootstrapServer(commandLineArguments.BaseUrl); var authenticationService = new AuthenticationService(server); statusPublisher = new StatusPublisher(server, authenticationService); var standUpModel = new StandUpModel(new DispatcherTimerWrapper(), commandLineArguments.DeskStateTimes.SittingTime, commandLineArguments.DeskStateTimes.StandingTime); standUpModel.DeskStateChanged += async(s, f) => await statusPublisher.PublishChangedDeskState(f.NewDeskState); var standUpViewModel = new StandUpViewModel(standUpModel, authenticationService, this); standUpViewModel.PropertyChanged += (sender, eventArgs) => { if (eventArgs.PropertyName.Equals("AuthenticationStatus")) { Task.Run(async() => await statusPublisher.PublishChangedDeskState(standUpModel.DeskState)); } }; MainWindow = new MainWindow(standUpViewModel); MainWindow.Show(); if (commandLineArguments.Update) { updateTask = Task.Run(async() => { using (var mgr = new UpdateManager(Settings.Default.UpdateUrl, "StandUpTimer")) { await mgr.UpdateApp(); } }); } }
public void Skipping_is_the_same_as_a_timer_tick() { var target = new StandUpModel(A.Fake <ITimer>(), SittingTime, StandingTime); Assert.That(target.DeskState, Is.EqualTo(DeskState.Sitting)); target.Skip(); Assert.That(target.DeskState, Is.EqualTo(DeskState.Standing)); }
public void Raise_an_event_when_the_state_is_changed() { var target = new StandUpModel(A.Fake <ITimer>(), SittingTime, StandingTime); var raised = false; target.DeskStateChanged += (s, e) => raised = true; target.Skip(); Assert.That(raised, Is.True); }
public void When_the_timer_ticks_Change_the_desk_state() { var timer = A.Fake <ITimer>(); var target = new StandUpModel(timer, SittingTime, StandingTime); Assert.That(target.DeskState, Is.EqualTo(DeskState.Sitting)); timer.Tick += Raise.WithEmpty().Now; Assert.That(target.DeskState, Is.EqualTo(DeskState.Standing)); timer.Tick += Raise.WithEmpty().Now; Assert.That(target.DeskState, Is.EqualTo(DeskState.Sitting)); }
public void The_current_leg_is_different_for_each_desk_state() { var timer = A.Fake <ITimer>(); var target = new StandUpModel(timer, SittingTime, StandingTime); Assert.That(target.CurrentLeg, Is.EqualTo(SittingTime)); timer.Tick += Raise.WithEmpty().Now; target.NewDeskStateStarted(); Assert.That(target.CurrentLeg, Is.EqualTo(StandingTime)); timer.Tick += Raise.WithEmpty().Now; target.NewDeskStateStarted(); Assert.That(target.CurrentLeg, Is.EqualTo(SittingTime)); }
public StandUpViewModel(StandUpModel model, IAuthenticationService authenticationService, IBringToForeground bringToForeground) { this.model = model; this.authenticationService = authenticationService; this.bringToForeground = bringToForeground; model.DeskStateChanged += (sender, args) => DeskStateEnded(); SetImageAccordingToDeskState(); ExitButtonVisibility = Visibility.Hidden; OkButtonVisibility = Visibility.Collapsed; CreativeCommonsVisibility = Visibility.Hidden; authenticationService.AuthenticationStateChanged += (sender, args) => OnPropertyChanged(() => AuthenticationStatus); updateTimer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(1) }; updateTimer.Tick += OnUpdateTimerTicked; updateTimer.Start(); }
public void The_change_time_is_the_time_when_the_new_desk_state_ends() { var now = new DateTime(2014, 5, 11); TestableDateTime.DateTime = A.Fake <IDateTime>(); A.CallTo(() => TestableDateTime.DateTime.Now).Returns(now); var timer = A.Fake <ITimer>(); var target = new StandUpModel(timer, SittingTime, StandingTime); Assert.That(target.ChangeTime, Is.EqualTo(now.Add(SittingTime))); timer.Tick += Raise.WithEmpty().Now; target.NewDeskStateStarted(); Assert.That(target.ChangeTime, Is.EqualTo(now.Add(StandingTime))); timer.Tick += Raise.WithEmpty().Now; target.NewDeskStateStarted(); Assert.That(target.ChangeTime, Is.EqualTo(now.Add(SittingTime))); }
protected override async Task OnInitializedAsync() { Model = new StandUpModel(); HasCredentials = (await CredentialService.GetCredentialsAsync()).Any(); GenerateLabel = "Generate!"; }