Add UnitTests

pull/1/head
unknown 6 years ago
parent 09cb770765
commit b82b763cc5

@ -43,7 +43,7 @@
<HintPath>..\packages\Microsoft.Owin.Hosting.4.0.1\lib\net45\Microsoft.Owin.Hosting.dll</HintPath> <HintPath>..\packages\Microsoft.Owin.Hosting.4.0.1\lib\net45\Microsoft.Owin.Hosting.dll</HintPath>
</Reference> </Reference>
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> <Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>C:\Users\a.bozhenov\source\repos\ZeroTests\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll</HintPath> <HintPath>..\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference> </Reference>
<Reference Include="Owin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f0ebd12fd5e55cc5, processorArchitecture=MSIL"> <Reference Include="Owin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f0ebd12fd5e55cc5, processorArchitecture=MSIL">
<HintPath>..\packages\Owin.1.0\lib\net40\Owin.dll</HintPath> <HintPath>..\packages\Owin.1.0\lib\net40\Owin.dll</HintPath>

@ -1 +1 @@
baf2f9d75e4982e81a51362dec180283f7786a6a affe24c0b0d3f87817c2fa3318e87e4ecf28560f

@ -0,0 +1,90 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using ZeroLevel;
namespace ZeroArrayExtensionsTest
{
[TestClass]
public class ArrayExtensionsTest
{
internal class EQDTO
{
public byte[] Arr;
public DateTime Date;
public string Title;
public long Num;
public override bool Equals(object obj)
{
return this.Equals(obj as EQDTO);
}
public bool Equals(EQDTO other)
{
if (other == null) return false;
if (ArrayExtensions.UnsafeEquals(this.Arr, other.Arr) == false) return false;
if (DateTime.Compare(this.Date, other.Date) != 0) return false;
if (string.Compare(this.Title, other.Title, StringComparison.OrdinalIgnoreCase) != 0) return false;
return this.Num == other.Num;
}
}
[TestMethod]
public void ByteArrayEqualTest()
{
// Arrange
var a1 = new byte[] { 3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 7 };
var a2 = new byte[] { 3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 7 };
var a3 = new byte[] { 3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9 };
var a4 = new byte[] { 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 7 };
byte[] a5 = null;
byte[] a6 = null;
var a7 = new byte[0];
var a8 = new byte[0];
// Assert
Assert.IsTrue(ArrayExtensions.UnsafeEquals(a1, a2));
Assert.IsTrue(ArrayExtensions.UnsafeEquals(a5, a6));
Assert.IsTrue(ArrayExtensions.UnsafeEquals(a7, a8));
Assert.IsFalse(ArrayExtensions.UnsafeEquals(a1, a3));
Assert.IsFalse(ArrayExtensions.UnsafeEquals(a1, a4));
Assert.IsFalse(ArrayExtensions.UnsafeEquals(a1, a5));
Assert.IsFalse(ArrayExtensions.UnsafeEquals(a1, a7));
Assert.IsFalse(ArrayExtensions.UnsafeEquals(a5, a7));
}
[TestMethod]
public void ArrayEqualTest()
{
// Arrange
var date = DateTime.Now;
var arr1 = new EQDTO[]
{
new EQDTO { Arr = new byte[] { 1,2,3}, Date = date, Num = 10, Title = "t1" },
new EQDTO { Arr = new byte[] { 1,2,4}, Date = date, Num = 20, Title = "t2" },
new EQDTO { Arr = new byte[] { 1,2,5}, Date = date, Num = 30, Title = "t3" },
new EQDTO { Arr = new byte[] { 1,2,6}, Date = date, Num = 40, Title = "t4" },
new EQDTO { Arr = new byte[] { 1,2,7}, Date = date, Num = 50, Title = "t5" }
};
var arr2 = new EQDTO[]
{
new EQDTO { Arr = new byte[] { 1,2,6}, Date = date, Num = 40, Title = "t4" },
new EQDTO { Arr = new byte[] { 1,2,7}, Date = date, Num = 50, Title = "t5" }
};
var arr3 = new EQDTO[]
{
new EQDTO { Arr = new byte[] { 1,2,6}, Date = date, Num = 40, Title = "t4" },
new EQDTO { Arr = new byte[] { 1,2,7}, Date = date, Num = 50, Title = "t5" },
new EQDTO { Arr = new byte[] { 1,2,7}, Date = date, Num = 50, Title = "t6" },
};
//Assert
Assert.IsTrue(ArrayExtensions.Contains(arr1, arr2));
Assert.IsFalse(ArrayExtensions.Contains(arr1, arr3));
}
}
}

