forked from bilal-fazlani/tracker-enabled-dbcontext
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFluentConfigurationTestsForIdentity.cs
99 lines (81 loc) · 3.04 KB
/
FluentConfigurationTestsForIdentity.cs
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using System;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TrackerEnabledDbContext.Common.Configuration;
using TrackerEnabledDbContext.Common.Testing;
using TrackerEnabledDbContext.Common.Testing.Extensions;
using TrackerEnabledDbContext.Common.Testing.Models;
namespace TrackerEnabledDbContext.Identity.IntegrationTests
{
[TestClass]
public class FluentConfigurationTestsForIdentity : PersistanceTests<TestTrackerIdentityContext>
{
[TestMethod]
public void Can_recognise_global_tracking_indicator_when_disabled()
{
GlobalTrackingConfig.Enabled = false;
EntityTracker
.TrackAllProperties<POCO>();
POCO model = ObjectFactory.Create<POCO>(false, true, Db);
model.AssertNoLogs(Db, model.Id);
}
[TestMethod]
public void Can_recognise_global_tracking_indicator_when_enabled()
{
EntityTracker.TrackAllProperties<POCO>();
POCO model = new POCO
{
Color = "Red",
Height = 67.4,
StartTime = new DateTime(2015, 5, 5)
};
Db.POCOs.Add(model);
Db.SaveChanges();
model.AssertAuditForAddition(Db, model.Id, null,
x=>x.Color,
x=>x.Id,
x=>x.Height,
x=>x.StartTime);
}
[TestMethod]
public async Task Can_Override_annotation_based_configuration_for_entity_skipTracking()
{
var model = new NormalModel();
EntityTracker
.OverrideTracking<NormalModel>()
.Disable();
string userName = RandomText;
Db.NormalModels.Add(model);
await Db.SaveChangesAsync(userName);
model.AssertNoLogs(Db, model.Id);
}
[TestMethod]
public void Can_Override_annotation_based_configuration_for_property()
{
var model = new TrackedModelWithMultipleProperties
{
Category = RandomChar, //tracked ->skipped
Description = RandomText, //skipped
IsSpecial = true, //tracked -> skipped
StartDate = new DateTime(2015, 5, 5), //skipped
Name = RandomText, //tracked
Value = RandomNumber //skipped -> Tracked
};
EntityTracker
.OverrideTracking<TrackedModelWithMultipleProperties>()
//enable tracking for value
.Enable(x => x.Value)
//disable for isSpecial
.Disable(x => x.IsSpecial)
.Disable(x => x.Category);
Db.TrackedModelsWithMultipleProperties.Add(model);
string userName = RandomText;
Db.SaveChanges(userName);
model.AssertAuditForAddition(Db, model.Id, userName,
x => x.Id,
x => x.Name,
x => x.Value);
}
//TODO: can track CHAR properties ? NO
}
}