草庐IT

c# - 起订量参数 TargetParameterCountException : Parameter count mismatch Exception

以下是我的通用基础存储库界面publicinterfaceIRepository{IQueryableAllIncluding(paramsExpression>[]includeProperties);}我的实体publicclassSdk{publicSdk(){this.Identifier=Guid.NewGuid().ToString();}publicvirtualICollectionAccessibleResources{get;set;}publicstringIdentifier{get;set;}}下面是具体的repopublicinterfaceISdkRepo

c# - 是否可以通过模拟/伪造来使丢失的锁导致测试失败?

我正在围绕Dictionary编写一个精简的包装器,该包装器设计为线程安全的。因此,需要一些锁,并且大部分逻辑都是围绕确保事物被正确锁定并以线程安全的方式访问。现在,我正在尝试对其进行单元测试。我想进行单元测试的一件大事是锁定行为,以确保它是正确的。但是,我从来没有在任何地方看到过这样做,所以我不确定该怎么做。另外,我知道我可以只使用一堆线程向墙上扔东西,但是对于这种类型的测试,不能保证它在出错时会失败。这取决于操作系统定义的线程调度行为。有哪些方法可以通过单元测试确保我的锁定行为是正确的? 最佳答案 锁定只是一个实现细节。您应该模

c# - 模拟 IRavenQueryable 并附加 Where() 表达式

我正在尝试为一个新的mvc3项目做一些基本的概念类型代码证明。我们将Moq与RavenDB结合使用。行动:publicActionResultIndex(stringid){varmodel=DocumentSession.Query().Where(f=>f.ResponsibleBusinessId==id);returnView(model);}测试:privatereadonlyFixture_fixture=newFixture();[Test]publicvoidIndex_Action_Returns_List_Of_FinancialTransactions_For_B

c# - 我该如何设置(最小起订量设置)

我想测试返回用户密码问题的代码部分。因此,我使用Moq制作了成员(member)提供程序的模型。我认为我不需要向您展示实际代码,只需要展示它的测试部分。//ArrangevarmembershipMock=newMock();membershipMock.Setup(m=>m.GetUser("test",false).PasswordQuestion).Returns("Password");authentication.Authenticate.Provider=membershipMock.Object;//Actvaractual=authentication.Password

c# - 模拟 IEnumerable<T> 类型的 GetEnumerator() 方法

以下测试用例在rhino模拟中失败:[TestFixture]publicclassEnumeratorTest{[Test]publicvoidShould_be_able_to_use_enumerator_more_than_once(){varnumbers=MockRepository.GenerateStub();numbers.Stub(x=>x.GetEnumerator()).Return(newList{1,2,3}.GetEnumerator());varsut=newObjectThatUsesEnumerator();varcorrectResult=sut.

c# - FakeItEasy 中的 Dummy 有什么用?

FakeItEasy中的Dummy有什么用?它与A.Fake或A.Ignored有何不同?谢谢:-) 最佳答案 FakeItEasy本身并没有真正使用虚拟实例,它只是一种创建可在测试中使用的虚拟实例的方法。例如,假设您要测试以下类:publicclassFoo{publicvoidBar(DateTimesomeDate);}现在,在您的一个测试中,您想要调用bar方法,但是传递给它的值对测试并不重要,而不是这样写:foo.Bar(newDateTime(2000,1,1));你可以这样写:foo.Bar(A.Dummy());这表

c# - 使用 rhino mocks 为每次调用返回不同的实例

我有这个代码:Expect.Call(factory.CreateOrder()).Return(newOrder()).Repeat.Times(4);当它被调用四次时,每次都返回相同的实例。我想要返回不同的实例。我希望能够做类似的事情:Expect.Call(factory.CreateOrder()).Return(()=>newOrder()).Repeat.Times(4);这可以通过某种方式完成吗? 最佳答案 而不是使用.Return(newOrder());尝试使用.Do((Func)delegate(){return

c# - 使用 FakeItEasy,如何获取假属性上设置的值?

使用FakeItEasy,我试图捕获一个假对象的属性值设置:首先是界面:interfaceISomeInterface{intMyProperty{get;set;}}然后是一段单元测试:varmyObject=A.Fake();intsaved=0;A.CallTo(()=>myObject.MyProperty).Invokes(x=>saved=?????);SomeMethod(myObject);Assert.That(saved,Is.EqualTo(100));并且拥有voidSomeMethod(ISomeInterfaceintf){intf.MyProperty=1

c# - stub 类的一个方法,让其他真正的方法使用这个 stub 的方法

我有一个TimeMachine类,它为我提供当前日期/时间值。该类看起来像这样:publicclassTimeMachine{publicvirtualDateTimeGetCurrentDateTime(){returnDateTime.Now;};publicvirtualDateTimeGetCurrentDate(){returnGetCurrentDateTime().Date;};publicvirtualTimeSpanGetCurrentTime(){returnGetCurrentDateTime().TimeOfDay;};}我想在我的测试中使用TimeMachin

c# - 在单元测试中模拟 IMemoryCache

我正在使用aspnetcore1.0和xunit。我正在尝试为一些使用IMemoryCache的代码编写单元测试。但是,每当我尝试在IMemoryCache中设置一个值时,我都会收到Null引用错误。我的单元测试代码是这样的:IMemoryCache被注入(inject)到我要测试的类中。但是,当我尝试在测试中的缓存中设置一个值时,我得到了一个空引用。publicTestGetSystemUnderTest(){varmockCache=newMock();returnnewTest(mockCache.Object);}[Fact]publicvoidTestCache(){vars