forked from tobyash86/WebGoat.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContextSetup.cs
More file actions
48 lines (39 loc) · 1.69 KB
/
ContextSetup.cs
File metadata and controls
48 lines (39 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using Microsoft.EntityFrameworkCore.ChangeTracking.Internal;
using Microsoft.EntityFrameworkCore.Metadata;
using Moq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WebGoatCore.Data;
using WebGoatCore.Models;
namespace WebGoat.NET.Tests.BlogRepositoryTests
{
internal static class ContextSetup
{
internal static Mock<NorthwindContext> CreateContext()
{
// create test DB
var initialBlogEntries = new List<BlogEntry> {
new BlogEntry() { Author = "admin", Contents = "Test Content", Id = 1, PostedDate = DateTime.Now, Responses = new List<BlogResponse>(), Title = "Test Title" }
}.AsQueryable();
Func<BlogEntry, EntityEntry<BlogEntry>> mockEntityEntry = (BlogEntry data) =>
{
var internalEntityEntry = new InternalEntityEntry(
new Mock<IStateManager>().Object,
new RuntimeEntityType(nameof(BlogEntry), typeof(BlogEntry), false, null, null, null, ChangeTrackingStrategy.Snapshot, null, false, null),
data);
var entityEntry = new EntityEntry<BlogEntry>(internalEntityEntry);
return entityEntry;
};
var mockSet = DbSetTestUtil.CreateDbSetMock(initialBlogEntries);
mockSet.Setup(m => m.Add(It.IsAny<BlogEntry>())).Returns(mockEntityEntry);
var context = new Mock<NorthwindContext>();
context.SetupGet(c => c.BlogEntries).Returns(mockSet.Object);
return context;
}
}
}