Skip to content

Commit

Permalink
Merge pull request #4 from yv989c/develop
Browse files Browse the repository at this point in the history
Ready for the world!
  • Loading branch information
yv989c authored Sep 2, 2022
2 parents b139406 + 9037b11 commit ff940a3
Show file tree
Hide file tree
Showing 13 changed files with 147 additions and 183 deletions.
16 changes: 9 additions & 7 deletions .github/workflows/ci-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,16 @@ jobs:
# Tests
- name: Build
run: msbuild BlazarTech.QueryableValues.EF6.sln -property:Configuration=Release -property:RestorePackages=false
#- name: Tests
# run: vstest.console.exe tests/QueryableValues.EF6.SqlServer.Tests.EF*/bin/Release/**/BlazarTech.QueryableValues.EF6.SqlServer.Tests.EF*.dll
- name: Tests
uses: microsoft/[email protected]
with:
testAssembly: BlazarTech.QueryableValues.EF6.SqlServer.Tests.EF*.dll
searchFolder: ./tests/QueryableValues.EF6.SqlServer.Tests.EF*/bin/Release/**/
runInParallel: false
run: |
& "C:/Program Files/Microsoft Visual Studio/2022/Enterprise/Common7/IDE/Extensions/TestPlatform/vstest.console.exe" ./tests/QueryableValues.EF6.SqlServer.Tests.EF*/bin/Release/**/BlazarTech.QueryableValues.EF6.SqlServer.Tests.EF*.dll
#uses: microsoft/[email protected]
#with:
# testAssembly: BlazarTech.QueryableValues.EF6.SqlServer.Tests.EF*.dll
# searchFolder: ./tests/QueryableValues.EF6.SqlServer.Tests.EF*/bin/Release/**/
# runInParallel: false
# vstestLocationMethod: location
# vstestLocation: 'C:/Program Files/Microsoft Visual Studio/2022/Enterprise/Common7/IDE/Extensions/TestPlatform/vstest.console.exe'

- name: Upload Artifacts
uses: actions/upload-artifact@v2
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<img src="/docs/images/icon.png" alt="Logo" style="width: 80px;">
</p>

# QueryableValues for EF6
# QueryableValues `EF6 Edition`

