-
Notifications
You must be signed in to change notification settings - Fork 463
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make UpstreamProtocol case insensitive (#264)
* Make UpstreamProtocol case insensitive * Add Tests
- Loading branch information
1 parent
3afce1b
commit f48c780
Showing
5 changed files
with
126 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
edge-hub/src/Microsoft.Azure.Devices.Edge.Hub.Service/AssemblyInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
|
||
using System.Runtime.CompilerServices; | ||
|
||
[assembly: InternalsVisibleTo("Microsoft.Azure.Devices.Edge.Hub.Service.Test")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
....Azure.Devices.Edge.Hub.Service.Test/Microsoft.Azure.Devices.Edge.Hub.Service.Test.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp2.1</TargetFramework> | ||
<TreatWarningsAsErrors>True</TreatWarningsAsErrors> | ||
<Configurations>Debug;Release;CodeCoverage</Configurations> | ||
<HighEntropyVA>true</HighEntropyVA> | ||
</PropertyGroup> | ||
|
||
<!-- | ||
Normally, the 'Debug' configuration would work for code coverage, but Microsoft.CodeCoverage currently requires '<DebugType>full</DebugType>' for .NET Core. | ||
See https://github.com/Microsoft/vstest-docs/blob/06f9dc0aeb47be7204dc4e1a98c110ead3e978c7/docs/analyze.md#setup-a-project. | ||
That setting seems to break the "Open Test" context menu in VS IDE, so we'll use a dedicated configuration for code coverage. | ||
--> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'CodeCoverage|AnyCPU' "> | ||
<IntermediateOutputPath>obj\CodeCoverage</IntermediateOutputPath> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\CodeCoverage</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" /> | ||
<PackageReference Include="Moq" Version="4.8.2" /> | ||
<PackageReference Include="xunit" Version="2.2.0" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" /> | ||
<PackageReference Include="Microsoft.CodeCoverage" Version="1.0.3" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\..\edge-util\test\Microsoft.Azure.Devices.Edge.Util.Test.Common\Microsoft.Azure.Devices.Edge.Util.Test.Common.csproj" /> | ||
<ProjectReference Include="..\..\src\Microsoft.Azure.Devices.Edge.Hub.Service\Microsoft.Azure.Devices.Edge.Hub.Service.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" /> | ||
</ItemGroup> | ||
|
||
</Project> |
66 changes: 66 additions & 0 deletions
66
edge-hub/test/Microsoft.Azure.Devices.Edge.Hub.Service.Test/StartupTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
|
||
namespace Microsoft.Azure.Devices.Edge.Hub.Service.Test | ||
{ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using Microsoft.Azure.Devices.Edge.Hub.CloudProxy; | ||
using Microsoft.Azure.Devices.Edge.Util; | ||
using Microsoft.Azure.Devices.Edge.Util.Test.Common; | ||
using Microsoft.Extensions.Configuration; | ||
using Moq; | ||
using Xunit; | ||
|
||
[Unit] | ||
public class StartupTest | ||
{ | ||
static IEnumerable<object[]> GetUpstreamProtocolData() | ||
{ | ||
yield return new object[] { "Mqtt", Option.Some(UpstreamProtocol.Mqtt) }; | ||
yield return new object[] { "MQTT", Option.Some(UpstreamProtocol.Mqtt) }; | ||
yield return new object[] { "mqtt", Option.Some(UpstreamProtocol.Mqtt) }; | ||
yield return new object[] { "MqTt", Option.Some(UpstreamProtocol.Mqtt) }; | ||
|
||
yield return new object[] { "Amqp", Option.Some(UpstreamProtocol.Amqp) }; | ||
yield return new object[] { "AMQP", Option.Some(UpstreamProtocol.Amqp) }; | ||
yield return new object[] { "amqp", Option.Some(UpstreamProtocol.Amqp) }; | ||
yield return new object[] { "AmqP", Option.Some(UpstreamProtocol.Amqp) }; | ||
|
||
yield return new object[] { "MqttWs", Option.Some(UpstreamProtocol.MqttWs) }; | ||
yield return new object[] { "MQTTWS", Option.Some(UpstreamProtocol.MqttWs) }; | ||
yield return new object[] { "mqttws", Option.Some(UpstreamProtocol.MqttWs) }; | ||
yield return new object[] { "MqTtWs", Option.Some(UpstreamProtocol.MqttWs) }; | ||
|
||
yield return new object[] { "AmqpWs", Option.Some(UpstreamProtocol.AmqpWs) }; | ||
yield return new object[] { "AMQPWs", Option.Some(UpstreamProtocol.AmqpWs) }; | ||
yield return new object[] { "amqpws", Option.Some(UpstreamProtocol.AmqpWs) }; | ||
yield return new object[] { "amqPwS", Option.Some(UpstreamProtocol.AmqpWs) }; | ||
|
||
yield return new object[] { "amqPwSt", Option.None<UpstreamProtocol>() }; | ||
yield return new object[] { "", Option.None<UpstreamProtocol>() }; | ||
yield return new object[] { " ", Option.None<UpstreamProtocol>() }; | ||
yield return new object[] { "mqttwebsockets", Option.None<UpstreamProtocol>() }; | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(GetUpstreamProtocolData))] | ||
public void ParseUpstreamProtocolTest(string input, Option<UpstreamProtocol> expectedValue) | ||
{ | ||
// Arrange | ||
IConfigurationRoot configRoot = new ConfigurationBuilder() | ||
.AddInMemoryCollection( | ||
new Dictionary<string, string> | ||
{ | ||
{ "UpstreamProtocol", input } | ||
}) | ||
.Build(); | ||
|
||
// Act | ||
Option<UpstreamProtocol> upstreamProtocol = Startup.GetUpstreamProtocol(configRoot); | ||
|
||
// Assert | ||
Assert.Equal(expectedValue.HasValue, upstreamProtocol.HasValue); | ||
Assert.Equal(expectedValue.OrDefault(), upstreamProtocol.OrDefault()); | ||
} | ||
} | ||
} |