本文整理汇总了C#中NMock.DynamicMock类的典型用法代码示例。如果您正苦于以下问题:C# DynamicMock类的具体用法?C# DynamicMock怎么用?C# DynamicMock使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DynamicMock类属于NMock命名空间,在下文中一共展示了DynamicMock类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShouldReturnBuildPluginLinksRelevantToThisProject
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();
}
示例2: Setup
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;
}
示例3: SetUp
public void SetUp()
{
stubProjectMonitor = new StubProjectMonitor("project");
mockAudioPlayer = new DynamicMock(typeof(IAudioPlayer));
mockAudioPlayer.Strict = true;
}
示例4: ShouldOnlyAllowOneThreadToResolveEachType
public void ShouldOnlyAllowOneThreadToResolveEachType()
{
TypeToTypeMap sharedMap = new HashtableTypeMap(Hashtable.Synchronized(new Hashtable()));
DynamicMock expectedToBeUsed = new DynamicMock(typeof(ImplementationResolver));
expectedToBeUsed.ExpectAndReturn("ResolveImplementation", typeof(TestClass), typeof(TestInterface));
DynamicMock notExpectedToBeUsed = new DynamicMock(typeof(ImplementationResolver));
notExpectedToBeUsed.ExpectNoCall("ResolveImplementation", typeof(Type));
StallingImplementationResolver stallingResolver = new StallingImplementationResolver((ImplementationResolver) expectedToBeUsed.MockInstance);
ImplementationResolver resolvingResolver = new CachingImplementationResolver(
stallingResolver, sharedMap);
ImplementationResolver moochingResolver = new CachingImplementationResolver((ImplementationResolver) notExpectedToBeUsed.MockInstance, sharedMap);
ImplementationResolverRunner resolvingRunner = new ImplementationResolverRunner(resolvingResolver, typeof(TestInterface));
Thread resolvingThread = new Thread(
new ThreadStart(resolvingRunner.runResolution));
ImplementationResolverRunner moochingRunner = new ImplementationResolverRunner(moochingResolver, typeof(TestInterface));
Thread moochingThread = new Thread(
new ThreadStart(moochingRunner.runResolution));
resolvingThread.Start();
moochingThread.Start();
Thread.Sleep(500); // allow moochingThread to catch up to resolvingThread
stallingResolver.Resume();
Assert.IsTrue(resolvingThread.Join(200), "Resolving thread did not complete before timeout.");
Assert.IsTrue(moochingThread.Join(200), "Mooching thread did not complete before timeout.");
expectedToBeUsed.Verify();
notExpectedToBeUsed.Verify();
Assert.AreEqual(typeof(TestClass), resolvingRunner.implementationType);
Assert.AreEqual(typeof(TestClass), moochingRunner.implementationType);
}
示例5: ShouldUseBuildLogTransformerToGenerateView
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();
}
示例6: SetUp
public void SetUp()
{
stubProjectMonitor = new StubProjectMonitor("project");
mockLampController = new DynamicMock(typeof(ILampController));
mockLampController.Strict = true;
ILampController lampController = mockLampController.MockInstance as ILampController;
configuration = new X10Configuration();
configuration.Enabled = true;
configuration.StartTime = DateTime.Parse("08:00");
configuration.EndTime = DateTime.Parse("18:00");
configuration.ActiveDays[(int)DayOfWeek.Sunday] = false;
configuration.ActiveDays[(int)DayOfWeek.Monday] = true;
configuration.ActiveDays[(int)DayOfWeek.Tuesday] = true;
configuration.ActiveDays[(int)DayOfWeek.Wednesday] = true;
configuration.ActiveDays[(int)DayOfWeek.Thursday] = true;
configuration.ActiveDays[(int)DayOfWeek.Friday] = true;
configuration.ActiveDays[(int)DayOfWeek.Saturday] = false;
stubCurrentTimeProvider = new StubCurrentTimeProvider();
stubCurrentTimeProvider.SetNow(new DateTime(2005, 11, 03, 12, 00, 00));
Assert.AreEqual(DayOfWeek.Thursday, stubCurrentTimeProvider.Now.DayOfWeek);
new X10Controller(
stubProjectMonitor,
stubCurrentTimeProvider,
configuration,
lampController);
}
示例7: Init
public void Init()
{
m_mock = new DynamicMock(typeof(IIgnoreOrderTest));
m_mock.Expect("Method",
new object[] { new IgnoreOrderConstraint(0, 1, 2 )},
new string[] { typeof(int[]).FullName });
}
示例8: AdjustScrollRange
public void AdjustScrollRange()
{
DynamicMock rootBox = new DynamicMock(typeof(IVwRootBox));
// This was taken out because it doesn't seem like the views code does this
// anymore. It just calls AdjustScrollRange for the original view that changed.
// Done as a part of TE-3576
//// result for style pane
//rootBox.ExpectAndReturn("Height", 900);
//rootBox.ExpectAndReturn("Width", 100);
//rootBox.ExpectAndReturn("Height", 1000);
//rootBox.ExpectAndReturn("Width", 100);
//rootBox.ExpectAndReturn("Height", 1000);
//rootBox.ExpectAndReturn("Width", 100);
//// result for draft pane
//rootBox.ExpectAndReturn("Height", 950);
//rootBox.ExpectAndReturn("Width", 100);
//rootBox.ExpectAndReturn("Height", 900);
//rootBox.ExpectAndReturn("Width", 100);
//rootBox.ExpectAndReturn("Height", 1000);
//rootBox.ExpectAndReturn("Width", 100);
// result for bt pane
rootBox.ExpectAndReturn("Height", 1100);
rootBox.ExpectAndReturn("Width", 100);
rootBox.ExpectAndReturn("Height", 900);
rootBox.ExpectAndReturn("Width", 100);
rootBox.ExpectAndReturn("Height", 950);
rootBox.ExpectAndReturn("Width", 100);
using (RootSiteGroup group = new RootSiteGroup())
{
DummyBasicView stylePane = new DummyBasicView();
DummyBasicView draftPane = new DummyBasicView();
DummyBasicView btPane = new DummyBasicView();
PrepareView(stylePane, 50, 300, (IVwRootBox)rootBox.MockInstance);
PrepareView(draftPane, 150, 300, (IVwRootBox)rootBox.MockInstance);
PrepareView(btPane, 150, 300, (IVwRootBox)rootBox.MockInstance);
group.AddToSyncGroup(stylePane);
group.AddToSyncGroup(draftPane);
group.AddToSyncGroup(btPane);
group.ScrollingController = btPane;
group.Controls.AddRange(new Control[] { stylePane, draftPane, btPane } );
btPane.ScrollMinSize = new Size(100, 1000);
btPane.ScrollPosition = new Point(0, 700);
// now call AdjustScrollRange on each of the panes.
// This simulates what the views code does.
// This was taken out because it doesn't seem like the views code does this
// anymore. It just calls AdjustScrollRange for the original view that changed.
// Done as a part of TE-3576
//stylePane.AdjustScrollRange(null, 0, 0, -100, 500);
//draftPane.AdjustScrollRange(null, 0, 0, -50, 500);
btPane.AdjustScrollRange(null, 0, 0, 100, 500);
Assert.AreEqual(1108, btPane.ScrollMinSize.Height, "Wrong ScrollMinSize");
Assert.AreEqual(800, -btPane.ScrollPosition.Y, "Wrong scroll position");
}
}
示例9: ViewManagerCreateView
public void ViewManagerCreateView()
{
#region Mock intialization
DynamicMock useCase = new DynamicMock(typeof(IUseCase));
DynamicMock engine = new DynamicMock(typeof(IRegexEngine));
DynamicMock view = new DynamicMock(typeof(IRegexView));
IRegexView viewMockInstance = (IRegexView)view.MockInstance;
IUseCase useCaseMockInstance = (IUseCase)useCase.MockInstance;
IRegexEngine engineMockInstance = (IRegexEngine)engine.MockInstance;
#endregion
useCase.ExpectAndReturn("CreateNewView", viewMockInstance);
useCase.ExpectAndReturn("CreateNewEngine", engineMockInstance);
engine.Expect("AttachView", withSameObjectAs(viewMockInstance));
view.Expect("Init", withSameObjectAs(engineMockInstance));
ViewManager factory = new ViewManager();
IRegexView newView = factory.CreateView(useCaseMockInstance);
useCase.Verify();
engine.Verify();
view.Verify();
Assert.AreSame(newView, viewMockInstance,"Returned view is not the same instance as expected");
}
示例10: SetupAndTeardownRemotingInfrastructure
public void SetupAndTeardownRemotingInfrastructure()
{
string configFile = CreateTemporaryConfigurationFile();
IMock mockCruiseManager = new RemotingMock(typeof (ICruiseManager));
IMock mockCruiseServer = new DynamicMock(typeof (ICruiseServer));
mockCruiseServer.ExpectAndReturn("CruiseManager", mockCruiseManager.MockInstance);
mockCruiseServer.ExpectAndReturn("CruiseManager", mockCruiseManager.MockInstance);
mockCruiseServer.Expect("Dispose");
using (new RemoteCruiseServer((ICruiseServer) mockCruiseServer.MockInstance, configFile))
{
Assert.AreEqual(2, ChannelServices.RegisteredChannels.Length);
Assert.IsNotNull(ChannelServices.GetChannel("ccnet"), "ccnet channel is missing");
Assert.IsNotNull(ChannelServices.GetChannel("ccnet2"), "ccnet2 channel is missing");
ICruiseManager remoteManager = (ICruiseManager) RemotingServices.Connect(typeof (ICruiseManager), "tcp://localhost:35354/" + RemoteCruiseServer.ManagerUri);
Assert.IsNotNull(remoteManager, "cruiseserver should be registered on tcp channel");
remoteManager = (ICruiseManager) RemotingServices.Connect(typeof (ICruiseManager), "http://localhost:35355/" + RemoteCruiseServer.ManagerUri);
Assert.IsNotNull(remoteManager, "cruiseserver should be registered on http channel");
}
Assert.AreEqual(0, ChannelServices.RegisteredChannels.Length, "all registered channels should be closed.");
mockCruiseServer.Verify();
mockCruiseManager.Verify();
}
示例11: SetupSelectionForParas
/// ------------------------------------------------------------------------------------
/// <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;
}
示例12: Setup
public void Setup()
{
cruiseRequestWrapperMock = new DynamicMock(typeof(ICruiseRequest));
buildNameRetrieverMock = new DynamicMock(typeof(IBuildNameRetriever));
recentBuildsViewBuilderMock = new DynamicMock(typeof(IRecentBuildsViewBuilder));
pluginLinkCalculatorMock = new DynamicMock(typeof(IPluginLinkCalculator));
velocityViewGeneratorMock = new DynamicMock(typeof(IVelocityViewGenerator));
linkFactoryMock = new DynamicMock(typeof(ILinkFactory));
linkListFactoryMock = new DynamicMock(typeof(ILinkListFactory));
farmServiceMock = new DynamicMock(typeof(IFarmService));
sideBarViewBuilder = new SideBarViewBuilder(
(ICruiseRequest) cruiseRequestWrapperMock.MockInstance,
(IBuildNameRetriever) buildNameRetrieverMock.MockInstance,
(IRecentBuildsViewBuilder) recentBuildsViewBuilderMock.MockInstance,
(IPluginLinkCalculator) pluginLinkCalculatorMock.MockInstance,
(IVelocityViewGenerator) velocityViewGeneratorMock.MockInstance,
(ILinkFactory) linkFactoryMock.MockInstance,
(ILinkListFactory)linkListFactoryMock.MockInstance,
(IFarmService) farmServiceMock.MockInstance,
null);
velocityResponse = new HtmlFragmentResponse("velocity view");
velocityContext = new Hashtable();
links = new IAbsoluteLink[] { new GeneralAbsoluteLink("link")};
serverLinks = new IAbsoluteLink[] { new GeneralAbsoluteLink("link")};
serverSpecifiers = new IServerSpecifier[] {new DefaultServerSpecifier("test")};
}
示例13: NewDynamicMock
public IMock NewDynamicMock(Type type)
{
DynamicMock mock = new DynamicMock(type);
mock.Strict = false;
mocks.Add(mock);
return mock;
}
示例14: TestSimpleSmtpNegotiation
public void TestSimpleSmtpNegotiation()
{
SmtpServer smtpserver=new SmtpServer("localhost");
EmailMessage emailMessage=GetTestHtmlAndTextMessage();
IMock mockSmtpProxy = new DynamicMock(typeof(ISmtpProxy));
mockSmtpProxy.ExpectAndReturn("Open", new SmtpResponse(220, "welcome to the mock object server"), null);
mockSmtpProxy.ExpectAndReturn("Helo", new SmtpResponse(250, "helo"), Dns.GetHostName());
mockSmtpProxy.ExpectAndReturn("MailFrom", new SmtpResponse(250, "mail from"), emailMessage.FromAddress);
foreach (EmailAddress rcpttoaddr in emailMessage.ToAddresses)
{
mockSmtpProxy.ExpectAndReturn("RcptTo", new SmtpResponse(250, "receipt to"), rcpttoaddr);
}
mockSmtpProxy.ExpectAndReturn("Data", new SmtpResponse(354, "data open"), null);
mockSmtpProxy.ExpectAndReturn("WriteData", new SmtpResponse(250, "data"), emailMessage.ToDataString());
mockSmtpProxy.ExpectAndReturn("Quit", new SmtpResponse(221, "quit"), null);
mockSmtpProxy.Expect("Close", null);
ISmtpProxy smtpProxy= (ISmtpProxy) mockSmtpProxy.MockInstance;
smtpserver.OverrideSmtpProxy(smtpProxy);
emailMessage.Send(smtpserver);
}
示例15: Setup
public void Setup()
{
cruiseRequestMock = new DynamicMock(typeof(ICruiseRequest));
requestMock = new DynamicMock(typeof(IRequest));
linkFactoryMock = new DynamicMock(typeof(ILinkFactory));
velocityViewGeneratorMock = new DynamicMock(typeof(IVelocityViewGenerator));
farmServiceMock = new DynamicMock(typeof(IFarmService));
viewBuilder = new TopControlsViewBuilder(
(ICruiseRequest) cruiseRequestMock.MockInstance,
(ILinkFactory) linkFactoryMock.MockInstance,
(IVelocityViewGenerator) velocityViewGeneratorMock.MockInstance,
(IFarmService) farmServiceMock.MockInstance,
null, null);
serverSpecifier = new DefaultServerSpecifier("myServer");
projectSpecifier = new DefaultProjectSpecifier(serverSpecifier, "myProject");
buildSpecifier = new DefaultBuildSpecifier(projectSpecifier, "myBuild");
expectedVelocityContext = new Hashtable();
response = new HtmlFragmentResponse("foo");
link1 = new GeneralAbsoluteLink("1");
link2 = new GeneralAbsoluteLink("2");
link3 = new GeneralAbsoluteLink("3");
link4 = new GeneralAbsoluteLink("4");
}