forked from lduchosal/ipnetwork
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
version 2.3.0, supporting serialization
- Loading branch information
Showing
15 changed files
with
431 additions
and
24 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
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: | ||
|
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
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
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
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
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
1 change: 1 addition & 0 deletions
1
src/System.Net.IPNetwork.TestProject.NetFramework/packages.config
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 |
---|---|---|
@@ -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> |
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
125 changes: 125 additions & 0 deletions
125
src/System.Net.IPNetwork.TestProject.Source/SerializeBinaryFormatterTest.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,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
87
src/System.Net.IPNetwork.TestProject.Source/SerializeJsonTest.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,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). | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.