Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ jobs:
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Install SQL Local DB
run: ./Setup.ps1
shell: pwsh
- name: Build and Test
run: ./Build.ps1
shell: pwsh
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ jobs:
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Install SQL Local DB
run: ./Setup.ps1
shell: pwsh
- name: Build and Test
run: ./Build.ps1
shell: pwsh
Expand Down
5 changes: 3 additions & 2 deletions AutoMapper.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29215.179
# Visual Studio Version 17
VisualStudioVersion = 17.0.32002.185
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{0691ABF2-B3C7-43BF-9862-2D8D1299CE58}"
ProjectSection(SolutionItems) = preProject
Expand All @@ -14,6 +14,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
Push.ps1 = Push.ps1
README.md = README.md
.github\workflows\release.yml = .github\workflows\release.yml
Setup.ps1 = Setup.ps1
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Benchmark", "src\Benchmark\Benchmark.csproj", "{B8051389-CB47-46FB-B234-9D49506704AA}"
Expand Down
32 changes: 32 additions & 0 deletions Setup.ps1
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;"

20 changes: 0 additions & 20 deletions src/IntegrationTests/App.config

This file was deleted.

2 changes: 1 addition & 1 deletion src/IntegrationTests/AutoMapper.IntegrationTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<ProjectReference Include="..\AutoMapper\AutoMapper.csproj" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="Shouldly" Version="4.0.3" />
<PackageReference Include="EntityFramework" Version="6.4.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" PrivateAssets="All" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
</ItemGroup>
Expand Down
107 changes: 54 additions & 53 deletions src/IntegrationTests/BuiltInTypes/ByteArray.cs
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 src/IntegrationTests/BuiltInTypes/DateTimeToNullableDateTime.cs
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;
}
Loading