@ -0,0 +1,165 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Reflection;
using ZeroInvokingTest.Models;
using ZeroLevel.Services.Invokation;
namespace ZeroInvokingTest
{
[TestClass]
public class InvokingTest
{
[TestMethod]
public void InvokeTypeAllMethod()
{
// Arrange
var invoker = InvokeWrapper.Create();
// Act
invoker.Configure<FakeClass>();
var identityGetString = invoker.GetInvokerIdentity("GetString", new Type[] { typeof(string) });
var identityGetNumber = invoker.GetInvokerIdentity("GetNumber", new Type[] { typeof(int) });
var identityGetDateTime = invoker.GetInvokerIdentity("GetDateTime", new Type[] { typeof(DateTime) });
var identityGetHelp = invoker.GetInvokerIdentity("GetHelp", null);
// Assert
Assert.AreEqual(invoker.Invoke(new FakeClass(), identityGetString, new object[] { "hello" }), "hello");
Assert.AreEqual(invoker.Invoke(new FakeClass(), identityGetNumber, new object[] { 100 }), 100);
var date = DateTime.Now;
Assert.AreEqual(invoker.Invoke(new FakeClass(), identityGetDateTime, new object[] { date }), date);
Assert.AreEqual(invoker.Invoke(new FakeClass(), identityGetHelp), "help");
}
[TestMethod]
public void InvokeTypeMethodByName()
{
// Arrange
var invoker = InvokeWrapper.Create();
// Act
//invoker.Configure<FakeClass>("GetString");
invoker.Configure<FakeClass>("GetHelp");
invoker.Configure<FakeClass>("GetNumber");
invoker.Configure<FakeClass>("GetDateTime");
var identityGetString = invoker.GetInvokerIdentity("GetString", new Type[] { typeof(string) });
var identityGetNumber = invoker.GetInvokerIdentity("GetNumber", new Type[] { typeof(int) });
var identityGetDateTime = invoker.GetInvokerIdentity("GetDateTime", new Type[] { typeof(DateTime) });
var identityGetHelp = invoker.GetInvokerIdentity("GetHelp", null);
// Assert
try
{
var obj = invoker.Invoke(new FakeClass(), identityGetString, new object[] { "hello" });
Assert.Fail("An exception should have been thrown");
}
catch { }
Assert.AreEqual(invoker.Invoke(new FakeClass(), identityGetNumber, new object[] { 100 }), 100);
var date = DateTime.Now;
Assert.AreEqual(invoker.Invoke(new FakeClass(), identityGetDateTime, new object[] { date }), date);
Assert.AreEqual(invoker.Invoke(new FakeClass(), identityGetHelp), "help");
}
[TestMethod]
public void InvokeTypeMethodByFilter()
{
// Arrange
var invoker = InvokeWrapper.Create();
// Act
invoker.Configure<FakeClass>(m => m.Name.Equals("GetHelp") || m.Name.Equals("GetNumber"));
var identityGetString = invoker.GetInvokerIdentity("GetString", new Type[] { typeof(string) });
var identityGetNumber = invoker.GetInvokerIdentity("GetNumber", new Type[] { typeof(int) });
var identityGetDateTime = invoker.GetInvokerIdentity("GetDateTime", new Type[] { typeof(DateTime) });
var identityGetHelp = invoker.GetInvokerIdentity("GetHelp", null);
// Assert
try
{
var obj = invoker.Invoke(new FakeClass(), identityGetString, new object[] { "hello" });
Assert.Fail("An exception should have been thrown");
}
catch { }
try
{
var date = DateTime.Now;
Assert.AreEqual(invoker.Invoke(new FakeClass(), identityGetDateTime, new object[] { date }), date);
Assert.Fail("An exception should have been thrown");
}
catch { }
Assert.AreEqual(invoker.Invoke(new FakeClass(), identityGetNumber, new object[] { 100 }), 100);
Assert.AreEqual(invoker.Invoke(new FakeClass(), identityGetHelp), "help");
}
[TestMethod]
public void InvokeByMethodsList()
{
// Arrange
var invoker = InvokeWrapper.Create();
// Act
invoker.Configure(new MethodInfo[]
{
typeof(FakeClass).GetMethod("GetHelp", BindingFlags.Public | BindingFlags.FlattenHierarchy| BindingFlags.Instance),
typeof(FakeClass).GetMethod("GetNumber", BindingFlags.NonPublic| BindingFlags.Instance),
typeof(FakeClass).GetMethod("GetDateTime", BindingFlags.NonPublic| BindingFlags.Instance),
typeof(FakeClass).GetMethod("GetString")
});
var identityGetString = invoker.GetInvokerIdentity("GetString", new Type[] { typeof(string) });
var identityGetNumber = invoker.GetInvokerIdentity("GetNumber", new Type[] { typeof(int) });
var identityGetDateTime = invoker.GetInvokerIdentity("GetDateTime", new Type[] { typeof(DateTime) });
var identityGetHelp = invoker.GetInvokerIdentity("GetHelp", null);
// Assert
Assert.AreEqual(invoker.Invoke(new FakeClass(), identityGetString, new object[] { "hello" }), "hello");
Assert.AreEqual(invoker.Invoke(new FakeClass(), identityGetNumber, new object[] { 100 }), 100);
var date = DateTime.Now;
Assert.AreEqual(invoker.Invoke(new FakeClass(), identityGetDateTime, new object[] { date }), date);
Assert.AreEqual(invoker.Invoke(new FakeClass(), identityGetHelp), "help");
}
[TestMethod]
public void InvokeByMethods()
{
// Arrange
var invoker = InvokeWrapper.Create();
// Act
invoker.Configure(typeof(FakeClass).GetMethod("GetHelp", BindingFlags.Public | BindingFlags.FlattenHierarchy | BindingFlags.Instance));
invoker.Configure(typeof(FakeClass).GetMethod("GetNumber", BindingFlags.NonPublic | BindingFlags.Instance));
invoker.Configure(typeof(FakeClass).GetMethod("GetDateTime", BindingFlags.NonPublic | BindingFlags.Instance));
invoker.Configure(typeof(FakeClass).GetMethod("GetString"));
var identityGetString = invoker.GetInvokerIdentity("GetString", new Type[] { typeof(string) });
var identityGetNumber = invoker.GetInvokerIdentity("GetNumber", new Type[] { typeof(int) });
var identityGetDateTime = invoker.GetInvokerIdentity("GetDateTime", new Type[] { typeof(DateTime) });
var identityGetHelp = invoker.GetInvokerIdentity("GetHelp", null);
// Assert
Assert.AreEqual(invoker.Invoke(new FakeClass(), identityGetString, new object[] { "hello" }), "hello");
Assert.AreEqual(invoker.Invoke(new FakeClass(), identityGetNumber, new object[] { 100 }), 100);
var date = DateTime.Now;
Assert.AreEqual(invoker.Invoke(new FakeClass(), identityGetDateTime, new object[] { date }), date);
Assert.AreEqual(invoker.Invoke(new FakeClass(), identityGetHelp), "help");
}
[TestMethod]
public void InvokeStaticByMethods()
{
// Arrange
var invoker = InvokeWrapper.Create();
// Act
invoker.Configure(typeof(StaticFakeClass).GetMethod("GetNumber", BindingFlags.NonPublic | BindingFlags.Static));
invoker.Configure(typeof(StaticFakeClass).GetMethod("GetDateTime", BindingFlags.NonPublic | BindingFlags.Static));
invoker.Configure(typeof(StaticFakeClass).GetMethod("GetString"));
var identityGetString = invoker.GetInvokerIdentity("GetString", new Type[] { typeof(string) });
var identityGetNumber = invoker.GetInvokerIdentity("GetNumber", new Type[] { typeof(int) });
var identityGetDateTime = invoker.GetInvokerIdentity("GetDateTime", new Type[] { typeof(DateTime) });
// Assert
Assert.AreEqual(invoker.InvokeStatic(identityGetString, new object[] { "hello" }), "hello");
Assert.AreEqual(invoker.InvokeStatic(identityGetNumber, new object[] { 100 }), 100);
var date = DateTime.Now;
Assert.AreEqual(invoker.InvokeStatic(identityGetDateTime, new object[] { date }), date);
}
[TestMethod]
public void InvokeByDelegate()
{
// Arrange
var invoker = InvokeWrapper.Create();
// Act
var func = new Func<string, bool>(str => str.Length > 0);
var name = invoker.Configure(func);
// Assert
Assert.IsTrue((bool)invoker.Invoke(func.Target, name, new object[] { "hello" }));
}
}
}

