Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C# SDK change with Hub's certificate and operation tasks #3847

Merged
merged 13 commits into from
Nov 20, 2017
8 changes: 4 additions & 4 deletions NuGet.Config
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<!-- To enable LocalFeed for testing uncomment the following line -->
<add key="NugetOfficialV3" value="https://api.nuget.org/v3/index.json" />
<add key="Local" value="tools/LocalNugetFeed" />
</packageSources>
<!-- To enable LocalFeed for testing uncomment the following line -->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anusapan what is the need to edit this file? All this is doing is deleting spaces. Can you revert this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverted

<add key="NugetOfficialV3" value="https://api.nuget.org/v3/index.json" />
<add key="Local" value="tools/LocalNugetFeed" />
</packageSources>
</configuration>
16 changes: 16 additions & 0 deletions src/SDKs/IotHub/IotHub.Tests/Helpers/IotHubTestUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,22 @@ public class IotHubTestUtilities
public static string DefaultResourceGroupName = "DotNetHubRG";
public static string DefaultUpdateResourceGroupName = "UpdateDotNetHubRG";
public static string EventsEndpointName = "events";
public static string DefaultCertificateIotHubName = "DotNetCertificateHub";
public static string DefaultCertificateResourceGroupName = "DotNetCertificateHubRG";
public static string DefaultIotHubCertificateName = "DotNetCertificateHubCertificate";
public static string DefaultIotHubCertificateSubject = "CN=Azure IoT Root CA";
public static string DefaultIotHubCertificateThumbprint = "9F0983E8F2DB2DB3582997FEF331247D872DEE32";
public static string DefaultIotHubCertificateType = "Microsoft.Devices/IotHubs/Certificates";
public static string DefaultIotHubCertificateContent = "MIIBvjCCAWOgAwIBAgIQG6PoBFT6GLJGNKn/EaxltTAKBggqhkjOPQQDAjAcMRow"
+ "GAYDVQQDDBFBenVyZSBJb1QgUm9vdCBDQTAeFw0xNzExMDMyMDUyNDZaFw0xNzEy"
+ "MDMyMTAyNDdaMBwxGjAYBgNVBAMMEUF6dXJlIElvVCBSb290IENBMFkwEwYHKoZI"
+ "zj0CAQYIKoZIzj0DAQcDQgAE+CgpnW3K+KRNIi/U6Zqe/Al9m8PExHX2KgakmGTf"
+ "E04nNBwnSoygWb0ekqpT+Lm+OP56LMMe9ynVNryDEr9OSKOBhjCBgzAOBgNVHQ8B"
+ "Af8EBAMCAgQwHQYDVR0lBBYwFAYIKwYBBQUHAwIGCCsGAQUFBwMBMB8GA1UdEQQY"
+ "MBaCFENOPUF6dXJlIElvVCBSb290IENBMBIGA1UdEwEB/wQIMAYBAf8CAQwwHQYD"
+ "VR0OBBYEFDjiklfHQzw1G0A33BcmRQTjAivTMAoGCCqGSM49BAMCA0kAMEYCIQCt"
+ "jJ4bAvoYuDhwr92Kk+OkvpPF+qBFiRfrA/EC4YGtzQIhAO79WPtbUnBQ5fsQnW2a"
+ "UAT4yJGWL+7l4/qfmqblb96n";
public static IotHubClient GetIotHubClient(MockContext context, RecordedDelegatingHandler handler = null)
{
if (handler != null)
Expand Down
6 changes: 5 additions & 1 deletion src/SDKs/IotHub/IotHub.Tests/IotHub.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@
<PackageId>IotHub.Tests</PackageId>
<Description>IotHub.Tests Class Library</Description>
<AssemblyName>IotHub.Tests</AssemblyName>
<VersionPrefix>1.0.1-preview</VersionPrefix>
<VersionPrefix>1.0.2-preview</VersionPrefix>
</PropertyGroup>

<PropertyGroup>
<TargetFrameworks>netcoreapp1.1</TargetFrameworks>
</PropertyGroup>

<PropertyGroup>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anusapan please use latest version of Resource manager to record all your tests. You are still using 1.1.0, latest version is 1.6.0
YOU will have add reference to the new nuget, use the namespace from the new nuget and remove all traces of old namespace and then record your tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added new references of ResourceManager and recorded test again

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.EventHub" Version="1.2.0" />
<PackageReference Include="Microsoft.Azure.Management.ServiceBus" Version="0.2.0-preview" />
Expand Down
4 changes: 2 additions & 2 deletions src/SDKs/IotHub/IotHub.Tests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.1")]
[assembly: AssemblyFileVersion("1.0.0.1")]
[assembly: AssemblyVersion("1.0.0.2")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anusapan AssemblyVersion only changes when you update the Major version. Please do not update AssemblyVersion and make it same as AssemblyFileVersion

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverted

[assembly: AssemblyFileVersion("1.0.0.2")]
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,17 @@ public void TestIotHubCreateLifeCycle()
IotHubTestUtilities.DefaultIotHubName,
IotHubTestUtilities.EventsEndpointName,
"testConsumerGroup");

// Get all of the available IoT Hub REST API operations
var operationList = this.iotHubClient.Operations.List();
Assert.True(operationList.Count() > 0);
Assert.True(operationList.Any(e => e.Name.Equals("Microsoft.Devices/iotHubs/Read", StringComparison.OrdinalIgnoreCase)));

// Get IoT Hub REST API read operation
var hubReadOperation = operationList.Where(e => e.Name.Equals("Microsoft.Devices/iotHubs/Read", StringComparison.OrdinalIgnoreCase));
Assert.True(hubReadOperation.Count().Equals(1));
Assert.True(hubReadOperation.First().Display.Provider.Equals("Microsoft Devices", StringComparison.OrdinalIgnoreCase));
Assert.True(hubReadOperation.First().Display.Operation.Equals("Get IotHub(s)", StringComparison.OrdinalIgnoreCase));
}
}

