Exemplo n.º 1
0
        public async Task GetModelsMultipleDtmisTryFromExpandedPartial()
        {
            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(dependencyResolution: ModelDependencyResolution.TryFromExpanded);
            ModelsRepositoryClient        client  = GetClient(ModelsRepositoryTestBase.ClientType.Local, 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);
            }
        }
Exemplo n.º 2
0
        public async Task GetModelsSingleDtmiWithDepsFromExtendsInline()
        {
            const string                 dtmi   = "dtmi:com:example:base;1";
            ModelsRepositoryClient       client = GetClient(ModelsRepositoryTestBase.ClientType.Local);
            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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        public async Task GetModelsEnsuresNoDupes()
        {
            const string dtmiDupe1 = "dtmi:azure:DeviceManagement:DeviceInformation;1";
            const string dtmiDupe2 = "dtmi:azure:DeviceManagement:DeviceInformation;1";

            ModelsRepositoryClient       client = GetClient(ModelsRepositoryTestBase.ClientType.Local);
            IDictionary <string, string> result = await client.GetModelsAsync(new[] { dtmiDupe1, dtmiDupe2 });

            result.Keys.Count.Should().Be(1);
            ModelsRepositoryTestBase.ParseRootDtmiFromJson(result[dtmiDupe1]).Should().Be(dtmiDupe1);
        }
Exemplo n.º 5
0
        public async Task GetModelsSingleDtmiWithDepsDisableDependencyResolution(ModelsRepositoryTestBase.ClientType clientType)
        {
            const string dtmi = "dtmi:com:example:Thermostat;1";

            ModelsRepositoryClientOptions options = new ModelsRepositoryClientOptions(dependencyResolution: ModelDependencyResolution.Disabled);
            ModelsRepositoryClient        client  = GetClient(clientType, options);

            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);
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        public async Task GetModelsMultipleDtmisWithDepsFromExtends()
        {
            const string                 dtmi1        = "dtmi:com:example:TemperatureController;1";
            const string                 dtmi2        = "dtmi:com:example:ConferenceRoom;1";
            const string                 expectedDeps = "dtmi:com:example:Thermostat;1,dtmi:azure:DeviceManagement:DeviceInformation;1,dtmi:com:example:Room;1";
            ModelsRepositoryClient       client       = GetClient(ModelsRepositoryTestBase.ClientType.Local);
            IDictionary <string, string> result       = await client.GetModelsAsync(new[] { dtmi1, dtmi2 });

            var expectedDtmis = $"{dtmi1},{dtmi2},{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);
            }
        }
Exemplo n.º 8
0
        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);
            }
        }
Exemplo n.º 9
0
        public async Task GetModelsSingleDtmiWithDepsFromExtendsInlineVariant()
        {
            const string dtmi     = "dtmi:com:example:base;2";
            const string expected = "dtmi:com:example:Freezer;1," +
                                    "dtmi:com:example:Thermostat;1";

            ModelsRepositoryClient       client = GetClient(ModelsRepositoryTestBase.ClientType.Local);
            IDictionary <string, string> result = await client.GetModelsAsync(dtmi);

            var expectedDtmis = $"{dtmi},{expected}".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);
            }
        }
Exemplo n.º 10
0
        public async Task GetModelsSingleDtmiTryFromExpanded(ModelsRepositoryTestBase.ClientType clientType)
        {
            const string dtmi         = "dtmi:com:example:TemperatureController;1";
            const string expectedDeps = "dtmi:com:example:Thermostat;1,dtmi:azure:DeviceManagement:DeviceInformation;1";

            var expectedDtmis = $"{dtmi},{expectedDeps}".Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);

            ModelsRepositoryClientOptions options = new ModelsRepositoryClientOptions(dependencyResolution: ModelDependencyResolution.TryFromExpanded);
            ModelsRepositoryClient        client  = GetClient(clientType, options);

            IDictionary <string, string> result = await client.GetModelsAsync(dtmi);

            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 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(resolutionOption: DependencyResolutionOption.Disabled));

            // We would expect 1 model without the resolution option override.
            IDictionary <string, string> result = await client.GetModelsAsync(dtmi, resolutionOption : DependencyResolutionOption.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);
            }
        }