Skip to content

Commit

Permalink
test records
Browse files Browse the repository at this point in the history
  • Loading branch information
mgravell committed Nov 16, 2020
1 parent f68280b commit 8a14c5e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

<PublishRepositoryUrl>true</PublishRepositoryUrl>

<LangVersion>8.0</LangVersion>
<LangVersion>9.0</LangVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)' == 'Release'">
Expand Down
49 changes: 43 additions & 6 deletions tests/Dapper.Tests/MiscTests.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
using Microsoft.CSharp.RuntimeBinder;
using System;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.Common;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CSharp.RuntimeBinder;
using Xunit;

#if NETCOREAPP3_1 || NET462 || NET472
namespace System.Runtime.CompilerServices
{
[EditorBrowsable(EditorBrowsableState.Never)]
internal static class IsExternalInit // yeah, don't do this!
{
}
}
#endif

namespace Dapper.Tests
{
[Collection("MiscTests")]
Expand Down Expand Up @@ -56,9 +65,17 @@ public enum TrapEnum : int
private struct CarWithAllProps
{
public string Name { get; set; }
public int Age { get; set; }
public int Age { get; init; }
public Car.TrapEnum Trap { get; init; }
}

private record PositionalCarRecord(string Name, int Age, Car.TrapEnum Trap);

public Car.TrapEnum Trap { get; set; }
private record NominalCarRecord
{
public string Name { get; init; }
public int Age { get; init; }
public Car.TrapEnum Trap { get; init; }
}

[Fact]
Expand All @@ -71,6 +88,26 @@ public void TestStructs()
Assert.Equal(2, (int)car.Trap);
}

[Fact]
public void TestPositionalRecord()
{
var car = connection.Query<PositionalCarRecord>("select 'Ford' Name, 21 Age, 2 Trap").First();

Assert.Equal(21, car.Age);
Assert.Equal("Ford", car.Name);
Assert.Equal(2, (int)car.Trap);
}

[Fact]
public void TestNominalRecord()
{
var car = connection.Query<NominalCarRecord>("select 'Ford' Name, 21 Age, 2 Trap").First();

Assert.Equal(21, car.Age);
Assert.Equal("Ford", car.Name);
Assert.Equal(2, (int)car.Trap);
}

[Fact]
public void TestStructAsParam()
{
Expand Down

0 comments on commit 8a14c5e

Please sign in to comment.