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

前端 未结 1 455
刺人心
刺人心 2021-01-15 14:32

Our team\'s application development involves using Effort Testing Tool to mock our Entity Framework\'s DbContext. However, it seems that Effort Testing Tool needs to be see

1条回答
  •  北恋
    北恋 (楼主)
    2021-01-15 14:51

    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));
    }
    

    0 讨论(0)
提交回复
热议问题