Пример #1
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Creates a simulated range selection
		/// </summary>
		/// <param name="hvoPara1"></param>
		/// <param name="hvoPara2"></param>
		/// <param name="ichAnchor"></param>
		/// <param name="ichEnd"></param>
		/// ------------------------------------------------------------------------------------
		public void SetupSelectionForParas(int hvoPara1, int hvoPara2, int ichAnchor, int ichEnd)
		{
			CheckDisposed();

			DynamicMock fakeSelHelper = new DynamicMock(typeof(SelectionHelper));
			fakeSelHelper.SetupResult("NumberOfLevels", 1);
			SelLevInfo[] topInfo = new SelLevInfo[1];
			topInfo[0].tag = StTextTags.kflidParagraphs;
			topInfo[0].hvo = hvoPara1;
			SelLevInfo[] bottomInfo = new SelLevInfo[1];
			bottomInfo[0].tag = StTextTags.kflidParagraphs;
			bottomInfo[0].hvo = hvoPara2;
			fakeSelHelper.SetupResult("LevelInfo", topInfo);
			fakeSelHelper.SetupResult("IchAnchor", ichAnchor);
			fakeSelHelper.SetupResult("IchEnd", ichEnd);
			fakeSelHelper.SetupResultForParams("GetLevelInfo", topInfo,
				SelectionHelper.SelLimitType.Top);
			fakeSelHelper.SetupResultForParams("GetLevelInfo", topInfo,
				SelectionHelper.SelLimitType.Anchor);
			fakeSelHelper.SetupResultForParams("GetLevelInfo", bottomInfo,
				SelectionHelper.SelLimitType.Bottom);
			fakeSelHelper.SetupResultForParams("GetLevelInfo", bottomInfo,
				SelectionHelper.SelLimitType.End);
			fakeSelHelper.SetupResultForParams("GetIch", ichAnchor,
				SelectionHelper.SelLimitType.Top);
			fakeSelHelper.SetupResultForParams("GetIch", ichEnd,
				SelectionHelper.SelLimitType.Bottom);
			m_currentSelection = (SelectionHelper)fakeSelHelper.MockInstance;
		}
		public void ShouldReturnBuildPluginLinksRelevantToThisProject()
		{
			DynamicMock buildPluginMock1 = new DynamicMock(typeof (IBuildPlugin));
			DynamicMock buildPluginMock2 = new DynamicMock(typeof (IBuildPlugin));
			DynamicMock buildPluginMock3 = new DynamicMock(typeof (IBuildPlugin));
			buildPluginMock1.SetupResult("LinkDescription", "Description 1");
			buildPluginMock1.SetupResult("NamedActions", new INamedAction[] {action1});
			buildPluginMock1.SetupResult("IsDisplayedForProject", true, typeof(IProjectSpecifier));
			buildPluginMock2.SetupResult("LinkDescription", "Description 2");
			buildPluginMock2.SetupResult("NamedActions", new INamedAction[] {action2});
			buildPluginMock2.SetupResult("IsDisplayedForProject", true, typeof(IProjectSpecifier));
			buildPluginMock3.SetupResult("IsDisplayedForProject", false, typeof(IProjectSpecifier));

			configurationMock.ExpectAndReturn("BuildPlugins", new IBuildPlugin[]
				{
					(IBuildPlugin) buildPluginMock1.MockInstance, (IBuildPlugin) buildPluginMock2.MockInstance, (IBuildPlugin) buildPluginMock3.MockInstance
				});
			linkFactoryMock.ExpectAndReturn("CreateBuildLink", link1, buildSpecifier, "Description 1", "Action Name 1");
			linkFactoryMock.ExpectAndReturn("CreateBuildLink", link2, buildSpecifier, "Description 2", "Action Name 2");

			IAbsoluteLink[] buildLinks = Plugins.GetBuildPluginLinks(buildSpecifier);

			Assert.AreSame(link1, buildLinks[0]);
			Assert.AreSame(link2, buildLinks[1]);
			Assert.AreEqual(2, buildLinks.Length);
			VerifyAll();
		}
