Skip to content

Commit

Permalink
version 2.3.0, supporting serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
lduchosal committed Mar 14, 2019
1 parent e486426 commit f2ca12d
Show file tree
Hide file tree
Showing 15 changed files with 431 additions and 24 deletions.
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '2.2.0.{build}'
version: '2.3.0.{build}'
image: Visual Studio 2017

assembly_info:
Expand Down
2 changes: 1 addition & 1 deletion doc/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ PROJECT_NAME = "IPNetwork"
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = 2.2.0
PROJECT_NUMBER = 2.3.0

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down
5 changes: 3 additions & 2 deletions nant/release.build
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<property name="ipnetwork.sln" value="..\src\ipnetwork.sln" />
<property name="doc.base" value="${project::get-base-directory()}\..\doc" />
<property name="doc.doxygen" value="${doc.base}\Doxyfile" />
<property name="release.version" value="2.2.0" />
<property name="release.version" value="2.3.0" />
<property name="release.doc" value="..\doc\html" />
<property name="release.base" value="..\release" />
<property name="src.base" value="..\" />
Expand All @@ -14,7 +14,8 @@
<property name="src.dir" value="..\src" />
<property name="consoleappnetframework.dir" value="..\src\System.Net.IPNetwork.ConsoleApplication.NetFramework\bin\Release" />
<property name="consoleappnetcore.dir" value="..\src\System.Net.IPNetwork.ConsoleApplication.NetCore\bin\Release\netcoreapp2.0" />
<property name="lib.dir.netstandard1.3" value="..\src\System.Net.IPNetwork\bin\release\netstandard1.3" />
<property name="lib.dir.netstandard2.0" value="..\src\System.Net.IPNetwork\bin\release\netstandard2.0" />
<property name="lib.dir.net47" value="..\src\System.Net.IPNetwork\bin\release\net47" />
<property name="lib.dir.net46" value="..\src\System.Net.IPNetwork\bin\release\net46" />
<property name="lib.dir.net45" value="..\src\System.Net.IPNetwork\bin\release\net45" />
<property name="lib.dir.net40" value="..\src\System.Net.IPNetwork\bin\release\net40" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,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("2.2.0.0")]
[assembly: AssemblyFileVersion("2.2.0.0")]
[assembly: AssemblyVersion("2.3.0.0")]
[assembly: AssemblyFileVersion("2.3.0.0")]
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,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("2.2.0.0")]
[assembly: AssemblyFileVersion("2.2.0.0")]
[assembly: AssemblyVersion("2.3.0.0")]
[assembly: AssemblyFileVersion("2.3.0.0")]
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Console, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Console.4.0.0\lib\net46\System.Console.dll</HintPath>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="12.0.1" targetFramework="net462" />
<package id="System.Console" version="4.3.1" targetFramework="net462" />
</packages>
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("2.2.0.0")]
[assembly: AssemblyFileVersion("2.2.0.0")]
[assembly: AssemblyVersion("2.3.0.0")]
[assembly: AssemblyFileVersion("2.3.0.0")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
using IPNetwork = System.Net.IPNetwork;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Xml.Serialization;
using System.IO;
using System.Xml;
using System.Text;
using Newtonsoft.Json;
using System.Runtime.Serialization.Formatters.Binary;

namespace System.Net.TestSerialization
{
[TestClass]
public class SerializeBinaryFormatterTest
{

[TestMethod]
public void Test_Serialize_BinaryFormatter()
{
var ipnetwork = IPNetwork.Parse("10.0.0.1/8");

BinaryFormatter serializer = new BinaryFormatter();
var mem = new MemoryStream();

serializer.Serialize(mem, ipnetwork);
var result = Convert.ToBase64String(mem.ToArray());

string expected = "AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uTmV0LklQTmV0d29yaywgVmVyc2lvbj0yLjIuMC4wLCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPTcxNzM0M2NjMmMyNWVkY2YFAQAAABRTeXN0ZW0uTmV0LklQTmV0d29yawEAAAAJSVBOZXR3b3JrAQIAAAAGAwAAAAoxMC4wLjAuMC84Cw==";

Assert.AreEqual(expected, result);
}

[TestMethod]
public void Test_Deserialize_BinaryFormatter()
{
string base64 = "AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uTmV0LklQTmV0d29yaywgVmVyc2lvbj0yLjIuMC4wLCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPTcxNzM0M2NjMmMyNWVkY2YFAQAAABRTeXN0ZW0uTmV0LklQTmV0d29yawEAAAAJSVBOZXR3b3JrAQIAAAAGAwAAAAoxMC4wLjAuMC84Cw==";
var bytes = Convert.FromBase64String(base64);
var mem = new MemoryStream(bytes);

BinaryFormatter serializer = new BinaryFormatter();
var result = serializer.Deserialize(mem);

var expected = IPNetwork.Parse("10.0.0.1/8");
Assert.AreEqual(expected, result);

}

[TestMethod]
public void Test_Serialize_Deserialize_BinaryFormatter()
{
var ipnetwork = IPNetwork.Parse("10.0.0.1/8");

BinaryFormatter serializer = new BinaryFormatter();
var mem = new MemoryStream();

serializer.Serialize(mem, ipnetwork);

mem.Position = 0;
var ipnetwork2 = serializer.Deserialize(mem);

Assert.AreEqual(ipnetwork, ipnetwork2);
}


[TestMethod]
[TestCategory("LongRunning")]
public void Test_1_000_000_Serialize_BinaryFormatter()
{
var ipnetwork = IPNetwork.Parse("10.0.0.1/8");

var serializer = new BinaryFormatter();
var mem = new MemoryStream();

for (int i = 0; i < 1000000; i++)
{
serializer.Serialize(mem, ipnetwork);
mem.SetLength(0);
}

// 5.13 seconds(Ad hoc).
}

[TestMethod]
[TestCategory("LongRunning")]
public void Test_1_000_000_Deserialize_BinaryFormatter()
{
string base64 = "AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uTmV0LklQTmV0d29yaywgVmVyc2lvbj0yLjIuMC4wLCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPTcxNzM0M2NjMmMyNWVkY2YFAQAAABRTeXN0ZW0uTmV0LklQTmV0d29yawEAAAAJSVBOZXR3b3JrAQIAAAAGAwAAAAoxMC4wLjAuMC84Cw==";
var bytes = Convert.FromBase64String(base64);
var mem = new MemoryStream(bytes);

var serializer = new BinaryFormatter();

for (int i = 0; i < 1000000; i++)
{
var result = serializer.Deserialize(mem);
mem.Position = 0;
}

// 11.949 seconds(Ad hoc).
}

[TestMethod]
[TestCategory("LongRunning")]
public void Test_1_000_000_Serialize_Deserialize_BinaryFormatter()
{
var ipnetwork = IPNetwork.Parse("10.0.0.1/8");

BinaryFormatter serializer = new BinaryFormatter();
var mem = new MemoryStream();

for (int i = 0; i < 1000000; i++)
{
serializer.Serialize(mem, ipnetwork);

mem.Position = 0;
var ipnetwork2 = serializer.Deserialize(mem);

mem.SetLength(0);

}

// 17.48 seconds(Ad hoc).

}
}
}
87 changes: 87 additions & 0 deletions src/System.Net.IPNetwork.TestProject.Source/SerializeJsonTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;

namespace System.Net.TestSerialization.NetFramework
{
[TestClass]
public class SerializeJsonTest
{
[TestMethod]
public void Test_Serialize_Json()
{
var ipnetwork = IPNetwork.Parse("10.0.0.1/8");

var result = JsonConvert.SerializeObject(ipnetwork);

string expected = "{\"IPNetwork\":\"10.0.0.0/8\"}";
Assert.AreEqual(expected, result);
}

[TestMethod]
public void Test_Deserialize_Json()
{
string json = "{\"IPNetwork\":\"10.0.0.0/8\"}";

var result = JsonConvert.DeserializeObject<IPNetwork>(json);

IPNetwork expected = IPNetwork.Parse("10.0.0.1/8");
Assert.AreEqual(expected, result);
}

[TestMethod]
public void Test_Serialize_Deserialize_Json()
{
var ipnetwork = IPNetwork.Parse("10.0.0.1/8");

var json = JsonConvert.SerializeObject(ipnetwork);
var result = JsonConvert.DeserializeObject<IPNetwork>(json);

Assert.AreEqual(ipnetwork, result);
}

[TestMethod]
[TestCategory("LongRunning")]
public void Test_1_000_000_Serialize_Json()
{
var ipnetwork = IPNetwork.Parse("10.0.0.1/8");

for (int i = 0; i < 1000000; i++)
{
var json = JsonConvert.SerializeObject(ipnetwork);
}

// 3.06 seconds(Ad hoc).
}

[TestMethod]
[TestCategory("LongRunning")]
public void Test_1_000_000_Deserialize_Json()
{
string json = "{\"IPNetwork\":\"10.0.0.0/8\"}";

for (int i = 0; i < 1000000; i++)
{
var result = JsonConvert.DeserializeObject<IPNetwork>(json);
}

// 10.20 seconds(Ad hoc).
}

[TestMethod]
[TestCategory("LongRunning")]
public void Test_1_000_000_Serialize_Deserialize_Json()
{
var ipnetwork = IPNetwork.Parse("10.0.0.1/8");

for (int i = 0; i < 1000000; i++)
{
var json = JsonConvert.SerializeObject(ipnetwork);
var result = JsonConvert.DeserializeObject<IPNetwork>(json);
}

// 13.49 seconds(Ad hoc).
}

}
}
Loading

0 comments on commit f2ca12d

Please sign in to comment.