Skip to content

Commit 2e5424e

Browse files
authored
Improve GetModel tests. (Azure#25068)
1 parent 6289249 commit 2e5424e

File tree

65 files changed

+544
-650
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+544
-650
lines changed

sdk/modelsrepository/Azure.IoT.ModelsRepository/tests/GetModelIntegrationTests.cs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using NUnit.Framework;
66
using System;
77
using System.Threading.Tasks;
8+
using System.Text.Json;
89

910
namespace Azure.IoT.ModelsRepository.Tests
1011
{
@@ -54,14 +55,27 @@ public void GetModelNonExistentDtmiFileThrowsException(ModelsRepositoryTestBase.
5455
act.Should().Throw<RequestFailedException>();
5556
}
5657

58+
[Test]
59+
public void GetModelInvalidFileContentFormatThrowsException()
60+
{
61+
const string dtmi = "dtmi:com:example:invalidformat;1";
62+
63+
ModelsRepositoryClient client = GetClient(ModelsRepositoryTestBase.ClientType.Local);
64+
Func<Task> act = async () => await client.GetModelAsync(dtmi);
65+
act.Should().Throw<JsonException>();
66+
}
67+
68+
[Test]
5769
public void GetModelInvalidDtmiDependencyThrowsException()
5870
{
5971
const string dtmi = "dtmi:com:example:invalidmodel;1";
6072
const string invalidDep = "dtmi:azure:fakeDeviceManagement:FakeDeviceInformation;2";
73+
string invalidDepPath = DtmiConventions.GetModelUri(invalidDep, new Uri(ModelsRepositoryTestBase.TestLocalModelsRepository)).LocalPath;
74+
string expectedExMsg = $"{string.Format(StandardStrings.GenericGetModelsError, invalidDep)} {string.Format(StandardStrings.ErrorFetchingModelContent, invalidDepPath)}";
6175

6276
ModelsRepositoryClient client = GetClient(ModelsRepositoryTestBase.ClientType.Local);
6377
Func<Task> act = async () => await client.GetModelAsync(dtmi);
64-
act.Should().Throw<RequestFailedException>().WithMessage($"Unable to resolve \"{invalidDep}\"");
78+
act.Should().Throw<RequestFailedException>().WithMessage(expectedExMsg);
6579
}
6680

6781
[TestCase(ModelsRepositoryTestBase.ClientType.Local, true)]
@@ -108,6 +122,27 @@ public async Task GetModelDependenciesComponents(ModelsRepositoryTestBase.Client
108122
}
109123
}
110124

125+
[Test]
126+
public async Task GetModelDependenciesComponentsInline()
127+
{
128+
const string dtmi = "dtmi:com:example:Phone;2";
129+
const string expectedDeps = "dtmi:com:example:Camera;3,dtmi:azure:DeviceManagement:DeviceInformation;1," +
130+
"dtmi:azure:DeviceManagement:DeviceInformation;2";
131+
132+
ModelsRepositoryClient client = GetClient(ModelsRepositoryTestBase.ClientType.Local);
133+
ModelResult result = await client.GetModelAsync(dtmi);
134+
var expectedDtmis = $"{dtmi},{expectedDeps}".Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);
135+
136+
result.Content.Count.Should().Be(expectedDtmis.Length);
137+
138+
foreach (var id in expectedDtmis)
139+
{
140+
result.Content.ContainsKey(id).Should().BeTrue();
141+
ModelsRepositoryTestBase.ParseRootDtmiFromJson(result.Content[id]).Should().Be(id);
142+
}
143+
}
144+
145+
[Test]
111146
public async Task GetModelDependenciesExtendsSingleRef()
112147
{
113148
const string dtmi = "dtmi:com:example:ConferenceRoom;1";
@@ -146,6 +181,7 @@ public async Task GetModelDependenciesExtendsArrayNoExpanded(ModelsRepositoryTes
146181
}
147182
}
148183

184+
[Test]
149185
public async Task GetModelNoDependenciesExtendsInline()
150186
{
151187
const string dtmi = "dtmi:com:example:base;1";
@@ -158,6 +194,7 @@ public async Task GetModelNoDependenciesExtendsInline()
158194
ModelsRepositoryTestBase.ParseRootDtmiFromJson(result.Content[dtmi]).Should().Be(dtmi);
159195
}
160196

197+
[Test]
161198
public async Task GetModelDependenciesExtendsArrayMixed()
162199
{
163200
const string dtmi = "dtmi:com:example:base;2";
@@ -191,6 +228,7 @@ public async Task GetModelDependenciesDisabledDependencyResolution(ModelsReposit
191228
ModelsRepositoryTestBase.ParseRootDtmiFromJson(result.Content[dtmi]).Should().Be(dtmi);
192229
}
193230

231+
[Test]
194232
public async Task GetModelDependenciesUseMetadataEnsureTryFromExpanded()
195233
{
196234
const string dtmi = "dtmi:com:example:DanglingExpanded;1";

sdk/modelsrepository/Azure.IoT.ModelsRepository/tests/SessionRecords/GetModelIntegrationTests/GetModelDependenciesComponents(Local,False).json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/modelsrepository/Azure.IoT.ModelsRepository/tests/SessionRecords/GetModelIntegrationTests/GetModelDependenciesComponents(Local,False)Async.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/modelsrepository/Azure.IoT.ModelsRepository/tests/SessionRecords/GetModelIntegrationTests/GetModelDependenciesComponents(Local,True).json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/modelsrepository/Azure.IoT.ModelsRepository/tests/SessionRecords/GetModelIntegrationTests/GetModelDependenciesComponents(Local,True)Async.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/modelsrepository/Azure.IoT.ModelsRepository/tests/SessionRecords/GetModelIntegrationTests/GetModelDependenciesComponents(Remote,False).json

Lines changed: 41 additions & 41 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)