• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Mockery类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: FindElementTwoBy

        public void FindElementTwoBy()
        {
            var mocks = new Mockery();
            var driver = mocks.NewMock<IAllDriver>();

            var elem1 = mocks.NewMock<IAllElement>();
            var elem2 = mocks.NewMock<IAllElement>();
            var elem3 = mocks.NewMock<IAllElement>();
            var elems12 = new List<IWebElement> { elem1, elem2 }.AsReadOnly();
            var elems23 = new List<IWebElement> { elem2, elem3 }.AsReadOnly();

            Expect.AtLeastOnce.On(driver).Method("FindElementsByName").With("cheese").Will(Return.Value(elems12));
            Expect.AtLeastOnce.On(driver).Method("FindElementsByName").With("photo").Will(Return.Value(elems23));

            var by = new ByAll(By.Name("cheese"), By.Name("photo"));

            // findElement
            Assert.That(by.FindElement(driver), Is.EqualTo(elem2));

            //findElements
            var result = by.FindElements(driver);
            Assert.That(result.Count, Is.EqualTo(1));
            Assert.That(result[0], Is.EqualTo(elem2));

            mocks.VerifyAllExpectationsHaveBeenMet();
        }
开发者ID:RanchoLi,项目名称:selenium,代码行数:26,代码来源:ByAllTests.cs


示例2: ShouldCreateInstanceWithCacheKeyAndInvokeDynamicFactoryTest

        public void ShouldCreateInstanceWithCacheKeyAndInvokeDynamicFactoryTest()
        {
            Mockery mockery;
            MockProxyFactory factory;
            IMockObject objectContract;
            MockProxyFactory.IInvokeDynamicFactory mockInvokeDynamicFactory;
            IDynamicInvocation mockDynamicInvocation;
            MethodInfo invokedMethodInfo;

            mockery = new Mockery();
            mockDynamicInvocation = mockery.NewMock<IDynamicInvocation>();
            mockInvokeDynamicFactory = mockery.NewMock<MockProxyFactory.IInvokeDynamicFactory>();

            invokedMethodInfo = (MethodInfo)MemberInfoProxy<IDisposable>.GetLastMemberInfo(exec => exec.Dispose());

            Expect.Once.On(mockInvokeDynamicFactory).Method("GetDynamicInvoker").With("myCacheKey", typeof(IMockObject)).Will(Return.Value(mockDynamicInvocation));

            factory = new MockProxyFactory();

            Assert.IsNotNull(factory);

            objectContract = factory.CreateInstance("myCacheKey", mockInvokeDynamicFactory);
            Assert.IsNotNull(objectContract);

            factory.Dispose();

            mockery.VerifyAllExpectationsHaveBeenMet();
        }
开发者ID:sami1971,项目名称:textmetal,代码行数:28,代码来源:ProxyFactoryTests.cs


示例3: StartUp

        public void StartUp()
        {
            Console.WriteLine("StartUp()");
            if (!_setupRun)
            {
                Console.WriteLine("Setting up");


                string rootPath = TestConfig.GetConfig().GetRipleyServerPath();
                BBC.Dna.AppContext.OnDnaStartup(rootPath);

                //Create the mocked inputcontext
                Mockery mock = new Mockery();
                _context = DnaMockery.CreateDatabaseInputContext();

                // Create a mocked site for the context
                ISite mockedSite = DnaMockery.CreateMockedSite(_context, 1, "h2g2", "h2g2", true, "comment");
                Stub.On(_context).GetProperty("CurrentSite").Will(Return.Value(mockedSite));
                Stub.On(mockedSite).GetProperty("ModClassID").Will(Return.Value(1));

                Stub.On(_context).Method("FileCacheGetItem").Will(Return.Value(false));
                Stub.On(_context).Method("FileCachePutItem").Will(Return.Value(false));

                // Initialise the profanities object
                var p = new ProfanityFilter(DnaMockery.CreateDatabaseReaderCreator(), DnaDiagnostics.Default, CacheFactory.GetCacheManager(), null, null);
                BBC.Dna.User user = new BBC.Dna.User(_context);
                Stub.On(_context).GetProperty("ViewingUser").Will(Return.Value(user));
                
                _setupRun = true;
            }
            Console.WriteLine("Finished StartUp()");
        }
