Skip to content

Commit

Permalink
Added support .Net 5 preview 7
Browse files Browse the repository at this point in the history
  • Loading branch information
RamanGreenFlux committed Jul 28, 2020
1 parent 673dd6b commit fd90443
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 155 deletions.
10 changes: 5 additions & 5 deletions src/MockQueryable/MockQueryable.Core/MockQueryable.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>netstandard2.1</TargetFramework>
<PackageId>MockQueryable.Core</PackageId>
<Authors>Roman Titov</Authors>
<Description>
Core package for MockQueryable extensions for mocking operations such ToListAsync, FirstOrDefaultAsync etc.
When writing tests for your application it is often desirable to avoid hitting the database. The extension allows you to achieve this by creating a context – with behavior defined by your tests – that makes use of in-memory data.
</Description>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageReleaseNotes>MockQueryable splitted into MockQueryable.Core and MockQueryable.EntityFrameworkCore</PackageReleaseNotes>
<PackageProjectUrl>https://github.com/romantitov/MockQueryable</PackageProjectUrl>
<RepositoryUrl>https://github.com/romantitov/MockQueryable</RepositoryUrl>
<PackageTags>Mock EntityFrameworkCore Queryable mock EF UnitTests EntityFrameworkCore</PackageTags>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>3.1.3</Version>
<AssemblyVersion>3.1.3.0</AssemblyVersion>
<FileVersion>3.1.3.0</FileVersion>
<PackageReleaseNotes>Added support .Net 5.0</PackageReleaseNotes>
<Version>5.0.0-preview.7</Version>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<FileVersion>5.0.0.0</FileVersion>
<Company></Company>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageIcon>logo.png</PackageIcon>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>netstandard2.1</TargetFramework>
<PackageId>MockQueryable.EntityFrameworkCore</PackageId>
<Authors>Roman Titov</Authors>
<Description>
Extension for mocking Entity Framework Core operations such ToListAsync, FirstOrDefaultAsync etc.
When writing tests for your application it is often desirable to avoid hitting the database. The extension allows you to achieve this by creating a context – with behavior defined by your tests – that makes use of in-memory data.
</Description>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageReleaseNotes>MockQueryable splitted into MockQueryable.Core and MockQueryable.EntityFrameworkCore</PackageReleaseNotes>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageProjectUrl>https://github.com/romantitov/MockQueryable</PackageProjectUrl>
<RepositoryUrl>https://github.com/romantitov/MockQueryable</RepositoryUrl>
<PackageTags>Mock EntityFrameworkCore Queryable mock EF UnitTests EntityFrameworkCore</PackageTags>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>3.1.3</Version>
<AssemblyVersion>3.1.3.0</AssemblyVersion>
<FileVersion>3.1.3.0</FileVersion>
<PackageReleaseNotes>Added support .Net 5.0</PackageReleaseNotes>
<Version>5.0.0-preview.7</Version>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<FileVersion>5.0.0.0</FileVersion>
<Company></Company>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageIcon>logo.png</PackageIcon>
Expand All @@ -36,7 +37,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.0-preview.7.20365.15" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Linq.Expressions;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore.Query.Internal;
using Microsoft.EntityFrameworkCore.Query;
using MockQueryable.Core;

namespace MockQueryable.EntityFrameworkCore
Expand Down
10 changes: 0 additions & 10 deletions src/MockQueryable/MockQueryable.FakeItEasy/FakeItEasyExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,6 @@ public static DbSet<TEntity> BuildMockDbSet<TEntity>(this IQueryable<TEntity> da
return mock;
}

[Obsolete("Use BuildMockDbSet<TEntity> instead")]
public static DbQuery<TEntity> BuildMockDbQuery<TEntity>(this IQueryable<TEntity> data) where TEntity : class
{
var mock = A.Fake<DbQuery<TEntity>>(
d => d.Implements<IAsyncEnumerable<TEntity>>().Implements<IQueryable<TEntity>>());
var enumerable = new TestAsyncEnumerableEfCore<TEntity>(data);
mock.ConfigureQueryableCalls(enumerable, data);
mock.ConfigureAsyncEnumerableCalls(enumerable);
return mock;
}

