我有一个测试的基类,它由以下方式组成:
[TestClass]
public abstract class MyBaseTest
{
protected static string myField = "";
[ClassInitialize]
public static void ClassInitialize(TestContext context)
{
// static field initialization
myField = "new value";
}
}
Run Code Online (Sandbox Code Playgroud)
现在我正在尝试创建一个继承自base的新测试,具有以下签名:
[TestClass]
public class MyTest : MyBaseTest
{
[TestMethod]
public void BaseMethod_ShouldHave_FieldInitialized()
{
Assert.IsTrue(myField == "new value");
}
}
Run Code Online (Sandbox Code Playgroud)
将ClassInitialize永远不会被孩子所谓的测试...什么是真实的,正确的使用测试初始化与MSTest的继承方式?
我正在研究构建在.NET 3.5之上的遗留应用程序.这是一个我无法改变的约束.我需要执行第二个线程来运行长时间运行的任务而不锁定UI.线程完成后,我需要以某种方式执行回调.
现在我尝试了这个伪代码:
Thread _thread = new Thread(myLongRunningTask) { IsBackground = True };
_tread.Start();
// wait until it's done
_thread.Join();
// execute finalizer
Run Code Online (Sandbox Code Playgroud)
第二个选项不锁定UI,如下所示:
Thread _thread = new Thread(myLongRunningTask) { IsBackground = True };
_tread.Start();
// wait until it's done
while(_thread.IsAlive)
{
Application.DoEvents();
Thread.Sleep(100);
}
// execute finalizer
Run Code Online (Sandbox Code Playgroud)
当然第二种解决方案并不好,因为它会过度充电._thread完成后执行回调的正确方法是什么?另外,我如何知道线程是否被取消或中止?
*注意:*我无法使用BackgroundWorker,我无法使用Async库,我需要使用本机线程类.
我有一个简单的模板,用于以这种方式构造的组合框:
<ComboBox DockPanel.Dock="Left" MinWidth="100" MaxHeight="24"
ItemsSource="{Binding Actions}">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Name}" Width="100" />
<Image Source="{Binding Converter={StaticResource TypeConverter}}" />
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
Run Code Online (Sandbox Code Playgroud)
所以,如果我使用这个代码,一切正常:
<TextBlock Text="{Binding Name}" Width="100" />
<!--<Image Source="{Binding Converter={StaticResource TypeConverter}}" /> -->
<Image Source="{StaticResource SecurityImage}" />
Run Code Online (Sandbox Code Playgroud)
但是,如果我使用转换器,它就不再起作用了.这是转换器,但我不知道如何从那里引用静态资源...
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var type = (Action)value;
var img = new BitmapImage();
switch (type.ActionType)
{
case ActionType.Security:
img.UriSource = new Uri("StructureImage", UriKind.Relative);
break;
case ActionType.Structural:
img.UriSource = new Uri("SecurityImage", UriKind.Relative); …Run Code Online (Sandbox Code Playgroud) 我已经将我的web api项目升级到最新版本,使用MVC 5应用程序运行正常,但这行代码在单元测试中不再有效:
string uri = this.Url.Link("DefaultApi", new { id = savedOrganization.Id });
Run Code Online (Sandbox Code Playgroud)
控制器的Url属性现在为null.这是我配置模拟控制器的方式:
var config = new HttpConfiguration();
var request = new HttpRequestMessage(HttpMethod.Post, "http://xxx/api/organization");
var route = config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}");
var routeData = new HttpRouteData(route, new HttpRouteValueDictionary {{"controller", "organization"}});
controller.ControllerContext = new HttpControllerContext(config, routeData, request);
controller.Request = request;
controller.Request.Properties[HttpPropertyKeys.HttpConfigurationKey] = config;
controller.Request.Properties[HttpPropertyKeys.HttpRouteDataKey] = routeData;
Run Code Online (Sandbox Code Playgroud)
在升级到MVC 5之前,它运行正常.
当我调试测试时,它显示Url属性现在为null

