Skip to content

Commit

Permalink
INCOMPATIBLE: empty list is not the same as null list now!
Browse files Browse the repository at this point in the history
  • Loading branch information
AqlaSolutions committed Oct 19, 2015
1 parent 601f1cc commit 72179a7
Show file tree
Hide file tree
Showing 15 changed files with 11,242 additions and 91 deletions.
1 change: 0 additions & 1 deletion Examples/ComparisonToNDCS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.IO;
using System.Runtime.Serialization;
using NUnit.Framework;
using NUnit.Framework.SyntaxHelpers;
using AqlaSerializer;

namespace Examples
Expand Down
1 change: 0 additions & 1 deletion Examples/Issues/Issue174cs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Text;
using NUnit.Framework;
using AqlaSerializer;
using NUnit.Framework.SyntaxHelpers;
using System.IO;

namespace Examples.Issues
Expand Down
9 changes: 5 additions & 4 deletions Examples/Issues/SO14436606.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,11 @@ public void ThreeApproachesAreCompatible()
CreateFieldsModel().Serialize(ms, CreateB());
fields = BitConverter.ToString(ms.GetBuffer(), 0, (int)ms.Length);
}

Assert.AreEqual(surrogate, fields, "fields vs surrogate");
Assert.AreEqual(surrogate, defaultRef_AFirst, "default-ref (A-first) vs surrogate");
Assert.AreEqual(surrogate, defaultRef_BFirst, "default-ref (B-first) vs surrogate");

// AqlaSerializer changed format
//Assert.AreEqual(surrogate, fields, "fields vs surrogate");
//Assert.AreEqual(surrogate, defaultRef_AFirst, "default-ref (A-first) vs surrogate");
//Assert.AreEqual(surrogate, defaultRef_BFirst, "default-ref (B-first) vs surrogate");
}

[Test]
Expand Down
1 change: 0 additions & 1 deletion Examples/Issues/SO7064824.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

using System.Diagnostics;
using System.IO;
using NUnit.Framework.SyntaxHelpers;
using System;
using NUnit.Framework;
using AqlaSerializer;
Expand Down
76 changes: 21 additions & 55 deletions Examples/ListTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using Examples.Ppt;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework.SyntaxHelpers;
using System;
using System.IO;
using System.Collections;
Expand Down Expand Up @@ -215,26 +214,7 @@ public void SerializeUnpackedSerializePacked()
Assert.AreNotSame(item.Items, clone.List);
Assert.IsTrue(item.Items.SequenceEqual(clone.List));
}

[Test]
public void UnpackedNullOrEmptyListDeserializesAsNull()
{
var item = new EntityWithUnpackedInts();
Assert.IsNull(item.ItemsNoDefault);
var clone = Serializer.DeepClone(item);
Assert.IsNull(clone.ItemsNoDefault);

item.ItemsNoDefault = new List<int>();
clone = Serializer.DeepClone(item);
Assert.IsNull(clone.ItemsNoDefault);

item.ItemsNoDefault.Add(123);
clone = Serializer.DeepClone(item);
Assert.IsNotNull(clone.ItemsNoDefault);
Assert.AreEqual(1, clone.ItemsNoDefault.Count);
Assert.AreEqual(123, clone.ItemsNoDefault[0]);
}


[Test]
public void PackedEmptyListDeserializesAsEmpty()
{
Expand All @@ -254,67 +234,53 @@ public void PackedEmptyListDeserializesAsEmpty()
Assert.AreEqual(1, clone.ListNoDefault.Count);
Assert.AreEqual(123, clone.ListNoDefault[0]);
}

[Test]
public void UnpackedNullOrEmptyArrayDeserializesAsNull()
public void PackedEmptyArrayDeserializesAsEmpty()
{
var item = new EntityWithUnpackedInts();
var item = new EntityWithPackedInts();
Assert.IsNull(item.ItemArray);
var clone = Serializer.DeepClone(item);
Assert.IsNull(clone.ItemArray);

item.ItemArray = new int[0];
clone = Serializer.DeepClone(item);
Assert.IsNull(clone.ItemArray);
Assert.IsNotNull(clone.ItemArray);
Assert.AreEqual(0, clone.ItemArray.Length);

item.ItemArray = new int[1] { 123 };
clone = Serializer.DeepClone(item);
Assert.IsNotNull(clone.ItemArray);
Assert.AreEqual(1, clone.ItemArray.Length);
Assert.AreEqual(123, clone.ItemArray[0]);


}



[Test]
public void PackedEmptyArrayDeserializesAsEmpty()
public void PackedNullListDeserializesAsNull()
{
var item = new EntityWithPackedInts();
Assert.IsNull(item.ItemArray);
Assert.IsNull(item.ListNoDefault);
var clone = Serializer.DeepClone(item);
Assert.IsNull(clone.ItemArray);

item.ItemArray = new int[0];
clone = Serializer.DeepClone(item);
Assert.IsNotNull(clone.ItemArray);
Assert.AreEqual(0, clone.ItemArray.Length);

item.ItemArray = new int[1] { 123 };
Assert.IsNull(clone.ListNoDefault);

item.ListNoDefault = null;
clone = Serializer.DeepClone(item);
Assert.IsNotNull(clone.ItemArray);
Assert.AreEqual(1, clone.ItemArray.Length);
Assert.AreEqual(123, clone.ItemArray[0]);
Assert.IsNull(clone.ListNoDefault);
}

[Test]
public void UnpackedNullOrEmptyCustomDeserializesAsNull()
public void PackedNullArrayDeserializesAsNull()
{
var item = new EntityWithUnpackedInts();
Assert.IsNull(item.Custom);
var item = new EntityWithPackedInts();
Assert.IsNull(item.ItemArray);
var clone = Serializer.DeepClone(item);
Assert.IsNull(clone.Custom);

item.Custom = new CustomEnumerable();
clone = Serializer.DeepClone(item);
Assert.IsNull(clone.Custom);
Assert.IsNull(clone.ItemArray);

item.Custom.Add(123);
item.ItemArray = null;
clone = Serializer.DeepClone(item);
Assert.IsNotNull(clone.Custom);
Assert.AreEqual(123, item.Custom.Single());
Assert.IsNull(clone.ItemArray);
}

[Test]
public void PackedEmptyCustomDeserializesAsEmpty()
{
Expand Down
4 changes: 2 additions & 2 deletions Examples/SimpleStream/SimpleStreamDemo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public void TestDuffEnum()
SomeEnumEntity dee = new SomeEnumEntity { Enum = SomeEnum.Foo };
Assert.IsTrue(Program.CheckBytes(dee, 0x10, 0x03));
}
[Test, ExpectedException(ExceptionType = typeof(ProtoException))]
[Test, ExpectedException(ExpectedException = typeof(ProtoException))]
public void TestSerializeUndefinedEnum()
{
SomeEnumEntity dee = new SomeEnumEntity { Enum = 0 };
Expand Down Expand Up @@ -301,7 +301,7 @@ public class NotAContract
{
public int X { get; set; }
}
[Test, ExpectedException(ExceptionType = typeof(InvalidOperationException))]
[Test, ExpectedException(ExpectedException = typeof(InvalidOperationException))]
public void TestNotAContract()
{
NotAContract nac = new NotAContract { X = 4 };
Expand Down
Binary file modified Tools/nunit.framework.dll
Binary file not shown.
Loading

0 comments on commit 72179a7

Please sign in to comment.