How to do this below? Object under test calls ReadAppSetting twice to get two different app settings and defaults a value when it cannot be found. First call returns null (it means the first moq setup did not work), second time ReadAppSetting returns as expected (moq setup worked). var mock = new Mock<IConfigReader>(); mock.Setup(foo => foo.ReadAppSetting("PropA", "George")) .Retu
如何在下面做到这一点? 被测对象调用ReadAppSetting两次以获取两个不同的应用程序设置,并在找不到它时默认值。 第一次调用返回null(这意味着第一次moq设置不起作用),第二次ReadAppSetting按预期返回(moq设置工作)。 var mock = new Mock<IConfigReader>(); mock.Setup(foo => foo.ReadAppSetting("PropA", "George")) .Returns("George"); mock.Setup(foo => foo.ReadAppSetting("PropB", "5000"))
I am trying to discover how to apply the async and await keywords to my xUnit tests. I am using xUnit 1.9 and Async CTP 1.3. Here is my test case I have an interface which specifies one asynchronous method call public interface IDoStuffAsync { Task AnAsyncMethod(string value); } I have a class which consumes the interface and calls the async method public class UseAnAsyncThing { pr
我试图发现如何将异步和等待关键字应用到我的xUnit测试中。 我正在使用xUnit 1.9和Async CTP 1.3。 这是我的测试用例 我有一个接口,指定一个异步方法调用 public interface IDoStuffAsync { Task AnAsyncMethod(string value); } 我有一个消耗接口并调用异步方法的类 public class UseAnAsyncThing { private readonly IDoStuffAsync _doStuffAsync; public UseAnAsyncThing(IDoStuffAsync doStuffAsync)
How do I verify that method was NOT called in Moq? Does it have something like AssertWasNotCalled? UPDATE: Starting from Version 3.0, a new syntax can be used: mock.Verify(foo => foo.Execute("ping"), Times.Never()); UPDATE : Since version 3, check the update to the question above or Dann's answer below. Either, make your mock strict so it will fail if you call a method for which yo
如何验证Moq中没有调用该方法? 它是否有像AssertWasNotCalled? 更新:从版本3.0开始,可以使用新的语法: mock.Verify(foo => foo.Execute("ping"), Times.Never()); 更新 :从版本3开始,检查上面问题的更新或Dann的答案。 要么,使你的模拟严格,所以它会失败,如果你打电话给你没有期望的方法 new Mock<IMoq>(MockBehavior.Strict) 或者,如果你想让你的模拟器松动,使用.Throws(Exception) var m = n
I am given a string of characters, in which every consequent pair of characters comprises an edge. What I mean by that is this is the string: ABBCAD. Edges of the string are: A->B B->C A->D Shortest path distance is A->D The task at hand is to build up a Directed Acyclic Graph in memory from the string using the above rule and find the shortest path staring at the root node(in t
我得到了一串字符,其中每个后续的字符对都包含一个边。 我的意思是这是字符串:ABBCAD。 字符串的边缘是: A->B B->C A->D 最短路径距离是A-> D 目前的任务是使用上述规则从字符串中建立一个定向非循环图,并找到最终路径盯着结束于终端节点的根节点(在本例中为A标签)。 NJKUUGHBNNJHYAPOYJHNRMNIKAIILFGJSNAICZQRNM 我收集其中一个方法,其任务是使用深度优先搜索算法。 这不是功课... 这是Djikst
I have a very simple .c file, with some obvious bugs inside it. #include <stdio.h> struct S { int x; }; void f(struct S s){ } void test() { struct S s; f(s); // warn } int test2(int x){ return 5/(x-x); // warn } int main(){ test(); test2(532); printf("Hejrr"); } I am trying to use the clang's static code analyzer tool (scan-build) to detect errors. When I run the t
我有一个非常简单的.c文件,里面有一些明显的错误。 #include <stdio.h> struct S { int x; }; void f(struct S s){ } void test() { struct S s; f(s); // warn } int test2(int x){ return 5/(x-x); // warn } int main(){ test(); test2(532); printf("Hejrr"); } 我正在尝试使用clang的静态代码分析工具(scan-build)来检测错误。 当我直接在文件上运行该工具时,例如使用以下命令: scan-bu
How do you measure the memory consumption of a thread in C#? The scenario I'm looking at is that a program is trying to solve some hard search problems, it kicks off a thread to look for a solution to one of them, the thread runs for a while, maybe it finds a solution, or maybe it runs over its memory allowance and therefore fails. But to implement that, it's necessary to find out how
如何衡量C#中线程的内存消耗? 我所看到的情景是,一个程序试图解决一些困难的搜索问题,它启动一个线程来寻找其中一个线程的解决方案,线程运行一段时间,也许它找到了解决方案,或者可能它运行在其内存容量上,因此失败。 但要实现这一点,有必要找出线程(而不是整个进程)使用的内存量。 有没有办法做到这一点? 线程共享一个共同的堆,但有自己的堆栈。 与其试图获得特定线程的内存消耗(你无法做到这一点),最好
Im working on a bot with the C# Bot Builder. Now, I know that there are quite a few example of how to deal with chaining dialogs. Like the FacebookAuthDialog or the ChainedEchoDialog. What i want to do: A user has to go through an Authorization Dialog and when thats done, i want to immediately put the user into the "UserDialog" where he can use all the functions which needed his au
我正在使用C#Bot Builder进行漫游。 现在,我知道有很多关于如何处理链接对话框的例子。 像FacebookAuthDialog或ChainedEchoDialog一样。 我想要做的是:用户必须通过授权对话框,当完成时,我想立即将用户放入“UserDialog”,他可以使用所有需要他认证的功能。 这是我的代码: public static readonly IDialog<string> dialog = Chain .PostToChain() .Switch( new Case<Message,
There are some posts that asks what the difference between those two are already. (why do I have to even mention this...) But my question is different in a way that I am calling "throw ex" in another error god-like handling method. public class Program { public static void Main(string[] args) { try { // something } catch (Exceptio
有一些帖子询问这两者之间的区别是什么。 (为什么我不得不提到这一点...) 但是我的问题不同于我在另一个错误神般的处理方法中称之为“抛出”的方式。 public class Program { public static void Main(string[] args) { try { // something } catch (Exception ex) { HandleException(ex); } } private static void HandleExcept
I have a web service that processes an HTTP request. The document it receives has an embeded DOCTYPE that specifies a .dtd file. I wish to use a newer XML schema validation file made for when newer devices connect to my service. I can successfully ignore the validation that goes on in the .dtd file, but the .dtd file must exist on my local hard drive. I want to remove these obsolete files, a
我有一个处理HTTP请求的Web服务。 它收到的文档具有指定.dtd文件的嵌入式DOCTYPE。 我希望使用更新的XML模式验证文件,以便在新设备连接到我的服务时进行验证。 我可以成功忽略.dtd文件中进行的验证,但.dtd文件必须存在于本地硬盘上。 我想删除这些过时的文件,并没有找到方法。 我正在处理的示例XML文档: <?xml version="1.0" encoding="us-ascii" standalone="no"?> <!DOCTYPE SomeMessage SYSTEM "SomeMess
What is the prefered method for creating a byte array from an input stream? Here is my current solution with .NET 3.5. Stream s; byte[] b; using (BinaryReader br = new BinaryReader(s)) { b = br.ReadBytes((int)s.Length); } Is it still a better idea to read and write chunks of the stream? It really depends on whether or not you can trust s.Length . For many streams, you just don't k
从输入流创建字节数组的首选方法是什么? 这是我目前使用.NET 3.5的解决方案。 Stream s; byte[] b; using (BinaryReader br = new BinaryReader(s)) { b = br.ReadBytes((int)s.Length); } 读取和写入数据流块是否更好? 这真的取决于你是否可以信任s.Length 。 对于许多流,你只是不知道会有多少数据。 在这种情况下 - 和.NET 4之前 - 我会使用这样的代码: public static byte[] ReadFully(Stream input) {