Radarr/NzbDrone.Core.Test/ProviderTests/AnalyticsProviderTests/AnalyticsProviderFixture.cs

147 lines
4.6 KiB
C#
Raw Normal View History

2012-02-15 02:20:32 +00:00
using System;
using System.Linq;
2012-01-25 03:09:49 +00:00
using DeskMetrics;
using Moq;
using NUnit.Framework;
using NzbDrone.Common;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Core;
2012-01-25 03:09:49 +00:00
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.ProviderTests.AnalyticsProviderTests
{
// ReSharper disable InconsistentNaming
public class AnalyticsProviderFixture : CoreTest
{
[SetUp]
public void Setup()
{
Mocker.GetMock<ConfigProvider>().SetupGet(c => c.UpdateUrl).Returns(UpdateProvider.DEFAULT_UPDATE_URL);
}
2012-02-15 02:20:32 +00:00
private void WithStageClient()
{
Mocker.SetConstant(new DeskMetricsClient(Guid.NewGuid().ToString(), AnalyticsProvider.DESKMETRICS_TEST_ID, new Version(9, 9, 9)));
}
2012-01-25 03:09:49 +00:00
[Test]
public void checkpoint_should_stop_existing_start_then_start_again()
{
Mocker.GetMock<IDeskMetricsClient>().SetupGet(c => c.Started).Returns(true);
var provider = Mocker.Resolve<AnalyticsProvider>();
provider.Checkpoint();
2012-02-15 02:20:32 +00:00
Mocker.GetMock<IDeskMetricsClient>().Verify(c => c.Start(), Times.Once());
Mocker.GetMock<IDeskMetricsClient>().Verify(c => c.Stop(), Times.Once());
2012-01-25 03:09:49 +00:00
}
[Test]
public void checkpoint_should_not_stop_existing_if_not_started()
{
Mocker.GetMock<IDeskMetricsClient>().SetupGet(c => c.Started).Returns(false);
var provider = Mocker.Resolve<AnalyticsProvider>();
provider.Checkpoint();
Mocker.GetMock<IDeskMetricsClient>().Verify(c => c.Start(), Times.Once());
Mocker.GetMock<IDeskMetricsClient>().Verify(c => c.Stop(), Times.Never());
}
[Test]
public void new_install_should_be_registered()
{
EnvironmentProvider.RegisterNewInstall = true;
2012-02-15 02:20:32 +00:00
var provider = Mocker.Resolve<AnalyticsProvider>();
provider.Checkpoint();
Mocker.GetMock<IDeskMetricsClient>().Verify(c => c.RegisterInstall(), Times.Once());
}
[Test]
public void new_install_should_only_be_registered_on_first_call()
{
EnvironmentProvider.RegisterNewInstall = true;
2012-01-25 03:09:49 +00:00
var provider = Mocker.Resolve<AnalyticsProvider>();
2012-02-15 02:20:32 +00:00
provider.Checkpoint();
provider.Checkpoint();
2012-01-25 03:09:49 +00:00
provider.Checkpoint();
Mocker.GetMock<IDeskMetricsClient>().Verify(c => c.RegisterInstall(), Times.Once());
}
[Test]
public void upgrade_should_not_register_install()
{
EnvironmentProvider.RegisterNewInstall = false;
2012-01-25 03:09:49 +00:00
var provider = Mocker.Resolve<AnalyticsProvider>();
provider.Checkpoint();
Mocker.GetMock<IDeskMetricsClient>().Verify(c => c.RegisterInstall(), Times.Never());
}
[Test]
public void shouldnt_register_anything_if_not_on_master_branch()
{
EnvironmentProvider.RegisterNewInstall = false;
Mocker.GetMock<ConfigProvider>().SetupGet(c => c.UpdateUrl).Returns("http://update.nzbdrone.com/master_auto/");
Mocker.GetMock<IDeskMetricsClient>(MockBehavior.Strict);
Mocker.Resolve<AnalyticsProvider>().Checkpoint();
}
[Test]
public void new_install_shouldnt_register_anything_if_not_on_master_branch()
{
EnvironmentProvider.RegisterNewInstall = true;
Mocker.GetMock<ConfigProvider>().SetupGet(c => c.UpdateUrl).Returns("http://update.nzbdrone.com/master_auto/");
Mocker.GetMock<IDeskMetricsClient>(MockBehavior.Strict);
Mocker.Resolve<AnalyticsProvider>().Checkpoint();
}
2012-02-15 02:20:32 +00:00
[Test]
public void should_be_able_to_call_deskmetrics_using_test_appid()
{
EnvironmentProvider.RegisterNewInstall = true;
2012-02-15 02:20:32 +00:00
Mocker.Resolve<AnalyticsProvider>().Checkpoint();
}
[TestCase("http://update.nzbdrone.com/master/")]
[TestCase("http://update.nzbdrone.com/master//")]
[TestCase("http://update.nzbdrone.com/master")]
[TestCase("http://update.nzbdrone.com/master ")]
[TestCase("http://update.nzbdrone.com/master/ ")]
[TestCase("http://UPDATE.nzbdrone.COM/master/ ")]
public void should_still_work_if_url_is_slightly_diffrent(string url)
{
Mocker.GetMock<ConfigProvider>().SetupGet(c => c.UpdateUrl).Returns(url);
var provider = Mocker.Resolve<AnalyticsProvider>();
provider.Checkpoint();
Mocker.GetMock<IDeskMetricsClient>().Verify(c => c.Start(), Times.Once());
}
2012-02-15 02:20:32 +00:00
2012-01-25 03:09:49 +00:00
}
}