示例#1
0
            public void Test_EfDataProvider_FluentApi()
            {
                var ctx = new OtherContextFromDbContext();
                var x   = new EntityFramework.Providers.EntityFrameworkDataProvider(_ => _
                                                                                    .UseDbContext(ev => ctx)
                                                                                    .AuditTypeExplicitMapper(cfg => cfg
                                                                                                             .Map <Blog, AuditBlog>()
                                                                                                             .Map <Post, AuditPost>())
                                                                                    .IgnoreMatchedProperties(true));


                Assert.AreEqual(true, x.IgnoreMatchedProperties);
                Assert.AreEqual(ctx, x.DbContextBuilder.Invoke(null));
                Assert.AreEqual(typeof(AuditBlog), x.AuditTypeMapper.Invoke(typeof(Blog), null));
                Assert.AreEqual(typeof(AuditPost), x.AuditTypeMapper.Invoke(typeof(Post), null));
                Assert.AreEqual(null, x.AuditTypeMapper.Invoke(typeof(AuditBlog), null));
            }
示例#2
0
            public void Test_EfDataProvider_FluentApi3()
            {
                var ctx = new OtherContextFromDbContext();
                var x   = new EntityFramework.Providers.EntityFrameworkDataProvider(_ => _
                                                                                    .UseDbContext(ev => ctx)
                                                                                    .AuditTypeNameMapper(s => "Audit" + s)
                                                                                    .AuditEntityAction((ev, ent, obj) =>
                {
                    return(((dynamic)obj).Id == 1);
                })
                                                                                    .IgnoreMatchedProperties(true));


                Assert.AreEqual(true, x.IgnoreMatchedProperties);
                Assert.AreEqual(ctx, x.DbContextBuilder.Invoke(null));
                Assert.AreEqual(typeof(AuditBlog), x.AuditTypeMapper.Invoke(typeof(Blog), null));
                Assert.AreEqual(typeof(AuditPost), x.AuditTypeMapper.Invoke(typeof(Post), null));
                Assert.AreEqual(true, x.AuditEntityAction.Invoke(new AuditEvent(), new EntityFramework.EventEntry(), new { Id = 1 }));
            }
示例#3
0
            public void Test_EfDataProvider_FluentApi4()
            {
                var ctx = new OtherContextFromDbContext();
                var x   = new EntityFramework.Providers.EntityFrameworkDataProvider(_ => _
                                                                                    .UseDbContext(ev => ctx)
                                                                                    .AuditTypeExplicitMapper(cfg => cfg
                                                                                                             .Map <Blog>(entry => entry.Action == "Update" ? typeof(AuditPost) : typeof(AuditBlog))
                                                                                                             .Map <Post, AuditPost>())
                                                                                    .IgnoreMatchedProperties(true));

                Assert.AreEqual(true, x.IgnoreMatchedPropertiesFunc(null));
                Assert.AreEqual(ctx, x.DbContextBuilder.Invoke(null));
                Assert.AreEqual(typeof(AuditPost), x.AuditTypeMapper.Invoke(typeof(Blog), new EntityFramework.EventEntry()
                {
                    Action = "Update"
                }));
                Assert.AreEqual(typeof(AuditBlog), x.AuditTypeMapper.Invoke(typeof(Blog), new EntityFramework.EventEntry()
                {
                    Action = "Insert"
                }));
                Assert.AreEqual(typeof(AuditPost), x.AuditTypeMapper.Invoke(typeof(Post), null));
                Assert.AreEqual(null, x.AuditTypeMapper.Invoke(typeof(AuditBlog), null));
            }