我有一个函数,它接受两个参数,并返回一个或另外50%的时间.
对此进行单元测试应确定可以返回两个参数.幸运的是,我不需要证明每个的概率是50%,但我需要证明两个参数都可以返回.
如何为此功能编写测试用例?
我正在用C#编写一个使用第三方COM DLL的应用程序,这个DLL在非托管内存中创建了大量资源(如位图,视频,数据结构).在挖掘时,我遇到了垃圾收集器的以下调用:
GC.AddMemoryPressure(long long bytesAllocated)
Run Code Online (Sandbox Code Playgroud)
它在MSDN中记录在这里:
http://msdn.microsoft.com/en-us/library/system.gc.addmemorypressure.aspx
这听起来像我应该调用的东西,因为这个外部dll正在创建CLR不知道的大量资源.
我想我有两个问题......
除了control.BringToFront()之外还有其他方法可以将控件带到前面吗?我在用户控件上有一系列标签,当我尝试将其中一个标签放在前面时,它无法正常工作.我甚至已经完成所有控件的循环并将它们全部发送回去,除了我感兴趣的那个并且它没有改变一件事.
以下是将标签添加到用户控件的方法
private void AddUserLabel()
{
UserLabel field = new UserLabel();
++fieldNumber;
field.Name = "field" + fieldNumber.ToString();
field.Top = field.FieldTop + fieldNumber;
field.Left = field.FieldLeft + fieldNumber;
field.Height = field.FieldHeight;
field.Width = field.FieldWidth;
field.RotationAngle = field.FieldRotation;
field.Barcode = field.BarCoded;
field.HumanReadable = field.HumanReadable;
field.Text = field.FieldText;
field.ForeColor = Color.Black;
field.MouseDown += new MouseEventHandler(label_MouseDown);
field.MouseUp += new MouseEventHandler(label_MouseUp);
field.MouseMove += new MouseEventHandler(label_MouseMove);
userContainer.Controls.Add(field);
SendLabelsToBack(); //Send All labels to back
userContainer.Controls[field.FieldName].BringToFront();
}
Run Code Online (Sandbox Code Playgroud)
这是将所有这些发送到后面的方法.
private void SendLabelsToBack()
{
foreach (UserLabel lbl in userContainer.Controls)
{ …Run Code Online (Sandbox Code Playgroud) 当我使用以下代码时,它可以工作,因为我使用的是 ListBox
<UserControl.Resources>
<Style BasedOn="{StaticResource {x:Type ListBox}}" TargetType="{x:Type ListBox}">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
<Setter Property="Background" Value="Transparent" />
</Style>
</UserControl.Resources>
Run Code Online (Sandbox Code Playgroud)
但是当我将以下代码用于 ListView 时,我收到警告/异常
<UserControl.Resources>
<Style BasedOn="{StaticResource {x:Type ListView}}" TargetType="{x:Type ListView}">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
<Setter Property="Background" Value="Transparent" />
</Style>
</UserControl.Resources>
Run Code Online (Sandbox Code Playgroud)
“未找到静态资源引用 'System.Windows.Controls.ListView'。”
为什么以及如何解决?我想要 ListView 的功能。
CSS 中有没有办法将任何元素的宽度设置为等于其父节点的宽度?我尝试过“继承” - 听起来很逻辑 - 但它不起作用。
提前致谢。
我正在尝试对xpath查找返回的节点执行xpath查找,但它似乎没有按预期工作.在文档的子节点上执行的XPaths似乎是针对文档的根节点执行的(在例如,库存标签.),而不是提供的节点的根.
我在这里错过了什么吗?我是XPath的新手.
另外,请不要回答"只做//书[作者='Neal Stephenson'/ title".我有一个合法的用例,这是一个简化的例子.
代码段
DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
domFactory.setNamespaceAware(true);
DocumentBuilder builder = domFactory.newDocumentBuilder();
Document doc = builder.parse("src/main/java/books.xml");
XPathFactory factory = XPathFactory.newInstance();
XPath xpath = factory.newXPath();
Node book = (Node) xpath.evaluate("//book[author='Neal Stephenson']", doc, XPathConstants.NODE);
Node title = (Node) xpath.evaluate("/title", book, XPathConstants.NODE); // I get null here.
Node inventory = (Node) xpath.evaluate("/inventory", book, XPathConstants.NODE); // this returns a node.
Run Code Online (Sandbox Code Playgroud)
是book.xml
<inventory>
<book year="2000">
<title>Snow Crash</title>
<author>Neal Stephenson</author>
<publisher>Spectra</publisher>
<isbn>0553380958</isbn>
<price>14.95</price>
</book>
<book year="2005">
<title>Burning Tower</title>
<author>Larry Niven</author>
<author>Jerry Pournelle</author>
<publisher>Pocket</publisher> …Run Code Online (Sandbox Code Playgroud) 我有6年以上的C/C++经验.明天开始大学任务,我将不得不使用C#.因此,我希望有一个您认为重要的链接/资源列表或一个广泛的教程 - 简而言之,您认为值得的一切.
编码风格,最佳实践,......
(我不知道我将使用的C#环境的任何细节(IDE,OS,w/e),第一次会议是明天晚上).
(我之前从未编写过C#)
还有一件事:我想使用Linux(kubuntu 10.4).有关Linux的IDE /环境/教程建议非常受欢迎.
谢谢你的帮助!
使用Subversion,我使用Visual SVN服务器在几分钟内完成并提供服务.是否有Mercurial的等价物,所以我可以运行hg.mydomain.com?
我为我的朋友创建了这个网站,然后我将它上传到了Amazon S3存储桶(http://ballard26.s3.amazonaws.com/index.html),当我访问该网站时,页面无法正确加载我有不明白为什么.有任何想法吗?
例如,stylesheet.css无法正确加载.如果你去http://ballard26.s3.amazonaws.com/stylesheet.css,它下载文件而不是加载为CSS.