Abstract support observer data provider to enable testing. Forgot to remove unused test from SupportObserverTests.

This commit is contained in:
Hawk Foreste 2018-03-22 11:15:56 -07:00
Родитель e55c0a4a57
Коммит 719de42bf0
7 изменённых файлов: 146 добавлений и 14 удалений

Просмотреть файл

@ -63,6 +63,14 @@ namespace Diagnostics.DataProviders
{
return "Mock";
}
else if (prefix == "SupportObserver" && (name == "IsProdConfigured" || name == "IsTestConfigured"))
{
return "false";
}
else if (prefix == "SupportObserver" && name == "IsMockConfigured")
{
return "true";
}
return string.Empty;
}

Просмотреть файл

@ -14,11 +14,7 @@ namespace Diagnostics.DataProviders
this.Name = name;
}
public string Name
{
get;
set;
}
public string Name { get; set; }
public object DefaultValue { get; set; }
}

Просмотреть файл

@ -23,6 +23,15 @@ namespace Diagnostics.DataProviders
[ConfigurationName("AppKey")]
public string AppKey { get; set; }
[ConfigurationName("IsProdConfigured", DefaultValue = true)]
public bool IsProdConfigured { get; set; }
[ConfigurationName("IsTestConfigured", DefaultValue = false)]
public bool IsTestConfigured { get; set; }
[ConfigurationName("IsMockConfigured", DefaultValue = false)]
public bool IsMockConfigured { get; set; }
/// <summary>
/// Uri for SupportObserverResourceAAD app
/// </summary>

Просмотреть файл

@ -11,12 +11,12 @@ namespace Diagnostics.DataProviders
private OperationDataCache _cache = new OperationDataCache();
public KustoDataProvider Kusto;
public SupportObserverDataProvider Observer;
public ISupportObserverDataProvider Observer;
public DataProviders(DataSourcesConfiguration configuration)
{
Kusto = new KustoDataProvider(_cache, configuration.KustoConfiguration);
Observer = new SupportObserverDataProvider(_cache, configuration.SupportObserverConfiguration);
Observer = SupportObserverDataProviderFactory.GetDataProvider(_cache, configuration);
}
}
}

Просмотреть файл

@ -0,0 +1,105 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Diagnostics.ModelsAndUtils.Models;
using Newtonsoft.Json.Linq;
namespace Diagnostics.DataProviders
{
/// <summary>
/// Use this class for testing purposes
/// </summary>
public class MockSupportObserverDataProvider : DiagnosticDataProvider, ISupportObserverDataProvider
{
public MockSupportObserverDataProvider(OperationDataCache cache) : base(cache)
{
}
public Task<JObject> GetAdminSitesByHostName(string stampName, string[] hostNames)
{
throw new NotImplementedException();
}
public Task<JObject> GetAdminSitesBySiteName(string stampName, string siteName)
{
throw new NotImplementedException();
}
public Task<IEnumerable<object>> GetAppServiceEnvironmentDeployments(string hostingEnvironmentName)
{
throw new NotImplementedException();
}
public Task<JObject> GetAppServiceEnvironmentDetails(string hostingEnvironmentName)
{
throw new NotImplementedException();
}
public Task<IEnumerable<Dictionary<string, string>>> GetCertificatesInResourceGroup(string subscriptionName, string resourceGroupName)
{
throw new NotImplementedException();
}
public Task<Dictionary<string, List<RuntimeSitenameTimeRange>>> GetRuntimeSiteSlotMap(string siteName)
{
throw new NotImplementedException();
}
public Task<Dictionary<string, List<RuntimeSitenameTimeRange>>> GetRuntimeSiteSlotMap(string stampName, string siteName)
{
throw new NotImplementedException();
}
public Task<IEnumerable<Dictionary<string, string>>> GetServerFarmsInResourceGroup(string subscriptionName, string resourceGroupName)
{
throw new NotImplementedException();
}
public Task<string> GetServerFarmWebspaceName(string subscriptionId, string serverFarm)
{
throw new NotImplementedException();
}
public Task<dynamic> GetSite(string siteName)
{
throw new NotImplementedException();
}
public Task<dynamic> GetSite(string stampName, string siteName)
{
throw new NotImplementedException();
}
public Task<string> GetSiteResourceGroupName(string siteName)
{
throw new NotImplementedException();
}
public Task<IEnumerable<Dictionary<string, string>>> GetSitesInResourceGroup(string subscriptionName, string resourceGroupName)
{
throw new NotImplementedException();
}
public Task<IEnumerable<Dictionary<string, string>>> GetSitesInServerFarm(string subscriptionId, string serverFarmName)
{
throw new NotImplementedException();
}
public Task<string> GetSiteWebSpaceName(string subscriptionId, string siteName)
{
throw new NotImplementedException();
}
public Task<string> GetStorageVolumeForSite(string stampName, string siteName)
{
throw new NotImplementedException();
}
public Task<string> GetWebspaceResourceGroupName(string subscriptionId, string webSpaceName)
{
throw new NotImplementedException();
}
}
}

Просмотреть файл

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Diagnostics.DataProviders
{
internal class SupportObserverDataProviderFactory
{
public static ISupportObserverDataProvider GetDataProvider(OperationDataCache cache, DataSourcesConfiguration configuration)
{
if (configuration.SupportObserverConfiguration.IsMockConfigured)
{
return new MockSupportObserverDataProvider(cache);
}
else
{
return new SupportObserverDataProvider(cache, configuration.SupportObserverConfiguration);
}
}
}
}

Просмотреть файл

@ -18,13 +18,6 @@ namespace Diagnostics.Tests.DataProviderTests
_dataProvider = new SupportObserverDataProvider(null, configuration.SupportObserverConfiguration);
}
[Fact]
public void GetHostnamesTest()
{
var hostnames = _dataProvider.GetSiteHostNames("realforsikring").Result;
Assert.Equal(3, hostnames.Count());
}
[Fact]
public void GetRuntimeSlotMap()
{