Beispiel #1
0
        public void OneLinerChild_RoutedCorrectly()
        {
            var mr  = new MockRepository();
            var sut = new SemContextStub();
            var expectedChildContext = MockRepository.GenerateStub <IAttributeContext>();

            sut.AttributeContextFactory = () => expectedChildContext;
            var sectionContext = mr.StrictMock <ISemanticContext>();

            sectionContext.Expect(sc => sc.FinishItem());
            var itemContext = mr.StrictMock <ISemanticContext>();

            itemContext.Expect(i => i.OnFinished += null).IgnoreArguments();

            sectionContext.Expect(sc => sc.PushLine(0, null, null, null))
            .Constraints(Is.Equal(0), Is.Same(null), Is.Equal("mykey"), Is.Anything())
            .Return(itemContext);
            sut.S1Func = _ => sectionContext;

            mr.ReplayAll();
            var result = sut.PushLine(0, "!s1", "mykey", new AhlAttribute[0]);

            Assert.AreSame(itemContext, result);
            itemContext.GetEventRaiser(i => i.OnFinished += null).Raise(itemContext, EventArgs.Empty);
            mr.VerifyAll();
        }
        public void a_call_to_ForEachOf_should_pass_the_correct_models_to_each_render_call()
        {
            var model2 = new PartialTestModel();
            var model3 = new PartialTestModel();

            _model.PartialModelArray = new[] { _partialModel, model2, model3 };

            _renderer.Expect(r => r.Render((IFubuPage)null, _partialModel, "PartialModelArray")).Return("test").Constraints(
                Is.Anything(),
                Is.Same(_partialModel),
                Is.NotNull(),
                Is.Anything());

            _renderer.Expect(r => r.Render((IFubuPage)null, model2, "PartialModelArray")).Return("").Constraints(
                Is.Anything(),
                Is.Same(model2),
                Is.NotNull(),
                Is.Anything());

            _renderer.Expect(r => r.Render((IFubuPage)null, model3, "PartialModelArray")).Return("").Constraints(
                Is.Anything(),
                Is.Same(model3),
                Is.NotNull(),
                Is.Anything());

            _expression.ForEachOf(m => m.PartialModelArray).ToString();

            _renderer.VerifyAllExpectations();
        }
        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));
            });
        }
        protected override void beforeEach()
        {
            theSettings = new ApplicationSettings();

            MockFor <IApplicationSourceFinder>().Stub(x => x.FindSource(null, null))
            .Constraints(Is.Same(theSettings),
                         Is.TypeOf <ApplicationStartResponse>())
            .Return(null);


            theResponse = ClassUnderTest.StartApplication(theSettings, null);
        }
        /// <summary>
        /// Ensures, that all interface methods delegate to Write() with correct level + arguments
        /// and that arguments are still not evaluated up to this point (e.g. calling ToString())
        /// </summary>
        private static void WriteIsCalledWithCorrectLogLevel(string levelName)
        {
            MockRepository mocks = new MockRepository();

            AbstractTestLogger    log           = (AbstractTestLogger)mocks.PartialMock(typeof(AbstractTestLogger));
            Exception             ex            = (Exception)mocks.StrictMock(typeof(Exception));
            object                messageObject = mocks.StrictMock(typeof(object));
            object                formatArg     = mocks.StrictMock(typeof(object));
            FormatMessageCallback failCallback  = TestFormatMessageCallback.FailCallback();

            MethodInfo[] logMethods = GetLogMethodSignatures(levelName);

            LogLevel logLevel = (LogLevel)Enum.Parse(typeof(LogLevel), levelName);

            using (mocks.Ordered())
            {
                log.Log(logLevel, null, null);
                LastCall.Constraints(Is.Equal(logLevel), Is.Anything(), Is.Null());
                log.Log(logLevel, null, ex);
                LastCall.Constraints(Is.Equal(logLevel), Is.Anything(), Is.Same(ex));
                log.Log(logLevel, null, null);
                LastCall.Constraints(Is.Equal(logLevel), Is.Anything(), Is.Null());
                log.Log(logLevel, null, ex);
                LastCall.Constraints(Is.Equal(logLevel), Is.Anything(), Is.Same(ex));
                log.Log(logLevel, null, null);
                LastCall.Constraints(Is.Equal(logLevel), Is.Anything(), Is.Null());
                log.Log(logLevel, null, ex);
                LastCall.Constraints(Is.Equal(logLevel), Is.Anything(), Is.Same(ex));
                log.Log(logLevel, null, null);
                LastCall.Constraints(Is.Equal(logLevel), Is.Anything(), Is.Null());
                log.Log(logLevel, null, ex);
                LastCall.Constraints(Is.Equal(logLevel), Is.Anything(), Is.Same(ex));
                log.Log(logLevel, null, null);
                LastCall.Constraints(Is.Equal(logLevel), Is.Anything(), Is.Null());
                log.Log(logLevel, null, ex);
                LastCall.Constraints(Is.Equal(logLevel), Is.Anything(), Is.Same(ex));
            }
            mocks.ReplayAll();

            Invoke(log, logMethods[0], messageObject);
            Invoke(log, logMethods[1], messageObject, ex);
            Invoke(log, logMethods[2], "format", new object[] { formatArg });
            Invoke(log, logMethods[3], "format", ex, new object[] { formatArg });
            Invoke(log, logMethods[4], CultureInfo.InvariantCulture, "format", new object[] { formatArg });
            Invoke(log, logMethods[5], CultureInfo.InvariantCulture, "format", ex, new object[] { formatArg });
            Invoke(log, logMethods[6], failCallback);
            Invoke(log, logMethods[7], failCallback, ex);
            Invoke(log, logMethods[8], CultureInfo.InvariantCulture, failCallback);
            Invoke(log, logMethods[9], CultureInfo.InvariantCulture, failCallback, ex);

            mocks.VerifyAll();
        }
        protected override void beforeEach()
        {
            theSettings = new ApplicationSettings();
            theSource   = MockFor <IApplicationSource>();
            theReset    = new ManualResetEvent(true);

            Services.PartialMockTheClassUnderTest();
            ClassUnderTest.Expect(x => x.StartApplication(theSource, theSettings, theReset));

            MockFor <IApplicationSourceFinder>().Stub(x => x.FindSource(null, null))
            .Constraints(Is.Same(theSettings),
                         Is.TypeOf <ApplicationStartResponse>())
            .Return(theSource);


            theResponse = ClassUnderTest.StartApplication(theSettings, theReset);
        }
