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


C# DynamicMock.ExpectAndReturn方法代码示例

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


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

示例1: 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

示例2: 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

示例3: AddEconomicActivityWhenNameAlreadyExist

        public void AddEconomicActivityWhenNameAlreadyExist()
        {
            _dynamicMock = new DynamicMock(typeof(EconomicActivityManager));
            EconomicActivity activity = new EconomicActivity { Name = "Services", Parent = new EconomicActivity { Id = 1 } };

            _dynamicMock.ExpectAndReturn("ThisActivityAlreadyExist", true, "Services", 1);
            _dynamicMock.ExpectAndReturn("AddEconomicActivity", 0, activity);

            _economicActivityManager = (EconomicActivityManager)_dynamicMock.MockInstance;
            _economicActivityServices = new EconomicActivityServices(_economicActivityManager);

            _economicActivityServices.AddEconomicActivity(activity);
        }
开发者ID:aelhadi,项目名称:opencbs,代码行数:13,代码来源:TestEconomicActivityServices.cs

示例4: AddEconomicActivity

        public void AddEconomicActivity()
        {
            _dynamicMock = new DynamicMock(typeof(EconomicActivityManager));
            EconomicActivity activity = new EconomicActivity { Name = "Services",Parent = new EconomicActivity {Id=1}};

            _dynamicMock.ExpectAndReturn("ThisActivityAlreadyExist", false, "Services", 1);
            _dynamicMock.ExpectAndReturn("AddEconomicActivity", 2, activity);

            _economicActivityManager = (EconomicActivityManager)_dynamicMock.MockInstance;
            _economicActivityServices = new EconomicActivityServices(_economicActivityManager);

            activity.Id = _economicActivityServices.AddEconomicActivity(activity);
            Assert.AreEqual(2,activity.Id);
        }
开发者ID:aelhadi,项目名称:opencbs,代码行数:14,代码来源:TestEconomicActivityServices.cs

示例5: 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

示例6: VerifyUserAgent

 public void VerifyUserAgent(string expected)
 {
     var mock = new DynamicMock(typeof(IAndroidJavaClass));
     mock.ExpectAndReturn("CallStatic", "1.0.0", "GetSdkVersion");
     Assert.AreEqual(
         string.Format(
             CultureInfo.InvariantCulture,
             expected,
             FacebookSdkVersion.Build),
         Constants.GraphApiUserAgent);
 }
开发者ID:barkinet,项目名称:facebook-sdk-for-unity,代码行数:11,代码来源:UserAgent.cs

示例7: CanAddTestCaseBuilder

        public void CanAddTestCaseBuilder()
        {
            DynamicMock mock = new DynamicMock( typeof(ITestCaseBuilder) );
            mock.ExpectAndReturn( "CanBuildFrom", true, null );
            mock.Expect( "BuildFrom" );

            IExtensionPoint ep = host.GetExtensionPoint("TestCaseBuilders");
            ep.Install( mock.MockInstance );
            host.TestBuilders.BuildFrom( null );

            mock.Verify();
        }
开发者ID:taoxiease,项目名称:asegrp,代码行数:12,代码来源:CoreExtensionsTests.cs

示例8: preferencesFetchedOnlyOnce

        public void preferencesFetchedOnlyOnce()
        {
            var dataModelMock = new DynamicMock( typeof( IDataModel) );

            var itemSimilarityMock = new DynamicMock( typeof(IItemSimilarity) );
            var candidateItemsStrategyMock = new DynamicMock( typeof (ICandidateItemsStrategy) );
            var mostSimilarItemsCandidateItemsStrategyMock =
            new DynamicMock( typeof(IMostSimilarItemsCandidateItemsStrategy) );

            IPreferenceArray preferencesFromUser = new GenericUserPreferenceArray(
            new List<IPreference>() {new GenericPreference(1L, 1L, 5.0f), new GenericPreference(1L, 2L, 4.0f)});

            dataModelMock.ExpectAndReturn("GetMinPreference", float.NaN);
            dataModelMock.ExpectAndReturn("GetMaxPreference", float.NaN);
            dataModelMock.ExpectAndReturn("GetPreferencesFromUser", preferencesFromUser, 1L);
            var dataModel = (IDataModel)dataModelMock.MockInstance;

            candidateItemsStrategyMock.ExpectAndReturn("GetCandidateItems", new FastIDSet(new long[] { 3L, 4L }),
            1L, preferencesFromUser, dataModel);

            itemSimilarityMock.ExpectAndReturn("ItemSimilarities", new double[] { 0.5, 0.3 },
            3L, preferencesFromUser.GetIDs());
            itemSimilarityMock.ExpectAndReturn("ItemSimilarities", new double[] { 0.4, 0.1 },
            4L, preferencesFromUser.GetIDs());

            //EasyMock.replay(dataModel, itemSimilarity, candidateItemsStrategy, mostSimilarItemsCandidateItemsStrategy);

            IRecommender recommender = new GenericItemBasedRecommender((IDataModel)dataModel,
            (IItemSimilarity)itemSimilarityMock.MockInstance,
            (ICandidateItemsStrategy)candidateItemsStrategyMock.MockInstance,
            (IMostSimilarItemsCandidateItemsStrategy)mostSimilarItemsCandidateItemsStrategyMock.MockInstance);

            recommender.Recommend(1L, 3);

            dataModelMock.Verify();
            itemSimilarityMock.Verify();
            candidateItemsStrategyMock.Verify();
            mostSimilarItemsCandidateItemsStrategyMock.Verify();
            //EasyMock.verify(dataModel, itemSimilarity, candidateItemsStrategy, mostSimilarItemsCandidateItemsStrategy);
        }
开发者ID:nreco,项目名称:recommender,代码行数:40,代码来源:GenericItemBasedRecommenderTest.cs

示例9: TestDeleteCity

        public void TestDeleteCity()
        {
            List<City> cities = new List<City>();
            City city = new City { Name = "New York", DistrictId = 12 };
            DynamicMock dynamicMock = new DynamicMock(typeof(LocationsManager));
            dynamicMock.ExpectAndReturn("AddCity", 3,city);
            dynamicMock.SetReturnValue("GetCities", cities);
            dynamicMock.Expect("DeleteCityById", 2);

            LocationsManager mocklocationManager = (LocationsManager)dynamicMock.MockInstance;
            LocationServices locationService = new LocationServices(mocklocationManager);
            locationService.DeleteCity(2);
            Assert.AreEqual(3, locationService.AddCity(city));
            Assert.AreEqual(0, locationService.GetCities().Count);
        }
开发者ID:aelhadi,项目名称:opencbs,代码行数:15,代码来源:TestLocationsServices.cs

示例10: init

        public void init()
        {
            sourceMock = new DynamicMock(typeof(ISecurity));
            positionMock = new DynamicMock(typeof(IPosition));
            positionListMock = new DynamicMock(typeof(IPositionsList));

            sourceMock.ExpectAndReturn(
                "get_Positions",
                (IPositionsList)positionListMock.MockInstance
            );
            positionListMock.ExpectAndReturn(
                "get_LastPositionClosed",
                (IPosition)positionMock.MockInstance
            );
        }
开发者ID:sherman,项目名称:onTSLab,代码行数:15,代码来源:ProfitPerMonthTest.cs

