草庐IT

lib_being_tested

全部标签

C#,NUnit : Is it possible to test that a DateTime is very close, 但不一定等于另一个?

假设我有这个测试:[Test]publicvoidSomeTest(){varmessage=newThing("foobar");Assert.That(thing.Created,Is.EqualTo(DateTime.Now));}例如,这可能会使Thing的构造函数失败,这会花费一些时间。是否有某种NUnit构造允许我指定Created时间不必完全等于DateTime.Now,只要它在一秒之内?是的,我知道构造函数不应该花费太多时间,但只是作为一个例子:p 最佳答案 没试过,但根据thedocs看起来这应该可行:Assert

c# - LINQ to Entities Group By 表达式给出 'Anonymous type projection initializer should be simple name or member access expression'

我在这个表达式中遇到了上述错误:varaggregate=fromtinentities.TraceLinesjoinminentities.MethodNames.Where("it.NameLIKE@searchTerm",newObjectParameter("searchTerm",searchTerm))ont.MethodHashequalsm.MethodHashwhere(t.CallTypeId&(int)types)==t.CallTypeId&&t.UserSessionProcessId==m_SessionIdgrouptbym.Nameintodselect

c# - NuGet 包无法为 lib 目录中的 DLL 添加对项目的引用

我正在尝试打包引用C++DLL的.NETDLL。nuspec文件如下所示:MyPackage1.0.0someauthorsomeownerfalse.NETWrapperforrebuilt64-bitversionofMyPackageCopyright2014当我检查生成的nupkg文件时,内部文件结构看起来是正确的。C++DLL在content中,.NETDLL在lib中。当我将nupkg安装到项目中时,内容DLL被添加到项目根目录,而libDLL被添加到解决方案packages目录。但是,没有引用被添加到项目中。我被迫手动添加引用。我尝试将以下节点添加到元数据,但无济于事:我

c# - 单元测试 Asp.Net WebApi : how to test correct routing of a method with [FromUri] parameters

我想测试这个Controller:[HttpGet]publicIListGetNotificationsByCustomerAndId([FromUri]string[]name,[FromUri]int[]lastNotificationID){return_storage.GetNotifications(name,lastNotificationID,_topX);}特别是,在此方法中,我想测试传入输入以形成请求Url的数组是否与进入routeData.Values的数组相同。如果对于单值参数(不是数组)它有效,但不适用于数组。如果我调试Values,我只会看到controll

c# - 这段代码怎么可能: "ArgumentOutOfRangeException: startIndex cannot be larger than length of string"?

我的C#代码中有以下方法://////Removesthefirst(leftmost)occurenceofafroma.//////Thestringtoremovethefrom.Cannotbenull.///Thesubstringtolookforandremovefromthe.Cannotbenull.//////Therestofthe,afterthefirst(leftmost)occurenceoftheinit(ifany)hasbeenremoved.////////////Ifthedoesnotoccurwithinthe,theisreturnedin

c# - Entity Framework : field of composite key cannot be nullable?

我有一个带有复合键的模型-行是键:publicclassItem{[Key,Column(Order=0)]publicintUserId{get;set;}[Key,Column(Order=1)]publicDateTime?Date{get;set;}}运行下面的代码会抛出异常DbEntityValidationException消息:TheDatefieldisrequired.:varit=newItem{Date=null,UserId=2};m_Entities.Items.Add(it);m_Entities.SaveChanges();//throwsexceptio

c# - 如何用像 C# 这样好的但多继承截肢的语言解决 "Must be MarshalByRefObject"?

如何在像C#这样的多继承截断语言中解决“必须是MarshalByRefObject”?问题很简单,在某些情况下你只需要继承这个类(基础设施要求)。在这里真的无关紧要,哪种情况。那么,如果您已经从其他类(您的域模型要求)继承了该类,您会怎么做?顺便说一句,好的应用程序框架,如spring.net,总是确保您不必继承此类,无论您需要将哪种基础架构应用于您的类。我想知道为什么我在这里得到-3票??:) 最佳答案 一般来说,如果您要在远程处理/WCF上下文中使用它,您只想创建一个对象MarshalByRef。这通常是一种足够特殊的情况,不会

c# - 无效的 URI : The hostname could not be parsed

我正在尝试构造一个URI。但是我无法处理错误的URI。有什么方法可以处理错误的URI?我正在使用的代码:if(reviews[e.Item.ItemIndex].URL.ToString().Contains("http:")){oURI=newUri(reviews[e.Item.ItemIndex].URL.ToString());}else{oURI=newUri("http://"+reviews[e.Item.ItemIndex].URL.ToString());}else部分因错误的URI而出错。谢谢! 最佳答案 调用U

JavaScript 样式/优化 : String. indexOf() v. Regex.test()

我最近遇到了这段JavaScript代码:if(",>=,,".indexOf(","+sCompOp+",")!=-1)我很感兴趣,因为要编写这个测试我会这样做:if(/(>=|)/.test(sCompOp))这只是风格上的差异,还是其他代码的作者了解一些我不知道的优化知识?或者也许有不同的充分理由这样做,或者不使用正则表达式......?在我看来,为此使用String.indexOf()有点难以阅读(但是,我对正则表达式很满意),但是有没有实例可能比编写等效的正则表达式“更好”?通过可能更快或更有效的“更好”(尽管显然这取决于浏览器的JavaScript引擎)或其他一些我不知道的

javascript - typescript 错误 : A 'super' call must be the first statement in the constructor when a class contains initialized properties

我的项目中有以下typescript错误..让我分享一下一个示例,以便您了解正在处理的内容。moduleCoreWeb{exportclassControllerimplementsIController{public$q;public$rootScope;public$scope:ng.IScope;public$state:ng.ui.IStateService;public$translate:ng.translate.ITranslateService;publicappEvents;publiccommonValidationsService;publicdefaultPag