本文整理汇总了C#中Mockery.NewMock方法的典型用法代码示例。如果您正苦于以下问题:C# Mockery.NewMock方法的具体用法?C# Mockery.NewMock怎么用?C# Mockery.NewMock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mockery
的用法示例。
在下文中一共展示了Mockery.NewMock方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}
示例2: 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();
}
示例3: 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>();
}
示例4: beforTest
public void beforTest()
{
mockery = new Mockery();
view = mockery.NewMock<IPlaylistCreatorView>();
task = mockery.NewMock<IPlaylistCreatorTask>();
presenter = new PlaylistCreatorPresenter(view, task);
}
示例5: SetUp
public void SetUp()
{
mocks = new Mockery();
mockDriver = mocks.NewMock<ISearchContext>();
mockElement = mocks.NewMock<IWebElement>();
mockExplicitDriver = mocks.NewMock<IWebDriver>();
}
示例6: 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));
}
示例7: 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();
}
示例8: 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!");
}
示例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");
}
示例10: 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();
}
示例11: 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();
}
示例12: TestEmailSendMailOrSystemMessage
public void TestEmailSendMailOrSystemMessage()
{
//Create the mocked inputcontext
Mockery mock = new Mockery();
IInputContext context = DnaMockery.CreateDatabaseInputContext();
//XmlDocument siteconfig = new XmlDocument();
//siteconfig.LoadXml("<SITECONFIG />");
// Create a mocked site for the context
ISite mockedSite = mock.NewMock<ISite>();
//Stub.On(mockedSite).GetProperty("SiteConfig").Will(Return.Value(siteconfig.FirstChild));
Stub.On(mockedSite).GetProperty("SiteID").Will(Return.Value(1));
Stub.On(mockedSite).GetProperty("SiteName").Will(Return.Value("h2g2"));
Stub.On(mockedSite).GetProperty("ModClassID").Will(Return.Value(1));
Stub.On(context).GetProperty("CurrentSite").Will(Return.Value(mockedSite));
IUser mockedUser = mock.NewMock<IUser>();
Stub.On(mockedUser).GetProperty("UserID").Will(Return.Value(1090558354));
Stub.On(context).GetProperty("ViewingUser").Will(Return.Value(mockedUser));
Stub.On(context).Method("GetSiteRoot").Will(Return.Value("dnadev.national.core.bbc.co.uk:8081/dna/"));
Stub.On(context).Method("SendMailOrSystemMessage");
MessageBoardStatistics mbStats = new MessageBoardStatistics(context);
mbStats.SendMessageBoardStatsEmail((new DateTime(2008, 1, 1)), "[email protected]", "[email protected]" );
}
示例13: 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);
}
示例14: beforTest
public void beforTest()
{
mockery = new Mockery();
view = mockery.NewMock<ITrackView>();
dao = mockery.NewMock<ITrackDao>();
presenter = new TrackPresenter(view, dao);
}
示例15: beforTest
public void beforTest()
{
mocks = new Mockery();
view = mocks.NewMock<IPlaylistSelectorView>();
task = mocks.NewMock<IPlaylistSelectorTask>();
lookupList = mocks.NewMock<ILookupList>();
presenter = new PlaylistSelectorPresenter(view, task);
}