Пример #3
0
		public void NextIsRaining()
		{
			IMock random = new DynamicMock(typeof(System.Random));
			WeatherRandom weather = new DefaultWeatherRandom((System.Random)random.MockInstance);

			random.SetupResult("NextDouble", 0.0);
			Assertion.Assert("is raining", weather.NextIsRaining());

			random.SetupResult("NextDouble", DefaultWeatherRandom.CHANCE_OF_RAIN);
			Assertion.Assert("is not raining", !weather.NextIsRaining());

			random.SetupResult("NextDouble", 1.0);
			Assertion.Assert("is not raining", !weather.NextIsRaining());
		}
		public void Setup()
		{
            ProjectStatusOnServer server = new ProjectStatusOnServer(new ProjectStatus("myProject", IntegrationStatus.Success, DateTime.Now),
                new DefaultServerSpecifier("myServer"));
            ProjectStatusListAndExceptions statusList = new ProjectStatusListAndExceptions(
                new ProjectStatusOnServer[] {
                    server
                }, new CruiseServerException[] {
                });

			farmServiceMock = new DynamicMock(typeof(IFarmService));
            farmServiceMock.SetupResult("GetProjectStatusListAndCaptureExceptions", statusList, typeof(IServerSpecifier), typeof(string));
			viewGeneratorMock = new DynamicMock(typeof(IVelocityViewGenerator));
			linkFactoryMock = new DynamicMock(typeof(ILinkFactory));
            ServerLocation serverConfig = new ServerLocation();
            serverConfig.ServerName = "myServer";
            configuration.Servers = new ServerLocation[] {
                serverConfig
            };
            var urlBuilderMock = new DynamicMock(typeof(ICruiseUrlBuilder));
            urlBuilderMock.SetupResult("BuildProjectUrl", string.Empty, typeof(string), typeof(IProjectSpecifier));

			plugin = new ProjectReportProjectPlugin((IFarmService) farmServiceMock.MockInstance,
				(IVelocityViewGenerator) viewGeneratorMock.MockInstance,
				(ILinkFactory) linkFactoryMock.MockInstance,
                configuration,
                (ICruiseUrlBuilder)urlBuilderMock.MockInstance);

			cruiseRequestMock = new DynamicMock(typeof(ICruiseRequest));
			cruiseRequest = (ICruiseRequest ) cruiseRequestMock.MockInstance;

		}
		public void ShouldUseBuildLogTransformerToGenerateView()
		{
			DynamicMock buildLogTransformerMock = new DynamicMock(typeof(IBuildLogTransformer));
			DynamicMock cruiseRequestMock = new DynamicMock(typeof(ICruiseRequest));
			DynamicMock buildSpecifierMock = new DynamicMock(typeof(IBuildSpecifier));
			DynamicMock requestStub = new DynamicMock(typeof(IRequest));

			ICruiseRequest cruiseRequest = (ICruiseRequest) cruiseRequestMock.MockInstance;
			IBuildSpecifier buildSpecifier = (IBuildSpecifier) buildSpecifierMock.MockInstance;
			IRequest request = (IRequest) requestStub.MockInstance;

			cruiseRequestMock.ExpectAndReturn("BuildSpecifier", buildSpecifier);
			cruiseRequestMock.SetupResult("Request", request);
			requestStub.SetupResult("ApplicationPath", "myAppPath");
			Hashtable expectedXsltArgs = new Hashtable();
			expectedXsltArgs["applicationPath"] = "myAppPath";
			buildLogTransformerMock.ExpectAndReturn("Transform", "transformed", buildSpecifier, new string[] { @"xsl\myxsl.xsl" }, new HashtableConstraint(expectedXsltArgs), null);

			XslReportBuildAction action = new XslReportBuildAction((IBuildLogTransformer) buildLogTransformerMock.MockInstance, null);
			action.XslFileName = @"xsl\myxsl.xsl";

			Assert.AreEqual("transformed", ((HtmlFragmentResponse)action.Execute(cruiseRequest)).ResponseFragment);

			buildLogTransformerMock.Verify();
			cruiseRequestMock.Verify();
			buildSpecifierMock.Verify();
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Setup the selection in footnote.
		/// </summary>
		/// <param name="footnote">The footnote.</param>
		/// <param name="book">The book.</param>
		/// <param name="iBook">The 0-based index of the book.</param>
		/// <param name="ichStart">The 0-based starting character index.</param>
		/// <param name="ichEnd">The 0-based ending character index.</param>
		/// ------------------------------------------------------------------------------------
		public void SetupSelectionInFootnote(IStFootnote footnote, IScrBook book,
			int iBook, int ichStart, int ichEnd)
		{
			CheckDisposed();

			DynamicMock fakeSelHelper = new DynamicMock(typeof(SelectionHelper));
			fakeSelHelper.SetupResult("GetTextPropId", StTxtParaTags.kflidContents, typeof(SelectionHelper.SelLimitType));
			fakeSelHelper.SetupResult("NumberOfLevels", 3);
			// Setup the anchor
			SelLevInfo[] topInfo = new SelLevInfo[3];
			IStTxtPara para = footnote[0];
			topInfo[0].tag = StTextTags.kflidParagraphs;
			topInfo[0].ihvo = 0;	// only one para per footnote allowed
			topInfo[0].hvo = para.Hvo;

			topInfo[1].tag = ScrBookTags.kflidFootnotes;
			topInfo[1].ihvo = footnote.IndexInOwner;
			topInfo[1].hvo = footnote.Hvo;

			topInfo[2].tag = BookFilter.Tag;
			topInfo[2].ihvo = iBook;
			topInfo[2].hvo = book.Hvo;

			// Setup the end
			SelLevInfo[] bottomInfo = new SelLevInfo[3];
			for(int i = 0; i < 3; i++)
				bottomInfo[i] = topInfo[i];

			fakeSelHelper.SetupResult("LevelInfo", topInfo);
			fakeSelHelper.SetupResult("IchAnchor", ichStart);
			fakeSelHelper.SetupResult("IchEnd", ichEnd);
			fakeSelHelper.SetupResultForParams("GetLevelInfo", topInfo,
				SelectionHelper.SelLimitType.Top);
			fakeSelHelper.SetupResultForParams("GetLevelInfo", topInfo,
				SelectionHelper.SelLimitType.Anchor);
			fakeSelHelper.SetupResultForParams("GetLevelInfo", bottomInfo,
				SelectionHelper.SelLimitType.Bottom);
			fakeSelHelper.SetupResultForParams("GetLevelInfo", bottomInfo,
				SelectionHelper.SelLimitType.End);
			fakeSelHelper.SetupResultForParams("GetIch", ichStart,
				SelectionHelper.SelLimitType.Top);
			fakeSelHelper.SetupResultForParams("GetIch", ichEnd,
				SelectionHelper.SelLimitType.Bottom);
			m_currentSelection = (SelectionHelper)fakeSelHelper.MockInstance;
		}
Пример #7
0
        [Test] public void IncorrectParameterConstraintMessage()
        {
            try
            {
                IMock Constraint = new DynamicMock(typeof(IConstraint));
                Constraint.SetupResult("Message", "wee woo");
                Constraint.SetupResult("Eval", false, typeof(object));

                mock.Expect("x", new IsAnything(), (IConstraint)Constraint.MockInstance);
                mock.Invoke("x", "hello", "world");
                Assertion.Fail("Expected VerifyException");
            }
            catch (VerifyException e)
            {
                Assertion.AssertEquals("x() called with incorrect parameter (2)", e.Reason);
                Assertion.AssertEquals("wee woo", e.Expected);
                Assertion.AssertEquals("world", e.Actual);
            }
        }
		public void Setup()
		{
			viewBuilderMock = new DynamicMock(typeof(IDeleteProjectViewBuilder));
			farmServiceMock = new DynamicMock(typeof(IFarmService));
			doDeleteProjectAction = new DoDeleteProjectAction((IDeleteProjectViewBuilder) viewBuilderMock.MockInstance, (IFarmService) farmServiceMock.MockInstance);

			cruiseRequestMock = new DynamicMock(typeof(ICruiseRequest));
			cruiseRequest = (ICruiseRequest) cruiseRequestMock.MockInstance;
			requestMock = new DynamicMock(typeof(IRequest));
			cruiseRequestMock.SetupResult("Request", requestMock.MockInstance);
		}
		public void SetUp()
		{
			mockProjectMonitor = new DynamicMock(typeof (IProjectMonitor));
			mockProjectMonitor.Strict = true;
			projectMonitor = (IProjectMonitor) mockProjectMonitor.MockInstance;

			mockConfiguration = new DynamicMock(typeof (ICCTrayMultiConfiguration));
			configuration = (ICCTrayMultiConfiguration) mockConfiguration.MockInstance;
            
            ISingleServerMonitor[] serverMonitors = new ISingleServerMonitor[0];
            mockConfiguration.SetupResult("GetServerMonitors", serverMonitors);
            mockConfiguration.SetupResult("GetProjectStatusMonitors", new IProjectMonitor[0], typeof(ISingleServerMonitor[]));
			mockConfiguration.SetupResult("Icons", new Icons());
            mockConfiguration.SetupResult("FixUserName", "John");
            GrowlConfiguration growlConfig = new GrowlConfiguration();
            mockConfiguration.SetupResult("Growl", growlConfig);            

			eventCount = 0;

			controller = new MainFormController(configuration, null, null);
		}
Пример #10
0
        [Test] public void StubbedMethodsCanBeCalledByOtherMethodsWithinObject()
        {
            DynamicMock mock = new DynamicMock(typeof(SameClass));

            mock.Ignore("A");
            mock.Ignore("c");
            SameClass sc = (SameClass)mock.MockInstance;

            mock.SetupResult("b", "hello");

            Assertion.AssertEquals("hello", sc.A());
        }
Пример #11
0
        public void MethodThatNeedsCastedReturnValue()
        {
            DynamicMock mock = new DynamicMock(typeof(ClassWithCastedReturnValue));

            short[] expectedResult = new short[] { 10 };
            mock.SetupResult("Method", expectedResult);

            ClassWithCastedReturnValue obj = (ClassWithCastedReturnValue)mock.MockInstance;

            short[] ret = (short[])obj.Method();

            Assertion.AssertEquals(expectedResult, ret);
        }
Пример #12
0
        [Test] public void SetAndGetPropertiesDoesNotWorkWithSetupReturn()
        {
            DynamicMock   mock         = new DynamicMock(typeof(IWithProperty));
            IWithProperty withProperty = (IWithProperty)mock.MockInstance;

            mock.SetupResult("Name", "fred");
            mock.Expect("Name", "jim");

            AssertEquals("Should be property Name", "fred", withProperty.Name);
            withProperty.Name = "jim";

            mock.Verify();
        }
        public void SetUp()
        {
            _authenticationMock = new DynamicMock(typeof(IAuthentication));
            _authenticationMock.SetupResult("Identifier", "johndoe");
            _sessionMock = new DynamicMock(typeof(ISessionCache));

            _manager = new SessionSecurityManager();
            _manager.Settings = new IAuthentication[]{
                _authenticationMock.MockInstance as IAuthentication
            };
            _manager.SessionCache = _sessionMock.MockInstance as ISessionCache;
            _manager.Initialise();
        }
Пример #14
0
        [Test] public void CanSetStubsAndExpectationsOnMethodsInTheSameClass()
        {
            DynamicMock mock = new DynamicMock(typeof(SameClass));

            mock.Ignore("A");
            SameClass sc = (SameClass)mock.MockInstance;

            mock.ExpectAndReturn("c", true);
            mock.SetupResult("b", "hello");

            AssertEquals("Should have overriden B()", "hello", sc.A());

            mock.Verify();
        }
        public void ShouldAddQuotesToStringFromVersionAssemblyProviderForFingerprintFromDate()
        {
            string testETag = "test e tag value";
            DateTime testDate = new DateTime(2007, 4, 20);
            DynamicMock mockVersionProvider = new DynamicMock(typeof(IVersionProvider));
            mockVersionProvider.SetupResult("GetVersion", testETag);

            ConditionalGetFingerprint testConditionalGetFingerprint =
                new FingerprintFactory((IVersionProvider) mockVersionProvider.MockInstance, null).BuildFromDate(testDate);
                

            string expectedETag = "\"" + testETag + "\"";
            Assert.AreEqual(expectedETag, testConditionalGetFingerprint.ETag);
        }
Пример #16
0
        public void MethodWithOutParamsFixedCall()
        {
            DynamicMock mock = new DynamicMock(typeof(IWithOutParam));

            mock.SetupResult("MethodWithOutParam", null, new string[] { "System.String", "System.Int32&" },
                             new object[] { null, 4711 });

            int           ret = 0;
            IWithOutParam obj = (IWithOutParam)mock.MockInstance;

            obj.MethodWithOutParam("a", out ret);
            Assertion.AssertEquals(4711, ret);
            obj.MethodWithOutParam("a", out ret);
            Assertion.AssertEquals(4711, ret);
        }
        public void Setup()
        {
            Teardown();
            Directory.CreateDirectory("testtemplates");
            using (var writer = new StreamWriter(@"testtemplates\testtemplate.vm"))
            {
                writer.Write("foo is $foo");
                writer.Flush();
                writer.Close();
            }

            configurationMock = new DynamicMock(typeof (IConfigureTheTransformer));
            configurationMock.SetupResult("TemplateDirectory", "testtemplates");
            viewTransformer =
                new LazilyInitialisingVelocityTransformer((IConfigureTheTransformer) configurationMock.MockInstance);
        }
		public void ShouldUseVelocityToMergeContextContentsWithTemplate()
		{
			Hashtable contextContents = new Hashtable();
			contextContents["foo"] = "bar";

			DynamicMock pathMapperMock = new DynamicMock(typeof(IPhysicalApplicationPathProvider));
			pathMapperMock.SetupResult("GetFullPathFor", Path.Combine(".", "templates"), typeof (string));

            DynamicMock pluginsMock = new DynamicMock(typeof(IPluginConfiguration));
            pluginsMock.SetupResult("TemplateLocation", null);

            DynamicMock configurationMock = new DynamicMock(typeof(IDashboardConfiguration));
            configurationMock.SetupResult("PluginConfiguration", pluginsMock.MockInstance);

            viewTransformer = new LazilyInitialisingVelocityTransformer((IPhysicalApplicationPathProvider)pathMapperMock.MockInstance,
                (IDashboardConfiguration)configurationMock.MockInstance);

			Assert.AreEqual("foo is bar", viewTransformer.Transform("testTransform.vm", contextContents));
		}
		public override void FixtureSetup()
		{
			base.FixtureSetup();

			string intType = "System.Int32";
			string intRef = intType + "&";
			string boolType = typeof(bool).FullName;
			string boolRef = boolType + "&";

			m_TextSelInfoArgs_anchor = new object[] { true, null, null, null, null, null, null };
			m_TextSelInfoArgs_end = new object[] { false, null, null, null, null, null, null };
			m_TextSelInfoTypes =
				new string[] { boolType, "SIL.FieldWorks.Common.COMInterfaces.ITsString&", intRef,
							 boolRef, intRef, intRef, intRef};

			m_selHelper = new DynamicMock(typeof(SelectionHelper));
			m_selHelper.Strict = true;
			m_selHelper.SetupResult("RestoreSelectionAndScrollPos", true);
			SelectionHelper.s_mockedSelectionHelper = (SelectionHelper)m_selHelper.MockInstance;
		}
Пример #20
0
        public void ReuseGeneratedAssembly()
        {
            DynamicMock mock = new DynamicMock(typeof(SameClass));

            mock.Ignore("A");
            mock.Ignore("c");
            SameClass sc = (SameClass)mock.MockInstance;

            mock.SetupResult("b", "hello");
            Assertion.AssertEquals("hello", sc.A());

            mock = new DynamicMock(typeof(SameClass));
            mock.Ignore("A");
            sc = (SameClass)mock.MockInstance;

            mock.ExpectAndReturn("c", true);
            mock.SetupResult("b", "hello");

            AssertEquals("Should have overriden B()", "hello", sc.A());
            mock.Verify();
        }
        public void CreatesAClientWithGivenClientNameIfSpecified()
        {
            // Setup
            DynamicMock p4Mock = new DynamicMock(typeof(P4));
            P4 p4 = (P4) p4Mock.MockInstance;
            p4.Client = "myClient";

            p4Mock.SetupResult("ViewForSpecifications", new string[] { "//mydepot/...", "//myotherdepot/..." });

            ProcessInfo processInfo = new ProcessInfo("createclient");
            ProcessInfo processInfoWithStdInContent = new ProcessInfo("createclient");
            processInfoWithStdInContent.StandardInputContent = "Client: myClient\n\nRoot:   c:\\my\\working\\dir\n\nView:\n //mydepot/... //myClient/mydepot/...\n //myotherdepot/... //myClient/myotherdepot/...\n";

            processInfoCreatorMock.ExpectAndReturn("CreateProcessInfo", processInfo, p4, "client -i");
            processExecutorMock.ExpectAndReturn("Execute", new ProcessResult("", "", 0, false), processInfoWithStdInContent);

            // Execute
            p4Initializer.Initialize(p4, "myProject", @"c:\my\working\dir");

            // Verify
            p4Mock.Verify();
            VerifyAll();
        }
Пример #22
0
		public void InsertFootnote_DisabledWhenSelectionRange()
		{
			CheckDisposed();

			m_mainWnd.m_mockedBookFilter.SetupResult("BookCount", 1);
			m_mainWnd.m_mockedEditingHelper.SetupResult("IsBackTranslation", false);
			m_mainWnd.m_mockedEditingHelper.SetupResult("IsPictureSelected", false);

			DynamicMock pete = new DynamicMock(typeof(IVwSelection));
			pete.SetupResult("IsRange", true);

			DynamicMock george = new DynamicMock(typeof(SelectionHelper));
			george.SetupResult("Selection", pete.MockInstance);
			m_mainWnd.m_mockedEditingHelper.SetupResult("CurrentSelection",george.MockInstance);

			Assert.IsTrue(m_mainWnd.OnUpdateInsertFootnoteDialog(m_dummyItemProps));
			Assert.IsFalse(m_dummyItemProps.Enabled, "Insert Footnote should be disabled.");
		}
Пример #23
0
		public void InsertChapterNumber_EnabledInScripture()
		{
			CheckDisposed();

			DynamicMock sel = new DynamicMock(typeof(IVwSelection));
			DynamicMock selHelper = new DynamicMock(typeof(SelectionHelper));
			selHelper.SetupResult("Selection", sel.MockInstance);
			m_mainWnd.m_mockedEditingHelper.SetupResult("CurrentSelection", selHelper.MockInstance);
			m_mainWnd.m_mockedEditingHelper.SetupResult("IsPictureSelected", false);
			m_mainWnd.m_mockedEditingHelper.SetupResult("CanInsertNumberInElement", true);
			m_mainWnd.m_mockedBookFilter.SetupResult("BookCount", 3);
			m_mainWnd.m_mockedEditingHelper.SetupResult("IsBackTranslation", false);
			m_mainWnd.m_mockedEditingHelper.SetupResult("CanInsertChapterNumber", true);

			Assert.IsTrue(m_mainWnd.OnUpdateInsertChapterNumber(m_dummyItemProps));

			Assert.IsTrue(m_dummyItemProps.Enabled,
				"Insert Chapter should be enabled when in Scripture text.");
		}
Пример #24
0
		public void UpdateGoToSubItems_EnabledWhenRequiredSelectionIsPresent()
		{
			CheckDisposed();

			m_mainWnd.m_mockedBookFilter.SetupResult("BookCount", 1);
			DynamicMock sel = new DynamicMock(typeof(IVwSelection));
			DynamicMock selHelper = new DynamicMock(typeof(SelectionHelper));
			SelLevInfo[] levInfo = new SelLevInfo[1];
			selHelper.SetupResult("LevelInfo", levInfo);

			selHelper.SetupResult("Selection", sel.MockInstance);
			m_mainWnd.m_mockedEditingHelper.SetupResult("CurrentSelection", selHelper.MockInstance);

			Assert.IsTrue(m_mainWnd.UpdateGoToSubItems(m_dummyItemProps, true));

			Assert.IsTrue(m_dummyItemProps.Enabled,
				"Go to Prev/Next subitem should be enabled when there is a selection.");
		}
Пример #25
0
		public void ReuseGeneratedAssembly()
		{
			DynamicMock mock = new DynamicMock(typeof(SameClass));
			mock.Ignore("A");
			mock.Ignore("c");
			SameClass sc = (SameClass)mock.MockInstance;

			mock.SetupResult("b", "hello");
			Assertion.AssertEquals("hello", sc.A());

			mock = new DynamicMock(typeof(SameClass));
			mock.Ignore("A");
			sc = (SameClass)mock.MockInstance;

			mock.ExpectAndReturn("c", true);
			mock.SetupResult("b", "hello");

			AssertEquals("Should have overriden B()", "hello", sc.A());
			mock.Verify();
		}
Пример #26
0
		public void MethodWithOutParamsFixedCall()
		{
			DynamicMock mock = new DynamicMock(typeof(IWithOutParam));

			mock.SetupResult("MethodWithOutParam", null, new string[] { "System.String", "System.Int32&" },
				new object[] { null, 4711 } );

			int ret = 0;
			IWithOutParam obj = (IWithOutParam)mock.MockInstance;
			obj.MethodWithOutParam("a", out ret);
			Assertion.AssertEquals(4711, ret);
			obj.MethodWithOutParam("a", out ret);
			Assertion.AssertEquals(4711, ret);
		}
Пример #27
0
		public void MethodThatNeedsCastedReturnValue()
		{
			DynamicMock mock = new DynamicMock(typeof(ClassWithCastedReturnValue));

			short[] expectedResult = new short[] { 10 };
			mock.SetupResult("Method", expectedResult);

			ClassWithCastedReturnValue obj = (ClassWithCastedReturnValue)mock.MockInstance;
			short[] ret = (short[])obj.Method();

			Assertion.AssertEquals(expectedResult, ret);
		}
Пример #28
0
		[Test] public void SetAndGetPropertiesDoesNotWorkWithSetupReturn()
		{
			DynamicMock mock = new DynamicMock(typeof(IWithProperty));
			IWithProperty withProperty = (IWithProperty)mock.MockInstance;

			mock.SetupResult("Name", "fred");
			mock.Expect("Name", "jim");

			AssertEquals("Should be property Name", "fred", withProperty.Name);
			withProperty.Name = "jim";

			mock.Verify();
		}
Пример #29
0
		[Test] public void CanSetStubsAndExpectationsOnMethodsInTheSameClass()
		{
			DynamicMock mock = new DynamicMock(typeof(SameClass));
			mock.Ignore("A");
			SameClass sc = (SameClass)mock.MockInstance;

			mock.ExpectAndReturn("c", true);
			mock.SetupResult("b", "hello");

			AssertEquals("Should have overriden B()", "hello", sc.A());

			mock.Verify();
		}
Пример #30
0
		[Test] public void StubbedMethodsCanBeCalledByOtherMethodsWithinObject()
		{
			DynamicMock mock = new DynamicMock(typeof(SameClass));
			mock.Ignore("A");
			mock.Ignore("c");
			SameClass sc = (SameClass)mock.MockInstance;

			mock.SetupResult("b", "hello");

			Assertion.AssertEquals("hello", sc.A());
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Sets up expected values for mocked back translation selection etc.
		/// </summary>
		/// <param name="nInsertVerseNumbersCalled">Number of times InsertVerseNumber gets
		/// called in the test.</param>
		/// <param name="hvoTrans"></param>
		/// <returns>Mock selection</returns>
		/// ------------------------------------------------------------------------------------
		private DynamicMock SetupMockedBtSelection(int nInsertVerseNumbersCalled, int hvoTrans)
		{
			DynamicMock sel = new DynamicMock(typeof(IVwSelection));
			sel.Strict = true;
			sel.SetupResult("SelType", VwSelType.kstText);
			sel.SetupResult("IsValid", true);

			m_selHelper.ExpectAndReturn(nInsertVerseNumbersCalled, "ReduceSelectionToIp",
				m_selHelper.MockInstance, SelectionHelper.SelLimitType.Top, false, true);

			ITsPropsBldr builder = TsPropsBldrClass.Create();
			ITsTextProps selProps = builder.GetTextProps();
			for (int i = 0; i < nInsertVerseNumbersCalled; i++)
			{
				m_selHelper.ExpectAndReturn("SelProps", selProps);
				m_selHelper.ExpectAndReturn("SetSelection", sel.MockInstance, true);
				m_selHelper.Expect(3, "AssocPrev", true); // 1
				m_selHelper.Expect("SetSelection", true);
			}
			m_selHelper.SetupResult("Selection", sel.MockInstance);

			m_selHelper.SetupResult("AssocPrev", true);
			m_selHelper.Expect("SetIPAfterUOW");

			return sel;
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Initializes the VwSelection mock and adds it as result of the
		/// SelectionHelper.Selection property.
		/// </summary>
		/// <param name="selHelper">The sel helper mock.</param>
		/// ------------------------------------------------------------------------------------
		public static void InitializeVwSelection(DynamicMock selHelper)
		{
			string[] kLocationArgs = new string[]{typeof(IVwGraphics).FullName,
				typeof(Rect).FullName, typeof(Rect).FullName, typeof(Rect).FullName + "&",
				typeof(Rect).FullName + "&", typeof(bool).FullName + "&", typeof(bool).FullName + "&"};

			DynamicMock sel = new DynamicMock(typeof(IVwSelection));
			sel.Strict = false;
			sel.SetupResult("SelType", VwSelType.kstText);
			sel.SetupResult("IsValid", true);
			sel.SetupResult("IsRange", false);
			sel.SetupResult("Location", null, kLocationArgs,
				new object[]{null, null, null, new Rect(10, 10, 10, 10),
					new Rect(0, 0, 0, 0), false, false });
			selHelper.SetupResult("Selection", sel.MockInstance);
		}
Пример #33
0
		public void MultiMessageSynchronize_IdenticalMessages()
		{
			CheckDisposed();

			m_mainWnd.ExpectAndReturn("PreSynchronize", true, new IsAnything());
			m_mainWnd.ExpectAndReturn("Synchronize", true, new IsAnything());
			m_app.MainWindows.Add((IFwMainWnd)m_mainWnd.MockInstance);

			DynamicMock otherMainWnd = new DynamicMock(typeof(IFwMainWnd));
			otherMainWnd.SetupResult("Cache", Cache);
			otherMainWnd.ExpectAndReturn("PreSynchronize", true, new IsAnything());
			otherMainWnd.ExpectAndReturn("Synchronize", true, new IsAnything());
			m_app.MainWindows.Add((IFwMainWnd)otherMainWnd.MockInstance);

			m_app.SuppressSynchronize(Cache);
			// we expect that the identical message will be discarded
			m_app.Synchronize(new SyncInfo(SyncMsg.ksyncUndoRedo, 0, 0), Cache);
			m_app.Synchronize(new SyncInfo(SyncMsg.ksyncUndoRedo, 0, 0), Cache);

			// This should call (Pre)Synchronize only once on each window
			m_app.ResumeSynchronize(Cache);

			m_mainWnd.Verify();
			otherMainWnd.Verify();
		}
Пример #34
0
		public void SetUp()
		{
			CheckDisposed();

			m_inMemoryCache = InMemoryFdoCache.CreateInMemoryFdoCache();
			m_mainWnd = new DynamicMock(typeof(IFwMainWnd));
			m_mainWnd.SetupResult("Cache", Cache);
			m_app = new DummyFwApp();
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Setup the mock rootbox
		/// </summary>
		/// <returns></returns>
		/// ------------------------------------------------------------------------------------
		private IVwRootBox SetupRootBox()
		{
			m_rootBox = new DynamicMock(typeof(IVwRootBox));
			m_rootBox.SetupResult("SetSite", null, typeof(IVwRootSite));
			m_rootBox.SetupResult("DataAccess", Cache.DomainDataByFlid);
			m_rootBox.SetupResult("SetRootObject", null, typeof(int), typeof(IVwViewConstructor),
				typeof(int), typeof(IVwStylesheet));
			m_rootBox.SetupResult("Height", 200); // JT: arbitrary values.
			m_rootBox.SetupResult("Width", 200);
			m_rootBox.SetupResult("Site", m_btView);
			m_rootBox.Ignore("Close");
			m_rootBox.Ignore("FlashInsertionPoint");
			m_rootBox.SetupResult("GetRootObject", null,
				new string[] { typeof(int).FullName + "&", typeof(IVwViewConstructor).FullName + "&", typeof(int).FullName + "&", typeof(IVwStylesheet).FullName + "&" },
				new object[] { 0, null, 0, null });

			return (IVwRootBox)m_rootBox.MockInstance;
		}
Пример #36
0
		public void MultiMessageSynchronize_DifferentCache()
		{
			CheckDisposed();

			m_mainWnd.ExpectAndReturn("PreSynchronize", true, new IsAnything());
			m_mainWnd.ExpectAndReturn("Synchronize", true, new IsAnything());
			m_app.MainWindows.Add((IFwMainWnd)m_mainWnd.MockInstance);

			InMemoryFdoCache differentCache = InMemoryFdoCache.CreateInMemoryFdoCache();
			try
			{
				DynamicMock otherMainWnd = new DynamicMock(typeof(IFwMainWnd));
				otherMainWnd.SetupResult("Cache", differentCache.Cache);
				otherMainWnd.ExpectAndReturn("PreSynchronize", true, new IsAnything());
				otherMainWnd.ExpectAndReturn("Synchronize", true, new IsAnything());
				m_app.MainWindows.Add((IFwMainWnd)otherMainWnd.MockInstance);

				m_app.SuppressSynchronize(Cache);
				m_app.Synchronize(new SyncInfo(SyncMsg.ksyncUndoRedo, 0, 0), Cache);
				m_app.Synchronize(new SyncInfo(SyncMsg.ksyncUndoRedo, 0, 0), differentCache.Cache);

				// This should call (Pre)Synchronize once for each main window
				m_app.ResumeSynchronize(Cache);

				m_mainWnd.Verify();
				otherMainWnd.Verify();
			}
			finally
			{
				differentCache.Dispose();
			}
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Setup the mock graphics object
		/// </summary>
		/// <returns></returns>
		/// ------------------------------------------------------------------------------------
		private IVwGraphics SetupGraphics()
		{
			//			m_vwGraphics = new DynamicMock(typeof(IVwGraphics));
			// JT: following three statements replace the one above, following the exmple
			// Eberhard set in InsertChapterNumberTests.
			m_vwGraphics = new DynamicMock(typeof(IVwGraphics), "MockIVwGraphics",
				typeof(DummyGraphics));
			m_vwGraphics.AdditionalReferences = new string[] { "TeDllTests.dll" };
			m_vwGraphics.Strict = true;
			m_vwGraphics.SetupResult("XUnitsPerInch", 96);
			m_vwGraphics.SetupResult("YUnitsPerInch", 96);

			return (IVwGraphics)m_vwGraphics.MockInstance;
		}