-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
177 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// ----------------------------------------------------------------------- | ||
// <copyright file="CrudGenerationTests.cs" company="Andrii Kurdiumov"> | ||
// Copyright (c) Andrii Kurdiumov. All rights reserved. | ||
// </copyright> | ||
// ----------------------------------------------------------------------- | ||
|
||
namespace SqlMarshal.Tests; | ||
|
||
using Microsoft.CodeAnalysis; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
[TestClass] | ||
public class CrudGenerationTests : CodeGenerationTestBase | ||
{ | ||
[TestMethod] | ||
public void FindAll_IList_Sync() | ||
{ | ||
string source = @" | ||
#nullable enable | ||
namespace Foo | ||
{ | ||
class TestEntity | ||
{ | ||
public int Id { get; set; } | ||
public string Name { get; set; } | ||
} | ||
[Repository(typeof(TestEntity))] | ||
partial class C | ||
{ | ||
private DbConnection connection; | ||
public partial IList<TestEntity> FindAll(); | ||
} | ||
}"; | ||
string output = this.GetGeneratedOutput(source, NullableContextOptions.Disable); | ||
|
||
Assert.IsNotNull(output); | ||
|
||
var expectedOutput = @"// <auto-generated> | ||
// Code generated by Stored Procedures Code Generator. | ||
// Changes may cause incorrect behavior and will be lost if the code is | ||
// regenerated. | ||
// </auto-generated> | ||
#nullable enable | ||
#pragma warning disable 1591 | ||
namespace Foo | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Data.Common; | ||
using System.Linq; | ||
partial class C | ||
{ | ||
public partial IList<Foo.TestEntity> FindAll() | ||
{ | ||
var connection = this.connection; | ||
using var command = connection.CreateCommand(); | ||
var sqlQuery = @""SELECT Id, Name FROM TestEntity""; | ||
command.CommandText = sqlQuery; | ||
using var reader = command.ExecuteReader(); | ||
var result = new List<TestEntity>(); | ||
while (reader.Read()) | ||
{ | ||
var item = new TestEntity(); | ||
var value_0 = reader.GetValue(0); | ||
item.Id = (int)value_0; | ||
var value_1 = reader.GetValue(1); | ||
item.Name = value_1 == DBNull.Value ? (string?)null : (string)value_1; | ||
result.Add(item); | ||
} | ||
reader.Close(); | ||
return result; | ||
} | ||
} | ||
}"; | ||
Assert.AreEqual(expectedOutput, output); | ||
} | ||
} |
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