lundi 28 septembre 2015

How to unit test what is setup in overridden OnModelCreating

It is probably a silly question, but I cannot figure it out. So, I have Entity Framework 6. I have MyDbContext : DbContext. In my context I have overridden OnModelCreating method:

protected override void OnModelCreating(DbModelBuilder modelBuilder)

Inside the method, I set up the database configuration. I would like to test what is set up. For instance, I have the following code:

modelBuilder.HasDefaultSchema("public");

I would like to have a unit test which checks that HasDefaultSchema with parameter value "public" is called.

Or like in the following example I would like to test that HasMany and WithMany methods of entity UserGroup are called:

 modelBuilder.Entity<UserGroup>()
             .HasMany<User>(g => g.Users)
             .WithMany(u => u.Groups)
             .Map(ug =>
                  {
                     ug.MapLeftKey("GroupId");
                     ug.MapRightKey("UserId");
                     ug.ToTable("UserGroupMembers");
                  });

Please advise. Thanks

Aucun commentaire:

Enregistrer un commentaire