Esempio n. 1
0
        public void ToString_ShouldBeDescriptiveForFinished()
        {
            var status = JobRunStatus.Create("do something")
                         .ToRunningState(StartTime)
                         .ToFinishedState(Result.Failure("failed!"), StartTime.Add(TimeSpan.FromSeconds(5)));

            status.ToString().Should().Be($"Task {status.Description} ({status.Id}) - {status.Result}");
        }
Esempio n. 2
0
        public void Duration_ShouldBeBasedOnCurrentDate()
        {
            var status = JobRunStatus.Create("do something")
                         .ToRunningState(DateTime.Now.Subtract(TimeSpan.FromMinutes(1)));

            status.Duration.HasValue.Should().BeTrue("because the task has started");
            status.Duration.Value.TotalSeconds.Should().BeGreaterOrEqualTo(60);
        }
Esempio n. 3
0
        public void ToString_ShouldBeDescriptiveForRunning()
        {
            var status = JobRunStatus.Create("do something").ToRunningState(StartTime);

            status.ToString()
            .Should()
            .Be($"Task {status.Description} ({status.Id}) - Running for {(int)status.Duration.Value.TotalSeconds} seconds");
        }
Esempio n. 4
0
        public void Duration_ShouldBeBasedOnStartAndCompleteDate()
        {
            var status = JobRunStatus.Create("do something")
                         .ToRunningState(StartTime)
                         .ToFinishedState(Result.Successful(), StartTime.AddMinutes(2));

            status.Duration.HasValue.Should().BeTrue("because the task has finished");
            status.Duration.Value.TotalSeconds.Should().Be(120);
        }
Esempio n. 5
0
        public void NullStatus_ShouldBeIgnored()
        {
            var presenter       = new FakeMessagePresenter();
            var statusPresenter = new JobRunStatusPresenter(presenter);

            statusPresenter.BeginPresenting(JobRunStatus.Create("task"));
            presenter.Clear();

            statusPresenter.PresentAnyChangesTo(null);

            presenter.WasMessageShown.Should().BeFalse("because nothing was given to the status presenter");
        }
Esempio n. 6
0
        public void SameMessage_ShouldNotLogAnything()
        {
            var presenter = new FakeMessagePresenter();
            var status    = JobRunStatus.Create("task");

            var statusPresenter = new JobRunStatusPresenter(presenter);

            statusPresenter.BeginPresenting(status);
            presenter.Clear();

            statusPresenter.PresentAnyChangesTo(status);

            presenter.WasMessageShown.Should().BeFalse("because no changes have been made yet");
        }
Esempio n. 7
0
        public void MessageChange_ShouldLogMessageAfterFirstTime()
        {
            var presenter = new FakeMessagePresenter();
            var status    = JobRunStatus.Create("task");

            var statusPresenter = new JobRunStatusPresenter(presenter);

            statusPresenter.BeginPresenting(status);
            statusPresenter.PresentAnyChangesTo(status.WithDifferentMessage("another"));
            presenter.Clear();

            statusPresenter.PresentAnyChangesTo(status.WithDifferentMessage("third"));

            presenter.WasMessageShown.Should().BeTrue("because the message changed");
        }
Esempio n. 8
0
        public void TaskStart_ShouldLogMessage()
        {
            var presenter = new FakeMessagePresenter();
            var status    = JobRunStatus.Create("task");

            var statusPresenter = new JobRunStatusPresenter(presenter);

            statusPresenter.BeginPresenting(status);

            presenter.Clear();

            var copy = status.ToRunningState(StartTime);

            statusPresenter.PresentAnyChangesTo(copy);

            presenter.WasMessageShown.Should().BeTrue("because the task started");
        }
Esempio n. 9
0
        public void TwoMessagesInARow_ShouldNotBePresented()
        {
            var presenter = new FakeMessagePresenter();
            var status    = JobRunStatus.Create("task");

            var statusPresenter = new JobRunStatusPresenter(presenter);

            statusPresenter.BeginPresenting(status);
            var another = status.WithDifferentMessage("another");

            statusPresenter.PresentAnyChangesTo(another);
            presenter.Clear();

            statusPresenter.PresentAnyChangesTo(another);

            presenter.WasMessageShown.Should().BeFalse("because the message did not change");
        }
Esempio n. 10
0
        public void Copy_ShouldCopyCurrentMessageIndex()
        {
            var status = JobRunStatus.Create("with message index");

            status.CurrentMessage       = "great times";
            status.CurrentMessageIndex  = 22;
            status.PreviousMessageIndex = 20;
            status.Messages             = new[] { "good times", "great times" };

            var copy = status.Copy();

            copy.CurrentMessageIndex.Should().Be(22);
            copy.PreviousMessageIndex.Should().Be(20);
            copy.Messages.Length.Should().Be(2);
            copy.Messages[0].Should().Be("good times");
            copy.Messages[1].Should().Be("great times");
        }
Esempio n. 11
0
        public void DifferentCurrentMessage_ShouldLogMessage()
        {
            var presenter = new FakeMessagePresenter();
            var status    = JobRunStatus.Create("task");

            var statusPresenter = new JobRunStatusPresenter(presenter);

            statusPresenter.BeginPresenting(status);

            presenter.Clear();

            var copy = status.ToRunningState(StartTime);

            copy.CurrentMessage = "different message";
            statusPresenter.PresentAnyChangesTo(copy);

            presenter.WasMessageShown.Should().BeTrue("because the message changed");
            presenter.MessageShown.Should().Be($"Latest: {copy.CurrentMessage}");
        }
Esempio n. 12
0
        public void Exception_ShouldSetAutoresetEventAndFail()
        {
            var jobServer = new Mock <IJobServer>();

            jobServer.Setup(s => s.GetJobRunStatus(It.IsAny <Guid>(), It.IsAny <int>())).Throws <HttpRequestException>();
            var autoResetEvent   = new FakeAutoResetEvent();
            var fakeTimerFactory = new FakeTimerFactory();

            var waiter = new SchedulerWaiter(() => jobServer.Object, autoResetEvent, fakeTimerFactory, new FakeMessagePresenter());

            autoResetEvent.WhatToDoDuringWaitOne = () =>
            {
                fakeTimerFactory.FireTimerAction();
            };

            var result = waiter.WaitForTaskToComplete(JobRunStatus.Create("sample task"));

            result.Result.IsSuccess.Should().BeFalse("because an exception was thrown by the scheduler");
            result.Result.FailureDescription.Should()
            .NotBeEmpty("because it should contain a description of what happened");
        }
Esempio n. 13
0
        public void ToString_ShouldBeDescriptiveForNotRun()
        {
            var status = JobRunStatus.Create("do something");

            status.ToString().Should().Be($"Task {status.Description} ({status.Id}) - Not yet run");
        }
Esempio n. 14
0
        public void Duration_ShouldBeNullBeforeRunning()
        {
            var status = JobRunStatus.Create("do something");

            status.Duration.Should().BeNull("because it hasn't yet started");
        }