Skip to content

Commit 5b3c4e0

Browse files
committed
fix build
1 parent 2e3bf15 commit 5b3c4e0

File tree

4 files changed

+104
-52
lines changed

4 files changed

+104
-52
lines changed

Open.Nat.UnitTests/InternetProtocolV6Tests.cs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@ public void TearDown()
3030
}
3131

3232
[TestMethod]
33+
#if NET35
34+
public void Connect()
35+
#else
3336
public async Task Connect()
37+
#endif
3438
{
35-
var nat = new NatDiscoverer();
36-
var cts = new CancellationTokenSource(5000);
3739
_server.WhenDiscoveryRequest = () =>
3840
"HTTP/1.1 200 OK\r\n"
3941
+ "Server: Custom/1.0 UPnP/1.0 Proc/Ver\r\n"
@@ -63,11 +65,34 @@ public async Task Connect()
6365
response.Close();
6466
};
6567

68+
var nat = new NatDiscoverer();
69+
#if NET35
70+
var cts = new CancellationTokenSource();
71+
cts.CancelAfter(5000);
72+
73+
NatDevice device =null;
74+
nat.DiscoverDeviceAsync(PortMapper.Upnp, cts)
75+
.ContinueWith(tt =>
76+
{
77+
device = tt.Result;
78+
Assert.IsNotNull(device);
79+
});
80+
81+
device.GetExternalIPAsync()
82+
.ContinueWith(tt =>
83+
{
84+
var ip = tt.Result;
85+
Assert.AreEqual(IPAddress.Parse("FE80::0202:B3FF:FE1E:8329"), ip);
86+
});
87+
88+
#else
89+
var cts = new CancellationTokenSource(5000);
6690
var device = await nat.DiscoverDeviceAsync(PortMapper.Upnp, cts);
6791
Assert.IsNotNull(device);
6892

6993
var ip = await device.GetExternalIPAsync();
7094
Assert.AreEqual(IPAddress.Parse("FE80::0202:B3FF:FE1E:8329"), ip);
95+
#endif
7196
}
7297
}
7398
}

Open.Nat.UnitTests/Open.Nat.UnitTests.csproj

