我正在尝试使用C#中的NUnit进行单元测试,这是一个自定义的授权属性.特别是在未被授权的情况下已经返回了特定的http状态代码和消息.
我的属性非常简单 - 看起来像这样:
public class AuthorizationAttribute : AuthorizeAttribute
{
public override void OnAuthorization(System.Web.Http.Controllers.HttpActionContext actionContext)
{
if (IsAuthorized(actionContext))
return;
HandleUnauthorizedRequest(actionContext);
}
protected override void HandleUnauthorizedRequest(System.Web.Http.Controllers.HttpActionContext actionContext)
{
actionContext.Response = actionContext.Request.CreateErrorResponse(HttpStatusCode.Forbidden, "You are not authorized to access this resource");
}
}
Run Code Online (Sandbox Code Playgroud)
所以为了测试这个(目前在测试领域是新的),我拼凑了下面的代码.在其中,我附加了一个通用标识与用户名和一些角色数据.
public void Given_UserIsNotInAuthorizedRoles_When_Auhtorizing_ReturnsForbidden()
{
// Arrange
IPrincipal principal = new GenericPrincipal(new GenericIdentity("TestName"), new[] { "TestRole" });
HttpActionContext mockActionContext = new HttpActionContext()
{
ControllerContext = new HttpControllerContext()
{
Request = new HttpRequestMessage(),
RequestContext = new HttpRequestContext() { Principal = principal …Run Code Online (Sandbox Code Playgroud) 我试图做的基本上是在这里回答无法打开引导模态窗口作为路线
然而,我的解决方案是行不通的.我收到一个错误
Error: [$injector:unpr] Unknown provider: $modalProvider <- $modal
My app has the ui.bootstrap module injected - here is my application config
var app = angular.module('app', ['ui.router', 'ui.bootstrap','ui.bootstrap.tpls', 'app.filters', 'app.services', 'app.directives', 'app.controllers'])
// Gets executed during the provider registrations and configuration phase. Only providers and constants can be
// injected here. This is to prevent accidental instantiation of services before they have been fully configured.
.config(['$stateProvider', '$locationProvider', function ($stateProvider, $locationProvider) {
// UI States, URL Routing & Mapping. For …Run Code Online (Sandbox Code Playgroud) 我一直在使用VS 2013,过去几个月广告已成功连接到我们的内部Team Foundation Server.
我的机器断电,然后在重新启动时我现在无法连接到服务器.
我收到以下错误
An error occurred. Detailed message: An error was raised by libgit2.
Category = Reference (Error). Corrupted loose
reference file: refs/remotes/origin/master
Run Code Online (Sandbox Code Playgroud)
我可以,在命令行中,在分支之间切换就好了 - 虽然不确定那是否会切换我的本地版本? - 对GIT来说很新鲜.
当我查看我的.git/repo文件夹中的'开发'和'主'文件时,主文件有一个空字符串(我可以突出显示一堆空格) - 开发一个很好并且有一个guid到位.这是问题吗?如果是的话,我该如何纠正呢?
如何纠正上述错误 - 甚至找出它实际意味着什么?
我对这个问题有一个相关问题NuGet包显示黄色感叹号.但是,没有一条评论对我有帮助.
我安装了.Net Core SDK(显示在控制台截图中)
当我创建一个新的.Net核心项目时; 如果它是一个网站,web api或控制台应用程序无关紧要 - 我得到相同的结果.
我采取的步骤如下:
我得到以下内容 - 每个引用都有黄色感叹号.
我正在运行最新版本的Visual Studio(此时)15.4.1
如果我使用命令行来创建项目,那么一切都很好.但是,如果我打开另一个开发人员创建的克隆项目,我会得到黄色感叹号.
知道我错误设置了什么吗?
我通常会使用 ClosedXML 来生成 Excel 文件。核心项目迫使我只使用 OpenXML。
将下载生成的 Excel 文件。
我遇到了一个问题,其中提供给 SpreadsheetDocument 的内存流为空。
我尝试了多种方法来生成流。下面的代码代表了一个精简版,只创建了最基本的东西。同样,内存流是0有长度的。
我知道我应该使用using()等。这只是精简代码以尝试让它工作。
生成excel的代码;这是来自File对象的构造函数。AsMemoryStream是一个属性声明为public MemoryStream AsMemoryStream { get; private set; }
public File(IList<T> items)
{
if (!items.Any())
throw new InvalidOperationException("items cannot be empty");
MemoryStream documentStream = new MemoryStream();
SpreadsheetDocument document = SpreadsheetDocument.Create(documentStream, DocumentFormat.OpenXml.SpreadsheetDocumentType.Workbook);
WorkbookPart workbookPart = document.AddWorkbookPart();
workbookPart.Workbook = new Workbook();
WorksheetPart worksheetPart = workbookPart.AddNewPart<WorksheetPart>();
worksheetPart.Worksheet = new Worksheet();
Sheets sheets = workbookPart.Workbook.AppendChild(new Sheets());
Sheet sheet = new Sheet { …Run Code Online (Sandbox Code Playgroud) 我已在 Azure 中设置了 SignalR 服务帐户。
我已将其设置为无服务器。
这记录在此处的规则设置下: https: //learn.microsoft.com/en-us/azure/azure-signalr/concept-upstream#rule-settings
我在 Node/TypeScript 中创建了一个 AZ Functions 应用程序,其中有一个包含 SignalRTrigger 输入和 SignalRMessages 输出的函数。考虑以下函数。
函数.js
{
"bindings": [
{
"type": "signalRTrigger",
"name": "invocation",
"hubName": "mailbox",
"category": "messages",
"event": "heartbeat",
"connectionStringSetting": "AzureSignalRConnectionString",
"parameterNames":[
"mailboxId"
],
"direction": "in"
},
{
"type": "signalR",
"name": "signalRMessages",
"hubName": "mailbox",
"connectionStringSetting": "AzureSignalRConnectionString",
"direction": "out"
}
],
"scriptFile": "../dist/heartbeat/index.js"
}
Run Code Online (Sandbox Code Playgroud)
还有index.js
import { AzureFunction, Context } from "@azure/functions"
const heartbeatTrigger: AzureFunction = async function (context: Context, invocation: any): …Run Code Online (Sandbox Code Playgroud) 我正在 C# 中创建一个服务,该服务将由将处理和存储文件的 ASP.Net Web API 使用。
作为 Web API 的一部分,我将文件存储在MemoryStreams 中,然后将其传递给服务进行实际处理和存储。
该服务的一部分是为每个文件生成一个新的文件名。
所以这引出了我的问题,现在是否有可能找出文件的文件类型/扩展名,因为它位于 MemoryStream 中?
我正在构建一个Windows服务,它将充当使用SignalR的现有站点的客户端.
在传递具体类时,我IHubProxy.On<>和IHubProxy.Invoke方法都有效.
例如,这有效:
hubProxy.On<MigrationRequest>("iSWindowsServiceRequest", request =>
MigrateData.Invoke(request));
Run Code Online (Sandbox Code Playgroud)
MigrationRequest看起来像这样:
public class MigrationRequest : IISWindowsServiceRequest
{
public MigrateWhat What { get; set; }
public MigrationFor For { get; set; }
public Guid EntityFor_Id { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
现在,如果我试试这个:
hubProxy.On<IISWindowsServiceRequest>("iSWindowsServiceRequest", request =>
Handshake.HandleRequest(request));
Run Code Online (Sandbox Code Playgroud)
我的要求永远不会被接受.
我希望实现的是创建单个pub-sub方法,而不是为该服务接受的每个具体类创建一个方法.
是否可以将接口传入On<>()方法?
同样适用于Invoke<>()- 如果我传递的对象包含任何接口的属性,则调用永远不会成功.
所以这不起作用:
public class ISWindowsServiceResponse
{
public IISWindowsServiceRequest OriginalRequest { get; set; }
public bool Success { get; set; }
public string Message { get; set; } …Run Code Online (Sandbox Code Playgroud) 经历了一个高级时刻,并努力让递归方法在 Javascript 中正确工作。
这里有类似的问答,但到目前为止我没有看到任何对我有帮助的东西。
话虽这么说,如果确实有重复,我将删除这个问题。
给定以下对象数组:
var collection = [
{
id: 1,
name: "Parent 1",
children: [
{ id: 11, name: "Child 1", children: [] },
{ id: 12, name: "Child 2", children: [] }
]
},
{
id: 2,
name: "Parent 2",
children: [
{
id: 20,
name: "Child 1",
children: [
{ id: 21, name: "Grand Child 1", children: [] },
{ id: 22, name: "Grand Child 2", children: [] }
]
}
]
},
{
id: …Run Code Online (Sandbox Code Playgroud) 我正在尝试构建自托管SignalR的Windows服务。
我已经阅读了诸如 了ASP.Net上的SignalR Self-Host等
我注意到,至少在看来,它们基于广播消息,似乎在收听周围找不到任何东西。
我需要收听服务内的消息以及广播。
我们已经有了背板设置-该站点使用了相同的设置。
在网站上,我可以通过Javascript加入一个小组。如何加入自托管SignalR服务中的群组。
在一个网站上,我在集线器上注册了一个回调。如何在自助服务中注册相同的回调?
我为注册和启动SignalR而准备的一些示例代码是:
GlobalHost.DependencyResolver.UseSqlServer(Settings.Default.ISDBContext);
app.Map("/signalr", map =>
{
map.UseCors(CorsOptions.AllowAll);
HubConfiguration hubConfig = new HubConfiguration()
{
EnableDetailedErrors = true,
EnableJSONP = true,
};
map.RunSignalR(hubConfig);
});
Run Code Online (Sandbox Code Playgroud)
然后,我像这样启动我的webApp:
SignalR = WebApp.Start<Startup>(options);
选项是我正在注册的网址。Startup是包含上面的signalR映射的启动类。
我之前没有建立过自托管服务,因此在这里几乎没有什么损失
c# ×5
signalr ×3
asp.net-core ×2
javascript ×2
angularjs ×1
arrays ×1
excel ×1
git ×1
memorystream ×1
node.js ×1
nunit ×1
openxml ×1
openxml-sdk ×1
recursion ×1
self-hosting ×1
tfs ×1
unit-testing ×1