-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
241 additions
and
12 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
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
48 changes: 48 additions & 0 deletions
48
test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue358Tests_Extended.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,48 @@ | ||
using ExtendedXmlSerializer.Configuration; | ||
using ExtendedXmlSerializer.Tests.ReportedIssues.Support; | ||
using FluentAssertions; | ||
using JetBrains.Annotations; | ||
using Xunit; | ||
|
||
namespace ExtendedXmlSerializer.Tests.ReportedIssues | ||
{ | ||
public sealed class Issue358Tests_Extended | ||
{ | ||
[Fact] | ||
public void Verify() | ||
{ | ||
var serializer = new ConfigurationContainer().EnableParameterizedContentWithPropertyAssignments() | ||
.EnableReferences() | ||
.Create() | ||
.ForTesting(); | ||
|
||
var length = new length(11); | ||
var instance = new vector(length, length); | ||
|
||
var cycled = serializer.Cycle(instance); | ||
cycled.L1.Should().BeSameAs(cycled.L2); | ||
} | ||
|
||
class length | ||
{ | ||
public length(int value) | ||
{ | ||
Value = value; | ||
} | ||
|
||
public int Value { [UsedImplicitly] get; } | ||
} | ||
|
||
class vector | ||
{ | ||
public vector(length l1, length l2) | ||
{ | ||
L1 = l1; | ||
L2 = l2; | ||
} | ||
|
||
public length L1 { get; } | ||
public length L2 { get; } | ||
} | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue396Tests.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,73 @@ | ||
using ExtendedXmlSerializer.Configuration; | ||
using ExtendedXmlSerializer.Tests.ReportedIssues.Support; | ||
using FluentAssertions; | ||
using System; | ||
using System.Collections.Generic; | ||
using Xunit; | ||
|
||
namespace ExtendedXmlSerializer.Tests.ReportedIssues | ||
{ | ||
public sealed class Issue396Tests | ||
{ | ||
[Fact] | ||
public void NodesListIsMissingNodes() | ||
{ | ||
var serializer = new ConfigurationContainer().UseOptimizedNamespaces() | ||
.EnableParameterizedContentWithPropertyAssignments() | ||
.UseAutoFormatting() | ||
.Type<Node>() | ||
.EnableReferences() | ||
.Create() | ||
.ForTesting(); | ||
var node1 = new Node(1); | ||
var node2 = new Node(2).AddNode(node1, isBidirectional: true); | ||
var node3 = new Node(3).AddNode(node2, isBidirectional: false); | ||
node1.AddNode(node3, isBidirectional: false); | ||
var nodesList = new List<Node> { node1, node2, node3 }; | ||
|
||
|
||
|
||
var cycled = serializer.Cycle(nodesList); | ||
cycled.Should().BeEquivalentTo(nodesList, config => config.IgnoringCyclicReferences()); | ||
} | ||
|
||
public sealed class Node : IEquatable<Node> | ||
{ | ||
private readonly List<Node> _linkedNodes; | ||
|
||
public Node(int id) : this(id, new List<Node>()) {} | ||
|
||
public Node(int id, List<Node> linkedNodes) | ||
{ | ||
Id = id; | ||
_linkedNodes = linkedNodes ?? new List<Node>(); | ||
} | ||
|
||
public int Id { get; } | ||
|
||
public IReadOnlyList<Node> LinkedNodes => _linkedNodes; | ||
|
||
// ReSharper disable once FlagArgument | ||
public Node AddNode(Node otherNode, bool isBidirectional = true) | ||
{ | ||
if (otherNode == null) | ||
throw new ArgumentNullException(nameof(otherNode)); | ||
if (ReferenceEquals(this, otherNode)) | ||
throw new ArgumentException($"You cannot link a node {Id} to itself."); | ||
|
||
_linkedNodes.Add(otherNode); | ||
if (isBidirectional) | ||
otherNode.AddNode(this, false); | ||
return this; | ||
} | ||
|
||
public bool Equals(Node other) => !ReferenceEquals(null, other) && Id == other.Id; | ||
|
||
public override bool Equals(object obj) => ReferenceEquals(this, obj) || obj is Node other && Equals(other); | ||
|
||
public override int GetHashCode() => Id; | ||
|
||
public override string ToString() => "Node " + Id; | ||
} | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue418Tests.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,60 @@ | ||
using ExtendedXmlSerializer.Configuration; | ||
using ExtendedXmlSerializer.Tests.ReportedIssues.Support; | ||
using FluentAssertions; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Xunit; | ||
|
||
namespace ExtendedXmlSerializer.Tests.ReportedIssues | ||
{ | ||
public sealed class Issue418Tests | ||
{ | ||
[Fact] | ||
public void Verify() | ||
{ | ||
var b1 = new Book(); | ||
var b2 = new Book(); | ||
|
||
var allBooks = new[] {b1, b2,}; | ||
|
||
var fs = new BookStore() | ||
{ | ||
AllBooks = allBooks, | ||
Genres = new[] | ||
{ | ||
new Genre | ||
{ | ||
Books = allBooks, | ||
}, | ||
new Genre | ||
{ | ||
Books = allBooks, | ||
}, | ||
} | ||
}; | ||
|
||
var serializer = new ConfigurationContainer().Type<Book[]>() | ||
.EnableReferences() | ||
.Create() | ||
.ForTesting(); | ||
|
||
var cycled = serializer.Cycle(fs); | ||
|
||
cycled.AllBooks.Should().BeSameAs(cycled.Genres.ElementAt(0).Books); | ||
cycled.AllBooks.Should().BeSameAs(cycled.Genres.ElementAt(1).Books); | ||
} | ||
|
||
class BookStore | ||
{ | ||
public IEnumerable<Book> AllBooks { get; set; } | ||
public IEnumerable<Genre> Genres { get; set; } | ||
} | ||
|
||
class Book {} | ||
|
||
class Genre | ||
{ | ||
public IEnumerable<Book> Books { get; set; } | ||
} | ||
} | ||
} |