我想测试一种我希望在特定情况下阻止的方法.
我尝试了TimeoutAttribute和的组合ExpectedExceptionAttribute:
[Test]
[Timeout(50), ExpectedException(typeof(ThreadAbortException))]
public void BlockingCallShouldBlock()
{
this.SomeBlockingCall();
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,这不起作用,因为ThreadAbortException我在这里读到似乎被NUnit本身抓住了.
有没有办法期待超时(使用NUnit)?
我正在使用任务并行库来运行一个任务 - 当取消时 - 抛出OperationCanceledException,然后使用AggregateException捕获它,如下所示.AggregateException包含TaskCanceledExceptions列表,它对应于抛出的异常.不幸的是,这些TaskCanceledExceptions似乎正在丢失原始异常抛出的堆栈跟踪.这是设计的吗?
try
{
task1.Wait();
}
catch (AggregateException aggEx)
{
var tcex = ex as TaskCanceledException;
if (tcex != null)
{
Debug.WriteLine("InnerException:{0}, Message:{1}, Source:{2}, StackTrace: {3}",
tcex.InnerException, tcex.Message, tcex.Source, tcex.StackTrace);
return true;
}
else
{
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
结果:
InnerException:, Message:A task was canceled., Source:, StackTrace:
Run Code Online (Sandbox Code Playgroud) c# .net-4.0 task-parallel-library cancellation aggregateexception
我有一些 T4 包含文件,我想在多个项目中重用它们。因此,我创建了一个 NuGet 包并将文件放置在该包的 Tools 文件夹中。现在它们已安装在该packages\PackageName.x.x.x\Tools文件夹中,我可以在项目的 T4 文件中添加包含指令。
但这样做的缺点是,路径中的版本号会在我创建包的新版本时发生变化。这将需要我更新项目中的所有包含指令。
有人知道对此有什么好的方法吗?
当前设置:
我正在使用以下命令设置构建任务以生成 SQL 迁移脚本:
dotnet ef migrations script --output "script.sql" --context MyContext
Run Code Online (Sandbox Code Playgroud)
但是,在 TeamCity 上运行构建时,构建失败并显示以下错误:
Could not execute because the specified command or file was not found.
Possible reasons for this include:
* You misspelled a built-in dotnet command.
* You intended to execute a .NET Core program, but dotnet-ef does not exist.
* You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found …Run Code Online (Sandbox Code Playgroud) 在实现自定义设置提供程序时,我注意到访问设置属性的值会将其IsDirty标志更改为true.
// Arrange
var property = new SettingsProperty("property1")
{
PropertyType = typeof(Color),
DefaultValue = "Green"
};
// Act
var result = new SettingsPropertyValue(property);
// Assert
Assert.That(result.IsDirty, Is.False);
Assert.That(result.PropertyValue, Is.EqualTo(Color.Green));
Assert.That(result.IsDirty, Is.False); // <-- Assertion fails
Run Code Online (Sandbox Code Playgroud)
Reflector给出了一个问题的答案,为什么PropertyValuegetter的行为是这样的 - 它包含如下语句:
if (_Value != null && !Property.PropertyType.IsPrimitive && !(_Value is string) && !(_Value is DateTime))
{
_UsingDefaultValue = false;
_ChangedSinceLastSerialized = true;
_IsDirty = true;
}
Run Code Online (Sandbox Code Playgroud)
乍一看奇怪的行为可以让任何人对此有所了解吗?
当解决方案已完全加载时,我想收到通知。受此答案启发,我尝试实施IVsSolutionEvents。
当我加载具有两个C#项目的解决方案时,请等到加载完成并最终关闭Visual Studio 2017时,输出仅显示以下跟踪消息:
VSTestPackage1: OnAfterOpenProject
VSTestPackage1: OnQueryCloseSolution
VSTestPackage1: OnQueryCloseProject
VSTestPackage1: OnQueryCloseProject
VSTestPackage1: OnBeforeCloseSolution
VSTestPackage1: OnQueryCloseProject
VSTestPackage1: OnBeforeCloseProject
VSTestPackage1: OnQueryCloseProject
VSTestPackage1: OnBeforeCloseProject
VSTestPackage1: OnAfterCloseSolution
Run Code Online (Sandbox Code Playgroud)
这是预期的行为吗?为什么OnAfterOpenSolution不被调用?
这是程序包的实现:
[PackageRegistration(UseManagedResourcesOnly = true)]
[InstalledProductRegistration("#110", "#112", "1.0", IconResourceID = 400)]
[Guid(PackageGuidString)]
[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1650:ElementDocumentationMustBeSpelledCorrectly",
Justification = "pkgdef, VS and vsixmanifest are valid VS terms")]
[ProvideAutoLoad(VSConstants.UICONTEXT.SolutionHasMultipleProjects_string)]
public sealed class VSPackage1 : Package, IVsSolutionEvents
{
public const string PackageGuidString = "2e655097-9510-4cf8-b9d4-ceeacebbaf3c";
private DTE _dte;
private uint _hSolutionEvents = uint.MaxValue;
private IVsSolution _solution; …Run Code Online (Sandbox Code Playgroud)