开发者ID:rocketeerbkw,项目名称:DNA,代码行数:32,代码来源:ReviewForumTests.cs


示例4: beforTest

 public void beforTest()
 {
     mockery = new Mockery();
     view = mockery.NewMock<ITrackView>();
     dao = mockery.NewMock<ITrackDao>();
     presenter = new TrackPresenter(view, dao);
 }
开发者ID:bjornebjornson,项目名称:Gema2008,代码行数:7,代码来源:TrackPresenter_Fixture.cs


示例5: TestCheckLoadAllowedURLListData

        public void TestCheckLoadAllowedURLListData()
        {
            Console.WriteLine("Before TestCheckLoadAllowedURLListData");

            //Create the mocked inputcontext
            Mockery mock = new Mockery();
            IInputContext mockedInputContext = DnaMockery.CreateDatabaseInputContext();
            //XmlDocument siteconfig = new XmlDocument();
            //siteconfig.LoadXml("<SITECONFIG />");
            ISite site = mock.NewMock<ISite>();
            //Stub.On(site).GetProperty("SiteConfig").Will(Return.Value(siteconfig.FirstChild));
            Stub.On(site).GetProperty("SiteID").Will(Return.Value(1));

            User user = new User(mockedInputContext);
            Stub.On(mockedInputContext).GetProperty("ViewingUser").Will(Return.Value(user));
            Stub.On(mockedInputContext).GetProperty("CurrentSite").Will(Return.Value(site));

            // Create the stored procedure reader for the UITemplate object
            using (IDnaDataReader reader = mockedInputContext.CreateDnaDataReader("getallallowedurls"))
            {
                Stub.On(mockedInputContext).Method("CreateDnaDataReader").With("getallallowedurls").Will(Return.Value(reader));
                AllowedURLs allowedURLs = new AllowedURLs();
                allowedURLs.LoadAllowedURLLists(mockedInputContext);
                Assert.IsTrue(allowedURLs.DoesAllowedURLListContain(1, "www.bbc.co.uk"), "Does not report that it contains the bbc web address");
            }
            Console.WriteLine("After TestCheckLoadAllowedURLListData");
        }
开发者ID:rocketeerbkw,项目名称:DNA,代码行数:27,代码来源:AllowedURLTests.cs


示例6: TestAppstoreShopListParseMechanics

        public void TestAppstoreShopListParseMechanics()
        {
            string xml =
            @"<roar tick=""130695522924"">
                <appstore>
                    <shop_list>
                        <shopitem product_identifier=""someidentifier"" label=""A label"">
                            <modifiers>
                                <grant_item ikey=""item_ikey_1""/>
                                <grant_stat ikey=""item_stat"" type=""some type"" value=""7""/>
                            </modifiers>
                        </shopitem>
                    </shop_list>
                </appstore>
            </roar>";

            System.Xml.XmlElement nn = RoarExtensions.CreateXmlElement(xml);
            Roar.DataConversion.Responses.Appstore.ShopList shop_list_parser = new Roar.DataConversion.Responses.Appstore.ShopList();

            Mockery mockery = new Mockery();
            Roar.DataConversion.IXCRMParser ixcrm_parser = mockery.NewMock<Roar.DataConversion.IXCRMParser>();
            shop_list_parser.ixcrm_parser = ixcrm_parser;
            IList<Roar.DomainObjects.Modifier> modifier_list = new List<Roar.DomainObjects.Modifier>();
            Expect.Once.On(ixcrm_parser).Method("ParseModifierList").With(nn.SelectSingleNode("./appstore/shop_list/shopitem/modifiers")).Will(Return.Value(modifier_list));

            ShopListResponse response = shop_list_parser.Build(nn);

            mockery.VerifyAllExpectationsHaveBeenMet();

            Assert.IsNotNull(response);
            Assert.AreEqual(response.shop_list.Count, 1);
            Assert.AreEqual(response.shop_list[0].product_identifier, "someidentifier");
            Assert.AreEqual(response.shop_list[0].label, "A label");
            Assert.AreEqual(response.shop_list[0].modifiers, modifier_list);
        }
开发者ID:QuiVeeGlobal,项目名称:sdk-unity,代码行数:35,代码来源:XmlToAppstoreText.cs


示例7: SetUp

 public void SetUp()
 {
     mocks = new Mockery();
     mockDriver = mocks.NewMock<ISearchContext>();
     mockElement = mocks.NewMock<IWebElement>();
     mockExplicitDriver = mocks.NewMock<IWebDriver>();
 }
开发者ID:RanchoLi,项目名称:selenium,代码行数:7,代码来源:PageFactoryTest.cs


示例8: beforTest

 public void beforTest()
 {
     mockery = new Mockery();
     view = mockery.NewMock<IPlaylistCreatorView>();
     task = mockery.NewMock<IPlaylistCreatorTask>();
     presenter = new PlaylistCreatorPresenter(view, task);
 }
开发者ID:bjornebjornson,项目名称:Gema2008,代码行数:7,代码来源:PlaylistCreatorPresenter_Fixture.cs


示例9: TestGetCommentsListForUser6

        public void TestGetCommentsListForUser6()
        {
            Console.WriteLine("Before CommentLists - TestGetCommentsListForUser6");
            //Create the mocked inputcontext
            Mockery mock = new Mockery();
            IInputContext mockedInputContext = mock.NewMock<IInputContext>();
            //XmlDocument siteconfig = new XmlDocument();
            //siteconfig.LoadXml("<SITECONFIG />");
            ISite site = mock.NewMock<ISite>();
            //Stub.On(site).GetProperty("SiteConfig").Will(Return.Value(siteconfig.FirstChild));
            Stub.On(site).GetProperty("SiteID").Will(Return.Value(1));

            User user = new User(mockedInputContext);
            Stub.On(mockedInputContext).GetProperty("ViewingUser").Will(Return.Value(user));
            Stub.On(mockedInputContext).GetProperty("CurrentSite").Will(Return.Value(site));

            // Create the stored procedure reader for the CommentList object
            IInputContext context = DnaMockery.CreateDatabaseInputContext();
            using (IDnaDataReader reader = context.CreateDnaDataReader("getusercommentsstats"))
            {
                using (IDnaDataReader reader2 = context.CreateDnaDataReader("fetchgroupsandmembers"))
                {
                    Stub.On(mockedInputContext).Method("CreateDnaDataReader").With("getusercommentsstats").Will(Return.Value(reader));
                    Stub.On(mockedInputContext).Method("CreateDnaDataReader").With("fetchgroupsandmembers").Will(Return.Value(reader2));

                    // Create a new CommentsList object and get the list of comments
                    CommentsList testCommentsList = new CommentsList(mockedInputContext);
                    Assert.IsTrue(testCommentsList.CreateRecentCommentsList(6, 1, 0, 20));
                }
            }
            Console.WriteLine("After CommentLists - TestGetCommentsListForUser6");
        }
开发者ID:rocketeerbkw,项目名称:DNA,代码行数:32,代码来源:CommentsListTests.cs


示例10: greatChangePriceChooserTest

        //[TestMethod]
        public void greatChangePriceChooserTest()
        {
            Mockery mocks = new Mockery();
            IDefaultHttpClient dhcMock = mocks.NewMock<IDefaultHttpClient>();

            Expect.Once.On(dhcMock).Method("SendHttpGetAndReturnResponseContent").With("http://parafia.biz/relics/market_show/70").Will(Return.Value(TestData.ParafiaBizMarketGreatChangeContent));

            String responseContent = dhcMock.SendHttpGetAndReturnResponseContent("http://parafia.biz/relics/market_show/70");

            HtmlNode.ElementsFlags.Remove("option");
            HtmlNodeCollection optionsNode = HtmlUtils.GetNodesCollectionByXPathExpression(responseContent, "//select[@id='market_id']/option");

            Random rand = new Random();
            int value = 10000;
            int counter;
            do
            {
                counter = 0;
                foreach (HtmlNode node in optionsNode)
                {
                    String txtValueForOption = node.InnerText;
                    if (!String.IsNullOrEmpty(txtValueForOption))
                    {
                        int valueForOption = int.Parse(Parafia.MainUtils.removeAllNotNumberCharacters(txtValueForOption));
                        if (valueForOption == value)
                            counter++;
                    }
                }
                if (counter != 0)
                    value = rand.Next(11642 - 100, 11642);
            }
            while (counter != 0);
        }
