小编Joh*_*son的帖子

Moq 实体框架 ExecuteSQLCommand

我读过使用 moq 时不能模拟非虚拟函数。我也读到这现在应该是可能的..这是真的吗?如果是这样,那么我想模拟以下查询:

DatabaseContext.Database.ExecuteSqlCommand(updateQuery, newValue);
Run Code Online (Sandbox Code Playgroud)

我在我的测试中覆盖了上下文

DAL.Context.DatabaseContext = mockContext.Object;
Run Code Online (Sandbox Code Playgroud)

我试过这个设置,但似乎查询仍然重复我的常规数据库

mockContext.Setup(c => c.Set<AppSalesAndResult>()).Returns(mockBudgetData.Object);
Run Code Online (Sandbox Code Playgroud)

任何想法,也许可以用其他东西替换executesqlcommand,以便上面的行可以捕获该集合的任何更新?由于性能原因,我在一次更新多行时使用 executesqlcommand。普通EF太慢

更新:

阅读下面的文章,How to Moq Entity Framework SqlQuery call我想知道类似的实现是否适用于 ExecuteSQLCommand...

c# entity-framework moq

8
推荐指数
1
解决办法
3375
查看次数

带有 WCF 的 Autofac - 嵌套生命周期问题

我有许多由 angularjs 使用的 WCF 服务设置。目前我遇到了一个我正在努力解决的问题。调用 WCF 服务时,我不断收到以下错误消息。任何有关如何解决问题的指示将不胜感激。可以在底部找到更详细的错误消息

无法解析实例,也无法从此 LifetimeScope 创建嵌套生命周期,因为它已被释放。

编辑:当我在 global.asax Application_BeginReques() 中构建容器时,它似乎也有效,因此不仅是 Application_Start。不知道为什么,但至少这比以前好......但是我以前时不时会发生这个错误,所以我不相信这种丑陋的解决方法

这是我的 global.asax

        ..
        ..

    protected void Application_Start(object sender, EventArgs e)
    {
        var containerBuilder = new IoC();

        // Register your service implementations.
        containerBuilder.Builder.RegisterType<Konstrukt.SL.Services.GetBudgetData>().Named<object>("GetBudgetDataService");
        containerBuilder.Builder.RegisterType<Konstrukt.SL.Services.GetReferenceData>().Named<object>("GetReferenceDataService");
        containerBuilder.Builder.RegisterType<Konstrukt.SL.Services.UpdateBudgetData>().Named<object>("UpdateBudgetDataService");
        ..
        ..
        containerBuilder.Builder.RegisterType<Konstrukt.SL.Services.DimValue>().Named<object>("DimValueService");
        containerBuilder.Builder.RegisterType<Konstrukt.SL.Services.DisplayNameMapping>().Named<object>("DisplayNameMappingService");
        ..
        ..

        // use only one context object per scope/request
        containerBuilder.Builder.RegisterType<Konstrukt.DAL.KonstruktEntities>().InstancePerLifetimeScope();

        AutofacHostFactory.Container = containerBuilder.Builder.Build();
    }
Run Code Online (Sandbox Code Playgroud)

这是我的 IoC 类,它注册了所有接口

public class IoC
{
    private ContainerBuilder _builder;
    public ContainerBuilder Builder 
    {
        get 
        {
            if (_builder == null)
            {
                _builder …
Run Code Online (Sandbox Code Playgroud)

c# wcf autofac

5
推荐指数
1
解决办法
9769
查看次数

标签 统计

c# ×2

autofac ×1

entity-framework ×1

moq ×1

wcf ×1