* Add initial classes * Add TelemetryProviders * Add new NodeCountService.cs and NodeTelemetryProvider * Add data contract attribute to UsageInformation Otherwise it wont serialize correctly * Implement more providers * Fix builders and propertyEditorTelemetry * Add MediaTelemetryProvider * Add MediaTelemetryProvider * Fix doubling of media telemetry * Move contentCount from NodeCountTelemetryProvider and move to ContentTelemetryProvider * Revert ContentTelemetryProvider changes * Add detailed information to TelemetryService * Add integration tests * Add more tests and todos for tests * Fix stylecop warnings * Use yield return instead of instantiating local list * Implement Macro test * Inject interface instead of implementation in TelemetryService * Fix TelemetryServiceTests.cs * Implement media tests * Implement propertyTypeTests * Implement constants instead of hardcoded strings * Add SystemInformationTelemetryProvider * Use SystemInformationTableDataProvider in UserDataService * Implement more properties * Add UsageInformation * Replace UserDataService with SystemInformationTelemetryProvider * Undo changes to UserDataService and obsolete it * Remove ISystemInformationTableDataProvider * Register SystemInformationTelemetryProvider as telemetry provider * Use constants for telemetry names * Make UserDataServiceTests test SystemInformationTelemetryProvider instead * Update UserDataServiceTests to cover new data * Add unit tests * Add integration test testing expected data is returned * Implement Analytics dashboard * Improve assertion message * Add text and styling to analyticspage * Rename consent to analytic * implement save button for consent level * Implement save button * Fix system information test * Add TelemetryResource * Move telemetry providers to infrastructure * Add database provider to system information * Set startvalue for slider * Fix unit tests * Implement MetricsConsentService using KeyValueService * Return void hen setting the telemetry level * fix startposition when not reloading * Add a couple tests * Update src/Umbraco.Core/Services/MetricsConsentService.cs * Rename ConsentLevel.cs * Use direct Enum instead of parsing * rename consent resource * add lazy database * refactor slider * Implement ng-if and propers pips * Make classes internal * Fix slider not loading when navigating to tab * Add telemetry level check to TelemetryService.cs * Add Consent for analytics text * Fix build errors for unit tests * Fix TelemetryServiceTests * revert package-lock.json * Fix integration test * Update slider * Update TelemetryService.cs * Apply suggestions from code review Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> Co-authored-by: Nikolaj Geisle <niko737@edu.ucl.dk> Co-authored-by: nikolajlauridsen <nikolajlauridsen@protonmail.ch>
122 lines
4.8 KiB
C#
122 lines
4.8 KiB
C#
using System;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.Extensions.Options;
|
|
using Moq;
|
|
using NUnit.Framework;
|
|
using Umbraco.Cms.Core;
|
|
using Umbraco.Cms.Core.Configuration;
|
|
using Umbraco.Cms.Core.Configuration.Models;
|
|
using Umbraco.Cms.Core.Models;
|
|
using Umbraco.Cms.Core.Services;
|
|
using Umbraco.Cms.Infrastructure.Persistence;
|
|
using Umbraco.Cms.Infrastructure.Telemetry.Providers;
|
|
|
|
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Telemetry
|
|
{
|
|
[TestFixture]
|
|
public class SystemInformationTelemetryProviderTests
|
|
{
|
|
[Test]
|
|
[TestCase(ModelsMode.Nothing)]
|
|
[TestCase(ModelsMode.InMemoryAuto)]
|
|
[TestCase(ModelsMode.SourceCodeAuto)]
|
|
[TestCase(ModelsMode.SourceCodeManual)]
|
|
public void ReportsModelsModeCorrectly(ModelsMode modelsMode)
|
|
{
|
|
var telemetryProvider = CreateProvider(modelsMode: modelsMode);
|
|
UsageInformation[] usageInformation = telemetryProvider.GetInformation().ToArray();
|
|
|
|
var actual = usageInformation.FirstOrDefault(x => x.Name == Constants.Telemetry.ModelsBuilderMode);
|
|
Assert.IsNotNull(actual?.Data);
|
|
Assert.AreEqual(modelsMode.ToString(), actual.Data);
|
|
}
|
|
|
|
[Test]
|
|
[TestCase(true)]
|
|
[TestCase(false)]
|
|
public void ReportsDebugModeCorrectly(bool isDebug)
|
|
{
|
|
var telemetryProvider = CreateProvider(isDebug: isDebug);
|
|
UsageInformation[] usageInformation = telemetryProvider.GetInformation().ToArray();
|
|
|
|
var actual = usageInformation.FirstOrDefault(x => x.Name == Constants.Telemetry.IsDebug);
|
|
Assert.IsNotNull(actual?.Data);
|
|
Assert.AreEqual(isDebug, actual.Data);
|
|
}
|
|
|
|
[Test]
|
|
[TestCase("en-US")]
|
|
[TestCase("de-DE")]
|
|
[TestCase("en-NZ")]
|
|
[TestCase("sv-SE")]
|
|
public void ReportsOsLanguageCorrectly(string culture)
|
|
{
|
|
Thread.CurrentThread.CurrentCulture = new CultureInfo(culture);
|
|
var telemetryProvider = CreateProvider();
|
|
|
|
UsageInformation[] usageInformation = telemetryProvider.GetInformation().ToArray();
|
|
var actual = usageInformation.FirstOrDefault(x => x.Name == Constants.Telemetry.OsLanguage);
|
|
|
|
Assert.NotNull(actual?.Data);
|
|
Assert.AreEqual(culture, actual.Data.ToString());
|
|
}
|
|
|
|
[Test]
|
|
[TestCase(GlobalSettings.StaticUmbracoPath, false)]
|
|
[TestCase("mycustompath", true)]
|
|
[TestCase("~/notUmbraco", true)]
|
|
[TestCase("/umbraco", true)]
|
|
[TestCase("umbraco", true)]
|
|
public void ReportsCustomUmbracoPathCorrectly(string path, bool isCustom)
|
|
{
|
|
var telemetryProvider = CreateProvider(umbracoPath: path);
|
|
|
|
UsageInformation[] usageInformation = telemetryProvider.GetInformation().ToArray();
|
|
var actual = usageInformation.FirstOrDefault(x => x.Name == Constants.Telemetry.CustomUmbracoPath);
|
|
|
|
Assert.NotNull(actual?.Data);
|
|
Assert.AreEqual(isCustom, actual.Data);
|
|
}
|
|
|
|
[Test]
|
|
[TestCase("Development")]
|
|
[TestCase("Staging")]
|
|
[TestCase("Production")]
|
|
public void ReportsCorrectAspEnvironment(string environment)
|
|
{
|
|
var telemetryProvider = CreateProvider(environment: environment);
|
|
|
|
UsageInformation[] usageInformation = telemetryProvider.GetInformation().ToArray();
|
|
var actual = usageInformation.FirstOrDefault(x => x.Name == Constants.Telemetry.AspEnvironment);
|
|
|
|
Assert.NotNull(actual?.Data);
|
|
Assert.AreEqual(environment, actual.Data);
|
|
}
|
|
|
|
private SystemInformationTelemetryProvider CreateProvider(
|
|
ModelsMode modelsMode = ModelsMode.InMemoryAuto,
|
|
bool isDebug = true,
|
|
string umbracoPath = "",
|
|
string environment = "")
|
|
{
|
|
var hostEnvironment = new Mock<IHostEnvironment>();
|
|
hostEnvironment.Setup(x => x.EnvironmentName).Returns(environment);
|
|
|
|
var databaseMock = new Mock<IUmbracoDatabase>();
|
|
databaseMock.Setup(x => x.DatabaseType.GetProviderName()).Returns("SQL");
|
|
|
|
return new SystemInformationTelemetryProvider(
|
|
Mock.Of<IUmbracoVersion>(),
|
|
Mock.Of<ILocalizationService>(),
|
|
Mock.Of<IOptions<ModelsBuilderSettings>>(x => x.Value == new ModelsBuilderSettings{ ModelsMode = modelsMode }),
|
|
Mock.Of<IOptions<HostingSettings>>(x => x.Value == new HostingSettings { Debug = isDebug }),
|
|
Mock.Of<IOptions<GlobalSettings>>(x => x.Value == new GlobalSettings{ UmbracoPath = umbracoPath }),
|
|
hostEnvironment.Object,
|
|
new Lazy<IUmbracoDatabase>(databaseMock.Object));
|
|
}
|
|
}
|
|
}
|