我使用IConfigurationRoute来访问这样的目录.
if (type == "error") directory = _config.GetValue<string>("Directories:SomeDirectory");
Run Code Online (Sandbox Code Playgroud)
_config是在构造函数中注入的IConfigurationRoot.
我尝试了以下方式来模拟它.
var mockConfigurationRoot = new Mock<IConfigurationRoot>();
mockConfigurationRoot.Setup(c => c.GetValue<string>("Directories: SomeDirectory"))
.Returns("SomeDirectory")
.Verifiable();
var config = mockConfigurationRoot.Object;
Run Code Online (Sandbox Code Playgroud)
问题是在运行测试时,Xunit会抛出异常说法
"System.NotSupportedException:Expression引用一个不属于模拟对象的方法"
我该如何解决这个问题?
我尝试了不同版本的StaticFiles.But它显示错误,因为IApplicationBuilder不包含UseStaticFiles().
"Microsoft.AspNetCore.StaticFiles": "1.1.1"
Run Code Online (Sandbox Code Playgroud)
我正在使用Microsoft提供的.net文档中提供的确切代码.这是我在Startup.cs中的内容.注意:app是IApplicationBuilder
app.UseStaticFiles(new StaticFileOptions()
{
FileProvider = new PhysicalFileProvider(
PathString.Combine(Directory.GetCurrentDiriectory(), @"Files")),
RequestPath = new PathString("/Files")
});
Run Code Online (Sandbox Code Playgroud)
要把它放在上下文中,我想读取"Files"文件夹中的目录和文件.这是我用来读取文件夹内容的代码行,但它总是返回null.注意:"initialFilePath"是文件夹"File"的相对路径.
var contents = _fileProvider.GetDirectoryContents(initalFilePath);
Run Code Online (Sandbox Code Playgroud)
谢谢
我想为用户提供一个按钮来更改整个网站的主题.我正在使用bootstrap".scss"文件.这是我做的:
我在"src/styles"文件夹中有"dark-styles.scss"和"light-styles.scss".这两个文件都覆盖了我需要覆盖的类和方法,并且还从"node-module"导入默认值的"bootstrap.scss".当我通过".angular-cli.json"向应用程序提供任何这些文件时,如下所示; 它完美地运作.
"styles": [
"../node_modules/font-awesome/css/font-awesome.css",
"../node_modules/@swimlane/ngx-datatable/release/index.css",
"../node_modules/@swimlane/ngx-datatable/release/assets/icons.css",
"../src/styles/dark-styles.scss"
],
Run Code Online (Sandbox Code Playgroud)
要么,
"styles": [
"../node_modules/font-awesome/css/font-awesome.css",
"../node_modules/@swimlane/ngx-datatable/release/index.css",
"../node_modules/@swimlane/ngx-datatable/release/assets/icons.css",
"../src/styles/light-styles.scss"
],
Run Code Online (Sandbox Code Playgroud)
如果我提供黑暗,主题是黑暗的,如果我提供光线,主题是光.
但我想要实现的是动态允许用户更改主题.因此,基于stackoverflow中的其他答案; 我在我的应用程序组件中访问了"文档",这也是我的根组件.它允许我访问整个html页面,其中我有一个链接标记,我可以从app-component设置.
HTML文件
<head>
<link id="theme" type="text/scss" rel="stylesheet" src="">
</head>
<body>
content .....
</body>
Run Code Online (Sandbox Code Playgroud)
角cli.json
"styles": [
"../node_modules/font-awesome/css/font-awesome.css",
"../node_modules/@swimlane/ngx-datatable/release/index.css",
"../node_modules/@swimlane/ngx-datatable/release/assets/icons.css"
],
Run Code Online (Sandbox Code Playgroud)
应用程序,组件:
import { Component, OnInit, Inject } from '@angular/core';
import { DOCUMENT } from '@angular/platform-browser';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
})
export class AppComponent implements OnInit {
currentTheme: string;
constructor( @Inject(DOCUMENT) private document) {
}
ngOnInit() {
this.currentTheme …Run Code Online (Sandbox Code Playgroud) 我无法使用Typescript切换bootstrap模式.我正在使用默认的bootstrap 4 Modal.这是代码.
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
这是一个Bootstrap 4提供的按钮来切换模态
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
Launch demo modal
</button>
Run Code Online (Sandbox Code Playgroud)
我没有在我的应用程序中使用此按钮.我想通过我的一个Angular 2组件中的函数来显示Modal.我使用以下代码访问了html元素.
ngOnInit() {
this.modalElement = document.getElementById('myModal');
}
Run Code Online (Sandbox Code Playgroud)
现在我需要激活模态以使用方法调用来显示它.我不打算找到解决办法.我尝试了像.show()和其他解决方案这样的方法,但都没有.
我正在 Jenkins 文件中定义环境变量。我正在使用 Pipeline Utility Steps Plugin 读取具有配置的目录中的 json 文件。当我回显读取的 json 文件时,输出是正确的,它正确读取并打印 json 文件。当我尝试访问与该 json 对象中的键关联的值时,出现错误:“没有这样的属性:class: java.lang.String 的internalCentralConsoleUrl ”
json 格式的配置文件看起来如下:
{
"activeVersion": "19.01.303",
"internalCentralConsoleUrl": "https://11.111.111:8083/api/v1",
"dataType": "APPLICATION_JSON"
}
Run Code Online (Sandbox Code Playgroud)
我正在管道中使用 readJSON 读取该文件。在下面的行中,尝试使用键访问 json 对象内的值。这给出了我上面提到的错误。
pipeline {
agent any
environment {
config = readJSON file: 'config.json'
baseUrl = "${config.internalCentralConsoleUrl}"
baseUrl2 = config['internalCentralConsoleUrl']
}
stages {}
}
Run Code Online (Sandbox Code Playgroud)
我上面尝试读取 json 值的两种方法都记录在此处链接的詹金斯页面中
我无法理解在这个简单的任务中是什么导致了问题。
Edit1:刚刚纠正了管道中的格式错误。
angular ×2
asp.net-core ×2
angular-cli ×1
c# ×1
jenkins ×1
json ×1
moq ×1
sass ×1
unit-testing ×1
webpack ×1
xunit.net ×1