我正在使用xUnit 2.0 集合夹具来共享许多不同测试类之间的公共数据库设置/拆卸.fixture还提供了一些辅助属性,因此我将它注入每个测试类.
我在文档中重新创建了示例,但是当我运行测试时,它立即失败:
以下构造函数参数没有匹配的fixture数据:IntegrationTestFixture fixture
无论我是使用xUnit Facts还是使用Theories,或者我正在使用哪个测试运行器,这似乎都会发生.
夹具:
public class IntegrationTestFixture : IDisposable
{
public IntegrationTestFixture()
{
// (setup code)
this.GeneratedTestName = [randomly generated];
}
public void Dispose()
{
// (teardown code)
}
public string GeneratedTestName { get; private set; }
}
Run Code Online (Sandbox Code Playgroud)
集合定义:
[CollectionDefinition("Live tests")]
public class IntegrationTestCollection : ICollectionFixture<IntegrationTestFixture>
{
// Intentionally left blank.
// This class only serves as an anchor for CollectionDefinition.
}
Run Code Online (Sandbox Code Playgroud)
测试:
[CollectionDefinition("Live tests")]
public class SomeTests
{
private readonly IntegrationTestFixture fixture;
public …
Run Code Online (Sandbox Code Playgroud) 我想调试基于.NET Core 2.2的空WebApi项目。
我安装Core 2.2 SDK x86
了目标框架并将其更改为2.2:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>
Run Code Online (Sandbox Code Playgroud)
当我开始调试该项目时,IIS
开始运行,但是在路由中api/values
我什么也没看到(它永远加载),并且出现此错误:
在没有引发CoreCLR启动事件的情况下退出了目标进程。确保将目标进程配置为使用.NET Core。如果目标进程未在.NET Core上运行,则可能会出现这种情况
在我的解决方案WPF
和Class Library
项目中。我想做到WebApi
这一点。就像我说的那样,它的空基项目由发起Visual Studio 2019
。我刚刚安装了Core 2.2
为什么会收到该错误以及我做错了什么?
c# asp.net-core asp.net-core-webapi visual-studio-2019 .net-core-2.2
SQL Server
如果不存在,我想制作用于创建数据库的脚本。
IF NOT EXISTS(SELECT * FROM sys.databases WHERE name = 'DataBase')
BEGIN
CREATE DATABASE DataBase
USE DataBase
CREATE TABLE TableName (
Id INT PRIMARY KEY IDENTITY (1, 1),
Name VARCHAR(100)
)
--more tables here
--some procedures here too
END
Run Code Online (Sandbox Code Playgroud)
从上面的代码我得到这个错误:
消息 911,级别 16,状态 1,第 5 行数据库“DataBase”不存在。确保正确输入名称。
当数据库不存在时,如何使用表和过程创建数据库?我想在一个查询中完成
我有个问题。我没有在堆栈上找到任何熟悉的问题,所以我在这里问,是否可以<mat-selection-list>
滚动(Angular 7)?当项目太多而无法容纳一个窗口时,我想在右侧显示滚动条。
<mat-card fxFlex="33%">
<mat-selection-list>
<mat-list-item
*ngFor="let product of products"
[class.selected]="product === selectedproduct"
(click)="onSelect(product)"
>
</mat-list-item>
</mat-selection-list>
Run Code Online (Sandbox Code Playgroud)
我正在处理 SignalR Clinet-Server 连接。我的服务器是WebApi Core 2.1
,我的客户端是WPF .NET Framework 4.7.2
.
在客户端,我有一个singleton
带有一个实例的集线器服务来接收来自服务器的消息:
using System.Collections.ObjectModel;
using Microsoft.AspNetCore.SignalR.Client;
public class HubService
{
//singleton
public static HubService Instance { get; } = new HubService();
public ObservableCollection<string> Notifications { get; set; }
public async void Initialize()
{
this.Notifications = new ObservableCollection<string>();
var hubConnection = new HubConnectionBuilder()
.WithUrl(UrlBuilder.BuildEndpoint("Notifications"))
.Build();
hubConnection.On<string>("ReciveServerUpdate", update =>
{
//todo
});
await hubConnection.StartAsync();
}
}
Run Code Online (Sandbox Code Playgroud)
我将其初始化为单例:
public MainWindowViewModel()
{
HubService.Instance.Initialize();
}
Run Code Online (Sandbox Code Playgroud)
当我在调试时,在MainWindowViewModel
我击中那个HubService
.
在 …
我想在我的集成测试中使用WebApplicationFactory
. 默认情况下, env 设置为Development
. 我的 Web 应用程序工厂的代码如下所示:
public class CustomWebApplicationFactory<TStartup> : WebApplicationFactory<TStartup>
where TStartup : class
{
protected override void ConfigureWebHost(IWebHostBuilder builder)
{
builder.UseSolutionRelativeContentRoot(AppContext.BaseDirectory);
base.ConfigureWebHost(builder);
}
protected override IWebHostBuilder CreateWebHostBuilder()
{
return WebHost.CreateDefaultBuilder()
.UseStartup<TStartup>()
.UseEnvironment("test"); // i want to launch `test` environment while im
// testing my app
}
}
Run Code Online (Sandbox Code Playgroud)
当我开始调试Startup
类时(当我运行测试时)我仍然得到Development
环境:
public Startup(IHostEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", false, true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", true)
// env.EnvironmentName is set to 'Development' …
Run Code Online (Sandbox Code Playgroud) 我有个问题。是否可以强制实体框架创建类的一个实例而不是(例如)IEnumerable
?
在我的数据库中,我只想拥有一个Farm
而不是Farms
. 我Farm
有我在 DBContext 中提到的所有其他列表:
public class FarmDbContext : DbContext
{
public FarmDbContext(DbContextOptions<FarmDbContext> options) : base(options) { }
public DbSet<Farm> Farms { get; set; } //i want to have one instance of farm
public DbSet<Machine> Machines { get; set; }
public DbSet<Stable> Stables { get; set; }
public DbSet<Worker> Workers { get; set; }
public DbSet<Cultivation> Cultivations { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
而我的 Farm 类,它是一个单例(具有私有构造函数的类,仅带有GetInstance()
方法):
public class Farm …
Run Code Online (Sandbox Code Playgroud) c# design-patterns entity-framework entity-framework-core asp.net-core
我有一个简单的 Api 函数:
// POST: api/Cultivation/Sow/1/5
[HttpGet("Sow/{grain}/{id}")]
public IActionResult Sow(Grain grain, int id) { }
Run Code Online (Sandbox Code Playgroud)
我的枚举看起来像这样:
public enum Grain
{
None,
Rice,
Corn,
Oats
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,是否可以Grain
从 Route 获取任何枚举?是的时候,怎么办?
如果否,如何以优雅的方式通过 int“查找”枚举,而无需 if 语句等?因为如果 myWebapi 不会采取enums
,那么通过简单的方法很容易做到int
我有个问题。
我正在Android 设备上制作按键动态应用程序。
现在,我使用度量字符串和EditText
. 我想抓住KeyDown
和KeyUp
在软件键盘上事件。
我的问题是,使用 Java 在 Android 上捕获KeyUp
和KeyDown
使用的最佳方法是什么?如果EditText
是一个不错的选择?如果它有方法来捕捉任何按键?
编辑
我想从上面的字符串中检测键并测量按下它的时间(例如开始测量KeyDown
和停止KeyUp
)。如果可能的话,我想阻止我的test string
(它的9RJhl6aH0n
,就像我的屏幕)中没有提到的其他键
编辑2
到目前为止我取得的成就是这样的,但是default
当我编码 line: 时,我的应用程序崩溃了measureText.setText("")
。它工作得很好,但仍然不会触发KeyDown
(或KeyPress
)。这些方法仅在KeyUp
用户输入字母时运行。顺序很重要!
measureText.addTextChangedListener(new TextWatcher(){
@Override
public void afterTextChanged(Editable arg0) {
switch(measureText.getText().toString()){
case "9":
break;
case "9R":
break;
case "9RJ":
break;
case "9RJh":
break;
case "9RJhl":
break;
case "9RJhl6":
break;
case "9RJhl6a":
break;
case …
Run Code Online (Sandbox Code Playgroud) 我有两个项目。
首先,WebApi
包含用于使用的集线器SignalR
:
public class NotificationsHub : Hub
{
public async Task GetUpdateForServer(string call)
{
await this.Clients.Caller.SendAsync("ReciveServerUpdate", call);
}
}
Run Code Online (Sandbox Code Playgroud)
我在Startup.cs
以下位置设置了该集线器:
public void ConfigureServices(IServiceCollection services)
{
// ofc there is other stuff here
services.AddHttpContextAccessor();
services.AddSignalR();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseSignalR(routes => routes.MapHub<NotificationsHub>("/Notifications"));
}
Run Code Online (Sandbox Code Playgroud)
我相信我会在以下时间发出这样的通知TaskController.cs
:
[HttpPost]
public async Task<IActionResult> PostTask([FromBody] TaskManager.Models.Task task)
{
if (!this.ModelState.IsValid)
{
return this.BadRequest(this.ModelState);
}
this.taskService.Add(task);
//here, after POST i want to notify whole clients
await …
Run Code Online (Sandbox Code Playgroud)