Beispiel #7
0
        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( );
        }
Beispiel #8
0
        public void ShouldAddToContextGenericTypeNotPreviouslyAdded()
        {
            var objectFactory = mocks.PartialMock <BaseObjectFactory>();

            objectFactory.Expect("AddToContext")
            .Callback((Lemming l) => l.ConcreteType == typeof(GenericService <int>))
            .Repeat.Once();

            objectFactory.Expect("AddToContext")
            .Callback((Lemming l) => l.ConcreteType != typeof(GenericService <int>))
            .Repeat.Any();

            objectFactory.Expect("FindObjectByType")
            .Constraints(Is.Same(typeof(GenericService <int>)))
            .Return(null)
            .Repeat.Once();

            objectFactory.Expect("FindObjectByType")
            .Constraints(Is.Same(typeof(GenericService <int>)))
            .Return(new GenericService <int>())
            .Repeat.Once();

            mocks.DynamicMock <IoCContainer>();
            iocContainer.Expect(x => x.GetObjectFactory()).Return(objectFactory).Repeat.Any();

            mocks.ReplayAll();

            Nails.Configure()
            .IoC.Container(iocContainer)
            .Lemming(typeof(GenericService <>))
            .Initialize(configureDefaults: false);

            objectFactory.GetObject <GenericService <int> >();

            objectFactory.VerifyAllExpectations();
        }
