diff --git a/NzbDrone.Common/EnviromentProvider.cs b/NzbDrone.Common/EnviromentProvider.cs index 47c9d0146..92fcab788 100644 --- a/NzbDrone.Common/EnviromentProvider.cs +++ b/NzbDrone.Common/EnviromentProvider.cs @@ -43,7 +43,7 @@ namespace NzbDrone.Common public static Guid UGuid { get; set; } - public static bool IsNewInstall { get; set; } + public static bool RegisterNewInstall { get; set; } public virtual bool IsUserInteractive { diff --git a/NzbDrone.Common/HttpProvider.cs b/NzbDrone.Common/HttpProvider.cs index 68745ebe3..3f6025565 100644 --- a/NzbDrone.Common/HttpProvider.cs +++ b/NzbDrone.Common/HttpProvider.cs @@ -3,7 +3,6 @@ using System; using System.Diagnostics; using System.IO; using System.Net; -using System.Security.Principal; using System.Text; using NLog; diff --git a/NzbDrone.Core.Test/CentralDispatchFixture.cs b/NzbDrone.Core.Test/CentralDispatchFixture.cs index 50775bbf8..204c84478 100644 --- a/NzbDrone.Core.Test/CentralDispatchFixture.cs +++ b/NzbDrone.Core.Test/CentralDispatchFixture.cs @@ -106,7 +106,7 @@ namespace NzbDrone.Core.Test public void app_should_be_marked_as_new_install_if_db_is_initilized_for_the_first_time() { WithRealDb(); - EnviromentProvider.IsNewInstall.Should().Be(true); + EnviromentProvider.RegisterNewInstall.Should().Be(true); } } diff --git a/NzbDrone.Core.Test/ProviderTests/AnalyticsProviderTests/AnalyticsProviderFixture.cs b/NzbDrone.Core.Test/ProviderTests/AnalyticsProviderTests/AnalyticsProviderFixture.cs index 0bdffe46e..1d84ac77e 100644 --- a/NzbDrone.Core.Test/ProviderTests/AnalyticsProviderTests/AnalyticsProviderFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/AnalyticsProviderTests/AnalyticsProviderFixture.cs @@ -1,4 +1,5 @@ -using System.Linq; +using System; +using System.Linq; using DeskMetrics; using Moq; using NUnit.Framework; @@ -19,6 +20,12 @@ namespace NzbDrone.Core.Test.ProviderTests.AnalyticsProviderTests Mocker.GetMock().SetupGet(c => c.UpdateUrl).Returns(UpdateProvider.DEFAULT_UPDATE_URL); } + + private void WithStageClient() + { + Mocker.SetConstant(new DeskMetricsClient(Guid.NewGuid().ToString(), AnalyticsProvider.DESKMETRICS_TEST_ID, new Version(9, 9, 9))); + } + [Test] public void checkpoint_should_stop_existing_start_then_start_again() { @@ -27,8 +34,8 @@ namespace NzbDrone.Core.Test.ProviderTests.AnalyticsProviderTests provider.Checkpoint(); - Mocker.GetMock().Verify(c=>c.Start(), Times.Once()); - Mocker.GetMock().Verify(c=>c.Stop(), Times.Once()); + Mocker.GetMock().Verify(c => c.Start(), Times.Once()); + Mocker.GetMock().Verify(c => c.Stop(), Times.Once()); } [Test] @@ -46,10 +53,24 @@ namespace NzbDrone.Core.Test.ProviderTests.AnalyticsProviderTests [Test] public void new_install_should_be_registered() { - EnviromentProvider.IsNewInstall = true; + EnviromentProvider.RegisterNewInstall = true; + + var provider = Mocker.Resolve(); + + provider.Checkpoint(); + + Mocker.GetMock().Verify(c => c.RegisterInstall(), Times.Once()); + } + + [Test] + public void new_install_should_only_be_registered_on_first_call() + { + EnviromentProvider.RegisterNewInstall = true; var provider = Mocker.Resolve(); + provider.Checkpoint(); + provider.Checkpoint(); provider.Checkpoint(); Mocker.GetMock().Verify(c => c.RegisterInstall(), Times.Once()); @@ -58,7 +79,7 @@ namespace NzbDrone.Core.Test.ProviderTests.AnalyticsProviderTests [Test] public void upgrade_should_not_register_install() { - EnviromentProvider.IsNewInstall = false; + EnviromentProvider.RegisterNewInstall = false; var provider = Mocker.Resolve(); @@ -71,7 +92,7 @@ namespace NzbDrone.Core.Test.ProviderTests.AnalyticsProviderTests [Test] public void shouldnt_register_anything_if_not_on_master_branch() { - EnviromentProvider.IsNewInstall = false; + EnviromentProvider.RegisterNewInstall = false; Mocker.GetMock().SetupGet(c => c.UpdateUrl).Returns("http://update.nzbdrone.com/master_auto/"); @@ -83,7 +104,7 @@ namespace NzbDrone.Core.Test.ProviderTests.AnalyticsProviderTests [Test] public void new_install_shouldnt_register_anything_if_not_on_master_branch() { - EnviromentProvider.IsNewInstall = true; + EnviromentProvider.RegisterNewInstall = true; Mocker.GetMock().SetupGet(c => c.UpdateUrl).Returns("http://update.nzbdrone.com/master_auto/"); @@ -92,6 +113,16 @@ namespace NzbDrone.Core.Test.ProviderTests.AnalyticsProviderTests Mocker.Resolve().Checkpoint(); } + [Test] + public void should_be_able_to_call_deskmetrics_using_test_appid() + { + EnviromentProvider.RegisterNewInstall = true; + Mocker.Resolve().Checkpoint(); + } + + + + [TestCase("http://update.nzbdrone.com/master/")] [TestCase("http://update.nzbdrone.com/master//")] @@ -110,6 +141,6 @@ namespace NzbDrone.Core.Test.ProviderTests.AnalyticsProviderTests Mocker.GetMock().Verify(c => c.Start(), Times.Once()); } - + } } diff --git a/NzbDrone.Core/CentralDispatch.cs b/NzbDrone.Core/CentralDispatch.cs index 095f8759f..9d4099121 100644 --- a/NzbDrone.Core/CentralDispatch.cs +++ b/NzbDrone.Core/CentralDispatch.cs @@ -71,10 +71,7 @@ namespace NzbDrone.Core var deskMetricsClient = new DeskMetricsClient(Kernel.Get().UGuid.ToString(), appId, _enviromentProvider.Version); Kernel.Bind().ToConstant(deskMetricsClient); - if (EnviromentProvider.IsProduction) - { - Kernel.Get().Checkpoint(); - } + Kernel.Get().Checkpoint(); } private void InitQuality() diff --git a/NzbDrone.Core/Datastore/Migrations/Migration20110707.cs b/NzbDrone.Core/Datastore/Migrations/Migration20110707.cs index 58a9e075c..f4901672e 100644 --- a/NzbDrone.Core/Datastore/Migrations/Migration20110707.cs +++ b/NzbDrone.Core/Datastore/Migrations/Migration20110707.cs @@ -12,7 +12,7 @@ namespace NzbDrone.Core.Datastore.Migrations protected override void MainDbUpgrade() { //This should not run unless for a clean install - EnviromentProvider.IsNewInstall = true; + EnviromentProvider.RegisterNewInstall = true; Database.AddTable("Series", new[] { diff --git a/NzbDrone.Core/Jobs/CheckpointJob.cs b/NzbDrone.Core/Jobs/CheckpointJob.cs index 533dee48e..af98a3e3d 100644 --- a/NzbDrone.Core/Jobs/CheckpointJob.cs +++ b/NzbDrone.Core/Jobs/CheckpointJob.cs @@ -19,7 +19,7 @@ namespace NzbDrone.Core.Jobs public CheckpointJob() { - + } public string Name @@ -34,10 +34,7 @@ namespace NzbDrone.Core.Jobs public void Start(ProgressNotification notification, int targetId, int secondaryTargetId) { - if(EnviromentProvider.IsProduction) - { - _analyticsProvider.Checkpoint(); - } + _analyticsProvider.Checkpoint(); } } } \ No newline at end of file