How would I configure Effort Testing Tool to mock Entity Framework's DbContext withOut the actual SQL Server Database up and running?

我怕爱的太早我们不能终老 提交于 2019-12-01 11:24:46

You only need that connection string because Effort needs to know where the EDMX file is.

The EDMX file contains all information required for creating an inmemory store with an identical schema you have in your database. You have to specify a connection string only because I thought it would be convenient if the user didn't have to mess with EDMX paths.

If you check the implementation of the CreateTransient method you will see that it merely uses the connection string to get the metadata part of it.

public static EntityConnection CreateTransient(string entityConnectionString, IDataLoader dataLoader)
{
    var metadata = GetEffortCompatibleMetadataWorkspace(ref entityConnectionString);
    var connection = DbConnectionFactory.CreateTransient(dataLoader);
    return CreateEntityConnection(metadata, connection);
}

private static MetadataWorkspace GetEffortCompatibleMetadataWorkspace(ref string entityConnectionString)
{
    entityConnectionString = GetFullEntityConnectionString(entityConnectionString);

    var connectionStringBuilder = new EntityConnectionStringBuilder(entityConnectionString);

    return MetadataWorkspaceStore.GetMetadataWorkspace(
        connectionStringBuilder.Metadata,
        metadata => MetadataWorkspaceHelper.Rewrite(
            metadata, 
            EffortProviderConfiguration.ProviderInvariantName, 
            EffortProviderManifestTokens.Version1));
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!