@ -0,0 +1,207 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ZeroLevel.Services.ObjectMapping;
using ZeroMappingTest.Models;
using System.Collections.Generic;
namespace ZeroMappingTest
{
[TestClass]
public class MappingTest
{
[TestMethod]
public void TestAbstractClassGetInfo()
{
// Arrange
var mapper = TypeMapper.Create<BaseClass>();
// Act
var list = new List<string>();
mapper.TraversalMembers(f => list.Add(f.Name));
// Assert
Assert.IsTrue(mapper.Exists("Id"));
Assert.IsTrue(mapper.Exists("Title"));
Assert.IsTrue(mapper.Exists("Description"));
Assert.IsTrue(list.Contains("Id"));
Assert.IsTrue(list.Contains("Title"));
Assert.IsTrue(list.Contains("Description"));
Assert.IsFalse(mapper.Exists("Version"));
Assert.IsFalse(mapper.Exists("Created"));
Assert.IsFalse(list.Contains("Version"));
Assert.IsFalse(list.Contains("Created"));
Assert.AreEqual(mapper.EntityType, typeof(BaseClass));
}
[TestMethod]
public void TestInheritedClassGetInfo()
{
// Arrange
var mapper = TypeMapper.Create<ChildClass>();
// Act
var list = new List<string>();
mapper.TraversalMembers(f => list.Add(f.Name));
// Assert
Assert.IsTrue(mapper.Exists("Id"));
Assert.IsTrue(mapper.Exists("Title"));
Assert.IsTrue(mapper.Exists("Description"));
Assert.IsTrue(mapper.Exists("Number"));
Assert.IsTrue(mapper.Exists("Balance"));
Assert.IsTrue(mapper.Exists("ReadOnlyProperty"));
Assert.IsTrue(mapper.Exists("WriteOnlyProperty"));
Assert.IsTrue(list.Contains("Id"));
Assert.IsTrue(list.Contains("Title"));
Assert.IsTrue(list.Contains("Description"));
Assert.IsTrue(list.Contains("Number"));
Assert.IsTrue(list.Contains("Balance"));
Assert.IsTrue(list.Contains("ReadOnlyProperty"));
Assert.IsTrue(list.Contains("WriteOnlyProperty"));
Assert.IsFalse(mapper.Exists("HiddenField"));
Assert.IsFalse(mapper.Exists("Version"));
Assert.IsFalse(mapper.Exists("Created"));
Assert.IsFalse(list.Contains("HiddenField"));
Assert.IsFalse(list.Contains("Version"));
Assert.IsFalse(list.Contains("Created"));
Assert.AreEqual(mapper.EntityType, typeof(ChildClass));
}
[TestMethod]
public void TestAbstractClassMapping()
{
// Arrange
var instance = new ChildClass
{
Id = Guid.Empty,
Title = "title",
Description = "description",
WriteOnlyProperty = 100,
Balance = 100,
Number = 100
};
var mapper = TypeMapper.Create<BaseClass>();
// Act
var id = Guid.NewGuid();
var title = "New title";
var description = "New description";
mapper.Set(instance, "Id", id);
mapper.Set(instance, "Title", title);
mapper.Set(instance, "Description", description);
// Assert
Assert.AreEqual<Guid>(mapper.Get<Guid>(instance, "Id"), id);
Assert.AreEqual<string>(mapper.Get<string>(instance, "Title"), title);
Assert.AreEqual<string>(mapper.Get<string>(instance, "Description"), description);
Assert.AreEqual(mapper.Get(instance, "Id"), id);
Assert.AreEqual(mapper.Get(instance, "Title"), title);
Assert.AreEqual(mapper.Get(instance, "Description"), description);
try
{
mapper.Get(instance, "Number");
Assert.Fail("Must be inaccessability");
}
catch
{
}
}
[TestMethod]
public void TestInheritedClassMapping()
{
// Arrange
var instance = new ChildClass
{
Id = Guid.Empty,
Title = "title",
Description = "description",
WriteOnlyProperty = 100,
Balance = 100,
Number = 100
};
var mapper = TypeMapper.Create<ChildClass>();
// Act
var id = Guid.NewGuid();
var title = "New title";
var description = "New description";
var number = 5465;
var balance = 5555;
mapper.Set(instance, "Id", id);
mapper.Set(instance, "Title", title);
mapper.Set(instance, "Description", description);
mapper.Set(instance, "Number", number);
mapper.Set(instance, "Balance", balance);
// Assert
Assert.AreEqual<Guid>(mapper.Get<Guid>(instance, "Id"), id);
Assert.AreEqual<string>(mapper.Get<string>(instance, "Title"), title);
Assert.AreEqual<string>(mapper.Get<string>(instance, "Description"), description);
Assert.AreEqual<int>(mapper.Get<int>(instance, "Number"), number);
Assert.AreEqual<int>(mapper.Get<int>(instance, "Balance"), balance);
Assert.AreEqual(mapper.Get(instance, "Id"), id);
Assert.AreEqual(mapper.Get(instance, "Title"), title);
Assert.AreEqual(mapper.Get(instance, "Description"), description);
Assert.AreEqual(mapper.Get(instance, "Number"), number);
Assert.AreEqual(mapper.Get(instance, "Balance"), balance);
try
{
var test = 1000;
mapper.Set(instance, "ReadOnlyProperty", test);
Assert.Fail("There should be no possibility to set a value.");
}
catch
{
}
try
{
mapper.Get(instance, "WriteOnlyProperty");
Assert.Fail("There should be no possibility to get a value.");
}
catch
{
}
try
{
mapper.GetOrDefault(instance, "WriteOnlyProperty", null);
}
catch
{
Assert.Fail("It should be possible to get the default value.");
}
try
{
mapper.Get(instance, "Number");
}
catch(Exception ex)
{
Assert.Fail(ex.Message);
}
}
[TestMethod]
public void TestMapperscaching()
{
// Arrange
var mapper1 = TypeMapper.Create<ChildClass>();
var mapper2 = TypeMapper.Create<ChildClass>();
var mapper3 = TypeMapper.Create<ChildClass>(false);
// Act
// Assert
Assert.AreSame(mapper1, mapper2);
Assert.AreNotSame(mapper1, mapper3);
Assert.AreNotSame(mapper3, mapper2);
}
}
}

