public async Task GetModelsMultipleDtmisWithDepsPartialTryFromExpanded(ModelsRepositoryTestBase.ClientType clientType, bool hasMetadata) { const string dtmisExpanded = "dtmi:com:example:TemperatureController;1," + // Expanded available. "dtmi:com:example:Thermostat;1," + "dtmi:azure:DeviceManagement:DeviceInformation;1"; const string dtmisNonExpanded = "dtmi:com:example:ColdStorage;1," + // Model uses extends[], No Expanded available. "dtmi:com:example:Room;1," + "dtmi:com:example:Freezer;1"; string[] expandedDtmis = dtmisExpanded.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries); string[] nonExpandedDtmis = dtmisNonExpanded.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries); string[] totalDtmis = expandedDtmis.Concat(nonExpandedDtmis).ToArray(); ModelsRepositoryClientOptions options = new ModelsRepositoryClientOptions(); ModelsRepositoryClient client = GetClient(ModelsRepositoryTestBase.ClientType.Local, hasMetadata, options); // Multi-resolve dtmi:com:example:TemperatureController;1 + dtmi:com:example:ColdStorage;1 IDictionary <string, string> result = await client.GetModelsAsync(new[] { expandedDtmis[0], nonExpandedDtmis[0] }); result.Keys.Count.Should().Be(totalDtmis.Length); foreach (string id in totalDtmis) { result.Should().ContainKey(id); ModelsRepositoryTestBase.ParseRootDtmiFromJson(result[id]).Should().Be(id); } }
public void GetModelsForNonExistentDtmiFileThrowsException(ModelsRepositoryTestBase.ClientType clientType) { const string dtmi = "dtmi:com:example:thermojax;999"; ModelsRepositoryClient client = GetClient(clientType); Func <Task> act = async() => await client.GetModelsAsync(dtmi); act.Should().Throw <RequestFailedException>(); }
public async Task GetModelsSingleDtmiNoDeps(ModelsRepositoryTestBase.ClientType clientType) { const string dtmi = "dtmi:com:example:Thermostat;1"; ModelsRepositoryClient client = GetClient(clientType); IDictionary <string, string> result = await client.GetModelsAsync(dtmi); result.Keys.Count.Should().Be(1); result.Should().ContainKey(dtmi); ModelsRepositoryTestBase.ParseRootDtmiFromJson(result[dtmi]).Should().Be(dtmi); }
public async Task GetModelDependenciesDisabledDependencyResolution(ModelsRepositoryTestBase.ClientType clientType) { const string dtmi = "dtmi:com:example:TemperatureController;1"; ModelsRepositoryClient client = GetClient(clientType); ModelResult result = await client.GetModelAsync(dtmi, ModelDependencyResolution.Disabled); result.Content.Count.Should().Be(1); result.Content.ContainsKey(dtmi).Should().BeTrue(); ModelsRepositoryTestBase.ParseRootDtmiFromJson(result.Content[dtmi]).Should().Be(dtmi); }
public async Task GetModelsEnsuresNoDupes(ModelsRepositoryTestBase.ClientType clientType) { const string dtmiDupe1 = "dtmi:azure:DeviceManagement:DeviceInformation;1"; const string dtmiDupe2 = "dtmi:azure:DeviceManagement:DeviceInformation;1"; ModelsRepositoryClient client = GetClient(clientType); IDictionary <string, string> result = await client.GetModelsAsync(new[] { dtmiDupe1, dtmiDupe2 }); result.Keys.Count.Should().Be(1); ModelsRepositoryTestBase.ParseRootDtmiFromJson(result[dtmiDupe1]).Should().Be(dtmiDupe1); }
public async Task GetModelsSingleDtmiWithDepsDisabledDependencyResolution(ModelsRepositoryTestBase.ClientType clientType) { const string dtmi = "dtmi:com:example:TemperatureController;1"; ModelsRepositoryClient client = GetClient(clientType); IDictionary <string, string> result = await client.GetModelsAsync(dtmi, ModelDependencyResolution.Disabled); result.Keys.Count.Should().Be(1); result.Should().ContainKey(dtmi); ModelsRepositoryTestBase.ParseRootDtmiFromJson(result[dtmi]).Should().Be(dtmi); }
public async Task GetModelsMultipleDtmisNoDeps(ModelsRepositoryTestBase.ClientType clientType) { const string dtmi1 = "dtmi:com:example:Thermostat;1"; const string dtmi2 = "dtmi:azure:DeviceManagement:DeviceInformation;1"; ModelsRepositoryClient client = GetClient(clientType); IDictionary <string, string> result = await client.GetModelsAsync(new string[] { dtmi1, dtmi2 }); result.Keys.Count.Should().Be(2); result.Should().ContainKey(dtmi1); result.Should().ContainKey(dtmi2); ModelsRepositoryTestBase.ParseRootDtmiFromJson(result[dtmi1]).Should().Be(dtmi1); ModelsRepositoryTestBase.ParseRootDtmiFromJson(result[dtmi2]).Should().Be(dtmi2); }
public void GetModelsWithWrongCasingThrowsException(ModelsRepositoryTestBase.ClientType clientType) { const string dtmi = "dtmi:com:example:thermostat;1"; ModelsRepositoryClient client = GetClient(clientType); string expectedExMsg = string.Format(StandardStrings.GenericGetModelsError, "dtmi:com:example:thermostat;1") + " " + string.Format(StandardStrings.IncorrectDtmiCasing, "dtmi:com:example:thermostat;1", "dtmi:com:example:Thermostat;1"); Func <Task> act = async() => await client.GetModelsAsync(dtmi); act.Should().Throw <RequestFailedException>().WithMessage(expectedExMsg); }
public async Task GetModelDependenciesComponents(ModelsRepositoryTestBase.ClientType clientType, bool hasMetadata) { const string dtmi = "dtmi:com:example:TemperatureController;1"; const string expectedDeps = "dtmi:com:example:Thermostat;1,dtmi:azure:DeviceManagement:DeviceInformation;1"; ModelsRepositoryClient client = GetClient(clientType, hasMetadata); ModelResult result = await client.GetModelAsync(dtmi); var expectedDtmis = $"{dtmi},{expectedDeps}".Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries); result.Content.Count.Should().Be(expectedDtmis.Length); foreach (var id in expectedDtmis) { result.Content.ContainsKey(id).Should().BeTrue(); ModelsRepositoryTestBase.ParseRootDtmiFromJson(result.Content[id]).Should().Be(id); } }
public async Task GetModelsSingleDtmiWithDeps(ModelsRepositoryTestBase.ClientType clientType) { const string dtmi = "dtmi:com:example:TemperatureController;1"; const string expectedDeps = "dtmi:com:example:Thermostat;1,dtmi:azure:DeviceManagement:DeviceInformation;1"; ModelsRepositoryClient client = GetClient(clientType); IDictionary <string, string> result = await client.GetModelsAsync(dtmi); var expectedDtmis = $"{dtmi},{expectedDeps}".Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries); result.Keys.Count.Should().Be(expectedDtmis.Length); foreach (var id in expectedDtmis) { result.Should().ContainKey(id); ModelsRepositoryTestBase.ParseRootDtmiFromJson(result[id]).Should().Be(id); } }
protected ModelsRepositoryClient GetClient(ModelsRepositoryTestBase.ClientType clientType, ModelsRepositoryClientOptions options = default) { if (options == null) { options = new ModelsRepositoryClientOptions(); } return (clientType == ModelsRepositoryTestBase.ClientType.Local ? InstrumentClient( new ModelsRepositoryClient( new Uri(ModelsRepositoryTestBase.TestLocalModelRepository), InstrumentClientOptions(options))) : InstrumentClient( new ModelsRepositoryClient( new Uri(ModelsRepositoryTestBase.TestRemoteModelRepository), InstrumentClientOptions(options)))); }
public async Task GetModelNoDependencies(ModelsRepositoryTestBase.ClientType clientType, bool hasMetadata) { const string dtmi1 = "dtmi:com:example:Thermostat;1"; const string dtmi2 = "dtmi:azure:DeviceManagement:DeviceInformation;1"; string[] dtmis = new[] { dtmi1, dtmi2 }; ModelsRepositoryClient client = GetClient(clientType, hasMetadata); // Multiple GetModel() execution with the same instance. foreach (var dtmi in dtmis) { ModelResult result = await client.GetModelAsync(dtmi); result.Content.Count.Should().Be(1); result.Content.ContainsKey(dtmi).Should().BeTrue(); ModelsRepositoryTestBase.ParseRootDtmiFromJson(result.Content[dtmi]).Should().Be(dtmi); } }
protected ModelsRepositoryClient GetClient( ModelsRepositoryTestBase.ClientType clientType = ModelsRepositoryTestBase.ClientType.Local, string repositoryLocation = null, ModelsRepositoryClientOptions options = default) { if (options == null) { options = new ModelsRepositoryClientOptions(); } if (string.IsNullOrEmpty(repositoryLocation)) { repositoryLocation = clientType == ModelsRepositoryTestBase.ClientType.Local ? ModelsRepositoryTestBase.TestLocalModelsRepository : ModelsRepositoryTestBase.ProdRemoteModelsRepositoryCDN; } return(InstrumentClient(new ModelsRepositoryClient(new Uri(repositoryLocation), InstrumentClientOptions(options)))); }
public async Task GetModelDependenciesExtendsArrayNoExpanded(ModelsRepositoryTestBase.ClientType clientType, bool hasMetadata) { const string dtmi = "dtmi:com:example:ColdStorage;1"; // Model uses extends[], expanded form not available. const string expectedDeps = "dtmi:com:example:Room;1,dtmi:com:example:Freezer;1," + "dtmi:com:example:Thermostat;1"; ModelsRepositoryClient client = GetClient(clientType, hasMetadata); ModelResult result = await client.GetModelAsync(dtmi); var expectedDtmis = $"{dtmi},{expectedDeps}".Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries); result.Content.Count.Should().Be(expectedDtmis.Length); foreach (var id in expectedDtmis) { result.Content.ContainsKey(id).Should().BeTrue(); ModelsRepositoryTestBase.ParseRootDtmiFromJson(result.Content[id]).Should().Be(id); } }
protected ModelsRepositoryClient GetClient( ModelsRepositoryTestBase.ClientType clientType, bool hasMetadata, ModelsRepositoryClientOptions options = default) { string targetLocation; if (clientType == ModelsRepositoryTestBase.ClientType.Local) { targetLocation = hasMetadata ? ModelsRepositoryTestBase.TestLocalModelsRepositoryWithMetadata : ModelsRepositoryTestBase.TestLocalModelsRepository; } else { targetLocation = hasMetadata ? ModelsRepositoryTestBase.ProdRemoteModelsRepositoryCDN : ModelsRepositoryTestBase.ProdRemoteModelsRepositoryGithub; } return(GetClient(repositoryLocation: targetLocation, options: options)); }
public async Task GetModelsSingleDtmiWithDepsResolutionOptionOverrideAsTryFromExpanded(ModelsRepositoryTestBase.ClientType clientType) { const string dtmi = "dtmi:com:example:DanglingExpanded;1"; const string expectedDeps = "dtmi:com:example:Thermostat;1,dtmi:azure:DeviceManagement:DeviceInformation;1"; ModelsRepositoryClient client = GetClient( clientType, new ModelsRepositoryClientOptions(dependencyResolution: ModelDependencyResolution.Disabled)); // We would expect 1 model without the resolution option override. IDictionary <string, string> result = await client.GetModelsAsync(dtmi, dependencyResolution : ModelDependencyResolution.TryFromExpanded); var expectedDtmis = $"{dtmi},{expectedDeps}".Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries); result.Keys.Count.Should().Be(expectedDtmis.Length); foreach (var id in expectedDtmis) { result.Should().ContainKey(id); ModelsRepositoryTestBase.ParseRootDtmiFromJson(result[id]).Should().Be(id); } }
public async Task GetModelsSingleDtmiWithDepsResolutionOptionOverrideAsDisabled(ModelsRepositoryTestBase.ClientType clientType) { const string dtmi = "dtmi:com:example:TemperatureController;1"; ModelsRepositoryClient client = GetClient(clientType); // We would expect 3 models without the resolution option override. IDictionary <string, string> result = await client.GetModelsAsync(dtmi, dependencyResolution : ModelDependencyResolution.Disabled); var expectedDtmis = $"{dtmi}".Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries); result.Keys.Count.Should().Be(expectedDtmis.Length); foreach (var id in expectedDtmis) { result.Should().ContainKey(id); ModelsRepositoryTestBase.ParseRootDtmiFromJson(result[id]).Should().Be(id); } }