1
+ using System . Collections . Generic ;
2
+ using System . Threading . Tasks ;
3
+ using Microsoft . VisualStudio . TestTools . UnitTesting ;
4
+ using TrackerEnabledDbContext . Common . Configuration ;
5
+ using TrackerEnabledDbContext . Common . Testing ;
6
+ using TrackerEnabledDbContext . Common . Testing . Extensions ;
7
+ using TrackerEnabledDbContext . Common . Testing . Models ;
8
+
9
+ namespace TrackerEnabledDbContext . Identity . IntegrationTests
10
+ {
11
+ [ TestClass ]
12
+ public class MetadataTests : PersistanceTests < TestTrackerIdentityContext >
13
+ {
14
+ [ TestMethod ]
15
+ public void ShouldAddSingleMetadata_WhenSingleMetadataIsProvided ( )
16
+ {
17
+ Db . ConfigureMetadata ( m =>
18
+ {
19
+ m . IpAddress = "192.168.2.23" ;
20
+ } ) ;
21
+
22
+ EntityTracker . TrackAllProperties < POCO > ( ) ;
23
+ POCO entity = ObjectFactory . Create < POCO > ( ) ;
24
+
25
+ Db . POCOs . Add ( entity ) ;
26
+ Db . SaveChanges ( "bilal" ) ;
27
+
28
+ entity . AssertAuditForAddition ( Db , entity . Id , "bilal" ,
29
+ x => x . Color , x => x . Height , x => x . StartTime , x => x . Id ) ;
30
+
31
+ entity . AssertMetadata ( Db , entity . Id , new Dictionary < string , string >
32
+ {
33
+ [ "IpAddress" ] = "192.168.2.23"
34
+ } ) ;
35
+ }
36
+
37
+ [ TestMethod ]
38
+ public async Task ShouldAddSingleMetadata_WhenSingleMetadataIsProvided_Async ( )
39
+ {
40
+ Db . ConfigureMetadata ( m =>
41
+ {
42
+ m . IpAddress = "192.168.2.23" ;
43
+ } ) ;
44
+
45
+ EntityTracker . TrackAllProperties < POCO > ( ) ;
46
+ POCO entity = ObjectFactory . Create < POCO > ( ) ;
47
+
48
+ Db . POCOs . Add ( entity ) ;
49
+ await Db . SaveChangesAsync ( "bilal" ) ;
50
+
51
+ entity . AssertAuditForAddition ( Db , entity . Id , "bilal" ,
52
+ x => x . Color , x => x . Height , x => x . StartTime , x => x . Id ) ;
53
+
54
+ entity . AssertMetadata ( Db , entity . Id , new Dictionary < string , string >
55
+ {
56
+ [ "IpAddress" ] = "192.168.2.23"
57
+ } ) ;
58
+ }
59
+
60
+ [ TestMethod ]
61
+ public void ShouldNotAddMetadata_WhenValueIsNull ( )
62
+ {
63
+ Db . ConfigureMetadata ( m =>
64
+ {
65
+ m . IpAddress = "192.168.2.23" ;
66
+ m . Country = null ;
67
+ m . Device = string . Empty ;
68
+ } ) ;
69
+
70
+ EntityTracker . TrackAllProperties < POCO > ( ) ;
71
+ POCO entity = ObjectFactory . Create < POCO > ( ) ;
72
+
73
+ Db . POCOs . Add ( entity ) ;
74
+ Db . SaveChanges ( ) ;
75
+
76
+ entity . AssertAuditForAddition ( Db , entity . Id , null ,
77
+ x => x . Color , x => x . Height , x => x . StartTime , x => x . Id ) ;
78
+
79
+ entity . AssertMetadata ( Db , entity . Id , new Dictionary < string , string >
80
+ {
81
+ [ "IpAddress" ] = "192.168.2.23" ,
82
+ [ "Device" ] = string . Empty
83
+ } ) ;
84
+ }
85
+ }
86
+ }
0 commit comments