@ -0,0 +1,14 @@
using System;
namespace ZeroMappingTest.Models
{
public abstract class BaseClass
{
public Guid Id;
public string Title { get; set; }
public string Description { get; set; }
protected long Version { get; set; }
private DateTime Created { get; set; }
}
}

@ -0,0 +1,7 @@
namespace ZeroInvokingTest.Models
{
public abstract class BaseFakeClass
{
public string GetHelp() => "help";
}
}

@ -0,0 +1,11 @@
namespace ZeroMappingTest.Models
{
public class ChildClass:
BaseClass
{
public int Number;
public int Balance { get; set; }
public int ReadOnlyProperty { get { return Number; } }
public int WriteOnlyProperty { set { Number = value; } }
}
}

@ -0,0 +1,11 @@
using System;
namespace ZeroInvokingTest.Models
{
public class FakeClass : BaseFakeClass
{
public string GetString(string line) => line;
internal int GetNumber(int number) => number;
private DateTime GetDateTime(DateTime date) => date;
}
}

@ -0,0 +1,11 @@
using System;
namespace ZeroInvokingTest.Models
{
public static class StaticFakeClass
{
public static string GetString(string line) => line;
internal static int GetNumber(int number) => number;
private static DateTime GetDateTime(DateTime date) => date;
}
}

@ -0,0 +1,20 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle("ZeroLevel.UnitTests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ZeroLevel.UnitTests")]
[assembly: AssemblyCopyright("Copyright © 2019")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("c500b489-c432-499d-b0e4-b41998b12c49")]
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

