我正在尝试为我的项目创建集成测试.我需要测试一个通过存储库调用存储过程的控制器.应在每个特定测试范围的运行中创建一个空数据库.所以我将实现以下步骤:
在我的解决方案中,我有.sqlproj所有表和SP.如何使用与C#代码相同的结构创建LocalDB.sqlproj?或者如何生成包含所有对象的脚本以在LocalDB上运行它?
在.sqlproj存在MyProjectName_Create.sql的 bin文件夹中,但它没有运行cmd.ExecuteNonQuery();
任何帮助/建议将不胜感激.谢谢
我在WebAPI的日志中收到以下错误
System.Web.HttpException(0x800703E3):客户端已断开连接.System.Web.Hosting中的System.Web.Hosting.IIS7WorkerRequest.EndRead(IAsyncResult asyncResult)处于System.Threading.Tasks.TaskFactory的System.Web.HttpBufferlessInputStream.EndRead(IAsyncResult asyncResult)1.FromAsyncTrimPromise 1.Complete(TInstance thisRef,Func 3 endMethod,IAsyncResult asyncResult) ,Boolean requiresSynchronization)---抛出异常的前一个位置的堆栈跟踪结束---在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)的System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)处System.IO.StreamReader.d__97.MoveNext()---从抛出异常的先前位置开始的堆栈跟踪结束---在System.Runtime.CompilerServices.TaskAwaiter的System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)处System.IO.StreamReader.d__62.MoveNext()中的.HandleNonSuccessAndDebuggerNotification(任务任务)---从抛出异常的上一个位置的堆栈跟踪结束---在System.Runtime 位于Microsoft.Owin.OwinRequest.d__0.MoveNext()的System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)的.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)---从抛出异常的上一个位置开始的堆栈跟踪结束---在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)处于System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务),位于Microsoft.Owin.Security.OAuth.OAuthAuthorizationServerHandler.d__22.MoveNext()---从抛出异常的先前位置开始的堆栈跟踪结束---在Microsoft.Owin.Security.OAuth的System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)的System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)处.OAuthAuthorizationServerHandler.d__0.MoveNext()---抛出异常的前一个位置的堆栈跟踪结束---在System.Runtime.CompilerServices.TaskAwaiter.Throw Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware 1.d__0.MoveNext()中的System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)中的ForSuonSuccess(任务任务)---从抛出异常的上一个位置开始的堆栈跟踪结束---在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)处于System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务),位于D:\ UAT中的Web.API.Middleware.OwinMiddleware.d__1.MoveNext()\Web.API\Middleware\OwinMiddleware.cs:第49行
如何通过异常过滤器处理和忽略这些异常?为什么会出现此错误,如何重现?我想抓住并忽略The client disconnected但不是全部HttpException
我看到了类似的问题,但我怎么能在异常过滤器中这样做呢?
我正在使用PostgreSQL,并且我的ApplicationDbContext如下:
public class ApplicationDbContext : DbContext
{
private readonly DatabaseSettings _databaseOptions;
public ApplicationDbContext() { }
public ApplicationDbContext(IOptions<DatabaseSettings> databaseOptions)
{
_databaseOptions = databaseOptions.Value;
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.HasPostgresExtension("citext");
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (_databaseOptions == null)
{
optionsBuilder.UseInMemoryDatabase(Guid.NewGuid().ToString());
}
else
{
optionsBuilder.UseNpgsql(_databaseOptions.ConnectionString,
npgsqlOptionsAction: sqlOptions =>
{
sqlOptions.EnableRetryOnFailure(
maxRetryCount: _databaseOptions.MaxRetryCount,
maxRetryDelay: TimeSpan.FromSeconds(_databaseOptions.MaxRetryDelay),
errorCodesToAdd: null);
});
}
}
}
Run Code Online (Sandbox Code Playgroud)
这种情况是许多其他情况的基础。我正在改善性能并尝试使用上下文池。文档说要添加轮询,我应该:
services.AddDbContextPool<EmployeeContext>(options => options.UseNpgsql(connection));
Run Code Online (Sandbox Code Playgroud)
但我想在OnConfiguring方法中存储.UseNpgsql和DbContext的其他配置。如何实现呢?
我想用Roslyn创建一个带代码分析器的新项目.但是我在Visual Studio 2015 Update 3中找不到任何模板.
据我所知,它应该是带有Code Fix的模板分析器.
我是VS的新手,有人可以帮助我,谢谢.
我正在开发一个简单的应用程序,我有点困惑.我有一个简单struct Point的int x和int y.而我用它Line
public class Line : Shape {
public Line() {
PointA = new Point(x: 0, y: 0);
PointB = new Point(x: 0, y: 0);
}
public Point PointA { get; set; }
public Point PointB { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
在某个地方
var line = new Line();
line.PointB = new Point(x: 4, y: 2);
Console.WriteLine($"Line start at {line.PointA.GetX()}:{line.PointA.GetY()}; end at {line.PointB.GetX()}:{line.PointB.GetY()}");
for (int i = 0; i < 10; i++) { …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用方法创建界面
void Import(int id, IDictionary<int, IDictionary<int, string>> items);
Run Code Online (Sandbox Code Playgroud)
然后像这样调用这个方法
Dictionary<int, Dictionary<int, string>> items = viewModel.Items
.GroupBy(t => t.Number)
.ToDictionary(t => t.Key, t => t.ToDictionary(x => x.LanguageId, x => x.Translation));
Import(id, items);
Run Code Online (Sandbox Code Playgroud)
我预计它应该有效,但出现错误
cannot convert from 'System.Collections.Generic.Dictionary<int, System.Collections.Generic.Dictionary<int, string>>' to 'System.Collections.Generic.IDictionary<int, System.Collections.Generic.IDictionary<int, string>>'
Run Code Online (Sandbox Code Playgroud)
为什么我不能在这里使用接口 IDictionary ?我应该手动投射吗?
我正在使用Serilog。为了避免在每个微服务中进行配置,我创建了一个扩展名为的私有NuGet包,例如
namespace DFX.Logging
{
public static class Extensions
{
public static IWebHostBuilder UseLogging(this IWebHostBuilder webHostBuilder) =>
webHostBuilder.UseSerilog((context, loggerConfiguration) =>
{
var logLevel = context.Configuration.GetValue<string>("Serilog:MinimumLevel");
if (!Enum.TryParse<LogEventLevel>(logLevel, true, out var level))
{
level = LogEventLevel.Information;
}
loggerConfiguration.Enrich
.FromLogContext()
.MinimumLevel.Is(level);
loggerConfiguration
.ReadFrom.Configuration(context.Configuration)
.WriteTo.Console(
theme: AnsiConsoleTheme.Code,
outputTemplate: "[{Timestamp:yy-MM-dd HH:mm:ss} {Level:u3}] {Message:lj} <s:{SourceContext}>{NewLine}{Exception}");
});
}
}
Run Code Online (Sandbox Code Playgroud)
在控制器(或其他地方)中创建记录器
private readonly ILogger _logger = Log.ForContext<Application>();
Run Code Online (Sandbox Code Playgroud)
为此,我需要使用添加using Serilog;。我想避免使用它,而只使用我的命名空间using DFX.Logging;。我该如何发财呢?到目前为止我尝试过的是:
namespace DFX.Logging
{
// custom wrapper
public static class Log
{
public static ILogger …Run Code Online (Sandbox Code Playgroud) c# ×7
c#-7.0 ×1
casting ×1
dictionary ×1
ef-core-2.2 ×1
resharper ×1
serilog ×1
sql-server ×1
struct ×1