-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #84 from jonsagara/feature/attrs
Add properties to cell and column attributes to expose constructor arguments
- Loading branch information
Showing
18 changed files
with
409 additions
and
10 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
25 changes: 25 additions & 0 deletions
25
SpreadCheetah.SourceGenerator.Test/Tests/CellValueTruncateTests.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,25 @@ | ||
using System.Reflection; | ||
using SpreadCheetah.SourceGeneration; | ||
using SpreadCheetah.SourceGenerator.Test.Models.CellValueTruncation; | ||
using Xunit; | ||
|
||
namespace SpreadCheetah.SourceGenerator.Test.Tests; | ||
|
||
public class CellValueTruncateTests | ||
{ | ||
[Fact] | ||
public void CellValueTruncate_ClassWithSingleAccessProperty_CanReadLength() | ||
{ | ||
// Arrange | ||
var property = typeof(ClassWithSingleAccessProperty).GetProperties(BindingFlags.Public | BindingFlags.Instance) | ||
.SingleOrDefault(p => string.Equals(p.Name, nameof(ClassWithSingleAccessProperty.Value), StringComparison.Ordinal)); | ||
|
||
// Act | ||
var cellValueTruncateAttr = property?.GetCustomAttribute<CellValueTruncateAttribute>(); | ||
|
||
// Assert | ||
Assert.NotNull(property); | ||
Assert.NotNull(cellValueTruncateAttr); | ||
Assert.Equal(1, cellValueTruncateAttr.Length); | ||
} | ||
} |
126 changes: 126 additions & 0 deletions
126
SpreadCheetah.SourceGenerator.Test/Tests/ColumnHeaderTests.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,126 @@ | ||
using System.Reflection; | ||
using SpreadCheetah.SourceGeneration; | ||
using SpreadCheetah.SourceGenerator.Test.Models.ColumnHeader; | ||
using Xunit; | ||
|
||
namespace SpreadCheetah.SourceGenerator.Test.Tests; | ||
|
||
public class ColumnHeaderTests | ||
{ | ||
[Fact] | ||
public void ColumnHeader_ClassWithPropertyReferenceColumnHeaders_CanReadTypeAndPropertyName() | ||
{ | ||
// Arrange | ||
var publicProperties = typeof(ClassWithPropertyReferenceColumnHeaders).GetProperties(BindingFlags.Public | BindingFlags.Instance); | ||
var firstNameProperty = publicProperties.SingleOrDefault(p => string.Equals(p.Name, nameof(ClassWithPropertyReferenceColumnHeaders.FirstName), StringComparison.Ordinal)); | ||
var lastNameProperty = publicProperties.SingleOrDefault(p => string.Equals(p.Name, nameof(ClassWithPropertyReferenceColumnHeaders.LastName), StringComparison.Ordinal)); | ||
var nationalityProperty = publicProperties.SingleOrDefault(p => string.Equals(p.Name, nameof(ClassWithPropertyReferenceColumnHeaders.Nationality), StringComparison.Ordinal)); | ||
var addressLine1Property = publicProperties.SingleOrDefault(p => string.Equals(p.Name, nameof(ClassWithPropertyReferenceColumnHeaders.AddressLine1), StringComparison.Ordinal)); | ||
var addressLine2Property = publicProperties.SingleOrDefault(p => string.Equals(p.Name, nameof(ClassWithPropertyReferenceColumnHeaders.AddressLine2), StringComparison.Ordinal)); | ||
var ageProperty = publicProperties.SingleOrDefault(p => string.Equals(p.Name, nameof(ClassWithPropertyReferenceColumnHeaders.Age), StringComparison.Ordinal)); | ||
|
||
// Act | ||
var firstNameColHeaderAttr = firstNameProperty?.GetCustomAttribute<ColumnHeaderAttribute>(); | ||
var lastNameColHeaderAttr = lastNameProperty?.GetCustomAttribute<ColumnHeaderAttribute>(); | ||
var nationalityColHeaderAttr = nationalityProperty?.GetCustomAttribute<ColumnHeaderAttribute>(); | ||
var addressLine1ColHeaderAttr = addressLine1Property?.GetCustomAttribute<ColumnHeaderAttribute>(); | ||
var addressLine2ColHeaderAttr = addressLine2Property?.GetCustomAttribute<ColumnHeaderAttribute>(); | ||
var ageColHeaderAttr = ageProperty?.GetCustomAttribute<ColumnHeaderAttribute>(); | ||
|
||
// Assert | ||
Assert.NotNull(firstNameProperty); | ||
Assert.NotNull(firstNameColHeaderAttr); | ||
Assert.Equal(typeof(ColumnHeaderResources), firstNameColHeaderAttr.Type); | ||
Assert.Equal(nameof(ColumnHeaderResources.Header_FirstName), firstNameColHeaderAttr.PropertyName); | ||
|
||
Assert.NotNull(lastNameProperty); | ||
Assert.NotNull(lastNameColHeaderAttr); | ||
Assert.Equal(typeof(ColumnHeaderResources), lastNameColHeaderAttr.Type); | ||
Assert.Equal(nameof(ColumnHeaderResources.Header_LastName), lastNameColHeaderAttr.PropertyName); | ||
|
||
Assert.NotNull(nationalityProperty); | ||
Assert.NotNull(nationalityColHeaderAttr); | ||
Assert.Equal(typeof(ColumnHeaders), nationalityColHeaderAttr.Type); | ||
Assert.Equal(nameof(ColumnHeaders.HeaderNationality), nationalityColHeaderAttr.PropertyName); | ||
|
||
Assert.NotNull(addressLine1Property); | ||
Assert.NotNull(addressLine1ColHeaderAttr); | ||
Assert.Equal(typeof(ColumnHeaders), addressLine1ColHeaderAttr.Type); | ||
Assert.Equal(nameof(ColumnHeaders.HeaderAddressLine1), addressLine1ColHeaderAttr.PropertyName); | ||
|
||
Assert.NotNull(addressLine2Property); | ||
Assert.NotNull(addressLine2ColHeaderAttr); | ||
Assert.Equal(typeof(ColumnHeaders), addressLine2ColHeaderAttr.Type); | ||
Assert.Equal(nameof(ColumnHeaders.HeaderAddressLine2), addressLine2ColHeaderAttr.PropertyName); | ||
|
||
Assert.NotNull(ageProperty); | ||
Assert.NotNull(ageColHeaderAttr); | ||
Assert.Equal(typeof(ColumnHeaders), ageColHeaderAttr.Type); | ||
Assert.Equal(nameof(ColumnHeaders.HeaderAge), ageColHeaderAttr.PropertyName); | ||
} | ||
|
||
[Fact] | ||
public void ColumnHeader_ClassWithSpecialCharacterColumnHeaders_CanReadName() | ||
Check warning on line 63 in SpreadCheetah.SourceGenerator.Test/Tests/ColumnHeaderTests.cs GitHub Actions / build
|
||
{ | ||
// Arrange | ||
var publicProperties = typeof(ClassWithSpecialCharacterColumnHeaders).GetProperties(BindingFlags.Public | BindingFlags.Instance); | ||
var firstNameProperty = publicProperties.SingleOrDefault(p => string.Equals(p.Name, nameof(ClassWithSpecialCharacterColumnHeaders.FirstName), StringComparison.Ordinal)); | ||
var lastNameProperty = publicProperties.SingleOrDefault(p => string.Equals(p.Name, nameof(ClassWithSpecialCharacterColumnHeaders.LastName), StringComparison.Ordinal)); | ||
var nationalityProperty = publicProperties.SingleOrDefault(p => string.Equals(p.Name, nameof(ClassWithSpecialCharacterColumnHeaders.Nationality), StringComparison.Ordinal)); | ||
var addressLine1Property = publicProperties.SingleOrDefault(p => string.Equals(p.Name, nameof(ClassWithSpecialCharacterColumnHeaders.AddressLine1), StringComparison.Ordinal)); | ||
var addressLine2Property = publicProperties.SingleOrDefault(p => string.Equals(p.Name, nameof(ClassWithSpecialCharacterColumnHeaders.AddressLine2), StringComparison.Ordinal)); | ||
var ageProperty = publicProperties.SingleOrDefault(p => string.Equals(p.Name, nameof(ClassWithSpecialCharacterColumnHeaders.Age), StringComparison.Ordinal)); | ||
var noteProperty = publicProperties.SingleOrDefault(p => string.Equals(p.Name, nameof(ClassWithSpecialCharacterColumnHeaders.Note), StringComparison.Ordinal)); | ||
var note2Property = publicProperties.SingleOrDefault(p => string.Equals(p.Name, nameof(ClassWithSpecialCharacterColumnHeaders.Note2), StringComparison.Ordinal)); | ||
|
||
// Act | ||
var firstNameColHeaderAttr = firstNameProperty?.GetCustomAttribute<ColumnHeaderAttribute>(); | ||
var lastNameColHeaderAttr = lastNameProperty?.GetCustomAttribute<ColumnHeaderAttribute>(); | ||
var nationalityColHeaderAttr = nationalityProperty?.GetCustomAttribute<ColumnHeaderAttribute>(); | ||
var addressLine1ColHeaderAttr = addressLine1Property?.GetCustomAttribute<ColumnHeaderAttribute>(); | ||
var addressLine2ColHeaderAttr = addressLine2Property?.GetCustomAttribute<ColumnHeaderAttribute>(); | ||
var ageColHeaderAttr = ageProperty?.GetCustomAttribute<ColumnHeaderAttribute>(); | ||
var noteColHeaderAttr = noteProperty?.GetCustomAttribute<ColumnHeaderAttribute>(); | ||
var note2ColHeaderAttr = note2Property?.GetCustomAttribute<ColumnHeaderAttribute>(); | ||
|
||
// Assert | ||
Assert.NotNull(firstNameProperty); | ||
Assert.NotNull(firstNameColHeaderAttr); | ||
Assert.Equal("First name", firstNameColHeaderAttr.Name); | ||
|
||
Assert.NotNull(lastNameProperty); | ||
Assert.NotNull(lastNameColHeaderAttr); | ||
Assert.Equal("", lastNameColHeaderAttr.Name); | ||
|
||
Assert.NotNull(nationalityProperty); | ||
Assert.NotNull(nationalityColHeaderAttr); | ||
Assert.Equal("Nationality (escaped characters \", \', \\)", nationalityColHeaderAttr.Name); | ||
|
||
Assert.NotNull(addressLine1Property); | ||
Assert.NotNull(addressLine1ColHeaderAttr); | ||
Assert.Equal("Address line 1 (escaped characters \r\n, \t)", addressLine1ColHeaderAttr.Name); | ||
|
||
Assert.NotNull(addressLine2Property); | ||
Assert.NotNull(addressLine2ColHeaderAttr); | ||
Assert.Equal(@"Address line 2 (verbatim | ||
string: "", \)", addressLine2ColHeaderAttr.Name); | ||
|
||
Assert.NotNull(ageProperty); | ||
Assert.NotNull(ageColHeaderAttr); | ||
Assert.Equal(""" | ||
Age ( | ||
raw | ||
string | ||
literal | ||
) | ||
""", ageColHeaderAttr.Name); | ||
|
||
Assert.NotNull(noteProperty); | ||
Assert.NotNull(noteColHeaderAttr); | ||
Assert.Equal("Note (unicode escape sequence 🌉, \ud83d\udc4d, \xE7)", noteColHeaderAttr.Name); | ||
|
||
Assert.NotNull(note2Property); | ||
Assert.NotNull(note2ColHeaderAttr); | ||
Assert.Equal($"Note 2 (constant interpolated string: This is a constant)", note2ColHeaderAttr.Name); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
SpreadCheetah.SourceGenerator.Test/Tests/ColumnOrderTests.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,42 @@ | ||
using System.Reflection; | ||
using SpreadCheetah.SourceGeneration; | ||
using SpreadCheetah.SourceGenerator.Test.Models.ColumnOrdering; | ||
using Xunit; | ||
|
||
namespace SpreadCheetah.SourceGenerator.Test.Tests; | ||
|
||
public class ColumnOrderTests | ||
{ | ||
[Fact] | ||
public void ColumnOrder_ClassWithPropertyReferenceColumnHeaders_CanReadOrder() | ||
{ | ||
// Arrange | ||
var publicProperties = typeof(ClassWithColumnOrdering).GetProperties(BindingFlags.Public | BindingFlags.Instance); | ||
var firstNameProperty = publicProperties.SingleOrDefault(p => string.Equals(p.Name, nameof(ClassWithColumnOrdering.FirstName), StringComparison.Ordinal)); | ||
var lastNameProperty = publicProperties.SingleOrDefault(p => string.Equals(p.Name, nameof(ClassWithColumnOrdering.LastName), StringComparison.Ordinal)); | ||
var gpaProperty = publicProperties.SingleOrDefault(p => string.Equals(p.Name, nameof(ClassWithColumnOrdering.Gpa), StringComparison.Ordinal)); | ||
var ageProperty = publicProperties.SingleOrDefault(p => string.Equals(p.Name, nameof(ClassWithColumnOrdering.Age), StringComparison.Ordinal)); | ||
|
||
// Act | ||
var firstNameColOrderAttr = firstNameProperty?.GetCustomAttribute<ColumnOrderAttribute>(); | ||
var lastNameColOrderAttr = lastNameProperty?.GetCustomAttribute<ColumnOrderAttribute>(); | ||
var gpaColOrderAttr = gpaProperty?.GetCustomAttribute<ColumnOrderAttribute>(); | ||
var ageColOrderAttr = ageProperty?.GetCustomAttribute<ColumnOrderAttribute>(); | ||
|
||
// Assert | ||
Assert.NotNull(firstNameProperty); | ||
Assert.NotNull(firstNameColOrderAttr); | ||
Assert.Equal(2, firstNameColOrderAttr.Order); | ||
|
||
Assert.NotNull(lastNameProperty); | ||
Assert.NotNull(lastNameColOrderAttr); | ||
Assert.Equal(1, lastNameColOrderAttr.Order); | ||
|
||
Assert.NotNull(gpaProperty); | ||
Assert.Null(gpaColOrderAttr); | ||
|
||
Assert.NotNull(ageProperty); | ||
Assert.NotNull(ageColOrderAttr); | ||
Assert.Equal(3, ageColOrderAttr.Order); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
SpreadCheetah.SourceGenerator.Test/Tests/ColumnWidthTests.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,25 @@ | ||
using System.Reflection; | ||
using SpreadCheetah.SourceGeneration; | ||
using SpreadCheetah.SourceGenerator.Test.Models.ColumnWidth; | ||
using Xunit; | ||
|
||
namespace SpreadCheetah.SourceGenerator.Test.Tests; | ||
|
||
public class ColumnWidthTests | ||
{ | ||
[Fact] | ||
public void ColumnWidth_ClassWithColumnWidth_CanReadOrder() | ||
{ | ||
// Arrange | ||
var nameProperty = typeof(ClassWithColumnWidth).GetProperties(BindingFlags.Public | BindingFlags.Instance) | ||
.SingleOrDefault(p => string.Equals(p.Name, nameof(ClassWithColumnWidth.Name), StringComparison.Ordinal)); | ||
|
||
// Act | ||
var nameColWidthAttr = nameProperty?.GetCustomAttribute<ColumnWidthAttribute>(); | ||
|
||
// Assert | ||
Assert.NotNull(nameProperty); | ||
Assert.NotNull(nameColWidthAttr); | ||
Assert.Equal(20, nameColWidthAttr.Width); | ||
} | ||
} |
Oops, something went wrong.