private static void ConfigureQueryableCalls<TEntity>(
this IQueryable<TEntity> mock,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>netstandard2.1</TargetFramework>
<PackageId>MockQueryable.FakeItEasy</PackageId>
<Authors>Roman Titov</Authors>
<Description>
Extension for mocking Entity Framework Core operations such ToListAsync, FirstOrDefaultAsync etc.
When writing tests for your application it is often desirable to avoid hitting the database. The extension allows you to achieve this by creating a context – with behavior defined by your tests – that makes use of in-memory data.
</Description>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageReleaseNotes>MockQueryable splitted into MockQueryable.Core and MockQueryable.EntityFrameworkCore</PackageReleaseNotes>
<PackageProjectUrl>https://github.com/romantitov/MockQueryable</PackageProjectUrl>
<RepositoryUrl>https://github.com/romantitov/MockQueryable</RepositoryUrl>
<PackageTags>Mock EntityFrameworkCore Queryable mock EF EFCore UnitTests FakeItEasy</PackageTags>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>3.1.3</Version>
<AssemblyVersion>3.1.3.0</AssemblyVersion>
<FileVersion>3.1.3.0</FileVersion>
<PackageReleaseNotes>Added support .Net 5.0</PackageReleaseNotes>
<Version>5.0.0-preview.7</Version>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<FileVersion>5.0.0.0</FileVersion>
<Company></Company>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageIcon>logo.png</PackageIcon>
Expand Down
10 changes: 5 additions & 5 deletions src/MockQueryable/MockQueryable.Moq/MockQueryable.Moq.csproj
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>netstandard2.1</TargetFramework>
<PackageId>MockQueryable.Moq</PackageId>
<Authors>Roman Titov</Authors>
<Description>
Extension for mocking Entity Framework Core operations such ToListAsync, FirstOrDefaultAsync etc.
When writing tests for your application it is often desirable to avoid hitting the database. The extension allows you to achieve this by creating a context – with behavior defined by your tests – that makes use of in-memory data.
</Description>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageReleaseNotes>MockQueryable splitted into MockQueryable.Core and MockQueryable.EntityFrameworkCore</PackageReleaseNotes>
<PackageProjectUrl>https://github.com/romantitov/MockQueryable</PackageProjectUrl>
<RepositoryUrl>https://github.com/romantitov/MockQueryable</RepositoryUrl>
<PackageTags>Mock EntityFrameworkCore Queryable mock EF EFCore UnitTests EntityFrameworkCore Moq</PackageTags>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>3.1.3</Version>
<AssemblyVersion>3.1.3.0</AssemblyVersion>
<FileVersion>3.1.3.0</FileVersion>
<PackageReleaseNotes>Added support .Net 5.0</PackageReleaseNotes>
<Version>5.0.0-preview.7</Version>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<FileVersion>5.0.0.0</FileVersion>
<Company></Company>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageIcon>logo.png</PackageIcon>
Expand Down
11 changes: 0 additions & 11 deletions src/MockQueryable/MockQueryable.Moq/MoqExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,6 @@ public static Mock<DbSet<TEntity>> BuildMockDbSet<TEntity>(this IQueryable<TEnti
return mock;
}

[Obsolete("Use BuildMockDbSet<TEntity> instead")]
public static Mock<DbQuery<TEntity>> BuildMockDbQuery<TEntity>(this IQueryable<TEntity> data)
where TEntity : class
{
var mock = new Mock<DbQuery<TEntity>>();
var enumerable = new TestAsyncEnumerableEfCore<TEntity>(data);
mock.As<IAsyncEnumerable<TEntity>>().ConfigureAsyncEnumerableCalls(enumerable);
mock.As<IQueryable<TEntity>>().ConfigureQueryableCalls(enumerable, data);
return mock;
}

private static void ConfigureDbSetCalls<TEntity>(this Mock<DbSet<TEntity>> mock)
where TEntity : class
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>netstandard2.1</TargetFramework>
<PackageId>MockQueryable.NSubstitute</PackageId>
<Authors>Roman Titov</Authors>
<Description>
Extension for mocking Entity Framework Core operations such ToListAsync, FirstOrDefaultAsync etc.
When writing tests for your application it is often desirable to avoid hitting the database. The extension allows you to achieve this by creating a context – with behavior defined by your tests – that makes use of in-memory data.
</Description>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageReleaseNotes>MockQueryable splitted into MockQueryable.Core and MockQueryable.EntityFrameworkCore</PackageReleaseNotes>
<PackageProjectUrl>https://github.com/romantitov/MockQueryable</PackageProjectUrl>
<RepositoryUrl>https://github.com/romantitov/MockQueryable</RepositoryUrl>
<PackageTags>Mock EntityFrameworkCore Queryable mock EF EFCore UnitTests EntityFrameworkCore NSubstitute</PackageTags>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>3.1.3</Version>
<AssemblyVersion>3.1.3.0</AssemblyVersion>
<FileVersion>3.1.3.0</FileVersion>
<PackageReleaseNotes>Added support .Net 5.0</PackageReleaseNotes>
<Version>5.0.0-preview.7</Version>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<FileVersion>5.0.0.0</FileVersion>
<Company></Company>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageIcon>logo.png</PackageIcon>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,6 @@ public static DbSet<TEntity> BuildMockDbSet<TEntity>(this IQueryable<TEntity> da
return mock;
}

[Obsolete("Use BuildMockDbSet<TEntity> instead")]
public static DbQuery<TEntity> BuildMockDbQuery<TEntity>(this IQueryable<TEntity> data) where TEntity : class
{
var mock = Substitute.For<DbQuery<TEntity>, IQueryable<TEntity>, IAsyncEnumerable<TEntity>>();
var enumerable = new TestAsyncEnumerableEfCore<TEntity>(data);
mock.ConfigureAsyncEnumerableCalls(enumerable);
mock.ConfigureQueryableCalls(enumerable, data);
return mock;
}

private static void ConfigureQueryableCalls<TEntity>(
this IQueryable<TEntity> mock,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,37 +69,11 @@ public async Task GetUserReports(DateTime from, DateTime to, int expectedCount)

}


[TestCase("01/20/2012", "06/20/2018", 5)]
[TestCase("01/20/2012", "06/20/2012", 4)]
[TestCase("01/20/2012", "02/20/2012", 3)]
[TestCase("01/20/2010", "02/20/2011", 0)]
public async Task GetUserReports_DbQuery(DateTime from, DateTime to, int expectedCount)
{
//arrange
var userRepository = A.Fake<IUserRepository>();
var service = new MyService(userRepository);
var users = new List<UserEntity>
{
new UserEntity{FirstName = "FirstName1", LastName = "LastName", DateOfBirth = DateTime.Parse("01/20/2012",UsCultureInfo.DateTimeFormat)},
new UserEntity{FirstName = "FirstName2", LastName = "LastName", DateOfBirth = DateTime.Parse("01/20/2012",UsCultureInfo.DateTimeFormat)},
new UserEntity{FirstName = "FirstName3", LastName = "LastName", DateOfBirth = DateTime.Parse("01/20/2012",UsCultureInfo.DateTimeFormat)},
new UserEntity{FirstName = "FirstName3", LastName = "LastName", DateOfBirth = DateTime.Parse("03/20/2012",UsCultureInfo.DateTimeFormat)},
new UserEntity{FirstName = "FirstName5", LastName = "LastName", DateOfBirth = DateTime.Parse("01/20/2018",UsCultureInfo.DateTimeFormat)},
};
//expect
var mock = users.AsQueryable().BuildMockDbQuery();
A.CallTo(() => userRepository.GetQueryable()).Returns(mock);
//act
var result = await service.GetUserReports(from, to);
//assert
Assert.AreEqual(expectedCount, result.Count);

}

//[TestCase("01/20/2012", "06/20/2018", 5)]
//[TestCase("01/20/2012", "06/20/2012", 4)]
//[TestCase("01/20/2012", "02/20/2012", 3)]
[TestCase("01/20/2010", "02/20/2011", 0)]
public async Task GetUserReports_AutoMap(DateTime from, DateTime to, int expectedCount)
{
//arrange
Expand Down
45 changes: 0 additions & 45 deletions src/MockQueryable/MockQueryable.Sample/MyServiceMoqTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,51 +89,6 @@ public async Task GetUserReports(DateTime from, DateTime to, int expectedCount)
Assert.AreEqual(expectedCount, result.Count);
}

[TestCase("01/20/2012", "06/20/2018", 5)]
[TestCase("01/20/2012", "06/20/2012", 4)]
[TestCase("01/20/2012", "02/20/2012", 3)]
[TestCase("01/20/2010", "02/20/2011", 0)]
public async Task GetUserReports_DbQuery(DateTime from, DateTime to, int expectedCount)
{
//arrange
var userRepository = new Mock<IUserRepository>();
var service = new MyService(userRepository.Object);
var users = new List<UserEntity>
{
new UserEntity
{
FirstName = "FirstName1", LastName = "LastName",
DateOfBirth = DateTime.Parse("01/20/2012", UsCultureInfo.DateTimeFormat)
},
new UserEntity
{
FirstName = "FirstName2", LastName = "LastName",
DateOfBirth = DateTime.Parse("01/20/2012", UsCultureInfo.DateTimeFormat)
},
new UserEntity
{
FirstName = "FirstName3", LastName = "LastName",
DateOfBirth = DateTime.Parse("01/20/2012", UsCultureInfo.DateTimeFormat)
},
new UserEntity
{
FirstName = "FirstName3", LastName = "LastName",
DateOfBirth = DateTime.Parse("03/20/2012", UsCultureInfo.DateTimeFormat)
},
new UserEntity
{
FirstName = "FirstName5", LastName = "LastName",
DateOfBirth = DateTime.Parse("01/20/2018", UsCultureInfo.DateTimeFormat)
}
};
//expect
var mock = users.AsQueryable().BuildMockDbQuery();
userRepository.Setup(x => x.GetQueryable()).Returns(mock.Object);
//act
var result = await service.GetUserReports(from, to);
//assert
Assert.AreEqual(expectedCount, result.Count);
}


[TestCase("01/20/2012", "06/20/2018", 5)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,32 +67,6 @@ public async Task GetUserReports(DateTime from, DateTime to, int expectedCount)
Assert.AreEqual(expectedCount, result.Count);
}

[TestCase("01/20/2012", "06/20/2018", 5)]
[TestCase("01/20/2012", "06/20/2012", 4)]
[TestCase("01/20/2012", "02/20/2012", 3)]
[TestCase("01/20/2010", "02/20/2011", 0)]
public async Task GetUserReports_DbQuery(DateTime from, DateTime to, int expectedCount)
{
//arrange
var userRepository = Substitute.For<IUserRepository>();
var service = new MyService(userRepository);
var users = new List<UserEntity>
{
new UserEntity{FirstName = "FirstName1", LastName = "LastName", DateOfBirth = DateTime.Parse("01/20/2012",UsCultureInfo.DateTimeFormat)},
new UserEntity{FirstName = "FirstName2", LastName = "LastName", DateOfBirth = DateTime.Parse("01/20/2012",UsCultureInfo.DateTimeFormat)},
new UserEntity{FirstName = "FirstName3", LastName = "LastName", DateOfBirth = DateTime.Parse("01/20/2012",UsCultureInfo.DateTimeFormat)},
new UserEntity{FirstName = "FirstName3", LastName = "LastName", DateOfBirth = DateTime.Parse("03/20/2012",UsCultureInfo.DateTimeFormat)},
new UserEntity{FirstName = "FirstName5", LastName = "LastName", DateOfBirth = DateTime.Parse("01/20/2018",UsCultureInfo.DateTimeFormat)},
};
//expect
var mock = users.AsQueryable().BuildMockDbQuery();
userRepository.GetQueryable().Returns(mock);
//act
var result = await service.GetUserReports(from, to);
//assert
Assert.AreEqual(expectedCount, result.Count);
}

[TestCase("01/20/2012", "06/20/2018", 5)]
[TestCase("01/20/2012", "06/20/2012", 4)]
[TestCase("01/20/2012", "02/20/2012", 3)]
Expand Down

0 comments on commit fd90443

Please sign in to comment.