@ -0,0 +1,335 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ZeroLevel.Network;
using ZeroLevel.Services.Serialization;
namespace ZeroLevel.UnitTests
{
[TestClass]
public class SerializationTests
{
private static bool TestOrderingEquals<T>(IEnumerable<T> A, IEnumerable<T> B, Func<T, T, bool> comparer)
{
if (A == null && B == null) return true;
if (A == null || B == null) return false;
if (A.Count() != B.Count()) return false;
var enumA = A.GetEnumerator();
var enumB = B.GetEnumerator();
while (enumA.MoveNext() && enumB.MoveNext())
{
if (enumA.Current == null && enumB.Current == null) continue;
if (comparer(enumA.Current, enumB.Current) == false) return false;
}
return true;
}
private void MakePrimitiveTest<T>(T value, Func<T, T, bool> comparator = null)
{
// Act
var data = MessageSerializer.SerializeCompatible<T>(value);
var clone = MessageSerializer.DeserializeCompatible<T>(data);
// Assert
if (comparator == null)
{
Assert.AreEqual<T>(value, clone);
}
else
{
Assert.IsTrue(comparator(value, clone));
}
}
private void MakeCollectionTest<T>(IEnumerable<T> value, Func<T, T, bool> comparator = null)
{
// Act
var data = MessageSerializer.SerializeCompatible<IEnumerable<T>>(value);
var clone = MessageSerializer.DeserializeCompatible<IEnumerable<T>>(data);
// Assert
if (value == null && clone != null && !clone.Any()) return; // OK
if (comparator == null)
{
Assert.IsTrue(CollectionComparsionExtensions.OrderingEquals(value, clone));
}
else
{
Assert.IsTrue(TestOrderingEquals(value, clone, comparator));
}
}
[TestMethod]
public void SerializeDateTime()
{
MakePrimitiveTest<DateTime>(DateTime.Now);
MakePrimitiveTest<DateTime>(DateTime.UtcNow);
MakePrimitiveTest<DateTime>(DateTime.Today);
MakePrimitiveTest<DateTime>(DateTime.Now.AddYears(2000));
MakePrimitiveTest<DateTime>(DateTime.MinValue);
MakePrimitiveTest<DateTime>(DateTime.MaxValue);
}
[TestMethod]
public void SerializeIPAddress()
{
var comparator = new Func<IPAddress, IPAddress, bool>((left, right) => NetUtils.Compare(left, right) == 0);
MakePrimitiveTest<IPAddress>(IPAddress.Any, comparator);
MakePrimitiveTest<IPAddress>(IPAddress.Broadcast, comparator);
MakePrimitiveTest<IPAddress>(IPAddress.IPv6Any, comparator);
MakePrimitiveTest<IPAddress>(IPAddress.IPv6Loopback, comparator);
MakePrimitiveTest<IPAddress>(IPAddress.IPv6None, comparator);
MakePrimitiveTest<IPAddress>(IPAddress.Loopback, comparator);
MakePrimitiveTest<IPAddress>(IPAddress.None, comparator);
MakePrimitiveTest<IPAddress>(IPAddress.Parse("93.111.16.58"), comparator);
}
[TestMethod]
public void SerializeIPEndPoint()
{
var comparator = new Func<IPEndPoint, IPEndPoint, bool>((left, right) => NetUtils.Compare(left, right) == 0);
MakePrimitiveTest<IPEndPoint>(new IPEndPoint(IPAddress.Any, 1), comparator);
MakePrimitiveTest<IPEndPoint>(new IPEndPoint(IPAddress.Broadcast, 600), comparator);
MakePrimitiveTest<IPEndPoint>(new IPEndPoint(IPAddress.IPv6Any, IPEndPoint.MaxPort), comparator);
MakePrimitiveTest<IPEndPoint>(new IPEndPoint(IPAddress.IPv6Loopback, 8080), comparator);
MakePrimitiveTest<IPEndPoint>(new IPEndPoint(IPAddress.IPv6None, 80), comparator);
MakePrimitiveTest<IPEndPoint>(new IPEndPoint(IPAddress.Loopback, 9000), comparator);
MakePrimitiveTest<IPEndPoint>(new IPEndPoint(IPAddress.None, 0), comparator);
MakePrimitiveTest<IPEndPoint>(new IPEndPoint(IPAddress.Parse("93.111.16.58"), IPEndPoint.MinPort), comparator);
}
[TestMethod]
public void SerializeGuid()
{
MakePrimitiveTest<Guid>(Guid.Empty);
MakePrimitiveTest<Guid>(Guid.NewGuid());
}
[TestMethod]
public void SerializeTimeSpan()
{
MakePrimitiveTest<TimeSpan>(TimeSpan.MaxValue);
MakePrimitiveTest<TimeSpan>(TimeSpan.MinValue);
MakePrimitiveTest<TimeSpan>(TimeSpan.Zero);
MakePrimitiveTest<TimeSpan>(TimeSpan.FromDays(1024));
MakePrimitiveTest<TimeSpan>(TimeSpan.FromMilliseconds(1));
MakePrimitiveTest<TimeSpan>(TimeSpan.FromTicks(1));
MakePrimitiveTest<TimeSpan>(TimeSpan.FromTicks(0));
}
[TestMethod]
public void SerializeString()
{
var comparator = new Func<string, string, bool>((left, right) =>
(left == null && right == null) ||
(left == null && right != null && right.Length == 0) ||
(left != null && left.Length == 0 && right == null) ||
string.Compare(left, right, StringComparison.InvariantCulture) == 0);
MakePrimitiveTest<String>("", comparator);
MakePrimitiveTest<String>(String.Empty, comparator);
MakePrimitiveTest<String>(null, comparator);
MakePrimitiveTest<String>("HELLO!", comparator);
MakePrimitiveTest<String>("𐌼𐌰𐌲 𐌲𐌻𐌴𐍃 𐌹̈𐍄𐌰𐌽, 𐌽𐌹 𐌼𐌹𐍃 𐍅𐌿 𐌽𐌳𐌰𐌽 𐌱𐍂𐌹𐌲𐌲𐌹𐌸", comparator);
}
[TestMethod]
public void SerializeInt32()
{
MakePrimitiveTest<Int32>(-0);
MakePrimitiveTest<Int32>(0);
MakePrimitiveTest<Int32>(-10);
MakePrimitiveTest<Int32>(10);
MakePrimitiveTest<Int32>(Int32.MinValue);
MakePrimitiveTest<Int32>(Int32.MaxValue);
}
[TestMethod]
public void SerializeInt64()
{
MakePrimitiveTest<Int64>(-0);
MakePrimitiveTest<Int64>(0);
MakePrimitiveTest<Int64>(-10);
MakePrimitiveTest<Int64>(10);
MakePrimitiveTest<Int64>(Int64.MinValue);
MakePrimitiveTest<Int64>(Int64.MaxValue);
MakePrimitiveTest<Int64>(Int64.MinValue / 2);
MakePrimitiveTest<Int64>(Int64.MaxValue / 2);
}
[TestMethod]
public void SerializeDecimal()
{
MakePrimitiveTest<Decimal>(-0);
MakePrimitiveTest<Decimal>(0);
MakePrimitiveTest<Decimal>(-10);
MakePrimitiveTest<Decimal>(10);
MakePrimitiveTest<Decimal>(Decimal.MinValue);
MakePrimitiveTest<Decimal>(Decimal.MaxValue);
MakePrimitiveTest<Decimal>(Decimal.MinValue / 2);
MakePrimitiveTest<Decimal>(Decimal.MaxValue / 2);
}
[TestMethod]
public void SerializeFloat()
{
MakePrimitiveTest<float>(-0);
MakePrimitiveTest<float>(0);
MakePrimitiveTest<float>(-10);
MakePrimitiveTest<float>(10);
MakePrimitiveTest<float>(float.MinValue);
MakePrimitiveTest<float>(float.MaxValue);
MakePrimitiveTest<float>(float.MinValue / 2);
MakePrimitiveTest<float>(float.MaxValue / 2);
}
[TestMethod]
public void SerializeDouble()
{
MakePrimitiveTest<Double>(-0);
MakePrimitiveTest<Double>(0);
MakePrimitiveTest<Double>(-10);
MakePrimitiveTest<Double>(10);
MakePrimitiveTest<Double>(Double.MinValue);
MakePrimitiveTest<Double>(Double.MaxValue);
MakePrimitiveTest<Double>(Double.MinValue / 2);
MakePrimitiveTest<Double>(Double.MaxValue / 2);
}
[TestMethod]
public void SerializeBoolean()
{
MakePrimitiveTest<Boolean>(true);
MakePrimitiveTest<Boolean>(false);
}
[TestMethod]
public void SerializeByte()
{
MakePrimitiveTest<Byte>(0);
MakePrimitiveTest<Byte>(-0);
MakePrimitiveTest<Byte>(1);
MakePrimitiveTest<Byte>(10);
MakePrimitiveTest<Byte>(128);
MakePrimitiveTest<Byte>(255);
}
[TestMethod]
public void SerializeBytes()
{
var comparator = new Func<byte[], byte[], bool>((left, right) =>
(left == null && (right == null || right.Length == 0)) || ArrayExtensions.UnsafeEquals(left, right));
MakePrimitiveTest<Byte[]>(null, comparator);
MakePrimitiveTest<Byte[]>(new byte[] { }, comparator);
MakePrimitiveTest<Byte[]>(new byte[] { 1 }, comparator);
MakePrimitiveTest<Byte[]>(new byte[] { 0, 1, 10, 100, 128, 255 }, comparator);
}
/*
COLLECTIONS
*/
[TestMethod]
public void SerializeCollectionDateTime()
{
MakeCollectionTest<DateTime>(null);
MakeCollectionTest<DateTime>(new DateTime[] { });
MakeCollectionTest<DateTime>(new DateTime[] { DateTime.Now, DateTime.UtcNow, DateTime.Today, DateTime.Now.AddYears(2000), DateTime.MinValue, DateTime.MaxValue });
}
[TestMethod]
public void SerializeCollectionIPAddress()
{
var comparator = new Func<IPAddress, IPAddress, bool>((left, right) => NetUtils.Compare(left, right) == 0);
MakeCollectionTest<IPAddress>(null);
MakeCollectionTest<IPAddress>(new IPAddress[] { IPAddress.Any, IPAddress.Broadcast, IPAddress.IPv6Any, IPAddress.IPv6Loopback, IPAddress.IPv6None, IPAddress.Loopback, IPAddress.None, IPAddress.Parse("93.111.16.58") }, comparator);
}
[TestMethod]
public void SerializeCollectionIPEndPoint()
{
var comparator = new Func<IPEndPoint, IPEndPoint, bool>((left, right) => NetUtils.Compare(left, right) == 0);
MakeCollectionTest<IPEndPoint>(null);
MakeCollectionTest<IPEndPoint>(new IPEndPoint[] { });
MakeCollectionTest<IPEndPoint>(new IPEndPoint[] { new IPEndPoint(IPAddress.Any, 1), new IPEndPoint(IPAddress.Broadcast, 600), new IPEndPoint(IPAddress.IPv6Any, IPEndPoint.MaxPort), new IPEndPoint(IPAddress.IPv6Loopback, 8080), new IPEndPoint(IPAddress.IPv6None, 80), new IPEndPoint(IPAddress.Loopback, 9000), new IPEndPoint(IPAddress.None, 0), new IPEndPoint(IPAddress.Parse("93.111.16.58"), IPEndPoint.MinPort) }, comparator);
}
[TestMethod]
public void SerializeCollectionGuid()
{
MakeCollectionTest<Guid>(null);
MakeCollectionTest<Guid>(new Guid[] { });
MakeCollectionTest<Guid>(new Guid[] { Guid.Empty, Guid.NewGuid() });
}
[TestMethod]
public void SerializeCollectionTimeSpan()
{
MakeCollectionTest<TimeSpan>(new TimeSpan[] { TimeSpan.MaxValue, TimeSpan.MinValue, TimeSpan.Zero, TimeSpan.FromDays(1024), TimeSpan.FromMilliseconds(1), TimeSpan.FromTicks(1), TimeSpan.FromTicks(0) });
}
[TestMethod]
public void SerializeCollectionString()
{
var comparator = new Func<string, string, bool>((left, right) =>
(left == null && right == null) ||
(left == null && right != null && right.Length == 0) ||
(left != null && left.Length == 0 && right == null) ||
string.Compare(left, right, StringComparison.InvariantCulture) == 0);
MakeCollectionTest<String>(new string[] { "", String.Empty, null, "HELLO!", "𐌼𐌰𐌲 𐌲𐌻𐌴𐍃 𐌹̈𐍄𐌰𐌽, 𐌽𐌹 𐌼𐌹𐍃 𐍅𐌿 𐌽𐌳𐌰𐌽 𐌱𐍂𐌹𐌲𐌲𐌹𐌸" }, comparator);
}
[TestMethod]
public void SerializeCollectionInt32()
{
MakeCollectionTest<Int32>(new int[] { -0, 0, -10, 10, Int32.MinValue, Int32.MaxValue });
}
[TestMethod]
public void SerializeCollectionInt64()
{
MakeCollectionTest<Int64>(new long[] { -0, 0, -10, 10, Int64.MinValue, Int64.MaxValue, Int64.MinValue / 2, Int64.MaxValue / 2 });
}
[TestMethod]
public void SerializeCollectionDecimal()
{
MakeCollectionTest<Decimal>(new Decimal[] { -0, 0, -10, 10, Decimal.MinValue, Decimal.MaxValue, Decimal.MinValue / 2, Decimal.MaxValue / 2 });
}
[TestMethod]
public void SerializeCollectionFloat()
{
MakeCollectionTest<float>(new float[] { -0, 0, -10, 10, float.MinValue, float.MaxValue, float.MinValue / 2, float.MaxValue / 2 });
}
[TestMethod]
public void SerializeCollectionDouble()
{
MakeCollectionTest<Double>(new Double[] { -0, 0, -10, 10, Double.MinValue, Double.MaxValue, Double.MinValue / 2, Double.MaxValue / 2 });
}
[TestMethod]
public void SerializeCollectionBoolean()
{
MakeCollectionTest<Boolean>(new Boolean[] { true, false, true });
}
[TestMethod]
public void SerializeCollectionByte()
{
MakeCollectionTest<Byte>(new byte[] { 0, 3, -0, 1, 10, 128, 255 });
}
[TestMethod]
public void SerializeCollectionBytes()
{
var comparator = new Func<byte[], byte[], bool>((left, right) =>
(left == null && (right == null || right.Length == 0)) || ArrayExtensions.UnsafeEquals(left, right));
MakeCollectionTest<Byte[]>(new Byte[][] { null, new byte[] { }, new byte[] { 1 }, new byte[] { 0, 1, 10, 100, 128, 255 } }, comparator);
}
}
}

