我写了一个小函数,它接受一个字符串类型变量作为参数.
我想知道是否有任何方法可以测试我的功能?
我不想使用单元测试的东西,因为它是矫枉过正的.
谢谢你的回复.
UPDATE
谢谢大家的回复.
我的情况是,这个函数将由事件处理程序触发.但是,我不想将句柄与我的函数绑定,我只想检查该函数是否有效.
那么最好的方法是编写一个单元测试?
我有一个与组合有关的问题.
I am actually developing a ecommerce site and I have a function to allow customer create product variant.
For example: Black Pant 34W 30L, Black Pant 38W 32L, White Pant 34W 30l. Those are defined as product variants.
Assume my pant has 3 options, and they are color, waist size and length.
I now have 3 list.
ListA = {"black", "white", "red"} //For the color
ListB = {30,32,34,36,38} //For the waist
ListC ={28,30,32,34} //For the length
Run Code Online (Sandbox Code Playgroud)
My question is …
每次启动Visual Studio 2012时,大约有6个文件会自动打开,即使它们在上一个会话中已经关闭了.我怎样才能使这些文件在每次启动时不再自动打开,所以我不再需要手动关闭它们?
我有一个关于如何比较两个字符串的问题.
这是代码.
string stringA = "This is a test item";
string stringB = "item test a is This";
Run Code Online (Sandbox Code Playgroud)
显然,stringB包含来自stringA的每个单词,但顺序不同.
我想要的结果应该是正确的.
我的问题是,我该怎么办?我试图使用.Contains()方法,但结果为FALSE.
感谢大家.
更新
谢谢大家的亲切回复.
这是我的澄清
我实际上是使用LINQ和EF构建数据库搜索功能.
假设一个项目的名称为"This is a test item".
如果用户输入"test a is this",我希望该功能足够智能以捕获上述项目.
有什么建议吗?
另一个更新
再次感谢你的帮助.
我喜欢Peter Ritchie的代码密码,Dave和EdFred的建议.
我有一些字符串,我想从他们那里得到索引编号.
这是一个例子.
var x = "FundList[10].Amount";
var y = "FundList[11].Amount";
var z = "FundList[15].Amount";
Run Code Online (Sandbox Code Playgroud)
我只是想获得10,11,15并将它们放入Int数组中.
目前,我使用的是一种愚蠢的方式,即将"FundList [","]"和".Amout"替换为"".
我想知道是否有更好的方法.
非常感谢你们.
我试图让问题尽可能简单,看起来确实引起了一些混乱.
这是我的代码.
这是我的PartialView的一部分.
@{
var txtIndexName = "FundList[" + Model.Index + "].Index";
var txtAmountName = "FundList[" + Model.Index + "].Amount";
var dropFiscalYearName = "FundList[" + Model.Index + "].FiscalYear";
}
Amount: <input type="text" name="@txtAmountName" id="@txtAmountName" />
Run Code Online (Sandbox Code Playgroud)
这是调用PartialView的JavaScript.每次用户单击锚链接时,都会调用PartialView.
function LoadContractOptionFundingPlanBlockByIndexNumber(indexNumber) {
$.ajax({
type: "POST",
url: "/Json/LoadContractOptionFundingPlanPartialView",
data: JSON.stringify({ index: indexNumber }),
contentType: "application/json; charset=utf-8"
}).success(function (result) {
$("#ContractOptionFundingPlanBlock").append(result);
});
Run Code Online (Sandbox Code Playgroud)
}
function GenerateOptionFundingPlanBlock() { …Run Code Online (Sandbox Code Playgroud)