-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
705 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,3 @@ | ||
{ | ||
"dotnet-test-explorer.testProjectPath": "./Tests/" | ||
} |
This file contains 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 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 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,31 @@ | ||
// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ | ||
// Licensed under MIT licence. See License.txt in the project root for license information. | ||
|
||
using AutoMapper; | ||
|
||
namespace Tests.Helpers | ||
{ | ||
public static class AutoMapperHelpers | ||
{ | ||
public static IMapper CreateMapper<T>() where T : Profile, new() | ||
{ | ||
var config = new MapperConfiguration(cfg => | ||
{ | ||
cfg.AddProfile(new T()); | ||
}); | ||
var mapper = config.CreateMapper(); | ||
return mapper; | ||
} | ||
|
||
public static IMapper CreateMapper<T1, T2>() where T1 : Profile, new() where T2 : Profile, new() | ||
{ | ||
var config = new MapperConfiguration(cfg => | ||
{ | ||
cfg.AddProfile(new T1()); | ||
cfg.AddProfile(new T2()); | ||
}); | ||
var mapper = config.CreateMapper(); | ||
return mapper; | ||
} | ||
} | ||
} |
This file contains 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,153 @@ | ||
// Copyright (c) 2016 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ | ||
// Licensed under MIT licence. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using DataLayer.Dtos; | ||
using DataLayer.EfClasses; | ||
using DataLayer.EfCode; | ||
|
||
namespace Tests.Helpers | ||
{ | ||
public static class DddEfTestData | ||
{ | ||
public const string DummyUserId = "UnitTestUserId"; | ||
public static readonly DateTime DummyBookStartDate = new DateTime(2010, 1, 1); | ||
|
||
public static void SeedDatabaseDummyBooks(this EfCoreContext context, int numBooks = 10) | ||
{ | ||
context.Books.AddRange(CreateDummyBooks(numBooks)); | ||
context.SaveChanges(); | ||
} | ||
|
||
public static Book CreateDummyBookOneAuthor() | ||
{ | ||
|
||
var book = new Book | ||
( | ||
"Book Title", | ||
"Book Description", | ||
DummyBookStartDate, | ||
"Book Publisher", | ||
123, | ||
null, | ||
new[] { new Author ("Test Author") } | ||
); | ||
|
||
return book; | ||
} | ||
|
||
public static List<Book> CreateDummyBooks(int numBooks = 10, bool stepByYears = false) | ||
{ | ||
var result = new List<Book>(); | ||
var commonAuthor = new Author("CommonAuthor"); | ||
for (int i = 0; i < numBooks; i++) | ||
{ | ||
var book = new Book | ||
( | ||
$"Book{i:D4} Title", | ||
$"Book{i:D4} Description", | ||
stepByYears ? DummyBookStartDate.AddYears(i) : DummyBookStartDate.AddDays(i), | ||
"Publisher", | ||
(short)(i + 1), | ||
$"Image{i:D4}", | ||
new[] { new Author( $"Author{i:D4}"), commonAuthor} | ||
); | ||
for (int j = 0; j < i; j++) | ||
{ | ||
book.AddReview((j % 5) + 1, null, j.ToString()); | ||
} | ||
|
||
result.Add(book); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
public static void SeedDatabaseFourBooks(this EfCoreContext context) | ||
{ | ||
context.Books.AddRange(CreateFourBooks()); | ||
context.SaveChanges(); | ||
} | ||
|
||
public static List<Book> CreateFourBooks() | ||
{ | ||
var martinFowler = new Author("Martin Fowler"); | ||
|
||
var books = new List<Book>(); | ||
|
||
var book1 = new Book | ||
( | ||
"Refactoring", | ||
"Improving the design of existing code", | ||
new DateTime(1999, 7, 8), | ||
null, | ||
40, | ||
null, | ||
new[] { martinFowler } | ||
); | ||
books.Add(book1); | ||
|
||
var book2 = new Book | ||
( | ||
"Patterns of Enterprise Application Architecture", | ||
"Written in direct response to the stiff challenges", | ||
new DateTime(2002, 11, 15), | ||
null, | ||
53, | ||
null, | ||
new []{martinFowler} | ||
); | ||
books.Add(book2); | ||
|
||
var book3 = new Book | ||
( | ||
"Domain-Driven Design", | ||
"Linking business needs to software design", | ||
new DateTime(2003, 8, 30), | ||
null, | ||
56, | ||
null, | ||
new[] { new Author("Eric Evans") } | ||
); | ||
books.Add(book3); | ||
|
||
var book4 = new Book | ||
( | ||
"Quantum Networking", | ||
"Entangled quantum networking provides faster-than-light data communications", | ||
new DateTime(2057, 1, 1), | ||
"Future Published", | ||
220, | ||
null, | ||
new[] { new Author("Future Person") } | ||
); | ||
book4.AddReview(5, | ||
"I look forward to reading this book, if I am still alive!", "Jon P Smith"); | ||
book4.AddReview(5, | ||
"I write this book if I was still alive!", "Albert Einstein"); book4.AddPromotion(219, "Save $1 if you order 40 years ahead!"); | ||
book4.AddPromotion(219, "Save 1$ by buying 40 years ahead"); | ||
|
||
books.Add(book4); | ||
|
||
return books; | ||
} | ||
|
||
public static void SeedDummyOrder(this EfCoreContext context, DateTime orderDate = new DateTime()) | ||
{ | ||
if (orderDate == new DateTime()) | ||
orderDate = DateTime.Today; | ||
var books = context.Books.ToList(); | ||
context.AddRange(BuildDummyOrder(DummyUserId, orderDate, books.First())); | ||
context.SaveChanges(); | ||
} | ||
|
||
private static Order BuildDummyOrder(string userId, DateTime orderDate, Book bookOrdered) | ||
{ | ||
var deliverDay = orderDate.AddDays(5); | ||
var bookOrders = new List<OrderBooksDto>() { new OrderBooksDto(1, bookOrdered, 1) }; | ||
return Order.CreateOrderFactory(userId, deliverDay, bookOrders)?.Result; | ||
} | ||
} | ||
} |
This file contains 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,30 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp2.0</TargetFramework> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="AutoMapper" Version="6.2.2" /> | ||
<PackageReference Include="EfCore.TestSupport" Version="1.3.0" /> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.0.1" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.6.1" /> | ||
<PackageReference Include="xunit" Version="2.3.1" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" /> | ||
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Folder Include="UnitTests\DataLayer\" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\DataLayer\DataLayer.csproj" /> | ||
<ProjectReference Include="..\GenericLibsBase\GenericLibsBase.csproj" /> | ||
<ProjectReference Include="..\RazorPageApp\RazorPageApp.csproj" /> | ||
<ProjectReference Include="..\ServiceLayer\ServiceLayer.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Oops, something went wrong.