-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unit test for OutOfMemoryException #6
- Loading branch information
Showing
7 changed files
with
100 additions
and
4 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
global using Microsoft.VisualStudio.TestTools.UnitTesting; |
53 changes: 53 additions & 0 deletions
53
test/Sql2Xls.Integration.Tests/Issue_0006_OutOfMemoryException.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,53 @@ | ||
using Microsoft.Extensions.Logging.Abstractions; | ||
using Sql2Xls.Excel; | ||
using Sql2Xls.Excel.Adapters; | ||
using System.Data; | ||
|
||
namespace Sql2Xls.Integration.Tests; | ||
|
||
[TestClass] | ||
public class Issue_0006_OutOfMemoryException | ||
{ | ||
private const string _CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; | ||
|
||
private string GetRandomString(Random rand, int len) | ||
{ | ||
return new string(Enumerable.Repeat(_CHARS, len) | ||
.Select(s => s[rand.Next(s.Length)]).ToArray()); | ||
} | ||
|
||
[TestMethod] | ||
[DataRow(154, 250_000, 20)] | ||
public void GenerateLargeExcel(int numberOfColumns, int numberOfRows, int fieldlen) | ||
{ | ||
Random rand = new Random(); | ||
|
||
DataTable dt = new DataTable("MyTable"); | ||
for (int j = 0; j < numberOfColumns; j++) | ||
{ | ||
dt.Columns.Add($"Column{j}", typeof(string)); | ||
} | ||
|
||
for (int i = 0; i < numberOfRows; i++) | ||
{ | ||
var row = dt.NewRow(); | ||
|
||
for (int j = 0; j < numberOfColumns; j++) | ||
{ | ||
row[$"Column{j}"] = GetRandomString(rand, fieldlen); | ||
} | ||
|
||
dt.Rows.Add(row); | ||
} | ||
|
||
var context = new ExcelExportContext() | ||
{ | ||
FileName = "c:\\datamigration\\excel\\test.xlsx", | ||
SheetName = "MyTable" | ||
}; | ||
|
||
using var excelAdapter = new ExcelExportSAXAdapter(NullLogger<ExcelExportSAXAdapter>.Instance); | ||
excelAdapter.Context = context; | ||
excelAdapter.LoadFromDataTable(dt); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
test/Sql2Xls.Integration.Tests/Sql2Xls.Integration.Tests.csproj
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 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
|
||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" /> | ||
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" /> | ||
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" /> | ||
<PackageReference Include="coverlet.collector" Version="6.0.0"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Sql2Xls\Sql2Xls.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |