Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
CleanArchitecture
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tsai
CleanArchitecture
Commits
87879f1f
Commit
87879f1f
authored
Dec 03, 2018
by
Steve Smith
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
All tests passing
parent
f7b373d1
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
35 additions
and
137 deletions
+35
-137
DatabasePopulator.cs
src/CleanArchitecture.Core/DatabasePopulator.cs
+1
-1
AppDbContext.cs
src/CleanArchitecture.Infrastructure/Data/AppDbContext.cs
+3
-3
20181203222230_InitialModel.Designer.cs
...e/Data/Migrations/20181203222230_InitialModel.Designer.cs
+0
-38
20181203222230_InitialModel.cs
...astructure/Data/Migrations/20181203222230_InitialModel.cs
+0
-31
AppDbContextModelSnapshot.cs
...frastructure/Data/Migrations/AppDbContextModelSnapshot.cs
+0
-36
SeedData.cs
src/CleanArchitecture.Web/SeedData.cs
+24
-25
ApiToDoItemsControllerListShould.cs
...Tests/Integration/Web/ApiToDoItemsControllerListShould.cs
+7
-3
No files found.
src/CleanArchitecture.Core/DatabasePopulator.cs
View file @
87879f1f
...
@@ -8,7 +8,7 @@ namespace CleanArchitecture.Core
...
@@ -8,7 +8,7 @@ namespace CleanArchitecture.Core
{
{
public
static
int
PopulateDatabase
(
IRepository
todoRepository
)
public
static
int
PopulateDatabase
(
IRepository
todoRepository
)
{
{
if
(
todoRepository
.
List
<
ToDoItem
>().
Any
()
)
return
0
;
if
(
todoRepository
.
List
<
ToDoItem
>().
Count
()
>=
5
)
return
0
;
todoRepository
.
Add
(
new
ToDoItem
todoRepository
.
Add
(
new
ToDoItem
{
{
...
...
src/CleanArchitecture.Infrastructure/Data/AppDbContext.cs
View file @
87879f1f
...
@@ -11,9 +11,9 @@ namespace CleanArchitecture.Infrastructure.Data
...
@@ -11,9 +11,9 @@ namespace CleanArchitecture.Infrastructure.Data
{
{
private
readonly
IDomainEventDispatcher
_dispatcher
;
private
readonly
IDomainEventDispatcher
_dispatcher
;
public
AppDbContext
(
DbContextOptions
options
)
:
base
(
options
)
//
public AppDbContext(DbContextOptions options) : base(options)
{
//
{
}
//
}
public
AppDbContext
(
DbContextOptions
<
AppDbContext
>
options
,
IDomainEventDispatcher
dispatcher
)
public
AppDbContext
(
DbContextOptions
<
AppDbContext
>
options
,
IDomainEventDispatcher
dispatcher
)
:
base
(
options
)
:
base
(
options
)
...
...
src/CleanArchitecture.Infrastructure/Data/Migrations/20181203222230_InitialModel.Designer.cs
deleted
100644 → 0
View file @
f7b373d1
// <auto-generated />
using
CleanArchitecture.Infrastructure.Data
;
using
Microsoft.EntityFrameworkCore
;
using
Microsoft.EntityFrameworkCore.Infrastructure
;
using
Microsoft.EntityFrameworkCore.Migrations
;
using
Microsoft.EntityFrameworkCore.Storage.ValueConversion
;
namespace
CleanArchitecture.Infrastructure.Data.Migrations
{
[
DbContext
(
typeof
(
AppDbContext
))]
[
Migration
(
"20181203222230_InitialModel"
)]
partial
class
InitialModel
{
protected
override
void
BuildTargetModel
(
ModelBuilder
modelBuilder
)
{
#pragma warning disable 612, 618
modelBuilder
.
HasAnnotation
(
"ProductVersion"
,
"2.1.4-rtm-31024"
);
modelBuilder
.
Entity
(
"CleanArchitecture.Core.Entities.ToDoItem"
,
b
=>
{
b
.
Property
<
int
>(
"Id"
)
.
ValueGeneratedOnAdd
();
b
.
Property
<
string
>(
"Description"
);
b
.
Property
<
bool
>(
"IsDone"
);
b
.
Property
<
string
>(
"Title"
);
b
.
HasKey
(
"Id"
);
b
.
ToTable
(
"ToDoItems"
);
});
#pragma warning restore 612, 618
}
}
}
src/CleanArchitecture.Infrastructure/Data/Migrations/20181203222230_InitialModel.cs
deleted
100644 → 0
View file @
f7b373d1
using
Microsoft.EntityFrameworkCore.Migrations
;
namespace
CleanArchitecture.Infrastructure.Data.Migrations
{
public
partial
class
InitialModel
:
Migration
{
protected
override
void
Up
(
MigrationBuilder
migrationBuilder
)
{
migrationBuilder
.
CreateTable
(
name
:
"ToDoItems"
,
columns
:
table
=>
new
{
Id
=
table
.
Column
<
int
>(
nullable
:
false
)
.
Annotation
(
"Sqlite:Autoincrement"
,
true
),
Title
=
table
.
Column
<
string
>(
nullable
:
true
),
Description
=
table
.
Column
<
string
>(
nullable
:
true
),
IsDone
=
table
.
Column
<
bool
>(
nullable
:
false
)
},
constraints
:
table
=>
{
table
.
PrimaryKey
(
"PK_ToDoItems"
,
x
=>
x
.
Id
);
});
}
protected
override
void
Down
(
MigrationBuilder
migrationBuilder
)
{
migrationBuilder
.
DropTable
(
name
:
"ToDoItems"
);
}
}
}
src/CleanArchitecture.Infrastructure/Data/Migrations/AppDbContextModelSnapshot.cs
deleted
100644 → 0
View file @
f7b373d1
// <auto-generated />
using
CleanArchitecture.Infrastructure.Data
;
using
Microsoft.EntityFrameworkCore
;
using
Microsoft.EntityFrameworkCore.Infrastructure
;
using
Microsoft.EntityFrameworkCore.Storage.ValueConversion
;
namespace
CleanArchitecture.Infrastructure.Data.Migrations
{
[
DbContext
(
typeof
(
AppDbContext
))]
partial
class
AppDbContextModelSnapshot
:
ModelSnapshot
{
protected
override
void
BuildModel
(
ModelBuilder
modelBuilder
)
{
#pragma warning disable 612, 618
modelBuilder
.
HasAnnotation
(
"ProductVersion"
,
"2.1.4-rtm-31024"
);
modelBuilder
.
Entity
(
"CleanArchitecture.Core.Entities.ToDoItem"
,
b
=>
{
b
.
Property
<
int
>(
"Id"
)
.
ValueGeneratedOnAdd
();
b
.
Property
<
string
>(
"Description"
);
b
.
Property
<
bool
>(
"IsDone"
);
b
.
Property
<
string
>(
"Title"
);
b
.
HasKey
(
"Id"
);
b
.
ToTable
(
"ToDoItems"
);
});
#pragma warning restore 612, 618
}
}
}
src/CleanArchitecture.Web/SeedData.cs
View file @
87879f1f
...
@@ -9,10 +9,26 @@ namespace CleanArchitecture.Web
...
@@ -9,10 +9,26 @@ namespace CleanArchitecture.Web
{
{
public
static
class
SeedData
public
static
class
SeedData
{
{
public
static
readonly
ToDoItem
ToDoItem1
=
new
ToDoItem
{
Title
=
"Get Sample Working"
,
Description
=
"Try to get the sample to build."
};
public
static
readonly
ToDoItem
ToDoItem2
=
new
ToDoItem
{
Title
=
"Review Solution"
,
Description
=
"Review the different projects in the solution and how they relate to one another."
};
public
static
readonly
ToDoItem
ToDoItem3
=
new
ToDoItem
{
Title
=
"Run and Review Tests"
,
Description
=
"Make sure all the tests run and review what they are doing."
};
public
static
void
Initialize
(
IServiceProvider
serviceProvider
)
public
static
void
Initialize
(
IServiceProvider
serviceProvider
)
{
{
using
(
var
dbContext
=
new
AppDbContext
(
using
(
var
dbContext
=
new
AppDbContext
(
serviceProvider
.
GetRequiredService
<
DbContextOptions
<
AppDbContext
>>()))
serviceProvider
.
GetRequiredService
<
DbContextOptions
<
AppDbContext
>>()
,
null
))
{
{
// Look for any TODO items.
// Look for any TODO items.
if
(
dbContext
.
ToDoItems
.
Any
())
if
(
dbContext
.
ToDoItems
.
Any
())
...
@@ -20,40 +36,23 @@ namespace CleanArchitecture.Web
...
@@ -20,40 +36,23 @@ namespace CleanArchitecture.Web
return
;
// DB has been seeded
return
;
// DB has been seeded
}
}
dbContext
.
ToDoItems
.
Add
(
new
ToDoItem
()
PopulateTestData
(
dbContext
);
{
Title
=
"Test Item 1"
,
Description
=
"Test Description One"
});
dbContext
.
ToDoItems
.
Add
(
new
ToDoItem
()
{
Title
=
"Test Item 2"
,
Description
=
"Test Description Two"
});
dbContext
.
SaveChanges
();
}
}
}
}
public
static
void
PopulateTestData
(
AppDbContext
dbContext
)
public
static
void
PopulateTestData
(
AppDbContext
dbContext
)
{
{
var
toDos
=
dbContext
.
ToDoItems
;
foreach
(
var
item
in
dbContext
.
ToDoItems
)
foreach
(
var
item
in
toDos
)
{
{
dbContext
.
Remove
(
item
);
dbContext
.
Remove
(
item
);
}
}
dbContext
.
SaveChanges
();
dbContext
.
SaveChanges
();
dbContext
.
ToDoItems
.
Add
(
new
ToDoItem
()
dbContext
.
ToDoItems
.
Add
(
ToDoItem1
);
{
dbContext
.
ToDoItems
.
Add
(
ToDoItem2
);
Title
=
"Test Item 1"
,
dbContext
.
ToDoItems
.
Add
(
ToDoItem3
);
Description
=
"Test Description One"
});
dbContext
.
ToDoItems
.
Add
(
new
ToDoItem
()
{
Title
=
"Test Item 2"
,
Description
=
"Test Description Two"
});
dbContext
.
SaveChanges
();
dbContext
.
SaveChanges
();
}
}
}
}
}
}
tests/CleanArchitecture.Tests/Integration/Web/ApiToDoItemsControllerListShould.cs
View file @
87879f1f
...
@@ -27,9 +27,13 @@ namespace CleanArchitecture.Tests.Integration.Web
...
@@ -27,9 +27,13 @@ namespace CleanArchitecture.Tests.Integration.Web
var
stringResponse
=
await
response
.
Content
.
ReadAsStringAsync
();
var
stringResponse
=
await
response
.
Content
.
ReadAsStringAsync
();
var
result
=
JsonConvert
.
DeserializeObject
<
IEnumerable
<
ToDoItem
>>(
stringResponse
).
ToList
();
var
result
=
JsonConvert
.
DeserializeObject
<
IEnumerable
<
ToDoItem
>>(
stringResponse
).
ToList
();
Assert
.
Equal
(
2
,
result
.
Count
());
Assert
.
Equal
(
3
,
result
.
Count
());
Assert
.
Equal
(
1
,
result
.
Count
(
a
=>
a
.
Title
==
"Test Item 1"
));
Assert
.
Contains
(
result
,
i
=>
i
.
Title
==
SeedData
.
ToDoItem1
.
Title
);
Assert
.
Equal
(
1
,
result
.
Count
(
a
=>
a
.
Title
==
"Test Item 2"
));
Assert
.
Contains
(
result
,
i
=>
i
.
Title
==
SeedData
.
ToDoItem2
.
Title
);
Assert
.
Contains
(
result
,
i
=>
i
.
Title
==
SeedData
.
ToDoItem3
.
Title
);
//Assert.Equal(1, result.Count(a => a == SeedData.ToDoItem1));
//Assert.Equal(1, result.Count(a => a == SeedData.ToDoItem2));
//Assert.Equal(1, result.Count(a => a == SeedData.ToDoItem3));
}
}
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment