Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
status-site
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Dmytro Bogatov
status-site
Commits
4b10513a
There was a problem fetching the pipeline summary.
Commit
4b10513a
authored
Jul 30, 2017
by
Dmytro Bogatov
Browse files
Options
Downloads
Patches
Plain Diff
Fix the issue.
parent
f18febdd
Branches
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/shared/Services/DataSeedService.cs
+43
-14
43 additions, 14 deletions
src/shared/Services/DataSeedService.cs
test/UnitTests/Services/DataSeedServiceTest.cs
+25
-1
25 additions, 1 deletion
test/UnitTests/Services/DataSeedServiceTest.cs
with
68 additions
and
15 deletions
src/shared/Services/DataSeedService.cs
+
43
−
14
View file @
4b10513a
...
...
@@ -8,6 +8,7 @@ using Microsoft.EntityFrameworkCore;
using
System.Threading.Tasks
;
using
Microsoft.Extensions.Logging
;
using
Microsoft.Extensions.Configuration
;
using
System.Reflection
;
namespace
StatusMonitor.Shared.Services
{
...
...
@@ -185,15 +186,30 @@ namespace StatusMonitor.Shared.Services
/// </summary>
private
bool
SeedSpecificEntity
<
T
>(
List
<
T
>
values
,
DbSet
<
T
>
dbSets
)
where
T
:
class
{
if
(
values
.
Count
!=
dbSets
.
Count
())
var
inserted
=
false
;
foreach
(
var
item
in
values
)
{
dbSets
.
Clear
();
_context
.
SaveChanges
();
dbSets
.
AddRange
(
values
);
if
(
dbSets
.
Any
(
i
=>
i
==
item
))
{
var
element
=
dbSets
.
Single
(
i
=>
i
==
item
);
PropertyInfo
[]
properties
=
typeof
(
T
).
GetProperties
();
foreach
(
PropertyInfo
property
in
properties
)
{
property
.
SetValue
(
element
,
property
.
GetValue
(
item
));
}
}
else
{
dbSets
.
Add
(
item
);
inserted
=
true
;
}
_context
.
SaveChanges
();
return
true
;
}
return
false
;
return
inserted
;
}
/// <summary>
...
...
@@ -206,20 +222,33 @@ namespace StatusMonitor.Shared.Services
/// These are to be replaced by values.</param>
/// <returns>True if values has been replaced, false if values were in sync and did not require
/// replacement.</returns>
private
async
Task
<
bool
>
SeedSpecificEntityAsync
<
T
>(
List
<
T
>
values
,
DbSet
<
T
>
dbSets
,
bool
ignoreCount
=
false
)
where
T
:
class
private
async
Task
<
bool
>
SeedSpecificEntityAsync
<
T
>(
List
<
T
>
values
,
DbSet
<
T
>
dbSets
)
where
T
:
class
{
if
(
values
.
Count
!=
await
dbSets
.
CountAsync
()
||
ignoreCount
)
var
inserted
=
false
;
foreach
(
var
item
in
values
)
{
if
(
await
dbSets
.
AnyAsync
(
i
=>
i
==
item
))
{
if
(!
ignoreCount
)
var
element
=
await
dbSets
.
SingleAsync
(
i
=>
i
==
item
);
PropertyInfo
[]
properties
=
typeof
(
T
).
GetProperties
();
foreach
(
PropertyInfo
property
in
properties
)
{
dbSets
.
Clear
(
);
property
.
SetValue
(
element
,
property
.
GetValue
(
item
)
);
}
}
else
{
await
dbSets
.
AddAsync
(
item
);
inserted
=
true
;
}
await
_context
.
SaveChangesAsync
();
await
dbSets
.
AddRangeAsync
(
values
);
await
_context
.
SaveChangesAsync
();
return
true
;
}
return
false
;
return
inserted
;
}
}
}
This diff is collapsed.
Click to expand it.
test/UnitTests/Services/DataSeedServiceTest.cs
+
25
−
1
View file @
4b10513a
...
...
@@ -82,7 +82,7 @@ namespace StatusMonitor.Tests.UnitTests.Services
}
[
Fact
]
public
async
Task
Properly
Update
sData
()
public
async
Task
Properly
Add
sData
()
{
// Arrange
var
dataSeedService
=
new
DataSeedService
(
...
...
@@ -95,6 +95,7 @@ namespace StatusMonitor.Tests.UnitTests.Services
new
CompilationStage
{
Id
=
CompilationStages
.
M4
.
AsInt
(),
Name
=
"M4 stage"
},
new
CompilationStage
{
Id
=
CompilationStages
.
SandPiper
.
AsInt
(),
Name
=
"SandPiper"
}
});
await
_dataContext
.
SaveChangesAsync
();
// Act
await
dataSeedService
.
SeedDataAsync
();
...
...
@@ -106,6 +107,29 @@ namespace StatusMonitor.Tests.UnitTests.Services
);
}
[
Fact
]
public
async
Task
ProperlyUpdatesData
()
{
// Arrange
var
dataSeedService
=
new
DataSeedService
(
_dataContext
,
new
Mock
<
ILogger
<
DataSeedService
>>().
Object
,
_config
);
await
_dataContext
.
CompilationStages
.
AddRangeAsync
(
new
List
<
CompilationStage
>
{
new
CompilationStage
{
Id
=
CompilationStages
.
M4
.
AsInt
(),
Name
=
"M5 stage"
},
// here it is
new
CompilationStage
{
Id
=
CompilationStages
.
SandPiper
.
AsInt
(),
Name
=
"SandPiper"
}
});
await
_dataContext
.
SaveChangesAsync
();
// Act
await
dataSeedService
.
SeedDataAsync
();
// Assert
Assert
.
Equal
(
"test-title"
,
(
await
_dataContext
.
CompilationStages
.
SingleAsync
(
st
=>
st
.
Id
==
CompilationStages
.
M4
.
AsInt
())).
Name
);
}
[
Fact
]
public
async
Task
NoDuplicates
()
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment