有人能告诉我为什么检查异常的单元测试失败了吗?显然我真正的测试是检查其他代码,但我正在使用Int32.Parse来显示问题.
[Test]
public void MyTest()
{
Assert.That(Int32.Parse("abc"), Throws.Exception.TypeOf<FormatException>());
}
Run Code Online (Sandbox Code Playgroud)
测试失败,给出了这个错误.显然我正在尝试测试这个异常,我想我的语法中缺少一些东西.
Error 1 TestCase '.MyTest'
failed: System.FormatException : Input string was not in a correct format.
at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
at System.Int32.Parse(String s)
Run Code Online (Sandbox Code Playgroud)
由于我使用两个不同的通用集合名称空间(System.Collections.Generic和Iesi.Collections.Generic),我有冲突.在项目的其他部分,我使用的是nunit和mstest框架,但是当我打电话时Assert我想要使用nunit版本
using Assert = NUnit.Framework.Assert;
Run Code Online (Sandbox Code Playgroud)
哪个效果很好,但我想用泛型类型做同样的事情.但是,以下行不起作用
using ISet = System.Collections.Generic.ISet;
using ISet<> = System.Collections.Generic.ISet<>;
Run Code Online (Sandbox Code Playgroud)
有谁知道如何告诉.net如何使用泛型的using语句?
我正在使用SVG和angular.js开展大型项目,并且需要对svg指令模板提供可靠的支持.不幸的是,当angular渲染模板时,它会创建DOM节点,而不是SVG节点.我目前的工作是使用jquery.svg自己管理创建和删除节点,但它的限制.示例:http://plnkr.co/edit/Xk8wM3?p = preview
我想让指令element成为实际的svg元素,而不是一些没有真正做任何事情的虚假DOM元素.这将让我有效地使用ng-repeat和angular滤镜.
这是需要修复的plunkr:http://plnkr.co/edit/BPvGjf?p = preview
HTML
<svg>
<!--woot this one works-->
<shape d="M0,0L250,0L250,250L0,250z" fill="green"></shape>
<!--nesting directives doesn't work-->
<group>
<shape d="M0,0L150,0L150,150L0,150z" fill="red"></shape>
<shape d="M0,0L100,0L100,100L0,100z" fill="orange"></shape>
</group>
<!--ng repeat doesn't work-->
<shape d="{{square.path}}" fill="{{square.color}}" ng-repeat="square in squares | orderBy:'order'"></shape>
</svg>
Run Code Online (Sandbox Code Playgroud)
JavaScript的
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
$scope.squares = [{
path: "M0,0L50,0L50,50L0,50z",
color: 'blue',
order: 2
}, {
path: "M0,0L75,0L75,75L0,75z",
color: 'purple',
order: 1
}];
});
app.directive('group', function($compile) {
return …Run Code Online (Sandbox Code Playgroud) 我还在学习jQuery,但我找不到一个可靠的答案.我知道每次使用jQuery选择器$(...)都会产生性能成本,但是$(this)在使用它之前应该对它进行高速缓存会有很大的成本吗?
var $this = $(this);
Run Code Online (Sandbox Code Playgroud) 请参阅我的jsfiddler以获取示例.
如果还有另一种方式我们应该绑定/创建我们的数组/ etc也可以.我通过使用列表或跨度解决了这个问题
谢谢!
JS
var mainViewModel = function () {
var self = this;
this.Items = ko.observableArray();
this.init = function () {
var itemsArray = [];
for(var i = 0; i < 1300; i++){
itemsArray.push("My value is: " + i);
}
self.Items(itemsArray );
};
};
$(function () {
myApp = new mainViewModel();
ko.applyBindings(myApp);
myApp.init();
});?
Run Code Online (Sandbox Code Playgroud)
HTML
<!-- ko foreach: Items -->
<div data-bind="text: $data"></div>
<!-- /ko -->?
Run Code Online (Sandbox Code Playgroud) 我正在开发一个Web应用程序,允许用户选择一些文本,单击按钮,然后保存突出显示的文本.这在桌面浏览器中很有用(本例中为chrome),但在iOS中我遇到了本机文本选择问题,用户可以在其中更改所选文本.
以下是显示问题的JsFiddle(问题仅存在于iOS中):http://jsfiddle.net/JasonMore/gWZfb/
用户开始选择文本
用户展开其文本选择,然后单击"在上方显示所选文本"
只有第一个选中的单词" The "出现,即使我想要" 正义之路 "



这是我正在使用的JS:
$(function() {
$('#actionButton').click(function() {
$('#result').text(selectedRange.toString());
});
$('#slipsum').on('mouseup touchend','p', function() {
getSelectedRange();
});
});
var selectedRange = null;
var getSelectedRange = function() {
if (window.getSelection) {
selectedRange = window.getSelection().getRangeAt(0);
} else {
selectedRange = document.getSelection().getRangeAt(0);
}
};?
Run Code Online (Sandbox Code Playgroud)
HTML:
<h3>Selected Text:</h3>
<p id="result">
</p>
<br/>
<p>
<input type="button" id="actionButton" value="Show the selected text above" />
</p>
<!-- start slipsum code -->
<div id="slipsum">
<h1>Is she dead, …Run Code Online (Sandbox Code Playgroud) 我有一个看起来像这样的XDocument:
XDocument outputDocument = new XDocument(
new XElement("Document",
new XElement("Stuff")
)
);
Run Code Online (Sandbox Code Playgroud)
那我打电话的时候
outputDocument.ToString()
Run Code Online (Sandbox Code Playgroud)
输出到:
<Document>
<Stuff />
</Document>
Run Code Online (Sandbox Code Playgroud)
但我希望它看起来像这样:
<Document>
<Stuff>
</Stuff>
</Document>
Run Code Online (Sandbox Code Playgroud)
我意识到第一个是正确的,但我需要以这种方式输出它.有什么建议?
尝试使用https://github.com/RyanAmos/rethinkdb-vagrant设置rethinkdb
C:\rethinkdb-vagrant>vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
There are errors in the configuration of this machine. Please fix
the following errors and try again:
VirtualBox Provider:
* The following settings shouldn't exist: vm
Run Code Online (Sandbox Code Playgroud)
VagrantFile
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# Ubuntu 12.04, 64 bit
config.vm.box = 'precise64'
config.vm.box_url = 'http://files.vagrantup.com/precise64.box'
# Providers …Run Code Online (Sandbox Code Playgroud) 我创建了一个显示模板,当传递一个字符串时会呈现一个禁用的文本框
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<String>" %>
<%: Html.TextBoxFor(model => model, new { disabled = "disabled" })%>
Run Code Online (Sandbox Code Playgroud)
哪个效果很好.但是,出于某种原因,MVC想要通过它来尝试填充DateTimes和Ints,这就是抛出异常
传递到字典中的模型项的类型为"System.Int32",但此字典需要"System.String"类型的模型项.
有任何想法吗?
我不能为我的生活理解为什么这不起作用.对于某人来说,这应该是一个垒球.谢谢!
HTML
<div data-bind="foreach:Zones">
<div class="container" data-bind="style:{ top: ZoneY, left: ZoneX }, text: ZoneTest"></div>
</div>?
Run Code Online (Sandbox Code Playgroud)
CSS
.container { position: absolute; font-size: .75em; }
Run Code Online (Sandbox Code Playgroud)
使用Javascript
var viewModel = {
Zones: ko.observableArray([
{
ZoneX: 100,
ZoneY: 100,
ZoneTest: "hello world"
},
{
ZoneX: 200,
ZoneY: 200,
ZoneTest: "rage!"
}
])
};
ko.applyBindings();
Run Code Online (Sandbox Code Playgroud)