public void VerifyTransactionClosedDoomedFalse() { ITranEvSink mock = mockRepository.CreateMock <ITranEvSink>(); Expect.Call(() => mock.Handle(null, null)) .Constraints(RhinoIs.Null(), RhinoIs.Matching <TransactionClosedEventArgs>(args => args.IsDoomed == false)); GlobalTransactionManager.TransactionClosed += mock.Handle; ExecuteAtTheEndOfTest(() => GlobalTransactionManager.TransactionClosed -= mock.Handle); mockRepository.ReplayAll(); GlobalTransactionManager.BeginTransaction().Dispose(); }
public void should_serialize_the_envelope() { theSerializer.AssertWasCalled(x => x.Serialize(null, theNode), x => { x.Constraints(Is.Matching <Envelope>(o => { o.CorrelationId.ShouldBe(theEnvelope.CorrelationId); o.ShouldNotBeTheSameAs(theEnvelope); return(true); }), Is.Same(theNode)); }); }
public void VerifyTransactionClosingDoomedTrue() { ITranEvSink mock = mockRepository.CreateMock <ITranEvSink>(); Expect.Call(() => mock.Handle(null, null)) .Constraints(RhinoIs.Null(), RhinoIs.Matching <TransactionClosingEventArgs>(args => args.IsDoomed == true)); GlobalTransactionManager.TransactionClosing += mock.Handle; ExecuteAtTheEndOfTest(() => GlobalTransactionManager.TransactionClosing -= mock.Handle); mockRepository.ReplayAll(); using (GlobalTransactionManager.BeginTransaction()) { GlobalTransactionManager.DoomCurrentTransaction(); } }
private void ExpectLine(int lineNumber, int indent, string keyword, string key, params AhlAttribute[] ahlAttributes) { _parsingContext.Expect(c => c.PushLine(lineNumber, indent, keyword, key, ahlAttributes)) .IgnoreArguments() .Constraints( Is.Equal(lineNumber), Is.Equal(indent), Is.Equal(keyword), Is.Equal(key), Is.Matching <List <AhlAttribute> >(list => { CollectionAssert.AreEqual(ahlAttributes, list, new AhlAttributeComparer()); return(true); })); }
public void TestThatAddedElementAlwaysRaiseEvent() { BindingListExt <Customer> sut = CreateBindingListOnBasicCustomersList(); IBindingListEventSink mock = mockRepository.CreateMock <IBindingListEventSink>(); sut.AddingNew += mock.HandleAdded; Customer cust = new Customer() { Name = "Mark Fields", Age = 28 }; Expect.Call(() => mock.HandleAdded(sut, null)) .Constraints(RhinoIs.Equal(sut), RhinoIs.Matching <AddingNewEventArgs>(args => args.NewObject == cust)) .Repeat.Once(); mockRepository.ReplayAll(); sut.Filter = "Name == 'Alkampfer'"; sut.Add(cust); }
private void AddPushLine(int line, int indent, string keyword, string key, params AhlAttribute[] ahlAttributes) { var plo = new PushLineObject(line, indent, keyword, key, ahlAttributes); _semanticContext.Expect(sc => sc.PushLine(line, keyword, key, ahlAttributes)) .IgnoreArguments() .Constraints( Is.Equal(line), Is.Equal(keyword), Is.Equal(key), Is.Matching <List <AhlAttribute> >(list => { CollectionAssert.AreEqual(ahlAttributes, list, new AhlAttributeComparer()); return(true); })) .Return(_semanticContext); _scheduledPushLines.Add(plo); }
public void StoreDocument( ) { MockRepository mocks = new MockRepository( ); IIndexConnector conn = mocks.StrictMock <IIndexConnector>( ); IDocument doc = mocks.StrictMock <IDocument>( ); const string dummyState = "state"; const string content = "This is some test content."; const string title = "My Document"; Expect.Call(doc.Title).Return(title).Repeat.AtLeastOnce( ); Expect.Call(doc.Tokenize(content)).Return(Tools.Tokenize(content, WordLocation.Content)); Expect.Call(doc.Tokenize(title)).Return(Tools.Tokenize(title, WordLocation.Title)); Predicate <WordInfo[]> contentPredicate = array => array.Length == 5 && array[0].Text == "this" && array[1].Text == "is" && array[2].Text == "some" && array[3].Text == "test" && array[4].Text == "content"; Predicate <WordInfo[]> titlePredicate = array => array.Length == 2 && array[0].Text == "my" && array[1].Text == "document"; Predicate <WordInfo[]> keywordsPredicate = array => array.Length == 1 && array[0].Text == "test"; conn.DeleteDataForDocument(doc, dummyState); LastCall.On(conn); Expect.Call(conn.SaveDataForDocument(null, null, null, null, null)).IgnoreArguments( ) .Constraints(Is.Same(doc), Is.Matching(contentPredicate), Is.Matching(titlePredicate), Is.Matching(keywordsPredicate), Is.Same(dummyState)) .Return(8); mocks.ReplayAll( ); SqlIndex index = new SqlIndex(conn); Assert.AreEqual(8, index.StoreDocument(doc, new[] { "test" }, content, dummyState), "Wrong occurrence count"); mocks.VerifyAll( ); }
public void should_debug_log_the_cache_hit() { theLogger.AssertWasCalled(x => x.DebugMessage(new CacheHit()), x => x.Constraints(Is.Matching <CacheHit>(h => h.Description == theDescription))); }
public void TestInstantiate() { var tpl = new Template(); IInstantiatedTemplateControl ctl = null; var m1 = mocks.StrictMock <IMember>(); var m2 = mocks.StrictMock <IMember>(); var container = mocks.StrictMock <IContainer>(); Expect.Call(m1.Name).Return("m1").Repeat.Any(); Expect.Call(m2.Name).Return("m2").Repeat.Any(); Expect.Call(m1.Dependencies).Return(new string[] { }); Expect.Call(m2.Dependencies).Return(new string[] { "m1" }); Expect.Call(() => m1.Instantiate(null, null, container)).IgnoreArguments().Constraints(Is.Same(tpl), Is.NotNull(), Is.Same(container)).Do((Action <ITemplate, IInstantiatedTemplateControl, IContainer>)((_, c, __) => { ctl = c; })); Expect.Call(() => m2.Instantiate(null, null, container)).IgnoreArguments().Constraints(Is.Same(tpl), Is.Matching((IInstantiatedTemplateControl x) => object.ReferenceEquals(x, ctl)), Is.Same(container)); tpl.MainRenderFunction.AddFragment(new LiteralFragment("X")); mocks.ReplayAll(); tpl.AddMember(m1); tpl.AddMember(m2); var actual = tpl.Instantiate(container); Assert.AreSame(ctl, actual); actual.Id = "SomeId"; Assert.AreEqual("X", actual.Html); mocks.VerifyAll(); }
protected override void beforeEach() { thePart = new Part { Name = "something" }; Services.Inject <ISimplePropertyHandler <Part> >(Services.Container.GetInstance <SimplePropertyHandler <Part> >()); var theProperty = ReflectionHelper.GetProperty <Part>(c => c.WarrantyDays); MockFor <IFieldAccessService>().Stub(x => x.RightsFor(thePart, theProperty)).Return(AccessRight.ReadOnly).Constraints(Is.Equal(thePart), Is.Matching <PropertyInfo>(x => x.Name == theProperty.Name)); var update = new UpdatePropertyModel <Part>() { Id = Guid.NewGuid(), PropertyName = "WarrantyDays", PropertyValue = "abc", }; MockFor <IRepository>().Stub(x => x.Find <Part>(update.Id)).Return(thePart); result = ClassUnderTest.EditProperty(update); }
public void TestRender_WorksWithTwoInnerFragments() { var rf1 = mocks.StrictMock <IRenderFunction>(); var rf2 = mocks.StrictMock <IRenderFunction>(); var tpl = mocks.StrictMock <ITemplate>(); var ctl = mocks.StrictMock <IInstantiatedTemplateControl>(); var me = mocks.StrictMock <IControlHost>(); Expect.Call(ctl.Controls).Return(new Dictionary <string, IControl>() { { "CtlId", me } }); Expect.Call(tpl.GetMember("CtlId_inner1")).Return(rf1); Expect.Call(tpl.GetMember("CtlId_inner2")).Return(rf2); Expect.Call(rf1.Render(tpl, ctl)).Return("[x]"); Expect.Call(rf2.Render(tpl, ctl)).Return("[y]"); Expect.Call(() => me.SetInnerFragments(null)).IgnoreArguments().Constraints(Is.Matching <string[]>(x => x.Length == 2 && x[0] == "[x]" && x[1] == "[y]")); Expect.Call(me.Html).Return("[z]"); mocks.ReplayAll(); StringBuilder sb = new StringBuilder(); new InstantiatedControlFragment("CtlId", false, 2).Render(tpl, ctl, sb); Assert.AreEqual("[z]", sb.ToString()); mocks.VerifyAll(); }