如何在构造函数中手动创建需要IOptionsMonitor的类的类实例?
我的课
private readonly AuthenticationSettings _authenticationSettings;
public ActiveDirectoryLogic(IOptionsMonitor<AuthenticationSettings> authenticationSettings)
{
_authenticationSettings = authenticationSettings.CurrentValue;
}
Run Code Online (Sandbox Code Playgroud)
我的测试
AuthenticationSettings au = new AuthenticationSettings(){ ... };
var someOptions = Options.Create(new AuthenticationSettings());
var optionMan = new OptionsMonitor(someOptions); // dont work.
ActiveDirectoryLogic _SUT = new ActiveDirectoryLogic(au);
Run Code Online (Sandbox Code Playgroud)
我试图手动制作一个IOptionsMonitor对象,但不知道如何做。
c# integration-testing options asp.net-core asp.net-core-2.2
有没有办法在CSS网格内制作“外部网格间隙”(不仅仅是内部)?我需要在CSS网格周围添加空间,即高度和宽度为100%,就像这样(其中绿色是空间/间隙):
这是我当前的网格问题的一个小提琴示例:https : //jsfiddle.net/isakglans/4tkg8yfc/
html,body {
width:100%;
height:100%;
margin:0;
}
#wrapper {
position : relative;
height: 100%;
width: 100%;
}
#content {
height: 100%;
width: 100%;
position : absolute;
display: grid;
background-color: green;
grid-gap : 1em;
grid-template-columns: 1fr 1fr;
}
#content div {
background-color: blue;
}
.box1 {
grid-column: 1;
grid-row: 1;
}
.box2 {
grid-column: 1;
grid-row: 2;
}
.box3 {
grid-column: 2;
grid-row: 1;
}
.box4 {
grid-column: 2;
grid-row: 2;
}
Run Code Online (Sandbox Code Playgroud)
编辑: 我不想让滚动条出现-我也不想做溢出:隐藏以隐藏它们。
我注意到当我使用查询生成器时,我在不同的文件中写了很多数据库表名。如果我要更改数据库表名,我将不得不在我的项目中搜索和更改相当多的行。这是您的 Laravel 人员注意到并提出解决方案的问题吗?
我喜欢使用类模型而不是数据库名称的 Eloquent 方法;但是对于某些查询,我认为 Query Builder 是一个更好的解决方案(尽管我不是这方面的专家)。
问题。我如何使用 Eloquent 来生成此查询:
从营销活动中选择营销活动.名称、用户名称 LEFT JOIN 用户在营销活动.gamemaster_id = users.id 上,其中营销活动.状态 = 1
活动
id gamemaster_id name status
1 1 campaign1 1
2 2 campaign2 1
Run Code Online (Sandbox Code Playgroud)
用户
id name
1 rick
2 bob
Run Code Online (Sandbox Code Playgroud)
结果
id gamemaster_id name status gamemaster_name
1 1 campaign1 1 rick
2 2 campaign2 1 bob
Run Code Online (Sandbox Code Playgroud)
活动模型
class Campaign extends Model
{
public function gamemaster()
{
return $this->belongsTo('App\User', 'gamemaster_id');
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试使雄辩,但失败了:
$result = Campaign::where('status', '=', 1)->with('gamemaster')->select('name')->orderBy('users.updated_at', 'desc')->get();
Run Code Online (Sandbox Code Playgroud) 有没有很好的教程来解释如何在 Laravel 中模拟一个类?
我有点困惑,因为 Laravel 文档(5.2)只讨论了模拟门面、工作和事件(最后两个我从来没有老实说,工作我不知道它是什么)。
这基本上是我要测试的场景(简化为示例):
?php
class A
{
protected $B;
public function __construct($classB)
{
$this->B = $classB;
}
}
class B implements myInterface
{
public function methodToTest();
}
Run Code Online (Sandbox Code Playgroud)
我想模拟发送给 A 类构造函数的 B 类。我应该为接口和模拟类制作新文件吗?或者也许利用嘲笑库(我在stackOverflow上看到一些这样做)?顺便去哪里看嘲讽课;我在 Laravel 文档中找不到它。
有点困惑,我提前道歉。
我制作了一个自定义中间件,现在我想访问解决方案中另一个项目中的应用程序设置。我是否应该将 IConfiguration 对象注入到中间件构造函数中,并添加 Microsoft.Extensions.Configuration 的 using 语句?或者有更好的方法来做到这一点吗?
我正在使用 Core 2.1 处理 ASP.net 网页。
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using System;
using System.Threading.Tasks;
public class MyMiddleware
{
public IConfiguration _configuration;
public MyMiddleware(RequestDelegate next, IConfiguration config)
{
_next = next;
_ configuration = config;
}
Run Code Online (Sandbox Code Playgroud) laravel ×3
appsettings ×1
asp.net-core ×1
c# ×1
css ×1
css-grid ×1
css3 ×1
eloquent ×1
join ×1
middleware ×1
mocking ×1
options ×1
unit-testing ×1