Expand Down Expand Up @@ -179,7 +190,7 @@ public void TestIotHubUpdateLifeCycle()

iotHub.Properties.Routing = this.GetIotHubRoutingProperties(resourceGroup);
retIotHub = this.UpdateIotHub(resourceGroup, iotHub, IotHubTestUtilities.DefaultUpdateIotHubName);

Assert.NotNull(retIotHub);
Assert.Equal(IotHubTestUtilities.DefaultUpdateIotHubName, retIotHub.Name);
Assert.Equal(retIotHub.Properties.Routing.Routes.Count, 4);
Expand Down Expand Up @@ -213,6 +224,66 @@ public void TestIotHubUpdateLifeCycle()
}
}

[Fact]
public void TestIotHubCertificateLifeCycle()
{
using (MockContext context = MockContext.Start(this.GetType().FullName))
{
this.Initialize(context);

// Create Resource Group
var resourceGroup = this.CreateResourceGroup(IotHubTestUtilities.DefaultCertificateResourceGroupName);

// Check if Hub Exists and Delete
var operationInputs = new OperationInputs()
{
Name = IotHubTestUtilities.DefaultCertificateIotHubName
};

var iotHubNameAvailabilityInfo = this.iotHubClient.IotHubResource.CheckNameAvailability(operationInputs);

if (!(bool)iotHubNameAvailabilityInfo.NameAvailable)
{
this.iotHubClient.IotHubResource.Delete(
IotHubTestUtilities.DefaultCertificateResourceGroupName,
IotHubTestUtilities.DefaultCertificateIotHubName);

iotHubNameAvailabilityInfo = this.iotHubClient.IotHubResource.CheckNameAvailability(operationInputs);
Assert.Equal(true, iotHubNameAvailabilityInfo.NameAvailable);
}

// Create Hub
var iotHub = this.CreateIotHub(resourceGroup, IotHubTestUtilities.DefaultLocation, IotHubTestUtilities.DefaultCertificateIotHubName, null);

// Upload Certificate to the Hub
var newCertificateDescription = this.CreateCertificate(resourceGroup, IotHubTestUtilities.DefaultCertificateIotHubName, IotHubTestUtilities.DefaultIotHubCertificateName, IotHubTestUtilities.DefaultIotHubCertificateContent);
Assert.Equal(IotHubTestUtilities.DefaultIotHubCertificateName, newCertificateDescription.Name);
Assert.Equal(IotHubTestUtilities.DefaultIotHubCertificateSubject, newCertificateDescription.Properties.Subject);
Assert.Equal(IotHubTestUtilities.DefaultIotHubCertificateThumbprint, newCertificateDescription.Properties.Thumbprint);
Assert.Equal(IotHubTestUtilities.DefaultIotHubCertificateType, newCertificateDescription.Type);
Assert.False(newCertificateDescription.Properties.IsVerified);

// Get all certificates
var certificateList = this.GetCertificates(resourceGroup, IotHubTestUtilities.DefaultCertificateIotHubName);
Assert.True(certificateList.Value.Count().Equals(1));

// Get certificate
var certificate = this.GetCertificate(resourceGroup, IotHubTestUtilities.DefaultCertificateIotHubName, IotHubTestUtilities.DefaultIotHubCertificateName);
Assert.Equal(IotHubTestUtilities.DefaultIotHubCertificateName, certificate.Name);
Assert.Equal(IotHubTestUtilities.DefaultIotHubCertificateSubject, certificate.Properties.Subject);
Assert.Equal(IotHubTestUtilities.DefaultIotHubCertificateThumbprint, certificate.Properties.Thumbprint);
Assert.Equal(IotHubTestUtilities.DefaultIotHubCertificateType, certificate.Type);
Assert.False(certificate.Properties.IsVerified);

// Delete certificate
this.DeleteCertificate(resourceGroup, IotHubTestUtilities.DefaultCertificateIotHubName, IotHubTestUtilities.DefaultIotHubCertificateName, certificate.Etag);

// Get all certificate after delete
var certificateListAfterDelete = this.GetCertificates(resourceGroup, IotHubTestUtilities.DefaultCertificateIotHubName);
Assert.True(certificateListAfterDelete.Value.Count().Equals(0));
}
}