示例11: TestLoad

        public void TestLoad()
        {
            Document dm = new Document();

            dm.FileName = @"c:\abc.wordo";

            DynamicMock fs = new DynamicMock(typeof (IFileSystem));

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

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

            fs.Verify();

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

示例12: estimatePreference

        public void estimatePreference()
        {
            var dataModelMock = new DynamicMock( typeof( IDataModel) );
            var factorizerMock = new DynamicMock( typeof(IFactorizer) );
            var factorization = new Factorization_estimatePreference_TestMock();

            factorizerMock.ExpectAndReturn("Factorize", factorization);

             //EasyMock.replay(dataModel, factorizer, factorization);

            SVDRecommender svdRecommender = new SVDRecommender( (IDataModel)dataModelMock.MockInstance, (IFactorizer)factorizerMock.MockInstance);

            float estimate = svdRecommender.EstimatePreference(1L, 5L);
            Assert.AreEqual(1, estimate, EPSILON);

            factorizerMock.Verify();
            Assert.AreEqual(1, factorization.getItemFeaturesCallCount );
            Assert.AreEqual(1, factorization.getUserFeaturesCallCount);
            //EasyMock.verify(dataModel, factorizer, factorization);
        }
开发者ID:techmobstudios,项目名称:Certified-Mixtapes-Recommender,代码行数:20,代码来源:SVDRecommenderTest.cs

示例13: recommend

        public void recommend()
        {
            var dataModelMock = new DynamicMock( typeof(IDataModel) );
            var preferencesFromUserMock = new DynamicMock( typeof(IPreferenceArray) );
            var candidateItemsStrategyMock = new DynamicMock( typeof(ICandidateItemsStrategy) );
            var factorizerMock = new DynamicMock( typeof(IFactorizer) );
            var factorization = new Factorization_recommend_TestMock();

            FastIDSet candidateItems = new FastIDSet();
            candidateItems.Add(5L);
            candidateItems.Add(3L);

            factorizerMock.ExpectAndReturn("Factorize", factorization);

            dataModelMock.ExpectAndReturn("GetPreferencesFromUser", preferencesFromUserMock.MockInstance, (1L));

            candidateItemsStrategyMock.ExpectAndReturn("GetCandidateItems", candidateItems,
            1L, preferencesFromUserMock.MockInstance, dataModelMock.MockInstance);

            //EasyMock.replay(dataModel, candidateItemsStrategy, factorizer, factorization);

            SVDRecommender svdRecommender = new SVDRecommender(
            (IDataModel)dataModelMock.MockInstance,
            (IFactorizer)factorizerMock.MockInstance,
            (ICandidateItemsStrategy)candidateItemsStrategyMock.MockInstance);

            IList<IRecommendedItem> recommendedItems = svdRecommender.Recommend(1L, 5);
            Assert.AreEqual(2, recommendedItems.Count);
            Assert.AreEqual(3L, recommendedItems[0].GetItemID());
            Assert.AreEqual(2.0f, recommendedItems[0].GetValue(), EPSILON);
            Assert.AreEqual(5L, recommendedItems[1].GetItemID());
            Assert.AreEqual(1.0f, recommendedItems[1].GetValue(), EPSILON);

            dataModelMock.Verify();
            candidateItemsStrategyMock.Verify();
            factorizerMock.Verify();

            Assert.AreEqual(2, factorization.getItemFeaturesCallCount);
            Assert.AreEqual(2, factorization.getUserFeaturesCallCount);
            //EasyMock.verify(dataModel, candidateItemsStrategy, factorizer, factorization);
        }
开发者ID:techmobstudios,项目名称:Certified-Mixtapes-Recommender,代码行数:41,代码来源:SVDRecommenderTest.cs

示例14: TestPersist

        public void TestPersist()
        {
            //Gateway
            DynamicMock mockGateway = new DynamicMock(typeof(IUserGateway));
            IUserGateway gateway = (IUserGateway) mockGateway.MockInstance;

            //Validator
            DynamicMock mockValidator = new DynamicMock(typeof(IUserValidator));
            IUserValidator validator = (IUserValidator)mockValidator.MockInstance;

            //User
            User user = new User(gateway);

            //Expectations
            mockValidator.ExpectAndReturn("Validate", true, user);
            mockGateway.ExpectAndReturn("Persist", true, user);

            Assert.AreEqual(true, user.Persist(validator));
            mockValidator.Verify();
            mockGateway.Verify();
        }
开发者ID:pweibel,项目名称:DotNetMockingFrameworksDemo,代码行数:21,代码来源:NUnitMockTest.cs

示例15: CreateMockInstance

        /// <summary>
        /// Returns an IXWikiClient mock implementation to be used by unit tests.
        /// </summary>
        /// <returns>An IXWikiClient mock instance.</returns>
        public static IXWikiClient CreateMockInstance()
        {
            DynamicMock xWikiClientMock = new DynamicMock(typeof(IXWikiClient));
            xWikiClientMock.ExpectAndReturn("Login", true, new object[2]);
            xWikiClientMock.ExpectAndReturn("GetAvailableSyntaxes", new List<string>() { "XWiki 2.0", "XHTML" });
            xWikiClientMock.ExpectAndReturn("GetPagesNames", new List<string>() { "Page1" }, new object[1]);
            xWikiClientMock.ExpectAndReturn("SavePageHTML", true, new object[3]);
            xWikiClientMock.ExpectAndReturn("AddAttachment", true, new object[2] { PAGE_FULL_NAME, "localFolder\\Document1_TempExport_files/image002.jpg" });
            xWikiClientMock.ExpectAndReturn("GetAttachmentURL", "http://127.0.0.1:8080/xwiki/bin/download/Main/Page1/image002.jpg", new object[] { PAGE_FULL_NAME, "image002.jpg" });

            SetObjSummariesForGetObjects(ref xWikiClientMock);

            SetObjForGetObject(ref xWikiClientMock);

            return (IXWikiClient)xWikiClientMock.MockInstance;
        }
开发者ID:xwiki-contrib,项目名称:xwiki-office,代码行数:20,代码来源:XWikiClientUtil.cs


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