我是单元测试C#Web API控制器 - 每个都需要几个参数来初始化.我目前在每个测试中都有这个代码,但它非常笨重.如何将此代码放入[TestInitialize]以便在每次测试之前运行?
我尝试了以下但显然它超出了testmethods的范围.
[TestInitialize]
public void TestInitialize()
{
APIContext apicon = new APIContext();
xRepository xRep = new xRepository(apicon);
var controller = new relevantController(cRep);
controller.Request = new HttpRequestMessage();
controller.Configuration = new HttpConfiguration();
relevantFactoryModel update = new relevantFactoryModel();
}
Run Code Online (Sandbox Code Playgroud)
谢谢
我想创建一个简单的按钮,将移动用户重定向到相应的应用商店链接,具体取决于他们正在运行的移动操作系统(ios,android或wp8) - 或者如果不在移动设备上,则提供发送包含相应链接的电子邮件...有任何想法吗?
我目前使用Azure移动应用程序为我的应用程序提供了后端解决方案.我启用了facebook,twitter,google和Microsoft登录.我正在尝试添加自定义登录流程.我已经设置了一个Auth0帐户和应用程序,当我使用auth0 lock widget在应用程序中发出请求时,我能够从auth0获取令牌和配置文件.
我遵循了这个指南:https://shellmonger.com/2016/04/08/30-days-of-zumo-v2-azure-mobile-apps-day-5-custom-authentication/并进入舞台'Custom服务器中的JWT验证'但这是我被卡住的地方......我的后端是在C#而不是node.js,那么我该如何做与本教程相同的操作并验证JWT令牌,然后从我的前端访问表控制器使用azureClient.login/azureClient.table的应用程序?
编辑:好的,所以你会在@AdrianHall的评论主题中看到我已经成功地从我的cordova应用程序中生成一个令牌,但我的绊脚石现在让服务接受它而无需交换令牌.根据发布的指南,这是可能的.
这是我的客户端代码,它当前对auth0进行auth调用,并设置一些客户端来获取userID并生成包含新令牌的'currentUser'对象.
auth0.lock.show(auth0.options, function(err, profile, token) {
if (err) {
console.error('Error authenticating with Auth0: ', err);
alert(err);
} else {
debugger;
var userID;
if (profile.user_id.indexOf("auth0") > -1) {
userID = profile.user_id.replace("auth0|", "");
} else if (profile.user_id.indexOf("facebook") > -1) {
userID = profile.user_id.replace("facebook|", "");
} else if (profile.user_id.indexOf("twitter") > -1) {
userID = profile.user_id.replace("twitter|", "");
} else if (profile.user_id.indexOf("microsoft") > -1) {
userID = profile.user_id.replace("microsoft|", "");
} else if (profile.user_id.indexOf("google-oauth2") > …Run Code Online (Sandbox Code Playgroud) 我对WP8开发相对较新,并且遇到了一个我无法弄清楚的问题,即使经过数小时的谷歌搜索.
我正在使用visual studio 2012并使用NuGet实现了System.Net.Http,检查了引用,copy local设置为true,但它不会构建.
这是一个问候我的错误信息:
CA0001 Error Running Code Analysis CA0001 : The following error was encountered while reading module '3D Protect Premium': Could not resolve member reference: [System.Net.Http, Version=1.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]System.Net.Http.HttpClient::PostAsync. [Errors and Warnings] (Global)
Run Code Online (Sandbox Code Playgroud)
我如何解决这个问题,所以引用的版本是正确的?
编辑
代码在下面添加.这似乎不成问题,它只是引用 - 我认为我的误解是诚实的,我只是不知道什么是System.Net.Http汇编!
//Creates a new HttpClient Instance
var client = new HttpClient();
// This is the postdata
// Data forms an array and is used to populate the remote MySQL DB
var postData = new List<KeyValuePair<string, string>>();
postData.Add(new KeyValuePair<string, string>("name", …Run Code Online (Sandbox Code Playgroud) 我有以下代码,它成功写入XML文件.但是,由于正在进行tagRegistry.Save()调用,它每次都会覆盖.如何在现有文件中添加新的XElement?目前文件只是被覆盖.
public void saveTag()
{
if (File.Exists("/tagRegistry.xml"))
{
XElement tagRegistry = XElement.Load("/tagRegistry.xml");
XElement newTag = new XElement("Tag",
new XElement("tag", stringUid),
new XElement("name", desiredName),
new XElement("latitude", latitude),
new XElement("longitude", longitude));
tagRegistry.Add(newTag);
using (var storage = IsolatedStorageFile.GetUserStoreForApplication())
{
using (Stream stream = storage.CreateFile("/tagRegistry.xml"))
{
tagRegistry.Save(stream);
}
}
}
else
{
XDocument tagRegistry = new XDocument(new XElement("SmartSafe"));
tagRegistry.Element("SmartSafe").Add(new XElement("Tag",
new XElement("tag", stringUid),
new XElement("name", desiredName),
new XElement("latitude", latitude),
new XElement("longitude", longitude)));
using (var storage = IsolatedStorageFile.GetUserStoreForApplication())
{
using (Stream stream = storage.CreateFile("/tagRegistry.xml"))
{ …Run Code Online (Sandbox Code Playgroud)