最近我使用Visual Studio 2017(15.6.3)从头开始创建了一个ASP.NET MVC Core项目.我发现了通常的JavaScript框架:
但不幸的是,所有Bower的支持都消失了!没有bower.json,没有.bowerrc,没有"管理凉亭包......"了:
Visual Studio的ASP.NET MVC Core模板有什么问题?鲍尔变得过时了吗?
如果Bower已被弃用,请不要将此问题复制到如何在Visual Studio 2017中使用bower包!我不喜欢指向已弃用技术的修复程序.
我想缩小一个问题:用NPM取代Bower最简单(最直观)的方法是什么?鲍尔一样做了与它的.bowerrc:{ "directory": "wwwroot/lib" }?
asp.net-mvc visual-studio visual-studio-templates bower asp.net-core
我正在评估使用EF6结合的单元测试
http://www.codeproject.com/Articles/460175/Two-strategies-for-testing-Entity-Framework-Effort是一个非常好的参考,但现在我卡住了.
我有2个测试项目(一个用于Effort,另一个用于SQL CE).如果我单独运行两个都很好.使用ReSharper测试运行器连续运行最后一个测试项目总是失败.或
System.InvalidOperationException:在尝试添加"已加载"事件处理程序之前,实体框架已在使用DbConfiguration实例."加载"事件处理程序只能在使用实体框架之前作为应用程序启动的一部分添加.
要么
System.InvalidOperationException:在尝试设置"SqlCeConfiguration"实例之前,实体框架使用了默认的DbConfiguration实例.在使用任何Entity Framework功能之前,必须在应用程序启动时设置"SqlCeConfiguration"实例,或者必须在应用程序的配置文件.
它总是一样的.后继继承了前一个DbConfiguration实例.如何在没有副作用的情况下运行两个测试项目/配置?
这是我的DbContext类:
public class DataContext : DbContext
{
public DataContext(string connectionString) : base(connectionString)
{ Configuration.LazyLoadingEnabled = false; }
public DataContext(DbConnection connection) : base(connection, true)
{ Configuration.LazyLoadingEnabled = false; }
}
Run Code Online (Sandbox Code Playgroud)
那是Effort的测试夹具:
[TestFixtureSetUp]
public void TestFixtureSetup()
{
EffortProviderConfiguration.RegisterProvider();
var connection = DbConnectionFactory.CreateTransient();
var dbContext = new DataContext(connection);
...
}
Run Code Online (Sandbox Code Playgroud)
这是SQL CE的测试夹具:
[TestFixtureSetUp]
public void TestFixtureSetup()
{
const string filePath = @"LocalDb.sdf"; …Run Code Online (Sandbox Code Playgroud) 我实现了以下分层数据结构:Tree <T>→Branch <T>→T.
更新:很多人问:为什么不使用对象代替<T>(或<dynamic>或其他)?所以我修改了我的问题来陈述我的"约束".开始了...
这是一个例子Tree:
*
??Negative
? ??-2
??0
? ??0
??Positive
? ??2
? ??12
? ??2147483647
*
??Spring
? ??Mar
? ??Apr
? ??May
??Summer
? ??Jun
? ??Jul
? ??Aug
??Fall
? ??Sep
? ??Oct
? ??Nov
??Winter
? ??Dec
? ??Jan
? ??Feb
Run Code Online (Sandbox Code Playgroud)
在C#中实现:
public class Tree<T>
{
public readonly List<Branch<T>> Branches = new List<Branch<T>>();
}
public class Branch<T>
{
public readonly List<T> Leaves = new List<T>();
public string Name { …Run Code Online (Sandbox Code Playgroud) 我的应用程序在我的DbContext实现中没有无参数构造函数,我不喜欢为实现提供无参数构造函数IDbContextFactory<>.
原因是我想控制DbContext指向的位置.这就是我的所有构造函数都会要求ConnectionStringProvider的原因.
public class MyDbContext : DbContext
{
internal MyDbContext(IConnectionStringProvider provider) : base(provider.ConnectionString) {}
}
Run Code Online (Sandbox Code Playgroud)
和
public class MyContextFactory : IDbContextFactory<MyDbContext>
{
private readonly IConnectionStringProvider _provider;
public MyContextFactory(IConnectionStringProvider provider)
{
_provider = provider;
}
public MyDbContext Create()
{
return new MyDbContext(_provider.ConnectionString);
}
}
Run Code Online (Sandbox Code Playgroud)
我绝对不想添加默认构造函数!我已经这样做了,因为错误的App.config中的错误连接字符串或者假设默认连接字符串(如默认构造函数),它在生产时崩溃了DbContext.我想使用相同的基础设施
IConnectionStringProvider)Add-Migration脚本DbMigrator.GetPendingMigrations()目前我收到了一些消息:
上下文工厂类型'Test.MyContextFactory'没有公共无参数构造函数.添加公共无参数构造函数,在上下文程序集中创建IDbContextFactory实现,或使用DbConfiguration注册上下文工厂.
--- UPDATE ---
这可能与如何将连接字符串注入IDbContextFactory <T>的实例重复?但它没有解决方案.我解释原因:
Add-Migration连接字符串,所以我如何提供DbContext或IDbContextFactory<>消耗它?而不是无参数构造函数?
添加迁移MyMigration -ConnectionStringName"MyConnectionString"
DbMigrator.GetPendingMigrations()也存在同样的问题:我使用的也是无参数DbContext …看看这段疯狂的代码:
ICollection<int> list = new[] {1, 2, 3};
list.Add(4); // NotSupportedException: Collection was of a fixed size.
Run Code Online (Sandbox Code Playgroud)
我不怀疑这个例外!我想知道可以将一个简单的数组分配给ICollection<T>. 我看到了Array工具IList,ICollection但据我所知它从未实现ICollection<T>!
我的控制器有很多动作。某些用户只能访问所有内容,但以下一项操作除外:
[Authorize(Roles = "Admin")]
public class SecretsController : Controller
{
[Authorize]
public ActionResult Index()
{
return View(...);
}
...
}
Run Code Online (Sandbox Code Playgroud)
甚至[Authorize (Roles = null)]不起作用。方法属性将被忽略!我如何仅通过一项操作就能获得例外?喜欢AllowAnonymous允许它,但对登录用户可见吗?
我最近使用 Elasticsearch 2,想请求对所有文本字段进行查询。
GET myindex/mydata/_search
Run Code Online (Sandbox Code Playgroud)
GET myindex/mydata/_search
Run Code Online (Sandbox Code Playgroud)
查询返回预期结果,但没有任何突出显示。fields我经历过,当我手动缩小搜索范围时,我会突出显示:
{
"query": {
"simple_query_string": {
"query": "Raketenfahrrad"
}
},
"highlight": {
"fields": [ { "*": {} } ]
}
}
Run Code Online (Sandbox Code Playgroud)
但这不符合我的要求“搜索全部”,并且在将下一个新属性添加到mydata类型中时将会失败。
c# ×5
asp.net-mvc ×2
arrays ×1
asp.net-core ×1
bower ×1
generics ×1
icollection ×1
unit-testing ×1