Skip to content

Commit 57d6a94

Browse files
authored
[HealthcareApis] Add tests (Azure#34408)
1 parent 460f16e commit 57d6a94

File tree

50 files changed

+60493
-15
lines changed

Some content is hidden

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

50 files changed

+60493
-15
lines changed

sdk/healthcareapis/Azure.ResourceManager.HealthcareApis/Azure.ResourceManager.HealthcareApis.sln

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 16
4-
VisualStudioVersion = 16.0.30309.148
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.4.33213.308
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{40B78DA9-8E9D-4060-9DB6-C539715F2A52}") = "Azure.ResourceManager.HealthcareApis", "src\Azure.ResourceManager.HealthcareApis.csproj", "{0A3FBC6E-8411-4B10-B763-E18820E6BCA5}"
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.ResourceManager.HealthcareApis", "src\Azure.ResourceManager.HealthcareApis.csproj", "{0A3FBC6E-8411-4B10-B763-E18820E6BCA5}"
77
EndProject
8-
Project("{40B78DA9-8E9D-4060-9DB6-C539715F2A52}") = "Azure.ResourceManager.HealthcareApis.Tests", "tests\Azure.ResourceManager.HealthcareApis.Tests.csproj", "{82C11082-A9F4-4A44-AB6A-7A7021104704}"
9-
EndProject'
10-
Project("{40B78DA9-8E9D-4060-9DB6-C539715F2A52}") = "Azure.ResourceManager.HealthcareApis.Samples", "samples\Azure.ResourceManager.HealthcareApis.Samples.csproj", "{50439BF2-7177-4335-A90D-E74FF9051C6F}"
8+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.ResourceManager.HealthcareApis.Tests", "tests\Azure.ResourceManager.HealthcareApis.Tests.csproj", "{82C11082-A9F4-4A44-AB6A-7A7021104704}"
9+
EndProject
10+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.ResourceManager.HealthcareApis.Samples", "samples\Azure.ResourceManager.HealthcareApis.Samples.csproj", "{50439BF2-7177-4335-A90D-E74FF9051C6F}"
1111
EndProject
1212
Global
13-
GlobalSection(SolutionProperties) = preSolution
14-
HideSolutionNode = FALSE
15-
EndGlobalSection
16-
GlobalSection(ExtensibilityGlobals) = postSolution
17-
SolutionGuid = {E53B20F8-F1EA-409C-8326-F463B6F77A09}
18-
EndGlobalSection
1913
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2014
Debug|Any CPU = Debug|Any CPU
2115
Debug|x64 = Debug|x64
@@ -49,5 +43,23 @@ Global
4943
{82C11082-A9F4-4A44-AB6A-7A7021104704}.Release|x64.Build.0 = Release|Any CPU
5044
{82C11082-A9F4-4A44-AB6A-7A7021104704}.Release|x86.ActiveCfg = Release|Any CPU
5145
{82C11082-A9F4-4A44-AB6A-7A7021104704}.Release|x86.Build.0 = Release|Any CPU
46+
{50439BF2-7177-4335-A90D-E74FF9051C6F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
47+
{50439BF2-7177-4335-A90D-E74FF9051C6F}.Debug|Any CPU.Build.0 = Debug|Any CPU
48+
{50439BF2-7177-4335-A90D-E74FF9051C6F}.Debug|x64.ActiveCfg = Debug|Any CPU
49+
{50439BF2-7177-4335-A90D-E74FF9051C6F}.Debug|x64.Build.0 = Debug|Any CPU
50+
{50439BF2-7177-4335-A90D-E74FF9051C6F}.Debug|x86.ActiveCfg = Debug|Any CPU
51+
{50439BF2-7177-4335-A90D-E74FF9051C6F}.Debug|x86.Build.0 = Debug|Any CPU
52+
{50439BF2-7177-4335-A90D-E74FF9051C6F}.Release|Any CPU.ActiveCfg = Release|Any CPU
53+
{50439BF2-7177-4335-A90D-E74FF9051C6F}.Release|Any CPU.Build.0 = Release|Any CPU
54+
{50439BF2-7177-4335-A90D-E74FF9051C6F}.Release|x64.ActiveCfg = Release|Any CPU
55+
{50439BF2-7177-4335-A90D-E74FF9051C6F}.Release|x64.Build.0 = Release|Any CPU
56+
{50439BF2-7177-4335-A90D-E74FF9051C6F}.Release|x86.ActiveCfg = Release|Any CPU
57+
{50439BF2-7177-4335-A90D-E74FF9051C6F}.Release|x86.Build.0 = Release|Any CPU
58+
EndGlobalSection
59+
GlobalSection(SolutionProperties) = preSolution
60+
HideSolutionNode = FALSE
61+
EndGlobalSection
62+
GlobalSection(ExtensibilityGlobals) = postSolution
63+
SolutionGuid = {E53B20F8-F1EA-409C-8326-F463B6F77A09}
5264
EndGlobalSection
5365
EndGlobal

sdk/healthcareapis/Azure.ResourceManager.HealthcareApis/tests/Azure.ResourceManager.HealthcareApis.Tests.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2+
<ItemGroup>
3+
<PackageReference Include="Azure.ResourceManager.EventHubs" />
4+
</ItemGroup>
25
<ItemGroup>
36
<ProjectReference Include="..\src\Azure.ResourceManager.HealthcareApis.csproj" />
47
</ItemGroup>

sdk/healthcareapis/Azure.ResourceManager.HealthcareApis/tests/HealthcareApisManagementTestBase.cs

Lines changed: 72 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,37 @@
33

44
using Azure.Core;
55
using Azure.Core.TestFramework;
6+
using Azure.Core.TestFramework.Models;
7+
using Azure.ResourceManager.EventHubs;
8+
using Azure.ResourceManager.HealthcareApis.Models;
69
using Azure.ResourceManager.Resources;
710
using Azure.ResourceManager.TestFramework;
811
using NUnit.Framework;
12+
using System;
913
using System.Threading.Tasks;
1014

1115
namespace Azure.ResourceManager.HealthcareApis.Tests
1216
{
1317
public class HealthcareApisManagementTestBase : ManagementRecordedTestBase<HealthcareApisManagementTestEnvironment>
1418
{
1519
protected ArmClient Client { get; private set; }
20+
protected AzureLocation DefaultLocation = AzureLocation.EastUS;
21+
protected string ResourceGroupNamePrefix = "HealthCareApisRG";
1622

1723
protected HealthcareApisManagementTestBase(bool isAsync, RecordedTestMode mode)
1824
: base(isAsync, mode)
1925
{
26+
JsonPathSanitizers.Add("$..authority");
27+
UriRegexSanitizers.Add(new UriRegexSanitizer(@"/Microsoft.EventHub/namespaces/[^/]+api-version=(?<group>[a-z0-9-]+)", "**") { GroupForReplace = "group" });
28+
UriRegexSanitizers.Add(new UriRegexSanitizer(@"/Microsoft.EventHub/namespaces/[^/]+/eventhubs/[^/]+api-version=(?<group>[a-z0-9-]+)", "**") { GroupForReplace = "group" });
2029
}
2130

2231
protected HealthcareApisManagementTestBase(bool isAsync)
2332
: base(isAsync)
2433
{
34+
JsonPathSanitizers.Add("$..authority");
35+
UriRegexSanitizers.Add(new UriRegexSanitizer(@"/Microsoft.EventHub/namespaces/[^/]+api-version=(?<group>[a-z0-9-]+)", "**") { GroupForReplace = "group" });
36+
UriRegexSanitizers.Add(new UriRegexSanitizer(@"/Microsoft.EventHub/namespaces/[^/]+/eventhubs/[^/]+api-version=(?<group>[a-z0-9-]+)", "**") { GroupForReplace = "group" });
2537
}
2638

2739
[SetUp]
@@ -30,12 +42,69 @@ public void CreateCommonClient()
3042
Client = GetArmClient();
3143
}
3244

33-
protected async Task<ResourceGroupResource> CreateResourceGroup(SubscriptionResource subscription, string rgNamePrefix, AzureLocation location)
45+
protected async Task<ResourceGroupResource> CreateResourceGroup()
3446
{
35-
string rgName = Recording.GenerateAssetName(rgNamePrefix);
36-
ResourceGroupData input = new ResourceGroupData(location);
47+
SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync();
48+
string rgName = Recording.GenerateAssetName(ResourceGroupNamePrefix);
49+
ResourceGroupData input = new ResourceGroupData(DefaultLocation);
3750
var lro = await subscription.GetResourceGroups().CreateOrUpdateAsync(WaitUntil.Completed, rgName, input);
3851
return lro.Value;
3952
}
53+
54+
protected async Task<HealthcareApisWorkspaceResource> CreateHealthcareApisWorkspace(ResourceGroupResource resourceGroup, string workspaceName)
55+
{
56+
var data = new HealthcareApisWorkspaceData(DefaultLocation);
57+
var lro = await resourceGroup.GetHealthcareApisWorkspaces().CreateOrUpdateAsync(WaitUntil.Completed, workspaceName, data);
58+
return lro.Value;
59+
}
60+
61+
protected async Task<FhirServiceResource> CreateFhirService(HealthcareApisWorkspaceResource workspace, string fhirServiceName)
62+
{
63+
FhirServiceData data = new FhirServiceData(DefaultLocation)
64+
{
65+
Kind = "fhir-R4",
66+
AuthenticationConfiguration = new FhirServiceAuthenticationConfiguration()
67+
{
68+
Authority = $"https://login.microsoftonline.com/{Environment.GetEnvironmentVariable("TENANT_ID")}",
69+
Audience = $"https://{workspace.Data.Name}-{fhirServiceName}.fhir.azurehealthcareapis.com"
70+
},
71+
ImportConfiguration = new FhirServiceImportConfiguration()
72+
{
73+
IsEnabled = false,
74+
IsInitialImportMode = false,
75+
},
76+
ResourceVersionPolicyConfiguration = new FhirServiceResourceVersionPolicyConfiguration()
77+
{
78+
Default = "no-version",
79+
}
80+
};
81+
var lro = await workspace.GetFhirServices().CreateOrUpdateAsync(WaitUntil.Completed, fhirServiceName, data);
82+
return lro.Value;
83+
}
84+
85+
protected async Task<HealthcareApisIotConnectorResource> CreateHealthcareApisIotConnector(ResourceGroupResource resourceGroup, HealthcareApisWorkspaceResource workspace, string iotConnectorName)
86+
{
87+
// Create an Eventhub
88+
var eventhubNamespace = await resourceGroup.GetEventHubsNamespaces().CreateOrUpdateAsync(WaitUntil.Completed, Recording.GenerateAssetName("azmedtechspaces"), new EventHubsNamespaceData(resourceGroup.Data.Location));
89+
string eventHubName = Recording.GenerateAssetName("eventhub");
90+
var eventhub = await eventhubNamespace.Value.GetEventHubs().CreateOrUpdateAsync(WaitUntil.Completed, eventHubName, new EventHubData());
91+
92+
// Create an IotConnector
93+
var data = new HealthcareApisIotConnectorData(DefaultLocation)
94+
{
95+
IngestionEndpointConfiguration = new HealthcareApisIotConnectorEventHubIngestionConfiguration()
96+
{
97+
EventHubName = eventHubName,
98+
ConsumerGroup = "$Default",
99+
FullyQualifiedEventHubNamespace = $"{eventHubName}.servicesbus.windows.net",
100+
},
101+
DeviceMapping = new HealthcareApisIotMappingProperties()
102+
{
103+
Content = BinaryData.FromString("{\"templateType\": \"CollectionContent\",\"template\": []}"),
104+
},
105+
};
106+
var iotConnectorLro = await workspace.GetHealthcareApisIotConnectors().CreateOrUpdateAsync(WaitUntil.Completed, iotConnectorName, data);
107+
return iotConnectorLro.Value;
108+
}
40109
}
41110
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading;
9+
using System.Threading.Tasks;
10+
using Azure.Core.TestFramework;
11+
using Azure.ResourceManager.HealthcareApis.Models;
12+
using Azure.ResourceManager.Resources;
13+
using NUnit.Framework;
14+
15+
namespace Azure.ResourceManager.HealthcareApis.Tests
16+
{
17+
internal class DicomServiceTests : HealthcareApisManagementTestBase
18+
{
19+
private DicomServiceCollection _dicomServiceCollection;
20+
private const string _dicomServiceNamePrefix = "dicom";
21+
22+
public DicomServiceTests(bool isAsync) : base(isAsync)//, RecordedTestMode.Record)
23+
{
24+
}
25+
26+
[SetUp]
27+
public async Task SetUp()
28+
{
29+
var resourceGroup = await CreateResourceGroup();
30+
var workspace = await CreateHealthcareApisWorkspace(resourceGroup, Recording.GenerateAssetName("workspace"));
31+
_dicomServiceCollection = workspace.GetDicomServices();
32+
}
33+
34+
[RecordedTest]
35+
public async Task CreateOrUpdateExistGetGetAllDelete()
36+
{
37+
// CreateOrUpdate
38+
string dicomServiceName = Recording.GenerateAssetName(_dicomServiceNamePrefix);
39+
var dicomService = await CreateDicomService(dicomServiceName);
40+
ValidateDicomService(dicomService.Data, dicomServiceName);
41+
42+
// Exist
43+
var flag = await _dicomServiceCollection.ExistsAsync(dicomServiceName);
44+
Assert.IsTrue(flag);
45+
46+
// Get
47+
var getDicomService = await _dicomServiceCollection.GetAsync(dicomServiceName);
48+
ValidateDicomService(getDicomService.Value.Data, dicomServiceName);
49+
50+
// GetAll
51+
var list = await _dicomServiceCollection.GetAllAsync().ToEnumerableAsync();
52+
Assert.IsNotEmpty(list);
53+
ValidateDicomService(list.FirstOrDefault().Data, dicomServiceName);
54+
55+
// Delete
56+
await dicomService.DeleteAsync(WaitUntil.Completed);
57+
flag = await _dicomServiceCollection.ExistsAsync(dicomServiceName);
58+
Assert.IsFalse(flag);
59+
}
60+
61+
[TestCase(null)]
62+
[TestCase(false)]
63+
[TestCase(true)]
64+
public async Task AddRemoveTag(bool? useTagResource)
65+
{
66+
SetTagResourceUsage(Client, useTagResource);
67+
string dicomServiceName = Recording.GenerateAssetName(_dicomServiceNamePrefix);
68+
var dicomService = await CreateDicomService(dicomServiceName);
69+
70+
// AddTag
71+
await dicomService.AddTagAsync("addtagkey", "addtagvalue");
72+
dicomService = await _dicomServiceCollection.GetAsync(dicomServiceName);
73+
Assert.AreEqual(1, dicomService.Data.Tags.Count);
74+
KeyValuePair<string, string> tag = dicomService.Data.Tags.Where(tag => tag.Key == "addtagkey").FirstOrDefault();
75+
Assert.AreEqual("addtagkey", tag.Key);
76+
Assert.AreEqual("addtagvalue", tag.Value);
77+
78+
// RemoveTag
79+
await dicomService.RemoveTagAsync("addtagkey");
80+
dicomService = await _dicomServiceCollection.GetAsync(dicomServiceName);
81+
Assert.AreEqual(0, dicomService.Data.Tags.Count);
82+
}
83+
84+
private async Task<DicomServiceResource> CreateDicomService(string dicomServiceName)
85+
{
86+
DicomServiceData data = new DicomServiceData(DefaultLocation);
87+
var lro = await _dicomServiceCollection.CreateOrUpdateAsync(WaitUntil.Completed, dicomServiceName, data);
88+
return lro.Value;
89+
}
90+
91+
private void ValidateDicomService(DicomServiceData dicomService, string dicomServiceName)
92+
{
93+
Assert.IsNotNull(dicomService);
94+
Assert.AreEqual(dicomServiceName, dicomService.Id.Name);
95+
Assert.AreEqual(DefaultLocation, dicomService.Location);
96+
Assert.AreEqual("Succeeded", dicomService.ProvisioningState.ToString());
97+
Assert.AreEqual("Microsoft.HealthcareApis/workspaces/dicomservices", dicomService.ResourceType.ToString());
98+
}
99+
}
100+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading;
9+
using System.Threading.Tasks;
10+
using Azure.Core.TestFramework;
11+
using Azure.ResourceManager.HealthcareApis.Models;
12+
using NUnit.Framework;
13+
14+
namespace Azure.ResourceManager.HealthcareApis.Tests
15+
{
16+
internal class FhirServiceTests : HealthcareApisManagementTestBase
17+
{
18+
private const string fhirServicePrefixName = "fhir";
19+
private HealthcareApisWorkspaceResource _workspace;
20+
private FhirServiceCollection _fhirServiceCollection;
21+
22+
public FhirServiceTests(bool isAsync) : base(isAsync)//, RecordedTestMode.Record)
23+
{
24+
}
25+
26+
[SetUp]
27+
public async Task SetUp()
28+
{
29+
var resourceGroup = await CreateResourceGroup();
30+
_workspace = await CreateHealthcareApisWorkspace(resourceGroup, Recording.GenerateAssetName("workspace"));
31+
_fhirServiceCollection = _workspace.GetFhirServices();
32+
}
33+
34+
[RecordedTest]
35+
public async Task CreateOrUpdateExistGetGetAllDelete()
36+
{
37+
// CreateOrUpdate
38+
string fhirServiceName = Recording.GenerateAssetName(fhirServicePrefixName);
39+
var fhirService = await CreateFhirService(_workspace, fhirServiceName);
40+
ValidateFhirService(fhirService.Data, fhirServiceName);
41+
42+
// Exist
43+
var flag = await _fhirServiceCollection.ExistsAsync(fhirServiceName);
44+
Assert.IsTrue(flag);
45+
46+
// Get
47+
var getFhirService = await _fhirServiceCollection.GetAsync(fhirServiceName);
48+
ValidateFhirService(getFhirService.Value.Data, fhirServiceName);
49+
50+
// GetAll
51+
var list = await _fhirServiceCollection.GetAllAsync().ToEnumerableAsync();
52+
Assert.IsNotEmpty(list);
53+
ValidateFhirService(list.FirstOrDefault().Data, fhirServiceName);
54+
55+
// Delete
56+
await fhirService.DeleteAsync(WaitUntil.Completed);
57+
flag = await _fhirServiceCollection.ExistsAsync(fhirServiceName);
58+
Assert.IsFalse(flag);
59+
}
60+
61+
[TestCase(null)]
62+
[TestCase(false)]
63+
[TestCase(true)]
64+
public async Task AddRemoveTag(bool? useTagResource)
65+
{
66+
SetTagResourceUsage(Client, useTagResource);
67+
string fhirServiceName = Recording.GenerateAssetName(fhirServicePrefixName);
68+
var fhirService = await CreateFhirService(_workspace, fhirServiceName);
69+
70+
// AddTag
71+
await fhirService.AddTagAsync("addtagkey", "addtagvalue");
72+
fhirService = await _fhirServiceCollection.GetAsync(fhirServiceName);
73+
Assert.AreEqual(1, fhirService.Data.Tags.Count);
74+
KeyValuePair<string, string> tag = fhirService.Data.Tags.Where(tag => tag.Key == "addtagkey").FirstOrDefault();
75+
Assert.AreEqual("addtagkey", tag.Key);
76+
Assert.AreEqual("addtagvalue", tag.Value);
77+
78+
// RemoveTag
79+
await fhirService.RemoveTagAsync("addtagkey");
80+
fhirService = await _fhirServiceCollection.GetAsync(fhirServiceName);
81+
Assert.AreEqual(0, fhirService.Data.Tags.Count);
82+
}
83+
84+
private void ValidateFhirService(FhirServiceData fhirService, string fhirServiceName)
85+
{
86+
Assert.IsNotNull(fhirService);
87+
Assert.IsNotNull(fhirService.ETag);
88+
Assert.AreEqual(fhirServiceName, fhirService.Id.Name);
89+
Assert.AreEqual("fhir-R4", fhirService.Kind.ToString());
90+
Assert.AreEqual(DefaultLocation, fhirService.Location);
91+
Assert.AreEqual("Succeeded", fhirService.ProvisioningState.ToString());
92+
Assert.AreEqual("Enabled", fhirService.PublicNetworkAccess.ToString());
93+
Assert.AreEqual("Microsoft.HealthcareApis/workspaces/fhirservices", fhirService.ResourceType.ToString());
94+
Assert.AreEqual("no-version", fhirService.ResourceVersionPolicyConfiguration.Default.ToString());
95+
}
96+
}
97+
}

0 commit comments

Comments
 (0)