@ -0,0 +1,82 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props" Condition="Exists('..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{C500B489-C432-499D-B0E4-B41998B12C49}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ZeroLevel.UnitTests</RootNamespace>
<AssemblyName>ZeroLevel.UnitTests</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">15.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
<IsCodedUITest>False</IsCodedUITest>
<TestProjectType>UnitTest</TestProjectType>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
<Compile Include="ArrayToolsTest.cs" />
<Compile Include="InvokingTest.cs" />
<Compile Include="MappingTest.cs" />
<Compile Include="Models\BaseClass.cs" />
<Compile Include="Models\BaseFakeClass.cs" />
<Compile Include="Models\ChildClass.cs" />
<Compile Include="Models\FakeClass.cs" />
<Compile Include="Models\StaticFakeClass.cs" />
<Compile Include="SerializationTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ZeroLevel\ZeroLevel.csproj">
<Project>{37020d8d-34e8-4ec3-a447-8396d5080457}</Project>
<Name>ZeroLevel</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props'))" />
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets'))" />
</Target>
<Import Project="..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets" Condition="Exists('..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets')" />
</Project>

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="MSTest.TestAdapter" version="1.3.2" targetFramework="net472" />
<package id="MSTest.TestFramework" version="1.3.2" targetFramework="net472" />
</packages>

@ -7,6 +7,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ZeroLevel", "ZeroLevel\Zero
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ZeroLevel.Discovery", "ZeroLevel.Discovery\ZeroLevel.Discovery.csproj", "{4F55B23F-938C-4DA2-B6DC-B6BC66D36073}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ZeroLevel.Discovery", "ZeroLevel.Discovery\ZeroLevel.Discovery.csproj", "{4F55B23F-938C-4DA2-B6DC-B6BC66D36073}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ZeroLevel.UnitTests", "ZeroLevel.UnitTests\ZeroLevel.UnitTests.csproj", "{C500B489-C432-499D-B0E4-B41998B12C49}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -41,6 +43,18 @@ Global
{4F55B23F-938C-4DA2-B6DC-B6BC66D36073}.Release|x64.Build.0 = Release|Any CPU {4F55B23F-938C-4DA2-B6DC-B6BC66D36073}.Release|x64.Build.0 = Release|Any CPU
{4F55B23F-938C-4DA2-B6DC-B6BC66D36073}.Release|x86.ActiveCfg = Release|Any CPU {4F55B23F-938C-4DA2-B6DC-B6BC66D36073}.Release|x86.ActiveCfg = Release|Any CPU
{4F55B23F-938C-4DA2-B6DC-B6BC66D36073}.Release|x86.Build.0 = Release|Any CPU {4F55B23F-938C-4DA2-B6DC-B6BC66D36073}.Release|x86.Build.0 = Release|Any CPU
{C500B489-C432-499D-B0E4-B41998B12C49}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C500B489-C432-499D-B0E4-B41998B12C49}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C500B489-C432-499D-B0E4-B41998B12C49}.Debug|x64.ActiveCfg = Debug|Any CPU
{C500B489-C432-499D-B0E4-B41998B12C49}.Debug|x64.Build.0 = Debug|Any CPU
{C500B489-C432-499D-B0E4-B41998B12C49}.Debug|x86.ActiveCfg = Debug|Any CPU
{C500B489-C432-499D-B0E4-B41998B12C49}.Debug|x86.Build.0 = Debug|Any CPU
{C500B489-C432-499D-B0E4-B41998B12C49}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C500B489-C432-499D-B0E4-B41998B12C49}.Release|Any CPU.Build.0 = Release|Any CPU
{C500B489-C432-499D-B0E4-B41998B12C49}.Release|x64.ActiveCfg = Release|Any CPU
{C500B489-C432-499D-B0E4-B41998B12C49}.Release|x64.Build.0 = Release|Any CPU
{C500B489-C432-499D-B0E4-B41998B12C49}.Release|x86.ActiveCfg = Release|Any CPU
{C500B489-C432-499D-B0E4-B41998B12C49}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