RoutingProperties GetIotHubRoutingProperties(ResourceGroup resourceGroup)
{
var ehConnectionString = this.CreateExternalEH(resourceGroup, location);
Expand Down
28 changes: 26 additions & 2 deletions src/SDKs/IotHub/IotHub.Tests/ScenarioTests/IotHubTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,6 @@ protected IotHubDescription CreateIotHub(ResourceGroup resourceGroup, string loc
createIotHubDescription);
}



protected IotHubDescription UpdateIotHub(ResourceGroup resourceGroup, IotHubDescription iotHubDescription, string iotHubName)
{
return this.iotHubClient.IotHubResource.CreateOrUpdate(
Expand All @@ -201,5 +199,31 @@ protected ResourceGroup CreateResourceGroup(string resourceGroupName)
Location = IotHubTestUtilities.DefaultLocation
});
}

protected CertificateDescription CreateCertificate(ResourceGroup resourceGroup, string iotHubName, string certificateName, string certificateBodyDescriptionContent)
{
var createCertificateBodyDescription = new CertificateBodyDescription(certificateBodyDescriptionContent);

return this.iotHubClient.Certificates.CreateOrUpdate(
resourceGroup.Name,
iotHubName,
certificateName,
createCertificateBodyDescription);
}

protected CertificateListDescription GetCertificates(ResourceGroup resourceGroup, string iotHubName)
{
return this.iotHubClient.Certificates.ListByIotHub(resourceGroup.Name, iotHubName);
}

protected CertificateDescription GetCertificate(ResourceGroup resourceGroup, string iotHubName, string certificateName)
{
return this.iotHubClient.Certificates.Get(resourceGroup.Name, iotHubName, certificateName);
}

protected void DeleteCertificate(ResourceGroup resourceGroup, string iotHubName, string certificateName, string Etag)
{
this.iotHubClient.Certificates.Delete(resourceGroup.Name, iotHubName, certificateName, Etag);
}
}
}
Loading