[![MIT License](https://badgen.net/badge/license/MIT/blue)](https://github.com/yv989c/BlazarTech.QueryableValues.EF6/blob/main/LICENSE.md)
[![GitHub Stars](https://badgen.net/github/stars/yv989c/BlazarTech.QueryableValues.EF6?icon=github)][Repository]
Expand All @@ -16,7 +16,7 @@ For a detailed explanation of the problem solved by QueryableValues, please cont

> 💡 This is a streamlined version of the original [QueryableValues][QueryableValuesEFCoreRepository] for Entity Framework Core, which I have adapted to provide some of its features on [Entity Framework 6].
> 💡 Are you on Entity Framework Core? Use [the original version][QueryableValuesEFCoreRepository] of QueryableValues instead.
> 💡 Using Entity Framework Core? Then [the original version][QueryableValuesEFCoreRepository] of QueryableValues is what you need.
## When Should You Use It?
The `AsQueryableValues` extension method is intended for queries that are dependent upon a *non-constant* sequence of external values. In such cases, the underlying SQL query will be efficient on subsequent executions.
Expand All @@ -31,7 +31,7 @@ Your ⭐ on [this repository][Repository] also helps! Thanks! 🖖🙂
# Getting Started

## Installation
QueryableValues for EF6 is distributed as a [NuGet Package]. You can install it using the command below in your NuGet Package Manager Console window in Visual Studio:
QueryableValues `EF6 Edition` is distributed as a [NuGet Package]. You can install it using the command below in your NuGet Package Manager Console window in Visual Studio:

`Install-Package BlazarTech.QueryableValues.EF6.SqlServer`

Expand Down
2 changes: 1 addition & 1 deletion Version.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project>
<PropertyGroup>
<VersionPrefix>1.0.0-rc.2</VersionPrefix>
<VersionPrefix>1.0.0</VersionPrefix>
</PropertyGroup>
</Project>
6 changes: 3 additions & 3 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# QueryableValues for EF6
# QueryableValues `EF6 Edition`

[![MIT License](https://badgen.net/badge/license/MIT/blue)](https://github.com/yv989c/BlazarTech.QueryableValues.EF6/blob/main/LICENSE.md)
[![GitHub Stars](https://badgen.net/github/stars/yv989c/BlazarTech.QueryableValues.EF6?icon=github)][Repository]
Expand All @@ -12,7 +12,7 @@ For a detailed explanation of the problem solved by QueryableValues, please cont

> 💡 This is a streamlined version of the original [QueryableValues][QueryableValuesEFCoreRepository] for Entity Framework Core, which I have adapted to provide some of its features on [Entity Framework 6].
> 💡 Are you on Entity Framework Core? Use [the original version][QueryableValuesEFCoreRepository] of QueryableValues instead.
> 💡 Using Entity Framework Core? Then [the original version][QueryableValuesEFCoreRepository] of QueryableValues is what you need.
## When Should You Use It?
The `AsQueryableValues` extension method is intended for queries that are dependent upon a *non-constant* sequence of external values. In such cases, the underlying SQL query will be efficient on subsequent executions.
Expand All @@ -27,7 +27,7 @@ Your ⭐ on [this repository][Repository] also helps! Thanks! 🖖🙂
# Getting Started

## Installation
QueryableValues for EF6 is distributed as a [NuGet Package]. You can install it using the command below in your NuGet Package Manager Console window in Visual Studio:
QueryableValues `EF6 Edition` is distributed as a [NuGet Package]. You can install it using the command below in your NuGet Package Manager Console window in Visual Studio:

`Install-Package BlazarTech.QueryableValues.EF6.SqlServer`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,15 @@ public TestDbContext(string connectionString) : base(connectionString)
Database.SetInitializer<TestDbContext>(null);
}

public static TestDbContext Create()
public static TestDbContext Create(bool useDatabaseNullSemantics = false)
{
return new TestDbContext(DbUtil.GetConnectionString(false));
return new TestDbContext(DbUtil.GetConnectionString(false))
{
Configuration =
{
UseDatabaseNullSemantics = useDatabaseNullSemantics
}
};
}

protected override void OnModelCreating(DbModelBuilder modelBuilder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@ public TestDbContext(string connectionString) : base(connectionString)
{
}

public static TestDbContext Create()
public static TestDbContext Create(bool useDatabaseNullSemantics = false)
{
return new TestDbContext(DbUtil.GetConnectionString(true));
return new TestDbContext(DbUtil.GetConnectionString(true))
{
Configuration =
{
UseDatabaseNullSemantics = useDatabaseNullSemantics
}
};
}
}
}
9 changes: 9 additions & 0 deletions tests/QueryableValues.EF6.SqlServer.Tests.EF60/DbUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,14 @@ public static string GetConnectionString(bool useDatabaseFirst)
return connectionString;
}
}

public static ITestDbContextWithSauce CreateDbContext(bool useDatabaseFirst, bool useDatabaseNullSemantics)
{
var dbContext = useDatabaseFirst ?
(ITestDbContextWithSauce)DatabaseFirst.TestDbContext.Create(useDatabaseNullSemantics) :
CodeFirst.TestDbContext.Create(useDatabaseNullSemantics);

return dbContext;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Data.Entity;
using System;
using System.Data.Entity;

namespace BlazarTech.QueryableValues.EF6.SqlServer.Tests
{
Expand All @@ -7,7 +8,7 @@ public interface ITestDbContext
DbSet<DatabaseFirst.TestDataEntity> TestData { get; set; }
}

public interface ITestDbContextWithSauce : ITestDbContext, IQueryableValuesEnabledDbContext
public interface ITestDbContextWithSauce : ITestDbContext, IQueryableValuesEnabledDbContext, IDisposable
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,10 @@ public static IEnumerable<object[]> Data
{
get
{
var options = new (bool WithCount, bool IsEmpty)[]
foreach (var option in TestUtil.GetTestDataOptions())
{
(false, false),
(false, true),
(true, false),
(true, true)
};

#if NET5_0_OR_GREATER
foreach (var option in options)
{
yield return new object[] { CodeFirst.TestDbContext.Create(), option.WithCount, option.IsEmpty };
}
#else
foreach (var option in options)
{
yield return new object[] { CodeFirst.TestDbContext.Create(), option.WithCount, option.IsEmpty };
yield return new object[] { option.UseDatabaseFirst, option.UseDatabaseNullSemantics, option.WithCount, option.IsEmpty };
}

foreach (var option in options)
{
yield return new object[] { DatabaseFirst.TestDbContext.Create(), option.WithCount, option.IsEmpty };
}
#endif
}
}

Expand All @@ -57,10 +37,9 @@ private static int[] GetExpected(bool isEmpty, params int[] expected)

[Theory]
[MemberData(nameof(Data))]
public async Task Complex1<T>(T db, bool withCount, bool isEmpty)
where T : DbContext, ITestDbContext
public async Task Complex1(bool useDatabaseFirst, bool useDatabaseNullSemantics, bool withCount, bool isEmpty)
{
using (db)
using (var db = DbUtil.CreateDbContext(useDatabaseFirst, useDatabaseNullSemantics))
{
var sequence = GetSequence(getSequence(), withCount);

Expand Down Expand Up @@ -99,10 +78,9 @@ IEnumerable<short> getSequenceInt16()

[Theory]
[MemberData(nameof(Data))]
public async Task Complex2<T>(T db, bool withCount, bool isEmpty)
where T : DbContext, ITestDbContext
public async Task Complex2(bool useDatabaseFirst, bool useDatabaseNullSemantics, bool withCount, bool isEmpty)
{
using (db)
using (var db = DbUtil.CreateDbContext(useDatabaseFirst, useDatabaseNullSemantics))
{
var sequence = GetSequence(getSequence(), withCount);

Expand Down Expand Up @@ -156,10 +134,9 @@ IEnumerable<int> getSequenceInt32()

[Theory]
[MemberData(nameof(Data))]
public async Task Complex3<T>(T db, bool withCount, bool isEmpty)
where T : DbContext, ITestDbContext
public async Task Complex3(bool useDatabaseFirst, bool useDatabaseNullSemantics, bool withCount, bool isEmpty)
{
using (db)
using (var db = DbUtil.CreateDbContext(useDatabaseFirst, useDatabaseNullSemantics))
{
var sequenceStringUnicode = GetSequence(getSequenceString(), withCount);
var qvStringUnicode = db.AsQueryableValues(sequenceStringUnicode, isUnicode: true);
Expand Down Expand Up @@ -203,10 +180,9 @@ IEnumerable<int> getSequenceInt32()

[Theory]
[MemberData(nameof(Data))]
public async Task Complex4<T>(T db, bool withCount, bool isEmpty)
where T : DbContext, ITestDbContext
public async Task Complex4(bool useDatabaseFirst, bool useDatabaseNullSemantics, bool withCount, bool isEmpty)
{
using (db)
using (var db = DbUtil.CreateDbContext(useDatabaseFirst, useDatabaseNullSemantics))
{
var sequenceStringUnicode = GetSequence(getSequenceString(), withCount);
var qvStringUnicode = db.AsQueryableValues(sequenceStringUnicode, isUnicode: true);
Expand Down Expand Up @@ -258,11 +234,12 @@ IEnumerable<int> getSequenceInt32()

[Theory]
[MemberData(nameof(Data))]
public void DocsExamples<T>(T dbContext, bool withCount, bool isEmpty)
where T : DbContext, ITestDbContext
public void DocsExamples<T>(bool useDatabaseFirst, bool useDatabaseNullSemantics, bool withCount, bool isEmpty)
{
IEnumerable<int> values = isEmpty ? Array.Empty<int>() : GetSequence(Enumerable.Range(1, 4), withCount);

using var dbContext = DbUtil.CreateDbContext(useDatabaseFirst, useDatabaseNullSemantics);

{
var qvQuery = dbContext.AsQueryableValues(values);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,10 @@ public static IEnumerable<object[]> Data
{
get
{
var options = new (bool WithCount, bool IsEmpty)[]
foreach (var option in TestUtil.GetTestDataOptions())
{
(false, false),
(false, true),
(true, false),
(true, true)
};

#if NET5_0_OR_GREATER
foreach (var option in options)
{
yield return new object[] { CodeFirst.TestDbContext.Create(), option.WithCount, option.IsEmpty };
}
#else
foreach (var option in options)
{
yield return new object[] { CodeFirst.TestDbContext.Create(), option.WithCount, option.IsEmpty };
}

foreach (var option in options)
{
yield return new object[] { DatabaseFirst.TestDbContext.Create(), option.WithCount, option.IsEmpty };
yield return new object[] { option.UseDatabaseFirst, option.UseDatabaseNullSemantics, option.WithCount, option.IsEmpty };
}
#endif
}
}

Expand All @@ -57,10 +37,9 @@ private static int[] GetExpected(bool isEmpty, params int[] expected)

[Theory]
[MemberData(nameof(Data))]
public async Task Byte<T>(T db, bool withCount, bool isEmpty)
where T : DbContext, ITestDbContext
public async Task Byte(bool useDatabaseFirst, bool useDatabaseNullSemantics, bool withCount, bool isEmpty)
{
using (db)
using (var db = DbUtil.CreateDbContext(useDatabaseFirst, useDatabaseNullSemantics))
{
var sequence = GetSequence(getSequence(), withCount);
var qv = db.AsQueryableValues(sequence);
Expand Down Expand Up @@ -90,10 +69,9 @@ IEnumerable<byte> getSequence()

[Theory]
[MemberData(nameof(Data))]
public async Task Int16<T>(T db, bool withCount, bool isEmpty)
where T : DbContext, ITestDbContext
public async Task Int16(bool useDatabaseFirst, bool useDatabaseNullSemantics, bool withCount, bool isEmpty)
{
using (db)
using (var db = DbUtil.CreateDbContext(useDatabaseFirst, useDatabaseNullSemantics))
{
var sequence = GetSequence(getSequence(), withCount);
var qv = db.AsQueryableValues(sequence);
Expand Down Expand Up @@ -122,10 +100,9 @@ IEnumerable<short> getSequence()

[Theory]
[MemberData(nameof(Data))]
public async Task Int32<T>(T db, bool withCount, bool isEmpty)
where T : DbContext, ITestDbContext
public async Task Int32(bool useDatabaseFirst, bool useDatabaseNullSemantics, bool withCount, bool isEmpty)
{
using (db)
using (var db = DbUtil.CreateDbContext(useDatabaseFirst, useDatabaseNullSemantics))
{
var sequence = GetSequence(getSequence(), withCount);
var qv = db.AsQueryableValues(sequence);
Expand Down Expand Up @@ -156,10 +133,9 @@ IEnumerable<int> getSequence()

[Theory]
[MemberData(nameof(Data))]
public async Task Int64<T>(T db, bool withCount, bool isEmpty)
where T : DbContext, ITestDbContext
public async Task Int64(bool useDatabaseFirst, bool useDatabaseNullSemantics, bool withCount, bool isEmpty)
{
using (db)
using (var db = DbUtil.CreateDbContext(useDatabaseFirst, useDatabaseNullSemantics))
{
var sequence = GetSequence(getSequence(), withCount);
var qv = db.AsQueryableValues(sequence);
Expand Down Expand Up @@ -189,10 +165,9 @@ IEnumerable<long> getSequence()

[Theory]
[MemberData(nameof(Data))]
public async Task String<T>(T db, bool withCount, bool isEmpty)
where T : DbContext, ITestDbContext
public async Task String(bool useDatabaseFirst, bool useDatabaseNullSemantics, bool withCount, bool isEmpty)
{
using (db)
using (var db = DbUtil.CreateDbContext(useDatabaseFirst, useDatabaseNullSemantics))
{
var sequence = GetSequence(getSequence(), withCount);
var qv = db.AsQueryableValues(sequence, false);
Expand Down Expand Up @@ -222,10 +197,9 @@ IEnumerable<string> getSequence()

[Theory]
[MemberData(nameof(Data))]
public async Task StringUnicode<T>(T db, bool withCount, bool isEmpty)
where T : DbContext, ITestDbContext
public async Task StringUnicode(bool useDatabaseFirst, bool useDatabaseNullSemantics, bool withCount, bool isEmpty)
{
using (db)
using (var db = DbUtil.CreateDbContext(useDatabaseFirst, useDatabaseNullSemantics))
{
var sequence = GetSequence(getSequence(), withCount);
var qv = db.AsQueryableValues(sequence, true);
Expand Down Expand Up @@ -255,10 +229,9 @@ IEnumerable<string> getSequence()

[Theory]
[MemberData(nameof(Data))]
public async Task Guid<T>(T db, bool withCount, bool isEmpty)
where T : DbContext, ITestDbContext
public async Task Guid(bool useDatabaseFirst, bool useDatabaseNullSemantics, bool withCount, bool isEmpty)
{
using (db)
using (var db = DbUtil.CreateDbContext(useDatabaseFirst, useDatabaseNullSemantics))
{
var sequence = GetSequence(getSequence(), withCount);
var qv = db.AsQueryableValues(sequence);
Expand Down
Loading

0 comments on commit ff940a3

Please sign in to comment.