Beispiel #9
0
        protected override void beforeEach()
        {
            theCache = new StubOutputCache(MockFor <IRecordedOutput>())
            {
                CacheHits = false
            };
            Services.Inject <IOutputCache>(theCache);


            theDescription = new Dictionary <string, string>();
            MockFor <IResourceHash>().Stub(x => x.Describe()).Return(theDescription);
            MockFor <IResourceHash>().Stub(x => x.CreateHash())
            .Return(theResource);


            theLogger = MockFor <ILogger>();
            Services.Inject <ILogger>(new InteractionContextLogger(theLogger));

            Services.PartialMockTheClassUnderTest();
            theGeneratedOutput = new RecordedOutput(null);



            ClassUnderTest.Expect(x => x.CreateOutput(theResource, null)).Constraints(Is.Same(theResource), Is.Anything())
            .Return(theGeneratedOutput);



            ClassUnderTest.Inner = MockFor <IActionBehavior>();
            ClassUnderTest.Invoke();
        }
Beispiel #10
0
        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();
        }
        public void TestRender_Works()
        {
            var tpl = mocks.StrictMock <ITemplate>();
            var ctl = mocks.StrictMock <IInstantiatedTemplateControl>();
            var f1  = mocks.StrictMock <IFragment>();
            var f2  = mocks.StrictMock <IFragment>();

            Expect.Call(f1.TryMergeWithNext(f2)).Return(null);
            Expect.Call(() => f1.Render(null, null, null)).IgnoreArguments().Constraints(Is.Same(tpl), Is.Same(ctl), Is.NotNull()).Do((Action <ITemplate, IInstantiatedTemplateControl, StringBuilder>)((_, __, sb) => sb.Append("[a]")));
            Expect.Call(() => f2.Render(null, null, null)).IgnoreArguments().Constraints(Is.Same(tpl), Is.Same(ctl), Is.NotNull()).Do((Action <ITemplate, IInstantiatedTemplateControl, StringBuilder>)((_, __, sb) => sb.Append("[b]")));
            mocks.ReplayAll();
            var m = new RenderFunctionMember("Test", "");

            m.AddFragment(f1);
            m.AddFragment(f2);
            Assert.AreEqual("[a][b]", m.Render(tpl, ctl));
            mocks.VerifyAll();
        }
        private void TestTryProcess_DefFragmentWorks(bool hasParams)
        {
            XmlNode node = Globals.GetXmlNode("<def-fragment name=\"FragName\"" + (hasParams ? " params=\"some param\"" : "") + "><x/><y/></def-fragment>");
            RenderFunctionMember innerFunction = null;

            using (mocks.Ordered()) {
                Expect.Call(template.HasMember("FragName")).Return(false);
                Expect.Call(() => docProcessor.ProcessRecursive(null, null, null)).IgnoreArguments().Constraints(Is.Same(node.ChildNodes[0]), Is.Same(template), Is.NotSame(renderFunction)).Do((Action <XmlNode, ITemplate, IRenderFunction>)((_, __, x) => { innerFunction = (RenderFunctionMember)x; x.AddFragment(new LiteralFragment("[a]")); }));
                Expect.Call(() => docProcessor.ProcessRecursive(null, null, null)).IgnoreArguments().Constraints(Is.Same(node.ChildNodes[1]), Is.Same(template), Is.NotNull()).Do((Action <XmlNode, ITemplate, IRenderFunction>)((_, __, x) => { Assert.AreSame(innerFunction, x); x.AddFragment(new LiteralFragment("[b]")); }));
                Expect.Call(template.HasMember("FragName")).Return(false);
                Expect.Call(() => template.AddMember(null)).IgnoreArguments().Do((Action <IMember>)(m => Assert.AreSame(innerFunction, m)));
            }
            mocks.ReplayAll();
            Assert.IsTrue(new FunctionDefinitionAndCallNodeProcessor().TryProcess(docProcessor, node, false, template, innerFunction));

            Assert.AreEqual("FragName", innerFunction.Name);
            Assert.AreEqual(hasParams ? "some param" : "", innerFunction.Parameters);
            Assert.IsTrue(new[] { new LiteralFragment("[a]"), new LiteralFragment("[b]") }.SequenceEqual(innerFunction.Fragments));
            Assert.AreEqual(0, fragments.Count);
            mocks.VerifyAll();
        }
Beispiel #13
0
 public void Removing(object sender, DomainObject domainObject)
 {
     Removing(null, (DomainObjectCollectionChangeEventArgs)null);
     LastCall.Constraints(Mocks_Is.Same(sender), Mocks_Property.Value("DomainObject", domainObject));
 }