开发者ID:wrobeseb,项目名称:parRobot,代码行数:34,代码来源:LoginTest.cs


示例11: TestGetHandlerFor

		public void TestGetHandlerFor()
		{
			Mockery mocks;
			IOTAProject mockProject;
			IUser mockUser;
			IGenerator mockGenerator;
			mocks = new Mockery();
			mockProject = mocks.NewMock<IOTAProject>();
			mockUser = mocks.NewMock<IUser>();
			mockGenerator = mocks.NewMock<IGenerator>();
			//TODO: use Mock objects.
			string fileName = Path.Combine(Path.GetTempPath(), "test.dproj");
			Expect.AtLeast(3).On(mockProject).GetProperty("FileName").
				Will(Return.Value(fileName));
			Expect.Once.On(mockProject).Method("Save").WithAnyArguments().Will(Return.Value(true));
			Expect.Once.On(mockProject).Method("AddFile").WithAnyArguments().Will(Return.Value(null));
			Expect.Once.On(mockUser).Method("ProvideKeyFile").Will(Return.Value(null));
			Expect.Once.On(mockGenerator).Method("GenerateKey").WithAnyArguments().Will(Return.Value(true));
			IHandler handler = HandlerFactory.GetHandlerFor(mockProject);
			Assert.IsTrue(handler is Manner20UnsignedHandler);
			(handler as Manner20UnsignedHandler).User = mockUser;
			(handler as Manner20UnsignedHandler).Generator = mockGenerator;
			handler.Handle();
			IHandler handler2 = HandlerFactory.GetHandlerFor(mockProject);
			Assert.IsTrue(handler2 is Manner20SignedHandler);
			mocks.VerifyAllExpectationsHaveBeenMet();
		}
开发者ID:divyang4481,项目名称:lextudio,代码行数:27,代码来源:TestHandlerFactory.cs


示例12: SimpleInstantiation

        public void SimpleInstantiation()
        {
            Mockery mocks = new Mockery();

            IDataReader reader = mocks.NewMock<IDataReader>();

            Expect.Once.On(reader)
                .Method("Read")
                .Will(Return.Value(true));

            Expect.Once.On(reader)
                .Get["employee_id"]
                .Will(Return.Value(12));

            Expect.Once.On(reader)
                .Get["employee_name"]
                .Will(Return.Value("Alice"));

            Expect.Once.On(reader)
                .Method("Read")
                .Will(Return.Value(false));

            ObjectBuilder<Employee> builder = new ObjectBuilder<Employee>(reader);

            Employee alice = builder.Single();

            Assert.AreEqual(12, alice.ID);
            Assert.AreEqual("Alice", alice.Name);
        }
开发者ID:roniyud,项目名称:LINQWrapper,代码行数:29,代码来源:ObjectBuilderTests.cs


示例13: EnsureValidH2G2IDSucceedsToCreate

        public void EnsureValidH2G2IDSucceedsToCreate()
        {
            // Create a mockery of the input context
            Mockery mockery = new Mockery();
            IInputContext mockedContext = mockery.NewMock<IInputContext>();

            IDnaDataReader mockedReader = mockery.NewMock<IDnaDataReader>();
            Stub.On(mockedReader).Method("AddParameter").Will(Return.Value(mockedReader));
            Stub.On(mockedReader).Method("Execute").Will(Return.Value(mockedReader));
            Stub.On(mockedReader).GetProperty("HasRows").Will(Return.Value(true));
            Stub.On(mockedReader).Method("Read").Will(Return.Value(true));
            
            // Set the expiry date to be 1 minute from now
            Stub.On(mockedReader).Method("GetInt32").With("seconds").Will(Return.Value(60));
            Stub.On(mockedReader).Method("Dispose").Will(Return.Value(null));

            Stub.On(mockedContext).Method("CreateDnaDataReader").With("cachegetarticleinfo").Will(Return.Value(mockedReader));

            // Return false for now as it's bloody inpossible to test methods that use ref params!!!
            Stub.On(mockedContext).Method("FileCacheGetItem").Will(Return.Value(false));

            // Now create the setup object and create the guideentry
            GuideEntrySetup setup = new GuideEntrySetup(388217);
            GuideEntry testEntry = new GuideEntry(mockedContext, setup);

            // Test the initialisation code.
            Assert.IsTrue(testEntry.Initialise(), "Valid h2g2id should return true!");
        }
开发者ID:rocketeerbkw,项目名称:DNA,代码行数:28,代码来源:GuideEntryTests.cs


示例14: GivenRequestToContactFormListPageShouldSetSkipAndShowVariablesInXML

        public void GivenRequestToContactFormListPageShouldSetSkipAndShowVariablesInXML()
        {
            Mockery mock = new Mockery();
            IInputContext mockedInputContext = mock.NewMock<IInputContext>();
            ISite mockedSite = mock.NewMock<ISite>();

            Stub.On(mockedSite).GetProperty("SiteID").Will(Return.Value(1));
            Stub.On(mockedInputContext).GetProperty("CurrentSite").Will(Return.Value(mockedSite));

            IDnaDataReader mockedReader = mock.NewMock<IDnaDataReader>();
            Stub.On(mockedReader).Method("AddParameter");
            Stub.On(mockedReader).Method("Execute");
            Stub.On(mockedReader).GetProperty("HasRows").Will(Return.Value(false));
            Stub.On(mockedReader).Method("Dispose");
            Stub.On(mockedInputContext).Method("CreateDnaDataReader").With("getcontactformslist").Will(Return.Value(mockedReader));

            ContactFormListBuilder contactFormBuilder = new ContactFormListBuilder(mockedInputContext);

            int expectedShow = 200;
            int expectedSkip = 1000;
            int expectedSiteID = 66;

            Stub.On(mockedInputContext).Method("DoesParamExist").With("action", "process action param").Will(Return.Value(false));
            Stub.On(mockedInputContext).Method("DoesParamExist").With("dnaskip", "Items to skip").Will(Return.Value(true));
            Stub.On(mockedInputContext).Method("DoesParamExist").With("dnashow", "Items to show").Will(Return.Value(true));
            Stub.On(mockedInputContext).Method("GetParamIntOrZero").With("dnaskip", "Items to skip").Will(Return.Value(expectedSkip));
            Stub.On(mockedInputContext).Method("GetParamIntOrZero").With("dnashow", "Items to show").Will(Return.Value(expectedShow));
            Stub.On(mockedInputContext).Method("GetParamIntOrZero").With("dnasiteid", "The specified site").Will(Return.Value(expectedSiteID));

            XmlNode requestResponce = contactFormBuilder.GetContactFormsAsXml();

            Assert.AreEqual(expectedShow, Int32.Parse(requestResponce.SelectSingleNode("@SHOW").Value));
            Assert.AreEqual(expectedSkip, Int32.Parse(requestResponce.SelectSingleNode("@SKIP").Value));
            Assert.AreEqual(expectedSiteID, Int32.Parse(requestResponce.SelectSingleNode("@REQUESTEDSITEID").Value));
        }
开发者ID:rocketeerbkw,项目名称:DNA,代码行数:35,代码来源:CommentForumListTests.cs