@ -16,14 +16,11 @@ namespace ZeroLevel.Services.Extensions
return bytes.ToArray(); return bytes.ToArray();
} }
public static decimal ToDecimal(this byte[] bytes) public static decimal ToDecimal(this int[] parts)
{ {
var arr = new int[4]; bool sign = (parts[3] & 0x80000000) != 0;
for (int i = 0; i < 15; i += 4) byte scale = (byte)((parts[3] >> 16) & 0x7F);
{ return new Decimal(parts[0], parts[1], parts[2], sign, scale);
arr[i % 4] = BitConverter.ToInt32(bytes, i);
}
return new Decimal(arr);
} }
} }
} }

@ -16,6 +16,13 @@ namespace ZeroLevel.Network
return result == 0 ? x.Port.CompareTo(y.Port) : result; return result == 0 ? x.Port.CompareTo(y.Port) : result;
} }
public static int Compare(this IPAddress x, IPAddress y)
{
var xx = x.ToString();
var yy = y.ToString();
return string.CompareOrdinal(xx, yy);
}
public static IPEndPoint CreateIPEndPoint(string endPoint) public static IPEndPoint CreateIPEndPoint(string endPoint)
{ {
string[] ep = endPoint.Split(':'); string[] ep = endPoint.Split(':');

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using System.Net; using System.Net;
using System.Text; using System.Text;
using ZeroLevel.Services.Extensions;
namespace ZeroLevel.Services.Serialization namespace ZeroLevel.Services.Serialization
{ {
@ -63,8 +64,11 @@ namespace ZeroLevel.Services.Serialization
public decimal ReadDecimal() public decimal ReadDecimal()
{ {
var buffer = ReadBuffer(4); var p1 = ReadInt32();
return BitConverter.ToInt32(buffer, 0); var p2 = ReadInt32();
var p3 = ReadInt32();
var p4 = ReadInt32();
return BitConverterExt.ToDecimal(new int[] { p1, p2, p3, p4 });
} }
/// <summary> /// <summary>
@ -143,13 +147,13 @@ namespace ZeroLevel.Services.Serialization
public IPAddress ReadIP() public IPAddress ReadIP()
{ {
var addr = ReadLong(); var addr = ReadBytes();
return new IPAddress(addr); return new IPAddress(addr);
} }
public IPEndPoint ReadIPEndpoint() public IPEndPoint ReadIPEndpoint()
{ {
var addr = ReadLong(); var addr = ReadIP();
var port = ReadInt32(); var port = ReadInt32();
return new IPEndPoint(addr, port); return new IPEndPoint(addr, port);
} }

@ -144,12 +144,12 @@ namespace ZeroLevel.Services.Serialization
public void WriteIP(IPAddress ip) public void WriteIP(IPAddress ip)
{ {
WriteLong(ip.Address); WriteBytes(ip.GetAddressBytes());
} }
public void WriteIPEndpoint(IPEndPoint endpoint) public void WriteIPEndpoint(IPEndPoint endpoint)
{ {
WriteLong(endpoint.Address.Address); WriteIP(endpoint.Address);
WriteInt32(endpoint.Port); WriteInt32(endpoint.Port);
} }

@ -1 +1 @@
23b05e1da25edde99ed56a899f894605a2243d39 4d221d21073e6ec70fc75d0c6e7d2458aa0f2b9a

Loading…
Cancel
Save

Powered by TurnKey Linux.