Added test project
This commit is contained in:
parent
6290a4f0e4
commit
dcd1a77ed5
@ -4,6 +4,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CSV Metrics Logger", "CSV M
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CSV Metrics Logger Generator", "CSV Metrics Logger Generator\CSV Metrics Logger Generator.csproj", "{559505B4-5322-4CFD-ABB9-D835C2A7EC09}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "Tests\Tests.csproj", "{871708D2-633C-4D78-86EF-A1B72043B652}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
6
Tests/TestDataOneLine.cs
Normal file
6
Tests/TestDataOneLine.cs
Normal file
@ -0,0 +1,6 @@
|
||||
using CSV_Metrics_Logger;
|
||||
|
||||
namespace Tests;
|
||||
|
||||
[CSVRecord]
|
||||
public readonly partial record struct TestDataOneLine(string Name, sbyte Age);
|
9
Tests/TestDataRecordStructMixed.cs
Normal file
9
Tests/TestDataRecordStructMixed.cs
Normal file
@ -0,0 +1,9 @@
|
||||
using CSV_Metrics_Logger;
|
||||
|
||||
namespace Tests;
|
||||
|
||||
[CSVRecord]
|
||||
public readonly partial record struct TestDataRecordStructMixed(string Area, int Step, float Value, int Z)
|
||||
{
|
||||
public bool State { get; init; }
|
||||
}
|
13
Tests/TestDataRegularStruct.cs
Normal file
13
Tests/TestDataRegularStruct.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using CSV_Metrics_Logger;
|
||||
|
||||
namespace Tests;
|
||||
|
||||
[CSVRecord]
|
||||
public partial struct TestDataRegularStruct
|
||||
{
|
||||
public string City { get; set; }
|
||||
|
||||
public uint Age { get; set; }
|
||||
|
||||
public double Size { get; set; }
|
||||
}
|
84
Tests/Tests.cs
Normal file
84
Tests/Tests.cs
Normal file
@ -0,0 +1,84 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Tests;
|
||||
|
||||
[ExcludeFromCodeCoverage]
|
||||
public sealed class Tests
|
||||
{
|
||||
[Test]
|
||||
public void TestBasicImplementation()
|
||||
{
|
||||
var testData = new TestDataRecordStructMixed("Area1", 1, 1.1f, 7);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(typeof(TestDataRecordStructMixed).GetInterface("IConvertToCSV"), Is.Not.Null);
|
||||
Assert.That(typeof(TestDataRecordStructMixed).GetProperties(), Has.Length.EqualTo(5));
|
||||
|
||||
var numberColumns = testData.GetCSVColumnCount();
|
||||
Assert.That(numberColumns, Is.EqualTo(5));
|
||||
|
||||
var header = testData.GetCSVHeaders();
|
||||
Assert.That(header, Is.EquivalentTo(new[] { "Area", "Step", "Value", "Z", "State" }));
|
||||
|
||||
var dataLine = testData.ConvertToCSVDataLine();
|
||||
Assert.That(dataLine, Is.EquivalentTo(new[] { "Area1", "1", "1.1", "7", "False" }));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestLongText()
|
||||
{
|
||||
var text = """
|
||||
This is a long text that should be split into multiple lines
|
||||
and should be able to be used as a multiline string
|
||||
...
|
||||
and on and on...
|
||||
""";
|
||||
var testData = new TestDataRecordStructMixed(text, 500_000, 0.00057f, -6_087);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
var dataLine = testData.ConvertToCSVDataLine();
|
||||
Assert.That(dataLine, Is.EquivalentTo(new[] { text, "500000", "0.00057", "-6087", "False" }));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestOneLineStructure()
|
||||
{
|
||||
var testData = new TestDataOneLine("Bob", 120);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
var numberColumns = testData.GetCSVColumnCount();
|
||||
Assert.That(numberColumns, Is.EqualTo(2));
|
||||
|
||||
var header = testData.GetCSVHeaders();
|
||||
Assert.That(header, Is.EquivalentTo(new[] { "Name", "Age" }));
|
||||
|
||||
var dataLine = testData.ConvertToCSVDataLine();
|
||||
Assert.That(dataLine, Is.EquivalentTo(new[] { "Bob", "120" }));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestRegularStruct()
|
||||
{
|
||||
var testData = new TestDataRegularStruct
|
||||
{
|
||||
City = "New York",
|
||||
Age = 35,
|
||||
Size = 1.85,
|
||||
};
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
var numberColumns = testData.GetCSVColumnCount();
|
||||
Assert.That(numberColumns, Is.EqualTo(3));
|
||||
|
||||
var header = testData.GetCSVHeaders();
|
||||
Assert.That(header, Is.EquivalentTo(new[] { "City", "Age", "Size" }));
|
||||
|
||||
var dataLine = testData.ConvertToCSVDataLine();
|
||||
Assert.That(dataLine, Is.EquivalentTo(new[] { "New York", "35", "1.85" }));
|
||||
});
|
||||
}
|
||||
}
|
30
Tests/Tests.csproj
Normal file
30
Tests/Tests.csproj
Normal file
@ -0,0 +1,30 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<WarningsAsErrors>CS8600;CS8602;CS8603</WarningsAsErrors>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.0"/>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0"/>
|
||||
<PackageReference Include="NUnit" Version="3.14.0"/>
|
||||
<PackageReference Include="NUnit.Analyzers" Version="3.9.0"/>
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="NUnit.Framework"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\CSV Metrics Logger Generator\CSV Metrics Logger Generator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
|
||||
<ProjectReference Include="..\CSV Metrics Logger\CSV Metrics Logger.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
Loading…
Reference in New Issue
Block a user