Skip to content

Commit d3a2db1

Browse files
committed
Initial Import
1 parent 89bd16e commit d3a2db1

78 files changed

Lines changed: 36478 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
2+
using UnitTestingDemo.Data.Adapters;
3+
using UnitTestingDemo.Data.EntityModels;
4+
5+
namespace UnitTestingDemo.Data.Tests.Adapters
6+
{
7+
[TestClass]
8+
public class BookEntityDomainAdapterTests
9+
{
10+
private BookEntityDomainAdapter _bookEntityDomainAdapter;
11+
12+
[TestInitialize]
13+
public void TestInitialize()
14+
{
15+
_bookEntityDomainAdapter = new BookEntityDomainAdapter();
16+
}
17+
18+
[TestMethod]
19+
public void Adapt_Id_IsEqual()
20+
{
21+
//Arrange
22+
var bookEntity = new BookEntity
23+
{
24+
Id = 1,
25+
Title = "Test Title",
26+
Author = "Chris Ayers"
27+
28+
};
29+
30+
//Act
31+
var book = _bookEntityDomainAdapter.Adapt(bookEntity);
32+
33+
//Assert
34+
Assert.AreEqual(bookEntity.Id, book.Id);
35+
}
36+
37+
[TestMethod]
38+
public void Adapt_Title_IsEqual()
39+
{
40+
//Arrange
41+
var bookEntity = new BookEntity
42+
{
43+
Id = 1,
44+
Title = "Test Title",
45+
Author = "Chris Ayers"
46+
47+
};
48+
49+
//Act
50+
var book = _bookEntityDomainAdapter.Adapt(bookEntity);
51+
52+
//Assert
53+
Assert.AreEqual(bookEntity.Title, book.Title);
54+
}
55+
56+
[TestMethod]
57+
public void Adapt_Author_IsEqual()
58+
{
59+
//Arrange
60+
var bookEntity = new BookEntity
61+
{
62+
Id = 1,
63+
Title = "Test Title",
64+
Author = "Chris Ayers"
65+
66+
};
67+
68+
//Act
69+
var book = _bookEntityDomainAdapter.Adapt(bookEntity);
70+
71+
//Assert
72+
Assert.AreEqual(bookEntity.Author, book.Author);
73+
}
74+
}
75+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp2.2</TargetFramework>
5+
6+
<IsPackable>false</IsPackable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
11+
<PackageReference Include="MSTest.TestAdapter" Version="1.3.2" />
12+
<PackageReference Include="MSTest.TestFramework" Version="1.3.2" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<ProjectReference Include="..\UnitTestingDemo.Data\UnitTestingDemo.Data.csproj" />
17+
</ItemGroup>
18+
19+
</Project>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
using UnitTestingDemo.Data.EntityModels;
3+
using UnitTestingDemo.Data.Interfaces;
4+
using UnitTestingDemo.Domain;
5+
6+
namespace UnitTestingDemo.Data.Adapters
7+
{
8+
public class BookDomainEntityAdapter : IBookDomainEntityAdapter
9+
{
10+
public BookEntity Adapt(Book book)
11+
{
12+
return new BookEntity
13+
{
14+
Id = book.Id,
15+
Title = book.Title,
16+
Author = book.Title
17+
};
18+
}
19+
}
20+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System;
2+
using UnitTestingDemo.Data.EntityModels;
3+
using UnitTestingDemo.Data.Interfaces;
4+
using UnitTestingDemo.Domain;
5+
6+
namespace UnitTestingDemo.Data.Adapters
7+
{
8+
public class BookEntityDomainAdapter : IBookEntityDomainAdapter
9+
{
10+
public Book Adapt(BookEntity bookEntity)
11+
{
12+
return new Book
13+
{
14+
Id = bookEntity.Id,
15+
Title = bookEntity.Title,
16+
Author = bookEntity.Author
17+
};
18+
}
19+
20+
public BookEntity FromDomain(Book book)
21+
{
22+
return new BookEntity
23+
{
24+
Id = book.Id,
25+
Title = book.Title,
26+
Author = book.Title
27+
};
28+
}
29+
}
30+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using UnitTestingDemo.Data.Contexts;
6+
using UnitTestingDemo.Data.EntityModels;
7+
using UnitTestingDemo.Data.Interfaces;
8+
using UnitTestingDemo.Domain;
9+
10+
namespace UnitTestingDemo.Data
11+
{
12+
public class BookRepository : IBookRepository
13+
{
14+
private readonly BookContext _bookContext;
15+
16+
public BookRepository(BookContext bookContext)
17+
{
18+
_bookContext = bookContext;
19+
}
20+
21+
public IList<BookEntity> GetAll()
22+
{
23+
return _bookContext.Books.ToList();
24+
}
25+
26+
public BookEntity GetById(int id)
27+
{
28+
throw new NotImplementedException();
29+
}
30+
31+
public void Save(BookEntity saveThis)
32+
{
33+
throw new NotImplementedException();
34+
}
35+
36+
public void Delete(BookEntity deleteThis)
37+
{
38+
throw new NotImplementedException();
39+
}
40+
}
41+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using Microsoft.EntityFrameworkCore;
2+
using UnitTestingDemo.Data.EntityModels;
3+
4+
namespace UnitTestingDemo.Data.Contexts
5+
{
6+
public class BookContext : DbContext
7+
{
8+
public BookContext(DbContextOptions<BookContext> options)
9+
: base(options)
10+
{ }
11+
12+
public DbSet<BookEntity> Books { get; set; }
13+
}
14+
15+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using UnitTestingDemo.Data.Interfaces;
2+
3+
namespace UnitTestingDemo.Data.EntityModels
4+
{
5+
public class BookEntity : IIntId
6+
{
7+
public int Id { get; set; }
8+
public string Title { get; set; }
9+
public string Author { get; set; }
10+
}
11+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using UnitTestingDemo.Data.EntityModels;
2+
using UnitTestingDemo.Domain;
3+
4+
namespace UnitTestingDemo.Data.Interfaces
5+
{
6+
public interface IBookDomainEntityAdapter
7+
{
8+
BookEntity Adapt(Book book);
9+
}
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using UnitTestingDemo.Data.EntityModels;
2+
using UnitTestingDemo.Domain;
3+
4+
namespace UnitTestingDemo.Data.Interfaces
5+
{
6+
public interface IBookEntityDomainAdapter
7+
{
8+
Book Adapt(BookEntity bookEntity);
9+
}
10+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using UnitTestingDemo.Data.EntityModels;
5+
using UnitTestingDemo.Domain;
6+
7+
namespace UnitTestingDemo.Data.Interfaces
8+
{
9+
public interface IBookRepository
10+
: IRepository<BookEntity>
11+
{
12+
13+
}
14+
}

0 commit comments

Comments
 (0)