Lines changed: 48 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,54 @@
22
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
44
<PropertyGroup>
5-
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6-
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
5+
<SignAssembly>true</SignAssembly>
6+
</PropertyGroup>
7+
<PropertyGroup>
8+
<AssemblyOriginatorKeyFile>Open.Nat.snk</AssemblyOriginatorKeyFile>
9+
</PropertyGroup>
10+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug 3.5|AnyCPU'">
11+
<OutputPath>bin\Debug\net35\</OutputPath>
12+
<DefineConstants>TRACE;DEBUG;NET35</DefineConstants>
713
<ProjectGuid>{7A65D2F2-BFB5-4BE1-A54D-484A394DE745}</ProjectGuid>
814
<OutputType>Library</OutputType>
915
<AppDesignerFolder>Properties</AppDesignerFolder>
1016
<RootNamespace>Open.Nat.UnitTests</RootNamespace>
1117
<AssemblyName>Open.Nat.UnitTests</AssemblyName>
12-
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
18+
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
1319
<FileAlignment>512</FileAlignment>
14-
<TargetFrameworkProfile />
15-
</PropertyGroup>
16-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17-
<DebugSymbols>true</DebugSymbols>
18-
<DebugType>full</DebugType>
19-
<Optimize>false</Optimize>
20-
<OutputPath>bin\Debug\</OutputPath>
21-
<DefineConstants>DEBUG;TRACE</DefineConstants>
22-
<ErrorReport>prompt</ErrorReport>
23-
<WarningLevel>4</WarningLevel>
24-
<Prefer32Bit>false</Prefer32Bit>
2520
</PropertyGroup>
26-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
27-
<DebugType>pdbonly</DebugType>
28-
<Optimize>true</Optimize>
29-
<OutputPath>bin\Release\</OutputPath>
30-
<DefineConstants>TRACE</DefineConstants>
31-
<ErrorReport>prompt</ErrorReport>
32-
<WarningLevel>4</WarningLevel>
33-
<Prefer32Bit>false</Prefer32Bit>
21+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug 4.5|AnyCPU'">
22+
<OutputPath>bin\Debug\net45\</OutputPath>
23+
<DefineConstants>TRACE;DEBUG;NET45</DefineConstants>
24+
<ProjectGuid>{7A65D2F2-BFB5-4BE1-A54D-484A394DE745}</ProjectGuid>
25+
<OutputType>Library</OutputType>
26+
<AppDesignerFolder>Properties</AppDesignerFolder>
27+
<RootNamespace>Open.Nat.UnitTests</RootNamespace>
28+
<AssemblyName>Open.Nat.UnitTests</AssemblyName>
29+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
30+
<FileAlignment>512</FileAlignment>
3431
</PropertyGroup>
35-
<PropertyGroup>
36-
<SignAssembly>true</SignAssembly>
32+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release 3.5|AnyCPU'">
33+
<OutputPath>bin\Release\net35\</OutputPath>
34+
<DefineConstants>NET35</DefineConstants>
35+
<ProjectGuid>{7A65D2F2-BFB5-4BE1-A54D-484A394DE745}</ProjectGuid>
36+
<OutputType>Library</OutputType>
37+
<AppDesignerFolder>Properties</AppDesignerFolder>
38+
<RootNamespace>Open.Nat.UnitTests</RootNamespace>
39+
<AssemblyName>Open.Nat.UnitTests</AssemblyName>
40+
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
41+
<FileAlignment>512</FileAlignment>
3742
</PropertyGroup>
38-
<PropertyGroup>
39-
<AssemblyOriginatorKeyFile>Open.Nat.snk</AssemblyOriginatorKeyFile>
43+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release 4.5|AnyCPU'">
44+
<OutputPath>bin\Release\net45\</OutputPath>
45+
<DefineConstants>NET45</DefineConstants>
46+
<ProjectGuid>{7A65D2F2-BFB5-4BE1-A54D-484A394DE745}</ProjectGuid>
47+
<OutputType>Library</OutputType>
48+
<AppDesignerFolder>Properties</AppDesignerFolder>
49+
<RootNamespace>Open.Nat.UnitTests</RootNamespace>
50+
<AssemblyName>Open.Nat.UnitTests</AssemblyName>
51+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
52+
<FileAlignment>512</FileAlignment>
4053
</PropertyGroup>
4154
<ItemGroup>
4255
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
@@ -47,6 +60,15 @@
4760
<Reference Include="System.XML" />
4861
<Reference Include="System.Xml.Linq" />
4962
</ItemGroup>
63+
<ItemGroup>
64+
<Reference Include="System" />
65+
<Reference Include="System.Data" />
66+
<Reference Include="System.Xml" />
67+
<Reference Include="System.Threading, Version=1.0.2856.102, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" Condition="'$(Configuration)|$(Platform)' == 'Release 3.5|AnyCPU' OR '$(Configuration)|$(Platform)' == 'Debug 3.5|AnyCPU'">
68+
<HintPath>..\packages\TaskParallelLibrary.1.0.2856.0\lib\Net35\System.Threading.dll</HintPath>
69+
<Private>True</Private>
70+
</Reference>
71+
</ItemGroup>
5072
<ItemGroup>
5173
<Compile Include="InternetProtocolV6Tests.cs" />
5274
<Compile Include="UpnpMockServer.cs" />

