You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.4 KiB
50 lines
1.4 KiB
using System;
|
|
using System.Text;
|
|
using Moq;
|
|
using NUnit.Framework;
|
|
using NzbDrone.Common.Cloud;
|
|
using NzbDrone.Common.Http;
|
|
using NzbDrone.Common.Serializer;
|
|
using NzbDrone.Core.HealthCheck.Checks;
|
|
using NzbDrone.Core.Test.Framework;
|
|
using NzbDrone.Test.Common;
|
|
|
|
namespace NzbDrone.Core.Test.HealthCheck.Checks
|
|
{
|
|
[TestFixture]
|
|
public class SystemTimeCheckFixture : CoreTest<SystemTimeCheck>
|
|
{
|
|
[SetUp]
|
|
public void Setup()
|
|
{
|
|
Mocker.SetConstant<ISonarrCloudRequestBuilder>(new SonarrCloudRequestBuilder());
|
|
}
|
|
|
|
private void GivenServerTime(DateTime dateTime)
|
|
{
|
|
var json = new ServiceTimeResponse {DateTimeUtc = dateTime}.ToJson();
|
|
|
|
Mocker.GetMock<IHttpClient>()
|
|
.Setup(s => s.Execute(It.IsAny<HttpRequest>()))
|
|
.Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), Encoding.ASCII.GetBytes(json)));
|
|
}
|
|
|
|
[Test]
|
|
public void should_not_return_error_when_system_time_is_close_to_server_time()
|
|
{
|
|
GivenServerTime(DateTime.UtcNow);
|
|
|
|
Subject.Check().ShouldBeOk();
|
|
}
|
|
|
|
[Test]
|
|
public void should_return_error_when_system_time_is_more_than_one_day_from_server_time()
|
|
{
|
|
GivenServerTime(DateTime.UtcNow.AddDays(2));
|
|
|
|
Subject.Check().ShouldBeError();
|
|
ExceptionVerification.ExpectedErrors(1);
|
|
}
|
|
}
|
|
}
|