-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Converting integration tests to EF Core #3881
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
81973ba
Changed reference and fixed usings
jbogard 0520c95
Converting all EF 6 tests to EF Core; Adding missing EF Core extensions
jbogard 372f972
Merge branch 'master' into efcore
jbogard e12dc73
Adding setup script to install SQL Local DB per https://github.com/ac…
jbogard File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,32 @@ | ||
| # Taken from psake https://github.com/psake/psake | ||
|
|
||
| <# | ||
| .SYNOPSIS | ||
| This is a helper function that runs a scriptblock and checks the PS variable $lastexitcode | ||
| to see if an error occcured. If an error is detected then an exception is thrown. | ||
| This function allows you to run command-line programs without having to | ||
| explicitly check the $lastexitcode variable. | ||
| .EXAMPLE | ||
| exec { svn info $repository_trunk } "Error executing SVN. Please verify SVN command-line client is installed" | ||
| #> | ||
| function Exec | ||
| { | ||
| [CmdletBinding()] | ||
| param( | ||
| [Parameter(Position=0,Mandatory=1)][scriptblock]$cmd, | ||
| [Parameter(Position=1,Mandatory=0)][string]$errorMessage = ($msgs.error_bad_command -f $cmd) | ||
| ) | ||
| & $cmd | ||
| if ($lastexitcode -ne 0) { | ||
| throw ("Exec: " + $errorMessage) | ||
| } | ||
| } | ||
|
|
||
| Write-Host "Downloading" | ||
| Import-Module BitsTransfer | ||
| Start-BitsTransfer -Source https://download.microsoft.com/download/7/c/1/7c14e92e-bdcb-4f89-b7cf-93543e7112d1/SqlLocalDB.msi -Destination SqlLocalDB.msi | ||
| Write-Host "Installing" | ||
| Start-Process -FilePath "SqlLocalDB.msi" -Wait -ArgumentList "/qn", "/norestart", "/l*v SqlLocalDBInstall.log", "IACCEPTSQLLOCALDBLICENSETERMS=YES"; | ||
| Write-Host "Checking" | ||
| sqlcmd -l 60 -S "(localdb)\MSSQLLocalDB" -Q "SELECT @@VERSION;" | ||
|
|
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,75 +1,76 @@ | ||
| using System.ComponentModel.DataAnnotations; | ||
| using System.Data.Entity; | ||
| using System.Linq; | ||
| using System.Threading.Tasks; | ||
| using AutoMapper.UnitTests; | ||
| using Microsoft.EntityFrameworkCore; | ||
| using Shouldly; | ||
| using Xunit; | ||
|
|
||
| namespace AutoMapper.IntegrationTests | ||
| namespace AutoMapper.IntegrationTests.BuiltInTypes; | ||
|
|
||
| public class ByteArrayColumns : AutoMapperSpecBase, IAsyncLifetime | ||
| { | ||
| using UnitTests; | ||
| using QueryableExtensions; | ||
|
|
||
| public class ByteArrayColumns : AutoMapperSpecBase | ||
| public class Customer | ||
| { | ||
| public class Customer | ||
| { | ||
| [Key] | ||
| public int Id { get; set; } | ||
| public string FirstName { get; set; } | ||
| public string LastName { get; set; } | ||
|
|
||
| public byte[] RowVersion { get; set; } | ||
| } | ||
| [Key] | ||
| public int Id { get; set; } | ||
| public string FirstName { get; set; } | ||
| public string LastName { get; set; } | ||
|
|
||
| public class CustomerViewModel | ||
| { | ||
| public string FirstName { get; set; } | ||
| public string LastName { get; set; } | ||
| public byte[] RowVersion { get; set; } | ||
| } | ||
| public byte[] RowVersion { get; set; } | ||
| } | ||
|
|
||
| public class Context : DbContext | ||
| { | ||
| public Context() | ||
| { | ||
| Database.SetInitializer<Context>(new DatabaseInitializer()); | ||
| } | ||
| public class CustomerViewModel | ||
| { | ||
| public string FirstName { get; set; } | ||
| public string LastName { get; set; } | ||
| public byte[] RowVersion { get; set; } | ||
| } | ||
|
|
||
| public DbSet<Customer> Customers { get; set; } | ||
| } | ||
| public class Context : LocalDbContext | ||
| { | ||
| public DbSet<Customer> Customers { get; set; } | ||
| } | ||
|
|
||
| public class DatabaseInitializer : CreateDatabaseIfNotExists<Context> | ||
| public class DatabaseInitializer : CreateDatabaseIfNotExists<Context> | ||
| { | ||
| protected override void Seed(Context context) | ||
| { | ||
| protected override void Seed(Context context) | ||
| context.Customers.Add(new Customer | ||
| { | ||
| context.Customers.Add(new Customer | ||
| { | ||
| Id = 1, | ||
| FirstName = "Bob", | ||
| LastName = "Smith", | ||
| RowVersion = new byte[] { 1, 2, 3 } | ||
| }); | ||
| FirstName = "Bob", | ||
| LastName = "Smith", | ||
| RowVersion = new byte[] { 1, 2, 3 } | ||
| }); | ||
|
|
||
| base.Seed(context); | ||
| } | ||
| base.Seed(context); | ||
| } | ||
| } | ||
|
|
||
| protected override MapperConfiguration CreateConfiguration() => new(cfg => | ||
| { | ||
| cfg.CreateProjection<Customer, CustomerViewModel>(); | ||
| }); | ||
| protected override MapperConfiguration CreateConfiguration() => new(cfg => | ||
| { | ||
| cfg.CreateProjection<Customer, CustomerViewModel>(); | ||
| }); | ||
|
|
||
| [Fact] | ||
| public void Can_map_with_projection() | ||
| [Fact] | ||
| public void Can_map_with_projection() | ||
| { | ||
| using (var context = new Context()) | ||
| { | ||
| using (var context = new Context()) | ||
| var customerVms = ProjectTo<CustomerViewModel>(context.Customers).ToList(); | ||
| customerVms.ForEach(x => | ||
| { | ||
| var customerVms = ProjectTo<CustomerViewModel>(context.Customers).ToList(); | ||
| customerVms.ForEach(x => | ||
| { | ||
| x.RowVersion.SequenceEqual(new byte[] { 1, 2, 3 }).ShouldBeTrue(); | ||
| }); | ||
| } | ||
| x.RowVersion.SequenceEqual(new byte[] { 1, 2, 3 }).ShouldBeTrue(); | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| public async Task InitializeAsync() | ||
| { | ||
| var initializer = new DatabaseInitializer(); | ||
|
|
||
| await initializer.Migrate(); | ||
| } | ||
|
|
||
| public Task DisposeAsync() => Task.CompletedTask; | ||
| } | ||
79 changes: 45 additions & 34 deletions
79
src/IntegrationTests/BuiltInTypes/DateTimeToNullableDateTime.cs
This file contains hidden or 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 |
|---|---|---|
| @@ -1,46 +1,57 @@ | ||
| using Shouldly; | ||
| using System; | ||
| using System.Data.Entity; | ||
| using System; | ||
| using System.Linq; | ||
| using System.Threading.Tasks; | ||
| using AutoMapper.UnitTests; | ||
| using Microsoft.EntityFrameworkCore; | ||
| using Shouldly; | ||
| using Xunit; | ||
|
|
||
| namespace AutoMapper.UnitTests.Projection | ||
| namespace AutoMapper.IntegrationTests.BuiltInTypes; | ||
|
|
||
| public class DateTimeToNullableDateTime : AutoMapperSpecBase, IAsyncLifetime | ||
| { | ||
| public class DateTimeToNullableDateTime : AutoMapperSpecBase | ||
| public class Parent | ||
| { | ||
| public class Parent | ||
| { | ||
| public int Id { get; set; } | ||
| public int Value { get; set; } | ||
| public int Id { get; set; } | ||
| public int Value { get; set; } | ||
|
|
||
| } | ||
| public class ParentDto | ||
| { | ||
| public int? Value { get; set; } | ||
| public DateTime? Date { get; set; } | ||
| } | ||
| protected override MapperConfiguration CreateConfiguration() => new(cfg => | ||
| cfg.CreateProjection<Parent, ParentDto>().ForMember(dto => dto.Date, opt => opt.MapFrom(src => DateTime.MaxValue))); | ||
| public class TestContext : DbContext | ||
| { | ||
| public TestContext(): base() => Database.SetInitializer<TestContext>(new DatabaseInitializer()); | ||
| public DbSet<Parent> Parents { get; set; } | ||
| } | ||
| public class DatabaseInitializer : DropCreateDatabaseAlways<TestContext> | ||
| } | ||
| public class ParentDto | ||
| { | ||
| public int? Value { get; set; } | ||
| public DateTime? Date { get; set; } | ||
| } | ||
|
|
||
| private readonly DateTime _expected = new(2000, 1, 1); | ||
| protected override MapperConfiguration CreateConfiguration() => new(cfg => | ||
| cfg.CreateProjection<Parent, ParentDto>().ForMember(dto => dto.Date, opt => opt.MapFrom(src => _expected))); | ||
| public class TestContext : LocalDbContext | ||
| { | ||
| public DbSet<Parent> Parents { get; set; } | ||
| } | ||
| public class DatabaseInitializer : DropCreateDatabaseAlways<TestContext> | ||
| { | ||
| protected override void Seed(TestContext testContext) | ||
| { | ||
| protected override void Seed(TestContext testContext) | ||
| { | ||
| testContext.Parents.Add(new Parent{ Value = 5 }); | ||
| base.Seed(testContext); | ||
| } | ||
| testContext.Parents.Add(new Parent{ Value = 5 }); | ||
| base.Seed(testContext); | ||
| } | ||
| [Fact] | ||
| public void Should_not_fail() | ||
| } | ||
| [Fact] | ||
| public void Should_not_fail() | ||
| { | ||
| using (var context = new TestContext()) | ||
| { | ||
| using (var context = new TestContext()) | ||
| { | ||
| ProjectTo<ParentDto>(context.Parents).Single().Date.ShouldBe(DateTime.MaxValue); | ||
| } | ||
| ProjectTo<ParentDto>(context.Parents).Single().Date.ShouldBe(_expected); | ||
| } | ||
| } | ||
|
|
||
| public async Task InitializeAsync() | ||
| { | ||
| var initializer = new DatabaseInitializer(); | ||
|
|
||
| await initializer.Migrate(); | ||
| } | ||
|
|
||
| public Task DisposeAsync() => Task.CompletedTask; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.