-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removed target instances from cache after first access (#600)
- Loading branch information
1 parent
5b777b4
commit 3d3a4fd
Showing
2 changed files
with
172 additions
and
4 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
164 changes: 164 additions & 0 deletions
164
test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue599Tests.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,164 @@ | ||
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 Issue599Tests | ||
{ | ||
[Fact] | ||
public void Verify() | ||
{ | ||
var sut = new ConfigurationContainer().AllowTargetInstances().Create().ForTesting(); | ||
|
||
var instance = new NewDefinitionView | ||
{ | ||
Name = "Hello world", | ||
Description = "Does this work?", | ||
DescriptionFull = "This is a longer description", | ||
Average = 12345, | ||
Market = MarketClassification.Traditional, | ||
Result = Guid.NewGuid(), | ||
Price = 123.21M, | ||
Identifier = "unique", | ||
SimpleMode = true, | ||
Templates = new PackagingTemplateViews | ||
{ | ||
new() | ||
{ | ||
Name = "Testing", | ||
Fields = new List<TemplateField> { new TextField { FullName = "This works now right?", Id = 123 } } | ||
} | ||
}, | ||
Gratitude = new BeneficiaryDefinitionView { Enabled = true, Amount = 1234 } | ||
}; | ||
var content = sut.Serialize(instance); | ||
var target = new NewDefinitionView(); | ||
sut.UsingTarget(target).Deserialize(content).Should().BeEquivalentTo(instance); | ||
} | ||
|
||
public sealed class NewDefinitionView : DefinitionView | ||
{ | ||
public Guid? Result { get; set; } | ||
} | ||
|
||
public class DefinitionView | ||
{ | ||
public MarketClassification Market { get; set; } | ||
|
||
public string Name { get; set; } = default!; | ||
|
||
public string Description { get; set; } = string.Empty; | ||
|
||
public string DescriptionFull { get; set; } | ||
|
||
public string Identifier { get; set; } = default!; | ||
|
||
public decimal Price { get; set; } | ||
|
||
public decimal Average { get; set; } | ||
|
||
public PackagingTemplateViews Templates { get; set; } = default!; | ||
|
||
public bool SimpleMode { get; set; } = true; | ||
|
||
public BeneficiaryDefinitionView Gratitude { get; set; } = default!; | ||
} | ||
|
||
public sealed class BeneficiaryDefinitionView | ||
{ | ||
public bool Enabled { get; set; } | ||
|
||
public float Amount { get; set; } = .1f; | ||
} | ||
|
||
public enum MarketClassification : byte | ||
{ | ||
Standard = 1, | ||
Featured = 2, | ||
Treasure = 3, | ||
Traditional = 4, | ||
Mature = 5 | ||
} | ||
|
||
public sealed class PackagingTemplateViews : SelectedCollection<PackagingTemplate> | ||
{ | ||
public PackagingTemplateViews() : base(Array.Empty<PackagingTemplate>()) {} | ||
|
||
public PackagingTemplateViews(IEnumerable<PackagingTemplate> list) : base(list) {} | ||
|
||
public ICollection<TemplateFieldValue> Values { get; set; } = default!; | ||
} | ||
|
||
public class SelectedCollection<T> : List<T> | ||
{ | ||
public SelectedCollection(IEnumerable<T> list) : base(list) {} | ||
|
||
public virtual T Selected { get; set; } | ||
} | ||
|
||
public class PackagingTemplate : Template {} | ||
|
||
public abstract class Template | ||
{ | ||
public int Id { get; set; } | ||
|
||
public DateTimeOffset Created { get; set; } | ||
|
||
public string Identifier { get; set; } = default!; | ||
|
||
public string Name { get; set; } = default!; | ||
|
||
public string Description { get; set; } | ||
|
||
public ICollection<TemplateField> Fields { get; set; } = default!; | ||
} | ||
|
||
public class TextField : TemplateField | ||
{ | ||
public string FullName { get; set; } = default!; | ||
} | ||
|
||
public abstract class TemplateField | ||
{ | ||
public int Id { get; set; } | ||
|
||
public DateTimeOffset Created { get; set; } | ||
|
||
public string Identifier { get; set; } = default!; | ||
|
||
public string Name { get; set; } = default!; | ||
|
||
public string Description { get; set; } | ||
|
||
public bool IsRequired { get; set; } | ||
} | ||
|
||
public class TemplateFieldValue | ||
{ | ||
public long Id { get; set; } | ||
|
||
public TemplateField Field { get; set; } = default!; | ||
|
||
public TemplateValue Value { get; set; } = default!; | ||
|
||
public void Deconstruct(out TemplateField field, out TemplateValue value) | ||
{ | ||
field = Field; | ||
value = Value; | ||
} | ||
} | ||
|
||
public abstract class TemplateValue | ||
{ | ||
public long Id { get; set; } | ||
|
||
public bool Enabled { get; set; } | ||
|
||
public TemplateValue Clone() => MemberwiseClone().To<TemplateValue>(); | ||
} | ||
} | ||
} |