Open.Nat.UnitTests/UpnpMockServer.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,16 @@ private static void ResponseOk(HttpListenerContext context)
5858
private static void WhenRequestService(HttpListenerContext context)
5959
{
6060
var responseBytes = File.OpenRead("..\\..\\Responses\\ServiceDescription.txt");
61+
#if NET35
62+
var buffer = new byte[1024];
63+
int count;
64+
while ((count = responseBytes.Read(buffer, 0, buffer.Length)) != 0)
65+
{
66+
context.Response.OutputStream.Write(buffer, 0, count);
67+
}
68+
#else
6169
responseBytes.CopyTo(context.Response.OutputStream);
70+
#endif
6271
context.Response.OutputStream.Flush();
6372

6473
context.Response.Status(200, "OK");
@@ -85,7 +94,12 @@ public void Start()
8594

8695
private void StartAnnouncer()
8796
{
88-
Task.Run(() =>{
97+
#if NET35
98+
Task.Factory.StartNew(
99+
#else
100+
Task.Run(
101+
#endif
102+
() =>{
89103
var remoteIPEndPoint = new IPEndPoint(IPAddress.Any, 0);
90104
using (var udpClient = new UdpClient(1900))
91105
{
@@ -123,7 +137,12 @@ private void StartAnnouncer()
123137
private void StartServer()
124138
{
125139
_listener.Start();
126-
Task.Run(() => {
140+
#if NET35
141+
Task.Factory.StartNew(
142+
#else
143+
Task.Run(
144+
#endif
145+
() => {
127146
while (true)
128147
{
129148
ProcessRequest();

Open.Nat.sln

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,48 +30,34 @@ Global
3030
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3131
Debug 3.5|Any CPU = Debug 3.5|Any CPU
3232
Debug 4.5|Any CPU = Debug 4.5|Any CPU
33-
Debug|Any CPU = Debug|Any CPU
3433
Release 3.5|Any CPU = Release 3.5|Any CPU
3534
Release 4.5|Any CPU = Release 4.5|Any CPU
36-
Release|Any CPU = Release|Any CPU
3735
EndGlobalSection
3836
GlobalSection(ProjectConfigurationPlatforms) = postSolution
3937
{F5D74163-145F-47BF-83DC-D0E07249C6CA}.Debug 3.5|Any CPU.ActiveCfg = Debug 3.5|Any CPU
4038
{F5D74163-145F-47BF-83DC-D0E07249C6CA}.Debug 3.5|Any CPU.Build.0 = Debug 3.5|Any CPU
4139
{F5D74163-145F-47BF-83DC-D0E07249C6CA}.Debug 4.5|Any CPU.ActiveCfg = Debug 4.5|Any CPU
4240
{F5D74163-145F-47BF-83DC-D0E07249C6CA}.Debug 4.5|Any CPU.Build.0 = Debug 4.5|Any CPU
43-
{F5D74163-145F-47BF-83DC-D0E07249C6CA}.Debug|Any CPU.ActiveCfg = Debug 4.5|Any CPU
44-
{F5D74163-145F-47BF-83DC-D0E07249C6CA}.Debug|Any CPU.Build.0 = Debug 4.5|Any CPU
4541
{F5D74163-145F-47BF-83DC-D0E07249C6CA}.Release 3.5|Any CPU.ActiveCfg = Release 3.5|Any CPU
4642
{F5D74163-145F-47BF-83DC-D0E07249C6CA}.Release 3.5|Any CPU.Build.0 = Release 3.5|Any CPU
4743
{F5D74163-145F-47BF-83DC-D0E07249C6CA}.Release 4.5|Any CPU.ActiveCfg = Release 4.5|Any CPU
4844
{F5D74163-145F-47BF-83DC-D0E07249C6CA}.Release 4.5|Any CPU.Build.0 = Release 4.5|Any CPU
49-
{F5D74163-145F-47BF-83DC-D0E07249C6CA}.Release|Any CPU.ActiveCfg = Release 4.5|Any CPU
50-
{F5D74163-145F-47BF-83DC-D0E07249C6CA}.Release|Any CPU.Build.0 = Release 4.5|Any CPU
5145
{E92CFA66-F518-4E66-B0BA-76A7808C939A}.Debug 3.5|Any CPU.ActiveCfg = Debug 3.5|Any CPU
5246
{E92CFA66-F518-4E66-B0BA-76A7808C939A}.Debug 3.5|Any CPU.Build.0 = Debug 3.5|Any CPU
5347
{E92CFA66-F518-4E66-B0BA-76A7808C939A}.Debug 4.5|Any CPU.ActiveCfg = Debug 4.5|Any CPU
5448
{E92CFA66-F518-4E66-B0BA-76A7808C939A}.Debug 4.5|Any CPU.Build.0 = Debug 4.5|Any CPU
55-
{E92CFA66-F518-4E66-B0BA-76A7808C939A}.Debug|Any CPU.ActiveCfg = Debug 4.5|Any CPU
56-
{E92CFA66-F518-4E66-B0BA-76A7808C939A}.Debug|Any CPU.Build.0 = Debug 4.5|Any CPU
5749
{E92CFA66-F518-4E66-B0BA-76A7808C939A}.Release 3.5|Any CPU.ActiveCfg = Release 3.5|Any CPU
5850
{E92CFA66-F518-4E66-B0BA-76A7808C939A}.Release 3.5|Any CPU.Build.0 = Release 3.5|Any CPU
5951
{E92CFA66-F518-4E66-B0BA-76A7808C939A}.Release 4.5|Any CPU.ActiveCfg = Release 4.5|Any CPU
6052
{E92CFA66-F518-4E66-B0BA-76A7808C939A}.Release 4.5|Any CPU.Build.0 = Release 4.5|Any CPU
61-
{E92CFA66-F518-4E66-B0BA-76A7808C939A}.Release|Any CPU.ActiveCfg = Release 4.5|Any CPU
62-
{E92CFA66-F518-4E66-B0BA-76A7808C939A}.Release|Any CPU.Build.0 = Release 4.5|Any CPU
63-
{7A65D2F2-BFB5-4BE1-A54D-484A394DE745}.Debug 3.5|Any CPU.ActiveCfg = Debug|Any CPU
64-
{7A65D2F2-BFB5-4BE1-A54D-484A394DE745}.Debug 3.5|Any CPU.Build.0 = Debug|Any CPU
65-
{7A65D2F2-BFB5-4BE1-A54D-484A394DE745}.Debug 4.5|Any CPU.ActiveCfg = Debug|Any CPU
66-
{7A65D2F2-BFB5-4BE1-A54D-484A394DE745}.Debug 4.5|Any CPU.Build.0 = Debug|Any CPU
67-
{7A65D2F2-BFB5-4BE1-A54D-484A394DE745}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
68-
{7A65D2F2-BFB5-4BE1-A54D-484A394DE745}.Debug|Any CPU.Build.0 = Debug|Any CPU
69-
{7A65D2F2-BFB5-4BE1-A54D-484A394DE745}.Release 3.5|Any CPU.ActiveCfg = Release|Any CPU
70-
{7A65D2F2-BFB5-4BE1-A54D-484A394DE745}.Release 3.5|Any CPU.Build.0 = Release|Any CPU
71-
{7A65D2F2-BFB5-4BE1-A54D-484A394DE745}.Release 4.5|Any CPU.ActiveCfg = Release|Any CPU
72-
{7A65D2F2-BFB5-4BE1-A54D-484A394DE745}.Release 4.5|Any CPU.Build.0 = Release|Any CPU
73-
{7A65D2F2-BFB5-4BE1-A54D-484A394DE745}.Release|Any CPU.ActiveCfg = Release|Any CPU
74-
{7A65D2F2-BFB5-4BE1-A54D-484A394DE745}.Release|Any CPU.Build.0 = Release|Any CPU
53+
{7A65D2F2-BFB5-4BE1-A54D-484A394DE745}.Debug 3.5|Any CPU.ActiveCfg = Debug 3.5|Any CPU
54+
{7A65D2F2-BFB5-4BE1-A54D-484A394DE745}.Debug 3.5|Any CPU.Build.0 = Debug 3.5|Any CPU
55+
{7A65D2F2-BFB5-4BE1-A54D-484A394DE745}.Debug 4.5|Any CPU.ActiveCfg = Debug 4.5|Any CPU
56+
{7A65D2F2-BFB5-4BE1-A54D-484A394DE745}.Debug 4.5|Any CPU.Build.0 = Debug 4.5|Any CPU
57+
{7A65D2F2-BFB5-4BE1-A54D-484A394DE745}.Release 3.5|Any CPU.ActiveCfg = Release 3.5|Any CPU
58+
{7A65D2F2-BFB5-4BE1-A54D-484A394DE745}.Release 3.5|Any CPU.Build.0 = Release 3.5|Any CPU
59+
{7A65D2F2-BFB5-4BE1-A54D-484A394DE745}.Release 4.5|Any CPU.ActiveCfg = Release 4.5|Any CPU
60+
{7A65D2F2-BFB5-4BE1-A54D-484A394DE745}.Release 4.5|Any CPU.Build.0 = Release 4.5|Any CPU
7561
EndGlobalSection
7662
GlobalSection(SolutionProperties) = preSolution
7763
HideSolutionNode = FALSE

0 commit comments

Comments
 (0)