From 80fe5b0ec796fc3cd8af820a214d98f7cfe08385 Mon Sep 17 00:00:00 2001 From: Jon Sagara Date: Mon, 18 Nov 2024 10:04:13 -0800 Subject: [PATCH] Reduced the overlap in tests for the new column/cell attribute properties. --- .../Tests/CellFormatTests.cs | 44 ----- .../Tests/CellStyleTests.cs | 81 --------- .../Tests/CellValueConverterTests.cs | 121 +------------ .../Tests/CellValueTruncateTests.cs | 16 -- .../Tests/ColumnHeaderTests.cs | 2 +- .../Tests/ColumnOrderTests.cs | 165 ------------------ 6 files changed, 9 insertions(+), 420 deletions(-) diff --git a/SpreadCheetah.SourceGenerator.Test/Tests/CellFormatTests.cs b/SpreadCheetah.SourceGenerator.Test/Tests/CellFormatTests.cs index c12b6fe..52731e3 100644 --- a/SpreadCheetah.SourceGenerator.Test/Tests/CellFormatTests.cs +++ b/SpreadCheetah.SourceGenerator.Test/Tests/CellFormatTests.cs @@ -130,48 +130,4 @@ public void CellFormat_ClassWithCellStandardFormat_CanReadFormat() Assert.NotNull(cellFormatAttr); Assert.Equal(StandardNumberFormat.TwoDecimalPlaces, cellFormatAttr.Format); } - - [Fact] - public void CellFormat_ClassWithDateTimeCellFormat_CanReadFormat() - { - // Arrange - var property = typeof(ClassWithDateTimeCellFormat).GetProperties(BindingFlags.Public | BindingFlags.Instance) - .SingleOrDefault(p => string.Equals(p.Name, nameof(ClassWithDateTimeCellFormat.ToDate), StringComparison.Ordinal)); - - // Act - var cellFormatAttr = property?.GetCustomAttribute(); - - // Assert - Assert.NotNull(property); - Assert.NotNull(cellFormatAttr); - Assert.Equal(StandardNumberFormat.DateAndTime, cellFormatAttr.Format); - } - - [Fact] - public void CellFormat_ClassWithMultipleCellFormats_CanReadFormat() - { - // Arrange - var publicProperties = typeof(ClassWithMultipleCellFormats).GetProperties(BindingFlags.Public | BindingFlags.Instance); - var idProperty = publicProperties.SingleOrDefault(p => string.Equals(p.Name, nameof(ClassWithMultipleCellFormats.Id), StringComparison.Ordinal)); - var fromDateProperty = publicProperties.SingleOrDefault(p => string.Equals(p.Name, nameof(ClassWithMultipleCellFormats.FromDate), StringComparison.Ordinal)); - var priceProperty = publicProperties.SingleOrDefault(p => string.Equals(p.Name, nameof(ClassWithMultipleCellFormats.Price), StringComparison.Ordinal)); - - // Act - var idCellFormatAttr = idProperty?.GetCustomAttribute(); - var fromDateCellFormatAttr = fromDateProperty?.GetCustomAttribute(); - var priceCellFormatAttr = priceProperty?.GetCustomAttribute(); - - // Assert - Assert.NotNull(idProperty); - Assert.NotNull(idCellFormatAttr); - Assert.Equal("#.00", idCellFormatAttr.CustomFormat); - - Assert.NotNull(fromDateProperty); - Assert.NotNull(fromDateCellFormatAttr); - Assert.Equal(StandardNumberFormat.LongDate, fromDateCellFormatAttr.Format); - - Assert.NotNull(priceProperty); - Assert.NotNull(priceCellFormatAttr); - Assert.Equal("#.00", priceCellFormatAttr.CustomFormat); - } } diff --git a/SpreadCheetah.SourceGenerator.Test/Tests/CellStyleTests.cs b/SpreadCheetah.SourceGenerator.Test/Tests/CellStyleTests.cs index 0b2de55..4adb794 100644 --- a/SpreadCheetah.SourceGenerator.Test/Tests/CellStyleTests.cs +++ b/SpreadCheetah.SourceGenerator.Test/Tests/CellStyleTests.cs @@ -230,85 +230,4 @@ public void CellStyle_ClassWithCellStyle_CanReadStyleName() Assert.NotNull(cellStyleAttr); Assert.Equal("Price style", cellStyleAttr.StyleName); } - - [Fact] - public void CellStyle_ClassWithCellStyleOnDateTimeProperty_CanReadStyleName() - { - // Arrange - var property = typeof(ClassWithCellStyleOnDateTimeProperty).GetProperties(BindingFlags.Public | BindingFlags.Instance) - .SingleOrDefault(p => string.Equals(p.Name, nameof(ClassWithCellStyleOnDateTimeProperty.CreatedDate), StringComparison.Ordinal)); - - // Act - var cellStyleAttr = property?.GetCustomAttribute(); - - // Assert - Assert.NotNull(property); - Assert.NotNull(cellStyleAttr); - Assert.Equal("Created style", cellStyleAttr.StyleName); - } - - [Fact] - public void CellStyle_ClassWithCellStyleOnTruncatedProperty_CanReadStyleName() - { - // Arrange - var property = typeof(ClassWithCellStyleOnTruncatedProperty).GetProperties(BindingFlags.Public | BindingFlags.Instance) - .SingleOrDefault(p => string.Equals(p.Name, nameof(ClassWithCellStyleOnTruncatedProperty.Name), StringComparison.Ordinal)); - - // Act - var cellStyleAttr = property?.GetCustomAttribute(); - - // Assert - Assert.NotNull(property); - Assert.NotNull(cellStyleAttr); - Assert.Equal("Name style", cellStyleAttr.StyleName); - } - - [Fact] - public void CellStyle_ClassWithMultipleCellStyles_CanReadStyleName() - { - // Arrange - var publicProperties = typeof(ClassWithMultipleCellStyles).GetProperties(BindingFlags.Public | BindingFlags.Instance); - var firstNameProperty = publicProperties.SingleOrDefault(p => string.Equals(p.Name, nameof(ClassWithMultipleCellStyles.FirstName), StringComparison.Ordinal)); - var middleNameProperty = publicProperties.SingleOrDefault(p => string.Equals(p.Name, nameof(ClassWithMultipleCellStyles.MiddleName), StringComparison.Ordinal)); - var lastNameProperty = publicProperties.SingleOrDefault(p => string.Equals(p.Name, nameof(ClassWithMultipleCellStyles.LastName), StringComparison.Ordinal)); - var ageProperty = publicProperties.SingleOrDefault(p => string.Equals(p.Name, nameof(ClassWithMultipleCellStyles.Age), StringComparison.Ordinal)); - - // Act - var firstNameCellStyleAttr = firstNameProperty?.GetCustomAttribute(); - var middleNameCellStyleAttr = middleNameProperty?.GetCustomAttribute(); - var lastNameCellStyleAttr = lastNameProperty?.GetCustomAttribute(); - var ageCellStyleAttr = ageProperty?.GetCustomAttribute(); - - // Assert - Assert.NotNull(firstNameProperty); - Assert.NotNull(firstNameCellStyleAttr); - Assert.Equal("Name", firstNameCellStyleAttr.StyleName); - - Assert.NotNull(middleNameProperty); - Assert.Null(middleNameCellStyleAttr); - - Assert.NotNull(lastNameProperty); - Assert.NotNull(lastNameCellStyleAttr); - Assert.Equal("Name", lastNameCellStyleAttr.StyleName); - - Assert.NotNull(ageProperty); - Assert.NotNull(ageCellStyleAttr); - Assert.Equal("Age", ageCellStyleAttr.StyleName); - } - - [Fact] - public void CellStyle_RecordWithCellStyle_CanReadStyleName() - { - // Arrange - var property = typeof(RecordWithCellStyle).GetProperties(BindingFlags.Public | BindingFlags.Instance) - .SingleOrDefault(p => string.Equals(p.Name, nameof(RecordWithCellStyle.Name), StringComparison.Ordinal)); - - // Act - var cellStyleAttr = property?.GetCustomAttribute(); - - // Assert - Assert.NotNull(property); - Assert.NotNull(cellStyleAttr); - Assert.Equal("Name style", cellStyleAttr.StyleName); - } } \ No newline at end of file diff --git a/SpreadCheetah.SourceGenerator.Test/Tests/CellValueConverterTests.cs b/SpreadCheetah.SourceGenerator.Test/Tests/CellValueConverterTests.cs index c1713a7..d518a66 100644 --- a/SpreadCheetah.SourceGenerator.Test/Tests/CellValueConverterTests.cs +++ b/SpreadCheetah.SourceGenerator.Test/Tests/CellValueConverterTests.cs @@ -1,9 +1,9 @@ +using System.Globalization; +using System.Reflection; using SpreadCheetah.SourceGeneration; using SpreadCheetah.SourceGenerator.Test.Models.CellValueConverter; using SpreadCheetah.Styling; using SpreadCheetah.TestHelpers.Assertions; -using System.Globalization; -using System.Reflection; using Xunit; namespace SpreadCheetah.SourceGenerator.Test.Tests; @@ -109,7 +109,7 @@ public async Task CellValueConverter_ClassWithConverterAndCellStyle() Assert.Equal("ABC123", sheet["A1"].StringValue); Assert.True(sheet["A1"].Style.Font.Bold); } - + [Fact] public async Task CellValueConverter_ClassWithConverterOnCustomType() { @@ -121,7 +121,9 @@ public async Task CellValueConverter_ClassWithConverterOnCustomType() spreadsheet.AddStyle(style, "PercentType"); var obj = new ClassWithCellValueConverterOnCustomType { - Property = "Abc123", ComplexProperty = null, PercentType = new Percent(123) + Property = "Abc123", + ComplexProperty = null, + PercentType = new Percent(123) }; // Act @@ -131,9 +133,9 @@ public async Task CellValueConverter_ClassWithConverterOnCustomType() // Assert using var sheet = SpreadsheetAssert.SingleSheet(stream); Assert.Equal("Abc123", sheet["A1"].StringValue); - + Assert.Equal("-", sheet["B1"].StringValue); - + Assert.Equal(123, sheet["C1"].DecimalValue); Assert.True(sheet["C1"].Style.Font.Bold); } @@ -153,111 +155,4 @@ public void CellFormat_ClassWithCellValueConverter_CanReadConverterType() Assert.NotNull(cellValueConverterAttr); Assert.Equal(typeof(UpperCaseValueConverter), cellValueConverterAttr.ConverterType); } - - [Fact] - public void CellFormat_ClassWithCellValueConverterAndCellStyle_CanReadConverterType() - { - // Arrange - var property = typeof(ClassWithCellValueConverterAndCellStyle).GetProperties(BindingFlags.Public | BindingFlags.Instance) - .SingleOrDefault(p => string.Equals(p.Name, nameof(ClassWithCellValueConverterAndCellStyle.Id), StringComparison.Ordinal)); - - // Act - var cellValueConverterAttr = property?.GetCustomAttribute(); - - // Assert - Assert.NotNull(property); - Assert.NotNull(cellValueConverterAttr); - Assert.Equal(typeof(UpperCaseValueConverter), cellValueConverterAttr.ConverterType); - } - - [Fact] - public void CellFormat_ClassWithCellValueConverterOnCustomType_CanReadConverterType() - { - // Arrange - var publicProperties = typeof(ClassWithCellValueConverterOnCustomType).GetProperties(BindingFlags.Public | BindingFlags.Instance); - var property = publicProperties.SingleOrDefault(p => string.Equals(p.Name, nameof(ClassWithCellValueConverterOnCustomType.Property), StringComparison.Ordinal)); - var complexProperty = publicProperties.SingleOrDefault(p => string.Equals(p.Name, nameof(ClassWithCellValueConverterOnCustomType.ComplexProperty), StringComparison.Ordinal)); - var percentTypeProperty = publicProperties.SingleOrDefault(p => string.Equals(p.Name, nameof(ClassWithCellValueConverterOnCustomType.PercentType), StringComparison.Ordinal)); - - // Act - var propertyCellValueConverterAttr = property?.GetCustomAttribute(); - var complexPropertyCellValueConverterAttr = complexProperty?.GetCustomAttribute(); - var percentTypePropertyCellValueConverterAttr = percentTypeProperty?.GetCustomAttribute(); - - // Assert - Assert.NotNull(property); - Assert.Null(propertyCellValueConverterAttr); - - Assert.NotNull(complexProperty); - Assert.NotNull(complexPropertyCellValueConverterAttr); - Assert.Equal(typeof(NullToDashValueConverter), complexPropertyCellValueConverterAttr.ConverterType); - - Assert.NotNull(property); - Assert.NotNull(percentTypePropertyCellValueConverterAttr); - Assert.Equal(typeof(PercentToNumberConverter), percentTypePropertyCellValueConverterAttr.ConverterType); - } - - [Fact] - public void CellFormat_ClassWithGenericConverter_CanReadConverterType() - { - // Arrange - var publicProperties = typeof(ClassWithGenericConverter).GetProperties(BindingFlags.Public | BindingFlags.Instance); - var firstNameProperty = publicProperties.SingleOrDefault(p => string.Equals(p.Name, nameof(ClassWithGenericConverter.FirstName), StringComparison.Ordinal)); - var middleNameProperty = publicProperties.SingleOrDefault(p => string.Equals(p.Name, nameof(ClassWithGenericConverter.MiddleName), StringComparison.Ordinal)); - var lastNameProperty = publicProperties.SingleOrDefault(p => string.Equals(p.Name, nameof(ClassWithGenericConverter.LastName), StringComparison.Ordinal)); - var gpaProperty = publicProperties.SingleOrDefault(p => string.Equals(p.Name, nameof(ClassWithGenericConverter.Gpa), StringComparison.Ordinal)); - - // Act - var firstNamePropertyCellValueConverterAttr = firstNameProperty?.GetCustomAttribute(); - var middleNamePropertyCellValueConverterAttr = middleNameProperty?.GetCustomAttribute(); - var lastNamePropertyCellValueConverterAttr = lastNameProperty?.GetCustomAttribute(); - var gpaCellValueConverterAttr = gpaProperty?.GetCustomAttribute(); - - // Assert - Assert.NotNull(firstNameProperty); - Assert.Null(firstNamePropertyCellValueConverterAttr); - - Assert.NotNull(middleNameProperty); - Assert.NotNull(middleNamePropertyCellValueConverterAttr); - Assert.Equal(typeof(NullToDashValueConverter), middleNamePropertyCellValueConverterAttr.ConverterType); - - Assert.NotNull(lastNameProperty); - Assert.Null(lastNamePropertyCellValueConverterAttr); - - Assert.NotNull(gpaProperty); - Assert.NotNull(gpaCellValueConverterAttr); - Assert.Equal(typeof(NullToDashValueConverter), gpaCellValueConverterAttr.ConverterType); - } - - [Fact] - public void CellFormat_ClassWithReusedConverter_CanReadConverterType() - { - // Arrange - var publicProperties = typeof(ClassWithReusedConverter).GetProperties(BindingFlags.Public | BindingFlags.Instance); - var firstNameProperty = publicProperties.SingleOrDefault(p => string.Equals(p.Name, nameof(ClassWithReusedConverter.FirstName), StringComparison.Ordinal)); - var middleNameProperty = publicProperties.SingleOrDefault(p => string.Equals(p.Name, nameof(ClassWithReusedConverter.MiddleName), StringComparison.Ordinal)); - var lastNameProperty = publicProperties.SingleOrDefault(p => string.Equals(p.Name, nameof(ClassWithReusedConverter.LastName), StringComparison.Ordinal)); - var gpaProperty = publicProperties.SingleOrDefault(p => string.Equals(p.Name, nameof(ClassWithReusedConverter.Gpa), StringComparison.Ordinal)); - - // Act - var firstNamePropertyCellValueConverterAttr = firstNameProperty?.GetCustomAttribute(); - var middleNamePropertyCellValueConverterAttr = middleNameProperty?.GetCustomAttribute(); - var lastNamePropertyCellValueConverterAttr = lastNameProperty?.GetCustomAttribute(); - var gpaCellValueConverterAttr = gpaProperty?.GetCustomAttribute(); - - // Assert - Assert.NotNull(firstNameProperty); - Assert.NotNull(firstNamePropertyCellValueConverterAttr); - Assert.Equal(typeof(UpperCaseValueConverter), firstNamePropertyCellValueConverterAttr.ConverterType); - - Assert.NotNull(middleNameProperty); - Assert.Null(middleNamePropertyCellValueConverterAttr); - - Assert.NotNull(lastNameProperty); - Assert.NotNull(lastNamePropertyCellValueConverterAttr); - Assert.Equal(typeof(UpperCaseValueConverter), lastNamePropertyCellValueConverterAttr.ConverterType); - - Assert.NotNull(gpaProperty); - Assert.Null(gpaCellValueConverterAttr); - } } diff --git a/SpreadCheetah.SourceGenerator.Test/Tests/CellValueTruncateTests.cs b/SpreadCheetah.SourceGenerator.Test/Tests/CellValueTruncateTests.cs index c164201..0848a83 100644 --- a/SpreadCheetah.SourceGenerator.Test/Tests/CellValueTruncateTests.cs +++ b/SpreadCheetah.SourceGenerator.Test/Tests/CellValueTruncateTests.cs @@ -22,20 +22,4 @@ public void CellValueTruncate_ClassWithSingleAccessProperty_CanReadLength() Assert.NotNull(cellValueTruncateAttr); Assert.Equal(1, cellValueTruncateAttr.Length); } - - [Fact] - public void CellValueTruncate_ClassWithTruncation_CanReadLength() - { - // Arrange - var property = typeof(ClassWithTruncation).GetProperties(BindingFlags.Public | BindingFlags.Instance) - .SingleOrDefault(p => string.Equals(p.Name, nameof(ClassWithTruncation.Value), StringComparison.Ordinal)); - - // Act - var cellValueTruncateAttr = property?.GetCustomAttribute(); - - // Assert - Assert.NotNull(property); - Assert.NotNull(cellValueTruncateAttr); - Assert.Equal(15, cellValueTruncateAttr.Length); - } } diff --git a/SpreadCheetah.SourceGenerator.Test/Tests/ColumnHeaderTests.cs b/SpreadCheetah.SourceGenerator.Test/Tests/ColumnHeaderTests.cs index 2ee6bd3..7772439 100644 --- a/SpreadCheetah.SourceGenerator.Test/Tests/ColumnHeaderTests.cs +++ b/SpreadCheetah.SourceGenerator.Test/Tests/ColumnHeaderTests.cs @@ -60,7 +60,7 @@ public void ColumnHeader_ClassWithPropertyReferenceColumnHeaders_CanReadTypeAndP } [Fact] - public void ColumnHeader_ClassWithSpecialCharacterColumnHeaders_CanReadTypeAndPropertyName() + public void ColumnHeader_ClassWithSpecialCharacterColumnHeaders_CanReadName() { // Arrange var publicProperties = typeof(ClassWithSpecialCharacterColumnHeaders).GetProperties(BindingFlags.Public | BindingFlags.Instance); diff --git a/SpreadCheetah.SourceGenerator.Test/Tests/ColumnOrderTests.cs b/SpreadCheetah.SourceGenerator.Test/Tests/ColumnOrderTests.cs index 9b1bde1..89754c3 100644 --- a/SpreadCheetah.SourceGenerator.Test/Tests/ColumnOrderTests.cs +++ b/SpreadCheetah.SourceGenerator.Test/Tests/ColumnOrderTests.cs @@ -39,169 +39,4 @@ public void ColumnOrder_ClassWithPropertyReferenceColumnHeaders_CanReadOrder() Assert.NotNull(ageColOrderAttr); Assert.Equal(3, ageColOrderAttr.Order); } - - [Fact] - public void ColumnOrder_ReadOnlyRecordStructWithColumnOrdering_CanReadOrder() - { - // Arrange - var publicProperties = typeof(ReadOnlyRecordStructWithColumnOrdering).GetProperties(BindingFlags.Public | BindingFlags.Instance); - var firstNameProperty = publicProperties.SingleOrDefault(p => string.Equals(p.Name, nameof(ReadOnlyRecordStructWithColumnOrdering.FirstName), StringComparison.Ordinal)); - var lastNameProperty = publicProperties.SingleOrDefault(p => string.Equals(p.Name, nameof(ReadOnlyRecordStructWithColumnOrdering.LastName), StringComparison.Ordinal)); - var gpaProperty = publicProperties.SingleOrDefault(p => string.Equals(p.Name, nameof(ReadOnlyRecordStructWithColumnOrdering.Gpa), StringComparison.Ordinal)); - var ageProperty = publicProperties.SingleOrDefault(p => string.Equals(p.Name, nameof(ReadOnlyRecordStructWithColumnOrdering.Age), StringComparison.Ordinal)); - - // Act - var firstNameColOrderAttr = firstNameProperty?.GetCustomAttribute(); - var lastNameColOrderAttr = lastNameProperty?.GetCustomAttribute(); - var gpaColOrderAttr = gpaProperty?.GetCustomAttribute(); - var ageColOrderAttr = ageProperty?.GetCustomAttribute(); - - // 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); - } - - [Fact] - public void ColumnOrder_ReadOnlyStructWithColumnOrdering_CanReadOrder() - { - // Arrange - var publicProperties = typeof(ReadOnlyStructWithColumnOrdering).GetProperties(BindingFlags.Public | BindingFlags.Instance); - var firstNameProperty = publicProperties.SingleOrDefault(p => string.Equals(p.Name, nameof(ReadOnlyStructWithColumnOrdering.FirstName), StringComparison.Ordinal)); - var lastNameProperty = publicProperties.SingleOrDefault(p => string.Equals(p.Name, nameof(ReadOnlyStructWithColumnOrdering.LastName), StringComparison.Ordinal)); - var gpaProperty = publicProperties.SingleOrDefault(p => string.Equals(p.Name, nameof(ReadOnlyStructWithColumnOrdering.Gpa), StringComparison.Ordinal)); - var ageProperty = publicProperties.SingleOrDefault(p => string.Equals(p.Name, nameof(ReadOnlyStructWithColumnOrdering.Age), StringComparison.Ordinal)); - - // Act - var firstNameColOrderAttr = firstNameProperty?.GetCustomAttribute(); - var lastNameColOrderAttr = lastNameProperty?.GetCustomAttribute(); - var gpaColOrderAttr = gpaProperty?.GetCustomAttribute(); - var ageColOrderAttr = ageProperty?.GetCustomAttribute(); - - // 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); - } - - [Fact] - public void ColumnOrder_RecordClassWithColumnOrdering_CanReadOrder() - { - // Arrange - var publicProperties = typeof(RecordClassWithColumnOrdering).GetProperties(BindingFlags.Public | BindingFlags.Instance); - var firstNameProperty = publicProperties.SingleOrDefault(p => string.Equals(p.Name, nameof(RecordClassWithColumnOrdering.FirstName), StringComparison.Ordinal)); - var lastNameProperty = publicProperties.SingleOrDefault(p => string.Equals(p.Name, nameof(RecordClassWithColumnOrdering.LastName), StringComparison.Ordinal)); - var gpaProperty = publicProperties.SingleOrDefault(p => string.Equals(p.Name, nameof(RecordClassWithColumnOrdering.Gpa), StringComparison.Ordinal)); - var ageProperty = publicProperties.SingleOrDefault(p => string.Equals(p.Name, nameof(RecordClassWithColumnOrdering.Age), StringComparison.Ordinal)); - - // Act - var firstNameColOrderAttr = firstNameProperty?.GetCustomAttribute(); - var lastNameColOrderAttr = lastNameProperty?.GetCustomAttribute(); - var gpaColOrderAttr = gpaProperty?.GetCustomAttribute(); - var ageColOrderAttr = ageProperty?.GetCustomAttribute(); - - // 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); - } - - [Fact] - public void ColumnOrder_RecordStructWithColumnOrdering_CanReadOrder() - { - // Arrange - var publicProperties = typeof(RecordStructWithColumnOrdering).GetProperties(BindingFlags.Public | BindingFlags.Instance); - var firstNameProperty = publicProperties.SingleOrDefault(p => string.Equals(p.Name, nameof(RecordStructWithColumnOrdering.FirstName), StringComparison.Ordinal)); - var lastNameProperty = publicProperties.SingleOrDefault(p => string.Equals(p.Name, nameof(RecordStructWithColumnOrdering.LastName), StringComparison.Ordinal)); - var gpaProperty = publicProperties.SingleOrDefault(p => string.Equals(p.Name, nameof(RecordStructWithColumnOrdering.Gpa), StringComparison.Ordinal)); - var ageProperty = publicProperties.SingleOrDefault(p => string.Equals(p.Name, nameof(RecordStructWithColumnOrdering.Age), StringComparison.Ordinal)); - - // Act - var firstNameColOrderAttr = firstNameProperty?.GetCustomAttribute(); - var lastNameColOrderAttr = lastNameProperty?.GetCustomAttribute(); - var gpaColOrderAttr = gpaProperty?.GetCustomAttribute(); - var ageColOrderAttr = ageProperty?.GetCustomAttribute(); - - // 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); - } - - [Fact] - public void ColumnOrder_StructWithColumnOrdering_CanReadOrder() - { - // Arrange - var publicProperties = typeof(StructWithColumnOrdering).GetProperties(BindingFlags.Public | BindingFlags.Instance); - var firstNameProperty = publicProperties.SingleOrDefault(p => string.Equals(p.Name, nameof(StructWithColumnOrdering.FirstName), StringComparison.Ordinal)); - var lastNameProperty = publicProperties.SingleOrDefault(p => string.Equals(p.Name, nameof(StructWithColumnOrdering.LastName), StringComparison.Ordinal)); - var gpaProperty = publicProperties.SingleOrDefault(p => string.Equals(p.Name, nameof(StructWithColumnOrdering.Gpa), StringComparison.Ordinal)); - var ageProperty = publicProperties.SingleOrDefault(p => string.Equals(p.Name, nameof(StructWithColumnOrdering.Age), StringComparison.Ordinal)); - - // Act - var firstNameColOrderAttr = firstNameProperty?.GetCustomAttribute(); - var lastNameColOrderAttr = lastNameProperty?.GetCustomAttribute(); - var gpaColOrderAttr = gpaProperty?.GetCustomAttribute(); - var ageColOrderAttr = ageProperty?.GetCustomAttribute(); - - // 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); - } }