Skip to content
This repository was archived by the owner on Jun 26, 2024. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"sdk": {
"version": "2.1.500"
},
"msbuild-sdks": {
"MSBuild.Sdk.Extras": "1.5.4",
"__MSBuild.Sdk.Extras": "1.6.20-preview"
Expand Down
172 changes: 172 additions & 0 deletions src/protobuf-net.Test/Meta/Lists.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,53 @@ public void RoundTripTypedList_String()
Assert.True(obj.ListString.SequenceEqual(clone.ListString));
}

[Fact]
public void RoundTripTypedList_String_Null()
{
var model = TypeModel.Create();
model.Add(typeof(TypeWithLists), false).Add(1, "ListString");
TypeWithLists obj = new TypeWithLists();
obj.ListString = null;

TypeWithLists clone = (TypeWithLists)model.DeepClone(obj);
Assert.NotNull(clone);
Assert.Null(clone.ListString);

model.CompileInPlace();
clone = (TypeWithLists)model.DeepClone(obj);
Assert.NotNull(clone);
Assert.Null(clone.ListString);

clone = (TypeWithLists)model.Compile().DeepClone(obj);
Assert.NotNull(clone);
Assert.Null(clone.ListString);
}

[Fact]
public void RoundTripTypedList_String_Empty()
{
var model = TypeModel.Create();
model.Add(typeof(TypeWithLists), false).Add(1, "ListString");
TypeWithLists obj = new TypeWithLists();
obj.ListString = new List<string>();

TypeWithLists clone = (TypeWithLists)model.DeepClone(obj);
Assert.NotNull(clone);
Assert.NotNull(clone.ListString);
Assert.Empty(clone.ListString);

model.CompileInPlace();
clone = (TypeWithLists)model.DeepClone(obj);
Assert.NotNull(clone);
Assert.NotNull(clone.ListString);
Assert.Empty(clone.ListString);

clone = (TypeWithLists)model.Compile().DeepClone(obj);
Assert.NotNull(clone);
Assert.NotNull(clone.ListString);
Assert.Empty(clone.ListString);
}

[Fact]
public void RoundTripTypedIList_String()
{
Expand Down Expand Up @@ -151,6 +198,53 @@ public void RoundTripTypedIList_String()
Assert.True(obj.IListStringTyped.SequenceEqual(clone.IListStringTyped));
}

[Fact]
public void RoundTripTypedIList_String_Null()
{
var model = TypeModel.Create();
model.Add(typeof(TypeWithLists), false).Add(2, "IListStringTyped");
TypeWithLists obj = new TypeWithLists();
obj.IListStringTyped = null;

TypeWithLists clone = (TypeWithLists)model.DeepClone(obj);
Assert.NotNull(clone);
Assert.Null(clone.IListStringTyped);

model.CompileInPlace();
clone = (TypeWithLists)model.DeepClone(obj);
Assert.NotNull(clone);
Assert.Null(clone.IListStringTyped);

clone = (TypeWithLists)model.Compile().DeepClone(obj);
Assert.NotNull(clone);
Assert.Null(clone.IListStringTyped);
}

[Fact]
public void RoundTripTypedIList_String_Empty()
{
var model = TypeModel.Create();
model.Add(typeof(TypeWithLists), false).Add(2, "IListStringTyped");
TypeWithLists obj = new TypeWithLists();
obj.IListStringTyped = new List<string>();

TypeWithLists clone = (TypeWithLists)model.DeepClone(obj);
Assert.NotNull(clone);
Assert.NotNull(clone.IListStringTyped);
Assert.True(obj.IListStringTyped.Count == 0);

model.CompileInPlace();
clone = (TypeWithLists)model.DeepClone(obj);
Assert.NotNull(clone);
Assert.NotNull(clone.IListStringTyped);
Assert.True(obj.IListStringTyped.Count == 0);

clone = (TypeWithLists)model.Compile().DeepClone(obj);
Assert.NotNull(clone);
Assert.NotNull(clone.IListStringTyped);
Assert.True(obj.IListStringTyped.Count == 0);
}


[Fact]
public void RoundTripArrayList_String()
Expand Down Expand Up @@ -315,6 +409,84 @@ public void RoundTripIList_Int32()
Assert.True(obj.IListInt32Untyped.Cast<int>().SequenceEqual(clone.IListInt32Untyped.Cast<int>()));
}

[Fact]
public void RoundTripArray_String()
{
var model = TypeModel.Create();
model.Add(typeof(Arrays), false).Add(4, "BasicArray");
Arrays obj = new Arrays();
obj.BasicArray = new[] { "abc", "def" };

Arrays clone = (Arrays)model.DeepClone(obj);
Assert.NotNull(clone);
Assert.NotNull(clone.BasicArray);
Assert.True(obj.BasicArray.SequenceEqual(clone.BasicArray));

model.CompileInPlace();
clone = (Arrays)model.DeepClone(obj);
Assert.NotNull(clone);
Assert.NotNull(clone.BasicArray);
Assert.True(obj.BasicArray.SequenceEqual(clone.BasicArray));

clone = (Arrays)model.Compile().DeepClone(obj);
Assert.NotNull(clone);
Assert.NotNull(clone.BasicArray);
Assert.True(obj.BasicArray.SequenceEqual(clone.BasicArray));
}


[Fact]
public void RoundTripArray_String_Null()
{
var model = TypeModel.Create();
model.Add(typeof(Arrays), false).Add(4, "BasicArray");
Arrays obj = new Arrays();
obj.BasicArray = null;

Arrays clone = (Arrays)model.DeepClone(obj);
Assert.NotNull(clone);
Assert.Null(clone.BasicArray);

model.CompileInPlace();
clone = (Arrays)model.DeepClone(obj);
Assert.NotNull(clone);
Assert.Null(clone.BasicArray);

clone = (Arrays)model.Compile().DeepClone(obj);
Assert.NotNull(clone);
Assert.Null(clone.BasicArray);
}

[Fact]
public void RoundTripArray_String_Empty()
{
var model = TypeModel.Create();
model.Add(typeof(Arrays), false).Add(4, "BasicArray");
Arrays obj = new Arrays();
obj.BasicArray = new string[0];

Arrays clone = (Arrays)model.DeepClone(obj);
Assert.NotNull(clone);
Assert.NotNull(clone.BasicArray);
Assert.True(obj.BasicArray.Length == 0);

model.CompileInPlace();
clone = (Arrays)model.DeepClone(obj);
Assert.NotNull(clone);
Assert.NotNull(clone.BasicArray);
Assert.True(obj.BasicArray.Length == 0);

clone = (Arrays)model.Compile().DeepClone(obj);
Assert.NotNull(clone);
Assert.NotNull(clone.BasicArray);
Assert.True(obj.BasicArray.Length == 0);
}

public class Arrays
{
public string[] BasicArray { get; set; }
}

public class NastyType
{

Expand Down
73 changes: 73 additions & 0 deletions src/protobuf-net.Test/PreviousVersions.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading