-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathYCodeLabDbContextTest.cs
More file actions
39 lines (38 loc) · 1.4 KB
/
Copy pathYCodeLabDbContextTest.cs
File metadata and controls
39 lines (38 loc) · 1.4 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
using System;
using System.Linq;
using NUnit.Framework;
using YCodeLab.DB.Messaging;
using YCodeLab.DBFactory;
namespace YCodeLab.DB.Test
{
[TestFixture]
public class YCodeLabDbContextTest
{
[Test]
public void TestMessageCreatedTime()
{
var timeStamp = DateTime.UtcNow;
long? id = null;
{
var dbContextFactory = new YCodeLabDbContextFactory();
using var context = dbContextFactory.CreateDbContext();
var message = new Message
{
CreatedTime = DateTime.UtcNow + TimeSpan.FromHours(1),
};
context.Set<Message>().Add(message);
timeStamp = DateTime.UtcNow;
context.SaveChanges();
id = message.Id;
}
{
var dbContextFactory = new YCodeLabDbContextFactory();
using var context = dbContextFactory.CreateDbContext();
var message = context.Set<Message>()
.FirstOrDefault(e => e.Id == id);
Assert.That(message?.CreatedTime, Is.GreaterThan(timeStamp).And.LessThan(timeStamp + TimeSpan.FromSeconds(3)),
"The stored new message should have create_time the time right after the time stamp taken right before DbContext.SaveChanges method call.");
}
}
}
}