In the Entity Framework, you can configure the relationship between your objects using data annotations inside the actual class object:
public class Entity { [Key, Column(Order = 0)] public Guid PartOfPrimaryKey { get; set; } [Key, Column(Order = 1)] public Guid AlsoPartOfPrimaryKey { get; set; } }
or using the free API configuration
modelBuilder.Entity<Entity>() .HasKey(k => new { k.PartOfPrimaryKey, k.AlsoPartOfPrimaryKey });
Make it clear that you took a simple approach to setting up the API, how do you make sure that the configuration is done by mocking (using Moq) DbContext for unit testing?
When I cheat on DbContext , the OnModelCreating method OnModelCreating .
It explains how to test your application using a mocking framework, but it doesnβt explain how they care about the problem of "setting up" objects. Other posts I found also do not address this issue. I guess something simple is missing me.
Sidenote: I also know that this may not be a good idea for the unit test of your DbContext, because you will use LINQ for objects in your tests and LINQ for production . However, I still think there is an answer to my question.
Update: if I use data annotations instead, it works fine.
source share