Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
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