示例15: GivenCallingProcessInputParametersShouldSetSkipAndShowVariables

        //TODO: Talk with Mark H to understand the purpose of this test.
        //Why is this relevent specifically to ContactFormListBuilder for example?
        //Is it not a more generic unit test for base functionality?
        public void GivenCallingProcessInputParametersShouldSetSkipAndShowVariables()
        {
            Mockery mock = new Mockery();
            IInputContext mockedInputContext = mock.NewMock<IInputContext>();
            ISite mockedSite = mock.NewMock<ISite>();

            Stub.On(mockedSite).GetProperty("SiteID").Will(Return.Value(1));
            Stub.On(mockedInputContext).GetProperty("CurrentSite").Will(Return.Value(mockedSite));

            ContactFormListBuilder_Accessor privateAccessor = new ContactFormListBuilder_Accessor(mockedInputContext);

            int expectedShow = 20;
            int expectedSkip = 10;
            int expectedSiteID = 66;

            Stub.On(mockedInputContext).Method("DoesParamExist").With("skip", "Items to skip").Will(Return.Value(true));
            Stub.On(mockedInputContext).Method("DoesParamExist").With("show", "Items to show").Will(Return.Value(true));
            Stub.On(mockedInputContext).Method("GetParamIntOrZero").With("skip", "Items to skip").Will(Return.Value(expectedSkip));
            Stub.On(mockedInputContext).Method("GetParamIntOrZero").With("show", "Items to show").Will(Return.Value(expectedShow));
            Stub.On(mockedInputContext).Method("GetParamIntOrZero").With("dnasiteid", "The specified site").Will(Return.Value(expectedSiteID));

            privateAccessor.ProcessInputParameters();

            Assert.AreEqual(privateAccessor.show, expectedShow);
            Assert.AreEqual(privateAccessor.skip, expectedSkip);
            Assert.AreEqual(privateAccessor.requestedSiteID, expectedSiteID);
        }
开发者ID:rocketeerbkw,项目名称:DNA,代码行数:30,代码来源:ContactFormListBuilderTests.cs


示例16: TestXmlNoModClass

        public void TestXmlNoModClass()
        {
            Mockery mocks = new Mockery();
            IInputContext context = mocks.NewMock<IInputContext>();
            IDnaDataReader mockedReader = mocks.NewMock<IDnaDataReader>();
            Stub.On(context).Method("CreateDnaDataReader").Will(Return.Value(mockedReader));
            Stub.On(mockedReader).Method("Execute");
            Stub.On(mockedReader).Method("Dispose");
            IAction mockReaderResults = new MockedReaderResults(new object[] { true, false });
            Stub.On(mockedReader).Method("Read").Will(mockReaderResults);

            // Check Stored Procedure is called as expected.
            Expect.Never.On(mockedReader).Method("AddParameter").With("modclassid");

            Stub.On(mockedReader).Method("GetInt32NullAsZero").With("reasonid").Will(Return.Value(6));
            Stub.On(mockedReader).Method("GetStringNullAsEmpty").With("displayname").Will(Return.Value("DisplayName"));
            Stub.On(mockedReader).Method("GetStringNullAsEmpty").With("emailname").Will(Return.Value("EmailName"));
            Stub.On(mockedReader).Method("GetTinyIntAsInt").With("editorsonly").Will(Return.Value(0));

            ModerationReasons modReasons = new ModerationReasons(context);
            modReasons.GenerateXml(0);

            //Check XML.is as expected.
            XmlNode node = modReasons.RootElement.SelectSingleNode(@"MOD-REASONS");
            Assert.IsNotNull(node, "ModerationReasons Element Found");
            Assert.IsNull(modReasons.RootElement.SelectSingleNode(@"MOD-REASONS/@MODCLASSID"), "Moderation Class Id");
            Assert.IsNotNull(modReasons.RootElement.SelectSingleNode(@"MOD-REASONS/MOD-REASON[@DISPLAYNAME='DisplayName']"), "Displayname");
            Assert.IsNotNull(modReasons.RootElement.SelectSingleNode(@"MOD-REASONS/MOD-REASON[@EMAILNAME='EmailName']"), "Emailname");
            Assert.IsNotNull(modReasons.RootElement.SelectSingleNode(@"MOD-REASONS/MOD-REASON[@EDITORSONLY='0']"), "Editors Only");


            mocks.VerifyAllExpectationsHaveBeenMet();
        }
开发者ID:rocketeerbkw,项目名称:DNA,代码行数:33,代码来源:ModerationReasonsTests.cs


