Skip to content

Commit

Permalink
Accounted for rare state when namespace prefix is null.
Browse files Browse the repository at this point in the history
This is a rare state caused by the combination of several factors and extensions.  Let's hope it doesn't break something else out there. :p
  • Loading branch information
Mike-E-angelo authored Aug 14, 2020
1 parent e8abfa3 commit 02adccc
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ExtendedXmlSerializer/ExtensionModel/Xml/XmlWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ string Lookup(string parameter)
Add(string.Empty, parameter);
}

var result = parameter == this.Get(string.Empty) ? string.Empty : lookup;
var result = parameter == this.Get(string.Empty) || parameter == null ? string.Empty : lookup;
return result;
}

Expand Down
102 changes: 102 additions & 0 deletions test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue423Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
using ExtendedXmlSerializer.Configuration;
using ExtendedXmlSerializer.Tests.ReportedIssues.Support;
using FluentAssertions;
using JetBrains.Annotations;
using System.Collections.Generic;
using System.Linq;
using Xunit;

namespace ExtendedXmlSerializer.Tests.ReportedIssues
{
public sealed class Issue423Tests
{
[Fact]
public void Verify()
{
var subject = new Subject {Values = {"Hello", "World!"}};
var element = new[] {subject};

var serializer = new ConfigurationContainer().UseOptimizedNamespaces()
.EnableImplicitTyping(typeof(Subject))
.Create()
.ForTesting();
serializer.Cycle(element).Should().BeEquivalentTo(element.Cast<Subject>());
}

[Fact]
public void VerifyReported()
{
var config = new NewOptionSetFieldInfo
{
Values =
{
{123, "abc"},
{456, "def"}
}
};
var element = new[] {config};

var serializer = new ConfigurationContainer().UseOptimizedNamespaces()
.EnableImplicitTypingFromPublicNested<Issue423Tests>()
.EnableParameterizedContentWithPropertyAssignments()
.Create()
.ForTesting();

serializer.Cycle(config).Should().BeEquivalentTo(config);
serializer.Cycle(element).Should().BeEquivalentTo(element.Cast<NewOptionSetFieldInfo>());
}

public class ExistingOptionSetFieldInfo : NewFieldInfo
{
public ExistingOptionSetFieldInfo() : base(FieldType.OptionSet)
{
IsExistsOnSource = true;
}

public bool IsExistsOnSource { get; protected set; }

public string OptionSetName { get; set; }
}

public enum FieldType
{
OptionSet
}

public class NewFieldInfo
{
public NewFieldInfo(FieldType type)
{
Type = type;
}

public FieldType Type { get; }

public string Name { get; set; }

public string Description { get; set; } = null;

public bool IsRequired { get; set; }

public string TargetName { get; set; }

public bool ShouldCreateFieldOnTarget { get; set; }
}

public class NewOptionSetFieldInfo : ExistingOptionSetFieldInfo
{
public NewOptionSetFieldInfo()
{
IsExistsOnSource = false;
}

public Dictionary<int, string> Values { get; } = new Dictionary<int, string>();
}

sealed class Subject
{
[UsedImplicitly]
public List<string> Values { get; } = new List<string>();
}
}
}

0 comments on commit 02adccc

Please sign in to comment.