我们希望使用Microsoft.AspNet.Identity以提供基于自定义声明的身份验证.到目前为止,我们已经创建了自己的模型(IUserStype,IUserStore ...)和我们自己的身份验证方法.实际上,用户可以调用登录服务并使用UserStore和此组件提供的所有功能.
我不知道如何配置ASP.NET MVC应用程序以使用ASP.NET标识,因为MSDN上可用的唯一示例显示OWIN配置,但我的应用程序不能由owin自托管.那么我应该使用web.config配置此声明身份验证吗?在线提供任何样品?
我正在VS 2010中构建一个插件,我陷入了T4代.现在我已经实现了(像MSDN建议的)一个自定义T4主机来生成我的T4结果,我以这种方式使用它:
const string content = @"c:\Simple.tt";
var engine = new Engine();
var host = new MyTemplateHost();
var result = engine.ProcessTemplate(File.ReadAllText(content), host);
foreach (CompilerError error in host.Errors)
{
Console.WriteLine(error.ErrorText);
}
Run Code Online (Sandbox Code Playgroud)
这有效,直到我在模板中传递参数.一旦我在.tt文件中创建了一个参数,主机就会说它不知道如何解决它.我看到你可以使用TemplateSession来做到这一点,但我没弄明白如何将它传递给我的主机?是否有更好的方法使用C#从.tt生成代码并在运行时传递参数?也许我走错了路.
我正在使用PowerShell脚本来执行控制台应用程序,我试图从那里重定向标准输出和标准错误.我使用的代码如下:
$ProcessInfo = New-Object System.Diagnostics.ProcessStartInfo
$ProcessInfo.FileName = "myExe.exe"
$ProcessInfo.Arguments = "bla bla bla"
$ProcessInfo.RedirectStandardError = $true
$ProcessInfo.RedirectStandardOutput = $true
$ProcessInfo.UseShellExecute = $false
$Process = New-Object System.Diagnostics.Process
$Process.StartInfo = $ProcessInfo
$Process.Start() | Out-Null
$output = $Process.StandardOutput.ReadToEnd()
$errors = $Process.StandardError.ReadToEnd()
$Process.WaitForExit()
$output
$errors
return $Process.ExitCode
Run Code Online (Sandbox Code Playgroud)
到目前为止一切都那么好,如果我有错误,我可以看到它重定向到我的PowerShell控制台,如果我有输出,它也被重定向.问题是这个过程需要10分钟,与此同时我们不知道发生了什么.
在PowerShell中是否有任何方法我可以在进程运行时流式传输输出和错误的内容?在纯.NET中,我们可以订阅Process类的事件,我可以在PowerShell中执行相同的操作吗?
嗨,我正在使用AutoMapper从模型转移到Dto,它运行良好.在一个TypeConverter我需要注入一个必须由类型转换器使用的接口(服务),以进行转换.
如何在AutoMapper中完成此操作?
我试图通过将以下值添加到tsconfig.json中来设置项目中的Path别名:
"compilerOptions": {
"baseUrl": "src",
"paths": {
"@store/*": ["store/*"]
},
Run Code Online (Sandbox Code Playgroud)
如果我创建导入,则IntelliJ或VSCode都不会打扰我:
import { AppState } from '@store/index';
Run Code Online (Sandbox Code Playgroud)
但是,当我编译应用程序时,会收到以下警告:
The following changes are being made to your tsconfig.json file:
- compilerOptions.paths must not be set (aliased imports are not supported)
Run Code Online (Sandbox Code Playgroud)
它炸弹说找不到参考:
TypeScript error in C:/xyz.tsx(2,26):
Cannot find module '/store'. TS2307
Run Code Online (Sandbox Code Playgroud)
有任何解决方法或不支持的解决方法create-react-app --typescript?
我有一个ContextMenuStrip控件,允许你执行一个动作是两种不同的风格:Sync和Async.
我试图用泛型覆盖所有内容所以我这样做:
public class BaseContextMenu<T> : IContextMenu
{
private T executor;
public void Exec(Action<T> action)
{
action.Invoke(this.executor);
}
public void ExecAsync(Action<T> asyncAction)
{
// ...
}
Run Code Online (Sandbox Code Playgroud)
我如何编写异步方法以执行通用操作并同时使用菜单"执行某些操作"?我看到签名BeginInvoke是这样的:
asyncAction.BeginInvoke(this.executor, IAsyncCallback, object);
Run Code Online (Sandbox Code Playgroud) c# ×4
.net ×1
asp.net-mvc ×1
asynchronous ×1
automapper ×1
converter ×1
image ×1
mstest ×1
powershell ×1
process ×1
t4 ×1
typescript ×1
wpf ×1