示例17: TestGetImportantData_ExceptionHandeling

        public void TestGetImportantData_ExceptionHandeling()
        {
            //setup/arrange
            DateTime fromDate = DateTime.Now.Subtract(new TimeSpan(30, 0, 0, 0));
            DateTime toDate = DateTime.Now;
            Request request = new ImportantDataServiceRequestImpl();
            ImportantDataServiceRequest importantRequest = (ImportantDataServiceRequest)request;
            importantRequest.FromDate = fromDate;
            importantRequest.ToDate = toDate;
            DataSet response = new DataSet();
            Mockery mockery = new Mockery();
            Data mockData = mockery.NewMock<Data>();
            Expect.Once.On(mockData).Method("GetImportantDataWithDateRange").With(fromDate, toDate).Will(Throw.Exception(new Exception()));
            ImportantDataService service = new ImportantDataServiceImpl(mockData);

            //execute/act
            try
            {
                service.GetImportantData(request);
                //assert
                Assert.Fail("An Exception should have been thrown");
            }
            catch (ServiceException e)
            {
                Assert.AreEqual("The Service Invocation Failed", e.Message);
            }

            mockery.VerifyAllExpectationsHaveBeenMet();
        }
开发者ID:rdammkoehler,项目名称:C-TDDExamples,代码行数:29,代码来源:TestService.cs


示例18: SetupGiven

 private void SetupGiven(ref Mockery mocks, ref SimplestPossibleWorld world)
 {
     IGiven given = (IGiven)mocks.NewMock<IGiven>();
     Expect.AtLeast(1).On(given).Method("Setup").With(world);
     List<IGiven> GivenCollection = new List<IGiven>();
     GivenCollection.Add(given);
 }
开发者ID:BackupTheBerlios,项目名称:nbehave-svn,代码行数:7,代码来源:FakeStory.cs


示例19: SetUp

        public void SetUp()
        {
            _mock = new Mockery();
            _site = _mock.NewMock<ISite>();
            Stub.On(_site).GetProperty("DefaultSkin").Will(Return.Value(SITE_DEFAULT_SKIN));
            Stub.On(_site).Method("DoesSkinExist").With(SITE_DEFAULT_SKIN).Will(Return.Value(true));
            Stub.On(_site).Method("DoesSkinExist").With(INVALID_SKIN).Will(Return.Value(false));
            Stub.On(_site).Method("DoesSkinExist").With(USER_PREFERRED_SKIN).Will(Return.Value(true));
            Stub.On(_site).Method("DoesSkinExist").With(Is.Null).Will(Return.Value(false));
            Stub.On(_site).Method("DoesSkinExist").With(REQUESTED_SKIN).Will(Return.Value(true));
            Stub.On(_site).Method("DoesSkinExist").With(FILTER_DERIVED_SKIN).Will(Return.Value(true));
            Stub.On(_site).Method("DoesSkinExist").With("xml").Will(Return.Value(true));
            Stub.On(_site).GetProperty("SkinSet").Will(Return.Value("vanilla"));
            
            _user = _mock.NewMock<IUser>();

            _inputContext = _mock.NewMock<IInputContext>();
            Stub.On(_inputContext).GetProperty("CurrentSite").Will(Return.Value(_site));

            _outputContext = _mock.NewMock<IOutputContext>();
            Stub.On(_outputContext).Method("VerifySkinFileExists").Will(Return.Value(true));
    
            _skinSelector = new SkinSelector();
           
            _request = _mock.NewMock<IRequest>();
        }
开发者ID:rocketeerbkw,项目名称:DNA,代码行数:26,代码来源:SkinSelectorTests.cs


示例20: TestPersist

        public void TestPersist()
        {
            Mockery mocks = new Mockery();

            //Crate mocks
            IUserGateway mockGateway = mocks.NewMock<IUserGateway>();
            IUserValidator mockValidator = mocks.NewMock<IUserValidator>();

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

            //Expectations
            using(mocks.Ordered)
            {
                Expect.Once.On(mockValidator).Method("Validate").With(user).Will(Return.Value(true));
                Expect.Once.On(mockGateway).Method("Persist").With(user).Will(Return.Value(true));
            }

            //Assign gateway
            user.Gateway = mockGateway;

            //Test method
            Assert.AreEqual(true, user.Persist(mockValidator));

            mocks.VerifyAllExpectationsHaveBeenMet();
        }
开发者ID:pweibel,项目名称:DotNetMockingFrameworksDemo,代码行数:26,代码来源:NMock2Test.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Mocks类代码示例发布时间:2022-05-24
下一篇:
C# MockVsPackageManager类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap