小编use*_*278的帖子

模拟asp.net核心5.0的框架

我最近安装了Visual Studio 2015并启动了一个带有网站和asp类库的项目,该库将包含网站的单元测试.我通常使用Moq进行模拟,但尝试不同的模拟框架我并不陌生.我遇到的问题是我添加了Moq作为单元测试项目的参考并开始使用它.在我尝试编译之前,一切似乎都很好.

当我编译时,我收到一条错误消息:

ASP.NET Core 5.0 error CS0246: The type or namespace name 'Moq' could not be found (are you missing a using directive or an assembly reference?)

我注意到我可以在代码视图中切换ASP.NET 5.0和ASP.NET Core 5.0,当选择ASP.NET Core 5.0时,我会在选择ASP.NET 5.0时遇到错误但没有错误.我试着寻找答案,但我没有运气.

问题是Moq不能与vnext一起使用,我应该使用不同的框架(如果这样有效吗?)或者我能以某种方式解决这个问题吗?我的project.json:

{
"version": "1.0.0-*",
"dependencies": {
    "Web": "1.0.0-*",
    "Xunit.KRunner": "1.0.0-beta1",
    "xunit": "2.0.0-beta5-build2785",
    "Moq": "4.2.1409.1722"
},

"frameworks": {
    "aspnet50": {
        "dependencies": {
        }
    },
    "aspnetcore50": {
        "dependencies": {
        }
    }
},
"commands": {
    "test": "Xunit.KRunner"
}

}
Run Code Online (Sandbox Code Playgroud)

c# asp.net moq asp.net-core

26
推荐指数
2
解决办法
7659
查看次数

Asp vnext IServiceCollection存在于两个名称空间中

今天我创建了一个新的空vnext web项目并开始遵循本指南:http://www.asp.net/vnext/overview/aspnet-vnext/create-a-web-api-with-mvc-6

当我尝试添加:

using Microsoft.Framework.DependencyInjection;
Run Code Online (Sandbox Code Playgroud)

public void ConfigureServices(IServiceCollection services)
    {
        services.AddMvc();
    }
Run Code Online (Sandbox Code Playgroud)

我收到一个错误说:

The type 'IServiceCollection' exists in both 'Microsoft.Framework.DependencyInjection.IServiceCollection, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' and 'Microsoft.Framework.DependencyInjection.Interfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
Run Code Online (Sandbox Code Playgroud)

我一直在尝试aspnet.mvc的不同测试版,我从project.json中删除了aspnetcore50(因为它之前为我解决了问题).我还尝试指定要使用的命名空间,但它没有解决任何问题.现在我对如何解决这个问题缺乏想法.

我的project.json

{
"webroot": "wwwroot",
"version": "1.0.0-*",
"exclude": [
    "wwwroot"
],
"packExclude": [
    "node_modules",
    "bower_components",
    "**.kproj",
    "**.user",
    "**.vspscc"
],
"dependencies": {
    "Microsoft.AspNet.Server.IIS": "1.0.0-beta2",
    "Microsoft.AspNet.Mvc": "6.0.0-beta4-12857"
},
"frameworks" : {
    "aspnet50" : { }
}
}
Run Code Online (Sandbox Code Playgroud)

有没有人得到同样的错误并解决了它?

c# asp.net asp.net-mvc

16
推荐指数
1
解决办法
4881
查看次数

在应用程序洞察中设置用户名

我是应用程序洞察的新手,并且没有使用自定义事件进行设置,而且我使用了所有默认值.该应用程序基于MVC 5.在ApplicationInsights.config中有一条评论说:

"在应用程序中实现自定义用户跟踪时,请删除此遥测初始化程序,以确保准确地向Application Insights报告用户数量."

我们有一个页面,您需要登录,因此默认用户日志记录不是那么多,我们宁愿将用户名作为唯一标识符.基于评论,似乎这应该是某种常见的修改,因此易于修改.当试图谷歌"自定义用户跟踪"时,我发现任何有趣的东西似乎有点奇怪......

那么如何将Application Insights中的用户链接到我的用户名而不是一些似乎是默认行为的cookie呢?

asp.net-mvc azure-application-insights

9
推荐指数
1
解决办法
2034
查看次数

knockout viewmodel和requirejs

