我刚刚接管了一个有很多代码的应用程序,例如下面的异常被捕获,Console.Write(xxx)就在那里.
我想改变这个,所以我有一个简单的日志来审查现在有一个Console.write().
在asp.net mvc中获取此设置以在IIS服务器上查看文件的最简单方法是什么.
try
{
SmtpClient c = new SmtpClient("mail.xxx.org");
c.Send(msg);
}
catch (Exception ex)
{
Console.Write(ex.Message.ToString());
}
Run Code Online (Sandbox Code Playgroud) 我有一个不可变的类,其中包含一些在构造函数执行期间设置的私有字段.我想对这个构造函数进行单元测试,但我不确定这种情况下的"最佳实践".
简单的例子
这个类在Assembly1中定义:
public class Class2Test
{
private readonly string _StringProperty;
public Class2Test()
{
_StringProperty = ConfigurationManager.AppSettings["stringProperty"];
}
}
Run Code Online (Sandbox Code Playgroud)
此类在Assembly2中定义:
[TestClass]
public class TestClass
{
[TestMethod]
public void Class2Test_Default_Constructor()
{
Class2Test x = new Class2Test();
//what do I assert to validate that the field was set properly?
}
}
Run Code Online (Sandbox Code Playgroud)
编辑1:我已经用一个潜在的解决方案回答了这个问题,但我不确定这是否是"正确的方法".因此,如果您认为自己有更好的想法,请发布.
这个例子不值得测试,但假设构造函数有一些更复杂的逻辑.是避免测试构造函数的最佳方法,只是假设它对类的方法的所有测试都有效吗?
编辑2:看起来我做的样本有点简单.我已经用更合理的情况更新了它.
在Powershell中,我定义了一个名为的新PSDrive test.但是当我test:在控制台输入时会抛出错误.如果我键入cd test:它工作正常.
我不应该test只是通过键入导航到驱动器test:?
PS> New-PSDrive -name test -psprovider FileSystem -root C:\test
WARNING: column "CurrentLocation" does not fit into the display and was removed.
Name Used (GB) Free (GB) Provider Root
---- --------- --------- -------- ----
test 128.42 FileSystem C:\test
PS> test:
The term 'test:' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was …Run Code Online (Sandbox Code Playgroud) 我在网上看过这个例子:
$('#questionTextArea').each( function() {
var $this = $(this);
var $questionText = $("<textarea class='textAreaQuestion'></textarea>")
.attr('name',$this.attr('name'))
.attr('value',$this.val());
$question.append($questionText);
});
Run Code Online (Sandbox Code Playgroud)
它的位置是'.attr('name',$ this.attr('name'))',这是什么意思?这是否与'id'属性#questionTextArea具有相同的'name'属性,或者与'class'属性'textAreaQuestion'具有相同的'name'?
谢谢
我有一系列地图.
;; input
[{:country "MX", :video 12345, :customer "cid1"}
{:country "US", :video 12345, :customer "cid2"}
{:country "MX", :video 54321, :customer "cid1"}]
Run Code Online (Sandbox Code Playgroud)
我想将其转换为多图.我想生成.
;; output
{"cid1"
{:actions
[{:country "MX", :video 12345, :customer "cid1"}
{:country "MX", :video 12345, :customer "cid1"}]},
"cid2"
{:actions
[{:country "US", :video 12345, :customer "cid2"}]}}
Run Code Online (Sandbox Code Playgroud)
我觉得我应该用update-in.有些事情......我只是没有弄清楚究竟是什么some-fn-here样的,我认为其他人可能有同样的问题.
(defn add-mm-entry
[m e]
(update-in m [(:customer e)] some-fn-here))
(def output (reduce add-mm-entry {} input))
Run Code Online (Sandbox Code Playgroud)
我想在我工作的时候把它扔给社区.如果我走错了路,请告诉我.
我正在寻找一个符合以下要求的正则表达式:
这些示例应符合:
这些示例不匹配:
这主要是针对印度手机号码.
请提供示例,我已经搜索过Google,这些答案提供了过度验证.
我有一些简单的代码,使用方形布尔矩阵表示图形,其中行/列是节点,而true表示两个节点之间的无向链接.我正在使用False值初始化此矩阵,然后将值设置为True,其中存在链接.
我相信我初始化列表的方式是导致给定行中的每个单元格引用单个bool实例.结果是,如果我将任何单元格设置为True,则该行中的所有其他单元格也将变为True.
我应该如何初始化我的方形矩阵,以便所有值都是假的,但没有一个是通过引用与其他单元格共享的?
import sys
class Graph(object):
def __init__(self, nodeCount, links):
self.matrix = [[False] * nodeCount] * nodeCount
for l in links:
self.matrix[l[0]][l[1]] = True
def __str__(self):
s = " "
for i in range(len(self.matrix)):
s += str(i) + " "
s += "\n"
for r in range(len(self.matrix)):
s += str(r) + " "
for c in range(len(self.matrix)):
s += str(self.matrix[c][r])[0] + " "
s += "\n"
return s
g = Graph(5, [(2,3)])
print g
Run Code Online (Sandbox Code Playgroud)
另外,在GIST上
是否有可能将此功能,列表理解组合转换为单个列表理解(因此keep不需要)?
def keep(list, i, big):
for small in list[i+1:]:
if 0 == big % small:
return False
return True
multiples[:] = [n for i,n in enumerate(multiples) if keep(multiples, i, n)]
Run Code Online (Sandbox Code Playgroud) 我有格式的约会16-2-2012.
var k = getTomorrow('16-02-2012',1);
var myTime = k.getDate()+'-'+(k.getMonth()+1)+'-'+k.getFullYear();
Run Code Online (Sandbox Code Playgroud)
现在我想将mytime解析为日期对象.我试过了
SimpleDateFormat parserSDF=new SimpleDateFormat("dd-M-yyyy");
Date dtstr=parserSDF.parse(myTime);
Run Code Online (Sandbox Code Playgroud)
但它不起作用.有什么办法吗?
c# ×2
javascript ×2
python ×2
.net ×1
arrays ×1
asp.net ×1
clojure ×1
jquery ×1
list ×1
logging ×1
multimap ×1
powershell ×1
regex ×1
unit-testing ×1