当前位置: 首页>>代码示例>>C#>>正文


C# Mocks.DynamicMock类代码示例

本文整理汇总了C#中NUnit.Mocks.DynamicMock的典型用法代码示例。如果您正苦于以下问题:C# DynamicMock类的具体用法?C# DynamicMock怎么用?C# DynamicMock使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DynamicMock类属于NUnit.Mocks命名空间,在下文中一共展示了DynamicMock类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestEnterImportStateWithExclusiveLockedFile

		public void TestEnterImportStateWithExclusiveLockedFile()
		{
			try
			{
				m_stateMachine = new DynamicMock(typeof(IStateMachine));

				ImportState import = new ImportState();
				import.StateMachine = (IStateMachine)m_stateMachine.MockInstance;

				string exclusivelyLockedFilePath = Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\XMLPolicyStore.Tests\TestFiles\Sample\en.csv");
				Assert.IsTrue(File.Exists(exclusivelyLockedFilePath), "The file should exist on disk.");

				XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance;
				IPolicyLanguageStore policyLanguageStore = catalogueStore.LanguageStore;
				string xmlLang = System.IO.File.ReadAllText(Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\XMLPolicyStore.Tests\TestFiles\Sample\Languages\SamplePolicy.Language.xml"));
				Guid guid = policyLanguageStore.AddLanguage(xmlLang);

				import.FileName = exclusivelyLockedFilePath;

				//open the file with no sharing permissions (as if the file was open in another editor)
				using (FileStream fs = new FileStream(exclusivelyLockedFilePath, FileMode.Open, FileAccess.ReadWrite, FileShare.None))
				{
					import.Enter();
				}

				Assert.IsFalse(String.IsNullOrEmpty(import.ErrorMessage), "After entering the import state, DoImport should have caught (and failed gracefully) with an error message, because the file was exclusively locked");
			}
			finally
			{
				PolicyLanguageCache.Instance.Reset();
				XmlPolicyLanguageStore.Instance.Reset();
			}
		}
开发者ID:killbug2004,项目名称:WSProf,代码行数:33,代码来源:TestImportState.cs

示例2: testStrategy

        public void testStrategy()
        {
            FastIDSet itemIDsFromUser123 = new FastIDSet();
            itemIDsFromUser123.Add(1L);

            FastIDSet itemIDsFromUser456 = new FastIDSet();
            itemIDsFromUser456.Add(1L);
            itemIDsFromUser456.Add(2L);

            List<IPreference> prefs = new List<IPreference>();
            prefs.Add(new GenericPreference(123L, 1L, 1.0f));
            prefs.Add(new GenericPreference(456L, 1L, 1.0f));
            IPreferenceArray preferencesForItem1 = new GenericItemPreferenceArray(prefs);

            var dataModelMock = new DynamicMock(typeof(IDataModel));
            dataModelMock.ExpectAndReturn("GetPreferencesForItem", preferencesForItem1,  (1L));
            dataModelMock.ExpectAndReturn("GetItemIDsFromUser", itemIDsFromUser123, (123L));
            dataModelMock.ExpectAndReturn("GetItemIDsFromUser", itemIDsFromUser456, (456L));

            IPreferenceArray prefArrayOfUser123 =
            new GenericUserPreferenceArray( new List<IPreference>() {new GenericPreference(123L, 1L, 1.0f)} );

            ICandidateItemsStrategy strategy = new PreferredItemsNeighborhoodCandidateItemsStrategy();

            //EasyMock.replay(dataModel);

            FastIDSet candidateItems = strategy.GetCandidateItems(123L, prefArrayOfUser123, (IDataModel)dataModelMock.MockInstance);
            Assert.AreEqual(1, candidateItems.Count());
            Assert.True(candidateItems.Contains(2L));

            dataModelMock.Verify(); //  EasyMock.verify(dataModel);
        }
开发者ID:techmobstudios,项目名称:Certified-Mixtapes-Recommender,代码行数:32,代码来源:PreferredItemsNeighborhoodCandidateItemsStrategyTest.cs

示例3: TestImportWithEmptyFile

        public void TestImportWithEmptyFile()
        {
            try
            {
                m_stateMachine = new DynamicMock(typeof(IStateMachine));

                ImportState import = new ImportState();
                import.StateMachine = (IStateMachine)m_stateMachine.MockInstance;

                string pathToEmptyFile = Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\Projects\Hygiene\src\TestDocuments\empty.csv");
                Assert.IsTrue(File.Exists(pathToEmptyFile), "The file should exist on disk.");

                XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance;
                IPolicyLanguageStore policyLanguageStore = catalogueStore.LanguageStore;
                string xmlLang = System.IO.File.ReadAllText(Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\XMLPolicyStore.Tests\TestFiles\Sample\Languages\SamplePolicy.Language.xml"));
                Guid guid = policyLanguageStore.AddLanguage(xmlLang);

                import.FileName = pathToEmptyFile;

                Assert.IsTrue(string.IsNullOrEmpty(import.ErrorMessage), "set up failure - already an error message on the import state");
                import.Enter();
                Assert.AreEqual(Properties.Resources.INVALID_CSV_FILE, import.ErrorMessage, "Unexpected error message on the import state");
            }
            finally
            {
                PolicyLanguageCache.Instance.Reset();
                XmlPolicyLanguageStore.Instance.Reset();
            }
        }
开发者ID:killbug2004,项目名称:WSProf,代码行数:29,代码来源:TestImportState.cs

示例4: testStrategy

        public void testStrategy()
        {
            FastIDSet allItemIDs = new FastIDSet();
            allItemIDs.AddAll(new long[] { 1L, 2L, 3L });

            FastIDSet preferredItemIDs = new FastIDSet(1);
            preferredItemIDs.Add(2L);

            var dataModelMock = new DynamicMock( typeof( IDataModel ));
            dataModelMock.ExpectAndReturn("GetNumItems", 3);
            dataModelMock.ExpectAndReturn("GetItemIDs", allItemIDs.GetEnumerator());

            IPreferenceArray prefArrayOfUser123 = new GenericUserPreferenceArray( new List<IPreference>() {
            new GenericPreference(123L, 2L, 1.0f) } );

            ICandidateItemsStrategy strategy = new AllUnknownItemsCandidateItemsStrategy();

            //EasyMock.replay(dataModel);

            FastIDSet candidateItems = strategy.GetCandidateItems(123L, prefArrayOfUser123, (IDataModel)dataModelMock.MockInstance);
            Assert.AreEqual(2, candidateItems.Count() );
            Assert.True(candidateItems.Contains(1L));
            Assert.True(candidateItems.Contains(3L));

            dataModelMock.Verify();
            //EasyMock.verify(dataModel);
        }
开发者ID:techmobstudios,项目名称:Certified-Mixtapes-Recommender,代码行数:27,代码来源:AllUnknownItemsCandidateItemsStrategyTest.cs

示例5: SetUp

 public void SetUp ()
 {
     mock1 = new DynamicMock (typeof (IMessage));
     msg1 = (IMessage) mock1.MockInstance;
     mock2 = new DynamicMock (typeof (IMessage));
     msg2 = (IMessage) mock2.MockInstance;
 }
开发者ID:nlhepler,项目名称:mono,代码行数:7,代码来源:BinaryMessageFormatterTest.cs

示例6: SetUpCurrentVersion

		void SetUpCurrentVersion(long version, List<long> appliedVersions, bool assertRollbackIsCalled, bool includeBad)
		{
			var providerMock = new DynamicMock(typeof (ITransformationProvider));

			providerMock.SetReturnValue("get_MaxVersion", version);
			providerMock.SetReturnValue("get_AppliedMigrations", appliedVersions);
			providerMock.SetReturnValue("get_Logger", new Logger(false));
			if (assertRollbackIsCalled)
				providerMock.Expect("Rollback");
			else
				providerMock.ExpectNoCall("Rollback");

			_migrator = new Migrator((ITransformationProvider) providerMock.MockInstance, Assembly.GetExecutingAssembly(), false);

			// Enlève toutes les migrations trouvée automatiquement
			_migrator.MigrationsTypes.Clear();
			_upCalled.Clear();
			_downCalled.Clear();

			_migrator.MigrationsTypes.Add(typeof (FirstMigration));
			_migrator.MigrationsTypes.Add(typeof (SecondMigration));
			_migrator.MigrationsTypes.Add(typeof (ThirdMigration));
			_migrator.MigrationsTypes.Add(typeof (FourthMigration));
			_migrator.MigrationsTypes.Add(typeof (SixthMigration));

			if (includeBad)
				_migrator.MigrationsTypes.Add(typeof (BadMigration));
		}
开发者ID:CALUMO,项目名称:Migrator.NET,代码行数:28,代码来源:MigratorTestDates.cs

示例7: TestDirty

        public void TestDirty()
        {
            Document dm = new Document();
            Assert.IsFalse(dm.Dirty);

            dm.Text = "abc";
            Assert.IsTrue(dm.Dirty);

            dm.FileName = @"c:\abc.wordo";
            DynamicMock fs = new DynamicMock(typeof (IFileSystem));
            dm.Save((IFileSystem)fs.MockInstance);

            Assert.IsFalse(dm.Dirty);

            dm.Text = "abc2";

            Assert.IsTrue(dm.Dirty);

            dm.Save((IFileSystem)fs.MockInstance);

            Assert.IsFalse(dm.Dirty);

            fs.ExpectAndReturn("ReadAllText", "abc3", @"c:\abc.wordo");

            dm.Load((IFileSystem)fs.MockInstance);

            Assert.AreEqual("abc3", dm.Text);
            Assert.IsFalse(dm.Dirty);
        }
开发者ID:alfar,项目名称:WordBuilder,代码行数:29,代码来源:DocumentTest.cs

示例8: SetUp

        public void SetUp()
        {
            _mock = new DynamicMock(typeof(IErrorListRenderer));

            _list = new TestingErrorList((IErrorListRenderer)_mock.MockInstance);

            _trace1 = 
                "à SomeClass.SomeMethod() dans C:\\folder\\file1.cs:ligne 20\r\n" +
                "à ExternClass.ExternMethod()\r\n" +
                "à AnotherExternClass.AnotherExternMethod()\r\n" +
                "à SomeClass2.SomeMethod2() dans C:\\folder\\file2.cs:ligne 42\r\n" +
                "à SomeClass3.SomeMethod3() dans C:\\folder\\AnotherFile2.cs:ligne 93\r\n";

            _trace2 =
                "à SomeClass.SomeMethod() dans C:\\folder\\file1.cs:ligne 20\r\n" +
                "à ExternClass.ExternMethod()\r\n" +
                "à AnotherExternClass.AnotherExternMethod()\r\n" +
                "à SomeClass2.SomeMethod2() dans C:\\folder\\file2.cs:ligne 42\r\n";

            _selectionNotification = false;

            _list.SelectedItemChanged += new EventHandler(_list_SelectedItemChanged);

            return;
        }
开发者ID:Vernathic,项目名称:ic-AutoTest.NET4CTDD,代码行数:25,代码来源:TestErrorList.cs

示例9: ShouldUseFindsByNameToLocateElementsByName

        public void ShouldUseFindsByNameToLocateElementsByName()
        {
            DynamicMock driver = new DynamicMock(typeof(IAllDriver));

            driver.Expect("FindElementByName", new object[] { "cheese" });

            By by = By.Name("cheese");
            by.FindElement(driver.MockInstance as IAllDriver);
        }
开发者ID:v4viveksharma90,项目名称:selenium,代码行数:9,代码来源:ByTest.cs

示例10: Setup

 public void Setup() {
     subTrigger1Mock = new DynamicMock(typeof(ITrigger));
     subTrigger2Mock = new DynamicMock(typeof(ITrigger));
     subTrigger1 = (ITrigger)subTrigger1Mock.MockInstance;
     subTrigger2 = (ITrigger)subTrigger2Mock.MockInstance;
     trigger = new MultipleTrigger();
     trigger.FirstTrigger = subTrigger1;
     trigger.SecondTrigger = subTrigger2;  
 }
开发者ID:abc-software,项目名称:abc.processor,代码行数:9,代码来源:MultipleTriggerTest.cs

示例11: NewMockIErrorRenderer

        public static DynamicMock NewMockIErrorRenderer(string name, int hashcode)
        {
            DynamicMock res;

            res = new DynamicMock(name, typeof(IErrorDisplay));
            res.SetReturnValue("Equals", true);
            res.SetReturnValue("GetHashCode", hashcode);

            return (res);
        }
开发者ID:Phaiax,项目名称:dotnetautoupdate,代码行数:10,代码来源:MockHelper.cs

示例12: SearchParameters_With_No_SelectedFilters_Return_Only_Actives_And_Visibles

        public void SearchParameters_With_No_SelectedFilters_Return_Only_Actives_And_Visibles()
        {
            var searchParameterMock = new DynamicMock(typeof(ISearchParameters<Publication>));
            searchParameterMock.SetReturnValue("get_SelectedFilters", null);

            var solrQueryBuilder = new SolrQueryBuilder<Publication>((ISearchParameters<Publication>)searchParameterMock.MockInstance);
            var query = solrQueryBuilder.BuildQuery();

            Assert.IsTrue(query.Query.Equals("publication_state_id:Active AND publication_visible:true"));
        }
开发者ID:pampero,项目名称:cgFramework,代码行数:10,代码来源:SolrQueryBuilderTest.cs

示例13: IsLoginOK_WhenCalled_WritesToLog

        public void IsLoginOK_WhenCalled_WritesToLog()
        {
            DynamicMock mockLog = new DynamicMock(typeof(ILogger));
            mockLog.Expect("Write","login ok: user: u");

            var loginManager = new LoginManagerWithMock((ILogger)mockLog.MockInstance);
            loginManager.IsLoginOK("", "");

            mockLog.Verify();
        }
开发者ID:royosherove,项目名称:tddnetcoursedemos,代码行数:10,代码来源:1_LoginManagerTestsDemoNUnitMocks.cs

示例14: GetProvincesWithoutResult

        public void GetProvincesWithoutResult()
        {
            DynamicMock dynamicMock = new DynamicMock(typeof(LocationsManager));
            dynamicMock.SetReturnValue("GetProvinces",new List<Province>());

            LocationsManager locationsManager = (LocationsManager)dynamicMock.MockInstance;
            LocationServices locationServices = new LocationServices(locationsManager);

            Assert.AreEqual(0,locationServices.GetProvinces().Count);
        }
开发者ID:aelhadi,项目名称:opencbs,代码行数:10,代码来源:TestLocationsServices.cs

示例15: ShouldUseXPathToFindByNameIfDriverDoesNotImplementFindsByName

        // TODO (jimevan): This test is disabled in the Java implementation unit tests.
        // Is the functionality not implemented?
        public void ShouldUseXPathToFindByNameIfDriverDoesNotImplementFindsByName()
        {
            DynamicMock driver = new DynamicMock(typeof(IOnlyXPath));

            driver.Expect("FindElementByXPath", new object[] { "//*[@name='cheese']" });

            By by = By.Name("cheese");

            by.FindElement(driver.MockInstance as IOnlyXPath);
        }
开发者ID:v4viveksharma90,项目名称:selenium,代码行数:12,代码来源:ByTest.cs


注:本文中的NUnit.Mocks.DynamicMock类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。