我最近开始使用requirejs,当我尝试创建一个简单的viewmodel时,我得到一个奇怪的异常.例外来自knockout-2.1.0.js文件,例外是"只有可订阅的东西才能充当依赖关系".

define("PageViewModel", ["knockout-2.1.0"], function(ko) {
    return function PageViewModel() {
        var self = this;
        self.visiblePage = ko.observable("StartPage");
        self.showPage = function (pageName) {
            self.visiblePage(pageName);
        };
    };
});
Run Code Online (Sandbox Code Playgroud)

正如您所看到的那样,viewmodel非常简单,因为错误发生在knockout js文件中,看起来requirejs正常运行.我一直在看:http ://knockoutjs.com/documentation/amd-loading.html来到这一行时发生异常:self.visiblePage = ko.observable("StartPage");

关于我做错了什么的任何想法?

谢谢,路德维希

更新:这是包含pageviewmodel的模块:

define("ViewModelFactory", ["StorageService", "PageViewModel", "AddUnitViewModel", "AddRoomViewModel"],
function (StorageService, PageViewModel, AddUnitViewModel, AddRoomViewModel) {
    //var repositoryStorage = new StorageService();
    var createAddRoomVM = function () {
        var vm = new AddRoomViewModel();
        vm.setRepository = StorageService.getRoomRepository();
        return vm;
    };
    var createAddUnitVM = function () {
        var vm = new AddUnitViewModel();
        vm.setRepository = …
Run Code Online (Sandbox Code Playgroud)

mvvm viewmodel requirejs knockout.js

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

我在实体框架中放置条件的顺序是否重要

我在实体框架中放置条件的顺序是否重要?我知道 EF 在运行 SQL 查询之前做了一些优化。那么我首先提出什么条件重要吗?

例如(只是我们应用程序中真实查询的一个子集)。CaseNumber 是一个字符串,而 OrganizationId 是一个 guid。

context.Evaluation.Where(e => e.Case.CaseNumber.Contains(inputModel.CaseNumber) && e.Case.OrganizationId == inputModel.OrganizationId)
Run Code Online (Sandbox Code Playgroud)

或者

context.Evaluation.Where(e => e.Case.OrganizationId == inputModel.OrganizationId) && e.Case.CaseNumber.Contains(inputModel.CaseNumber)
Run Code Online (Sandbox Code Playgroud)

c# entity-framework

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

Unity类型没有可访问的构造函数

我最近开始使用统一,它似乎工作得很好,除了一个地方......我做了一些搜索,但我没有找到任何我可以应用于我的代码.

继承注册类型的代码:

Container.RegisterType<IVsoCommunicator, VsoCommunicator>();
Container.RegisterType<IIpxConnection, IpxCommunicator>();
Container.RegisterType<IConsentService, ConsentService>(new InjectionFactory(p => new ConsentService(p.Resolve<IIpxConnection>(), p.Resolve<IVsoCommunicator>())));
Container.RegisterType<ITimer, ConsentStatusPoller>(new InjectionFactory(p => new ConsentStatusPoller(p.Resolve<IConsentService>())));
Run Code Online (Sandbox Code Playgroud)

例外情况:

Resolution of the dependency failed, type = "UserManager.Services.ConsentStatusPoller", name = "(none)".
Exception occurred while: while resolving.

Exception is: InvalidOperationException - The type IConsentService does not have an accessible constructor.

-----------------------------------------------

At the time of the exception, the container was:

Resolving UserManager.Services.ConsentStatusPoller,(none)

Resolving parameter "consentService" of constructor UserManager.Services.ConsentStatusPoller(UserManager.Services.IConsentService consentService)

Resolving UserManager.Services.IConsentService,(none)
Run Code Online (Sandbox Code Playgroud)

我在这做错了什么?首先,我认为我有私事,但事实并非如此

将注册更改为:

Container.RegisterType<ISettingsConfiguration, SettingsConfiguration>();
Container.RegisterType<IUnitOfWork, UnitOfWork>();
Container.RegisterType<IVsoCommunicator, VsoCommunicator>();
Container.RegisterType<IIpxConnection, IpxCommunicator>(); …
Run Code Online (Sandbox Code Playgroud)

c# unity-container

2
推荐指数
2
解决办法
2万
查看次数