public void StartCruiseServerProject() { ConsoleRunnerArguments consoleArgs = new ConsoleRunnerArguments(); Mock mockCruiseServer = new DynamicMock(typeof(ICruiseServer)); mockCruiseServer.Expect("Start"); mockCruiseServer.Expect("WaitForExit"); Mock mockCruiseServerFactory = new DynamicMock(typeof(ICruiseServerFactory)); mockCruiseServerFactory.ExpectAndReturn("Create", mockCruiseServer.MockInstance, consoleArgs.UseRemoting, consoleArgs.ConfigFile); new ConsoleRunner(consoleArgs, (ICruiseServerFactory)mockCruiseServerFactory.MockInstance).Run(); mockCruiseServer.Verify(); }
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"); }
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(); }
public void ShouldBeAbleToSaveProjectsThatALoaderCanLoad() { ExecutableTask builder = new ExecutableTask(); builder.Executable = "foo"; FileSourceControl sourceControl = new FileSourceControl(); sourceControl.RepositoryRoot = "bar"; // Setup Project project1 = new Project(); project1.Name = "Project One"; project1.SourceControl = sourceControl; Project project2 = new Project(); project2.Name = "Project Two"; project2.SourceControl = sourceControl; ProjectList projectList = new ProjectList(); projectList.Add(project1); projectList.Add(project2); DynamicMock mockConfiguration = new DynamicMock(typeof(IConfiguration)); mockConfiguration.ExpectAndReturn("Projects", projectList); FileInfo configFile = new FileInfo(TempFileUtil.CreateTempFile(TempFileUtil.CreateTempDir(this), "loadernet.config")); // Execute DefaultConfigurationFileSaver saver = new DefaultConfigurationFileSaver(new NetReflectorProjectSerializer()); saver.Save((IConfiguration) mockConfiguration.MockInstance, configFile); DefaultConfigurationFileLoader loader = new DefaultConfigurationFileLoader(); IConfiguration configuration2 = loader.Load(configFile); // Verify Assert.IsNotNull (configuration2.Projects["Project One"]); Assert.IsNotNull (configuration2.Projects["Project Two"]); mockConfiguration.Verify(); }
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(); }
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); }
public void NullPortThrowsException() { Mock source = new DynamicMock(typeof(IUnmanagedSource)); source.ExpectNoCall("CreateFile", null, null, null, null, null, null, null); UnmanagedProvider.Source = (IUnmanagedSource) source.MockInstance; new PortStream(null); source.Verify(); }
public void InvalidPortName() { Mock source = new DynamicMock(typeof(IUnmanagedSource)); source.ExpectAndReturn("CreateFile", new IntPtr(2), null, null, null, null, null, null, null, null); source.ExpectAndReturn("GetFileType", FileType.Disk, new IntPtr(2)); UnmanagedProvider.Source = (IUnmanagedSource) source.MockInstance; new PortStream("xpto"); source.Verify(); }
public void ShouldNotGetSourceIfAutoGetSourceFalse() { DynamicMock executor = new DynamicMock(typeof(ProcessExecutor)); AccuRev accurev = new AccuRev((ProcessExecutor) executor.MockInstance); accurev.AutoGetSource = false; executor.ExpectNoCall("Execute", typeof(ProcessInfo)); accurev.GetSource(new IntegrationResult()); executor.Verify(); }
public void NoPermissionToUnmanaged() { new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Deny(); Mock handleMock = new DynamicMock(typeof(IUnmanagedSource)); handleMock.ExpectNoCall("CreateFile", null, null, null, null, null, null, null); UnmanagedProvider.Source = (IUnmanagedSource) handleMock.MockInstance; new PortStream("COM1"); handleMock.Verify(); SecurityPermission.RevertDeny(); }
public void ShouldUseObjectGiverToInstantiateActions() { DynamicMock objectSourceMock = new DynamicMock(typeof(ObjectSource)); Type typeToInstantiate = typeof(XslReportBuildAction); ICruiseAction instantiated = new XslReportBuildAction(null, null); objectSourceMock.ExpectAndReturn("GetByType", instantiated, typeToInstantiate); ActionInstantiatorWithObjectSource instantiator = new ActionInstantiatorWithObjectSource((ObjectSource) objectSourceMock.MockInstance); Assert.AreEqual(instantiated, instantiator.InstantiateAction(typeToInstantiate)); objectSourceMock.Verify(); }
public void CannotYetMockMembersWithOnlyAParamsArgument() { IMock mock = new DynamicMock(typeof(IWithParams)); mock.Expect("WithoutLeadingParameter", new Object[] { 1, 2, 3 }); IWithParams p = (IWithParams)mock.MockInstance; p.WithoutLeadingParameter(1, 2, 3); mock.Verify(); }
public void DefaultPowerShellShouldBe2IfInstalled() { IMock mockRegistry2 = new DynamicMock(typeof(IRegistry)); PowerShellTask task = new PowerShellTask((IRegistry)mockRegistry2.MockInstance, (ProcessExecutor)mockProcessExecutor.MockInstance); mockRegistry2.ExpectAndReturn("GetLocalMachineSubKeyValue", POWERSHELL2_PATH, PowerShellTask.regkeypowershell2,PowerShellTask.regkeyholder); Assert.AreEqual(POWERSHELL2_PATH + "\\powershell.exe", task.Executable); mockRegistry2.Verify(); mockProcessExecutor.Verify(); }
[Test] public void NamedDynamicMockImplementsAnInterface() { IMock mock = new DynamicMock(typeof(IBlah), "XBlah"); mock.ExpectAndReturn("DoStuff", "world", "hello"); IBlah blah = (IBlah)mock.MockInstance; Assertion.AssertEquals("world", blah.DoStuff("hello")); mock.Verify(); }
public void CanMockOverloadedMethods() { IMock mock = new DynamicMock(typeof(IOverloadedMethods)); mock.Expect("DoStuff", "one", 2); mock.Expect("DoStuff", "one"); IOverloadedMethods instance = (IOverloadedMethods)mock.MockInstance; instance.DoStuff("one", 2); instance.DoStuff("one"); mock.Verify(); }
public void ShouldDelegateExtensionToSubBuilder() { // Setup DynamicMock decoratedBuilderMock = new DynamicMock(typeof(IUrlBuilder)); decoratedBuilderMock.ExpectAndReturn("Extension", "foo"); // Execute AbsolutePathUrlBuilderDecorator decorator = new AbsolutePathUrlBuilderDecorator((IUrlBuilder) decoratedBuilderMock.MockInstance, null); decorator.Extension = "foo"; // Verify decoratedBuilderMock.Verify(); }
[Test] public void CanSetAndGetPropertiesOnAMockedInterface() { DynamicMock mock = new DynamicMock(typeof(IWithProperty)); IWithProperty withProperty = (IWithProperty)mock.MockInstance; mock.ExpectAndReturn("Name", "fred"); mock.Expect("Name", "joe"); AssertEquals("Should be property Name", "fred", withProperty.Name); withProperty.Name = "joe"; mock.Verify(); }
public void ShouldDelegateForEachFileAndSeparateWithLineBreaks() { DynamicMock delegateMock = new DynamicMock(typeof(ITransformer)); HtmlAwareMultiTransformer transformer = new HtmlAwareMultiTransformer((ITransformer) delegateMock.MockInstance); string input = "myinput"; delegateMock.ExpectAndReturn("Transform", @"<p>MyFirstOutput<p>", input, "xslFile1", null); delegateMock.ExpectAndReturn("Transform", @"<p>MySecondOutput<p>", input, "xslFile2", null); Assert.AreEqual(@"<p>MyFirstOutput<p><p>MySecondOutput<p>", transformer.Transform(input, new string[] { "xslFile1", "xslFile2" }, null)); delegateMock.Verify(); }
public void ShouldGetSourceIfAutoGetSourceTrue() { DynamicMock executor = new DynamicMock(typeof(ProcessExecutor)); AccuRev accurev = new AccuRev((ProcessExecutor) executor.MockInstance); accurev.AutoGetSource = true; ProcessInfo expectedProcessRequest = new ProcessInfo("accurev.exe", "update"); expectedProcessRequest.TimeOut = Timeout.DefaultTimeout.Millis; executor.ExpectAndReturn("Execute", new ProcessResult("foo", null, 0, false), expectedProcessRequest); accurev.GetSource(new IntegrationResult()); executor.Verify(); }
[Test] public void SetAndGetPropertiesDoesNotWorkWithSetupReturn() { DynamicMock mock = new DynamicMock(typeof(IWithProperty)); IWithProperty withProperty = (IWithProperty)mock.MockInstance; mock.SetupResult("Name", "fred"); mock.Expect("Name", "jim"); AssertEquals("Should be property Name", "fred", withProperty.Name); withProperty.Name = "jim"; mock.Verify(); }
[Test] public void CanMockMethodWithConstraint() { IMock mock = new DynamicMock(typeof(TwoMethods)); mock.Expect("Foo", new StartsWith("Hello")); mock.ExpectAndReturn("Bar", 5, new NotNull()); TwoMethods instance = (TwoMethods)mock.MockInstance; instance.Foo("Hello World"); Assertion.AssertEquals("Should get a result", 5, instance.Bar("not null")); mock.Verify(); }
[Test] public void CanExpectMultipleInputsAndReturnAValue() { IMock mock = new DynamicMock(typeof(IValueType)); ArrayList ret = new ArrayList(); DateTime date = DateTime.Now; mock.ExpectAndReturn("Query", ret, "hello", date); IValueType blah = (IValueType)mock.MockInstance; Assertion.AssertEquals(ret, blah.Query("hello", date)); mock.Verify(); }
[Test] public void CanSetStubsAndExpectationsOnMethodsInTheSameClass() { DynamicMock mock = new DynamicMock(typeof(SameClass)); mock.Ignore("A"); SameClass sc = (SameClass)mock.MockInstance; mock.ExpectAndReturn("c", true); mock.SetupResult("b", "hello"); AssertEquals("Should have overriden B()", "hello", sc.A()); mock.Verify(); }
public void ShouldHandleBaseURLsWithTrailingSlashes() { /// Setup DynamicMock decoratedBuilderMock = new DynamicMock(typeof(IUrlBuilder)); string baseUrl = "https://myserver:8080/myvdir/"; AbsolutePathUrlBuilderDecorator decorator = new AbsolutePathUrlBuilderDecorator((IUrlBuilder) decoratedBuilderMock.MockInstance, baseUrl); string actionName = "myAction"; decoratedBuilderMock.ExpectAndReturn("BuildUrl", "myRelativeUrl", actionName); /// Execute & Verify Assert.AreEqual(baseUrl + "myRelativeUrl", decorator.BuildUrl(actionName)); decoratedBuilderMock.Verify(); }
public void ShouldCallDelegateTransformerWithCorrectFileNames() { DynamicMock delegateMock = new DynamicMock(typeof(IMultiTransformer)); DynamicMock pathProviderStub = new DynamicMock(typeof(IPhysicalApplicationPathProvider)); PathMappingMultiTransformer transformer = new PathMappingMultiTransformer((IPhysicalApplicationPathProvider) pathProviderStub.MockInstance, (IMultiTransformer) delegateMock.MockInstance); pathProviderStub.ExpectAndReturn("GetFullPathFor", @"c:\myAppPath\xslFile1", "xslFile1"); pathProviderStub.ExpectAndReturn("GetFullPathFor", @"c:\myAppPath\xslFile2", "xslFile2"); delegateMock.ExpectAndReturn("Transform", "output", "myInput", new string[] { @"c:\myAppPath\xslFile1", @"c:\myAppPath\xslFile2" }, null); Assert.AreEqual("output", transformer.Transform("myInput", new string[] { "xslFile1", "xslFile2"}, null)); pathProviderStub.Verify(); delegateMock.Verify(); }
public void KillContainer() { Mock mockPicoContainer = new DynamicMock(typeof(IMutablePicoContainer)); IMutablePicoContainer picoContainer = mockPicoContainer.MockInstance as IMutablePicoContainer; mockPicoContainer.Expect("Stop"); mockPicoContainer.Expect("Dispose"); mockPicoContainer.ExpectAndReturn("Parent", new DefaultPicoContainer(picoContainer)); mockPicoContainer.Strict = true; LifeCycleContainerBuilder lifeCycleContainerBuilder = new StubLifeCycleContainerBuilder(); SimpleReference reference = new SimpleReference(); reference.Set(mockPicoContainer.MockInstance); lifeCycleContainerBuilder.KillContainer(reference); mockPicoContainer.Verify(); }
public void ShouldOnlyDisposeOnce() { 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"); RemoteCruiseServer server = new RemoteCruiseServer((ICruiseServer) mockCruiseServer.MockInstance, configFile); ((IDisposable)server).Dispose(); mockCruiseServer.ExpectNoCall("Dispose"); ((IDisposable)server).Dispose(); mockCruiseServer.Verify(); }
public void WhenBuildOccurredIsFiredTheDelegateIsInvokedThroughISynchronisedInvoke() { DynamicMock mockSynchronizeInvoke = new DynamicMock(typeof (ISynchronizeInvoke)); StubServerMonitor containedMonitor = new StubServerMonitor(@"tcp://blah/"); SynchronizedServerMonitor monitor = new SynchronizedServerMonitor( containedMonitor, (ISynchronizeInvoke) mockSynchronizeInvoke.MockInstance); MonitorServerQueueChangedEventHandler delegateToQueueChanged = new MonitorServerQueueChangedEventHandler(Monitor_QueueChanged); monitor.QueueChanged += delegateToQueueChanged; mockSynchronizeInvoke.Expect("BeginInvoke", delegateToQueueChanged, new IsTypeOf(typeof (object[]))); containedMonitor.OnQueueChanged(new MonitorServerQueueChangedEventArgs(null)); mockSynchronizeInvoke.Verify(); }
public void RunForceBuild() { Workflow project = new Workflow(); IMock taskMock1 = new DynamicMock(typeof (ITask)); taskMock1.Expect("Run", new NotNull()); IMock taskMock2 = new DynamicMock(typeof (ITask)); taskMock2.Expect("Run", new NotNull()); project.Tasks.Add(taskMock1.MockInstance); project.Tasks.Add(taskMock2.MockInstance); project.Integrate(ForceBuildRequest()); taskMock1.Verify(); taskMock2.Verify(); }
public void WhenBuildOccurredIsFiredTheDelegateIsInvokedThroughISynchronisedInvoke() { DynamicMock mockSynchronizeInvoke = new DynamicMock(typeof (ISynchronizeInvoke)); StubProjectMonitor containedMonitor = new StubProjectMonitor("test"); SynchronizedProjectMonitor monitor = new SynchronizedProjectMonitor( containedMonitor, (ISynchronizeInvoke) mockSynchronizeInvoke.MockInstance); MonitorBuildOccurredEventHandler delegateToBuildOccurred = new MonitorBuildOccurredEventHandler(Monitor_BuildOccurred); monitor.BuildOccurred += delegateToBuildOccurred; mockSynchronizeInvoke.Expect("BeginInvoke", delegateToBuildOccurred, new IsTypeOf(typeof (object[]))); containedMonitor.OnBuildOccurred(new MonitorBuildOccurredEventArgs(null, BuildTransition.StillFailing)); mockSynchronizeInvoke.Verify(); }
public void WhenPolledIsFiredTheDelegateIsInvokedThroughISynchronisedInvoke() { DynamicMock mockSynchronizeInvoke = new DynamicMock(typeof (ISynchronizeInvoke)); StubProjectMonitor containedMonitor = new StubProjectMonitor("test"); SynchronizedProjectMonitor monitor = new SynchronizedProjectMonitor( containedMonitor, (ISynchronizeInvoke) mockSynchronizeInvoke.MockInstance); MonitorPolledEventHandler delegateToPolledMethod = new MonitorPolledEventHandler(Monitor_Polled); monitor.Polled += delegateToPolledMethod; mockSynchronizeInvoke.Expect("BeginInvoke", delegateToPolledMethod, new IsTypeOf(typeof (object[]))); containedMonitor.OnPolled(new MonitorPolledEventArgs(containedMonitor)); mockSynchronizeInvoke.Verify(); }
public void MethodsAndPropertiesDoSimpleDelagationOntoInjectedMonitor() { DynamicMock mockServerMonitor = new DynamicMock(typeof (ISingleServerMonitor)); SynchronizedServerMonitor monitor = new SynchronizedServerMonitor( (ISingleServerMonitor) mockServerMonitor.MockInstance, null); mockServerMonitor.ExpectAndReturn("ServerUrl", @"tcp://blah/"); Assert.AreEqual(@"tcp://blah/", monitor.ServerUrl); mockServerMonitor.ExpectAndReturn("IsConnected", true); Assert.AreEqual(true, monitor.IsConnected); mockServerMonitor.Expect("Poll"); monitor.Poll(); mockServerMonitor.Verify(); }
public void ShouldDecorateUrlsToCreateAbsoluteURLs() { /// Setup DynamicMock decoratedBuilderMock = new DynamicMock(typeof(IUrlBuilder)); string baseUrl = "https://myserver:8080/myvdir"; AbsolutePathUrlBuilderDecorator decorator = new AbsolutePathUrlBuilderDecorator((IUrlBuilder) decoratedBuilderMock.MockInstance, baseUrl); string actionName = "myAction"; decoratedBuilderMock.ExpectAndReturn("BuildUrl", "myRelativeUrl", actionName); decoratedBuilderMock.ExpectAndReturn("BuildUrl", "myRelativeUrl2", actionName, "query"); decoratedBuilderMock.ExpectAndReturn("BuildUrl", "myPath/myRelativeUrl3", actionName, "query", "myPath/"); /// Execute & Verify Assert.AreEqual(baseUrl + "/myRelativeUrl", decorator.BuildUrl(actionName)); Assert.AreEqual(baseUrl + "/myRelativeUrl2", decorator.BuildUrl(actionName, "query")); Assert.AreEqual(baseUrl + "/myPath/myRelativeUrl3", decorator.BuildUrl(actionName, "query", "myPath/")); decoratedBuilderMock.Verify(); }
public void MethodsAndPropertiesDoSimpleDelagationOntoInjectedMonitor() { DynamicMock mockProjectMonitor = new DynamicMock(typeof (IProjectMonitor)); SynchronizedProjectMonitor monitor = new SynchronizedProjectMonitor( (IProjectMonitor) mockProjectMonitor.MockInstance, null); mockProjectMonitor.ExpectAndReturn("ProjectState", null); Assert.IsNull(monitor.ProjectState); Dictionary<string, string> parameters = new Dictionary<string, string>(); mockProjectMonitor.Expect("ForceBuild", parameters, (string)null); monitor.ForceBuild(parameters, null); mockProjectMonitor.Expect("Poll"); monitor.Poll(); mockProjectMonitor.Verify(); }
public void ShowHelp() { ConsoleRunnerArguments consoleArgs = new ConsoleRunnerArguments(); consoleArgs.UseRemoting = true; consoleArgs.ShowHelp = true; Mock mockCruiseServerFactory = new DynamicMock(typeof(ICruiseServerFactory)); mockCruiseServerFactory.ExpectNoCall("Create", typeof(bool), typeof(string)); ConsoleRunner runner = new ConsoleRunner(consoleArgs, (ICruiseServerFactory)mockCruiseServerFactory.MockInstance); runner.Run(); // FIXME: should we care for the usage text and the logging implementation? // If yes read it from the embedded resource //Assert.AreEqual(1, listener.Traces.Count); //Assert.IsTrue(listener.Traces[0].ToString().IndexOf(ConsoleRunnerArguments.Usage) > 0, "Wrong message was logged."); mockCruiseServerFactory.Verify(); }
public void ForceBuildCruiseServerProject() { ConsoleRunnerArguments consoleArgs = new ConsoleRunnerArguments(); consoleArgs.Project = "test"; Mock mockCruiseServer = new DynamicMock(typeof(ICruiseServer)); var projectConstraint = new ProjectRequestConstraint { ProjectName = "test" }; mockCruiseServer.ExpectAndReturn("ForceBuild", new Response { Result = ResponseResult.Success }, projectConstraint); mockCruiseServer.ExpectAndReturn("Stop", new Response { Result = ResponseResult.Success }, projectConstraint); mockCruiseServer.Expect("WaitForExit", projectConstraint); Mock mockCruiseServerFactory = new DynamicMock(typeof(ICruiseServerFactory)); mockCruiseServerFactory.ExpectAndReturn("Create", mockCruiseServer.MockInstance, consoleArgs.UseRemoting, consoleArgs.ConfigFile); new ConsoleRunner(consoleArgs, (ICruiseServerFactory)mockCruiseServerFactory.MockInstance).Run(); mockCruiseServer.Verify(); }
public void ReuseGeneratedAssembly() { DynamicMock mock = new DynamicMock(typeof(SameClass)); mock.Ignore("A"); mock.Ignore("c"); SameClass sc = (SameClass)mock.MockInstance; mock.SetupResult("b", "hello"); Assertion.AssertEquals("hello", sc.A()); mock = new DynamicMock(typeof(SameClass)); mock.Ignore("A"); sc = (SameClass)mock.MockInstance; mock.ExpectAndReturn("c", true); mock.SetupResult("b", "hello"); AssertEquals("Should have overriden B()", "hello", sc.A()); mock.Verify(); }
public void ShouldGetBuildLogAndReturnResultOfDelegateTransformer() { DynamicMock buildRetrieverMock = new DynamicMock(typeof(IBuildRetriever)); DynamicMock delegateTransformerMock = new DynamicMock(typeof(IMultiTransformer)); BuildRequestTransformer requestTransformer = new BuildRequestTransformer((IBuildRetriever) buildRetrieverMock.MockInstance, (IMultiTransformer) delegateTransformerMock.MockInstance); DefaultBuildSpecifier buildSpecifier = new DefaultBuildSpecifier(new DefaultProjectSpecifier(new DefaultServerSpecifier("myServer"), "myProject"), "myBuild"); Build build = new Build(buildSpecifier, "logContents"); buildRetrieverMock.ExpectAndReturn("GetBuild", build, buildSpecifier, null); string[] fileNames = new string[] { "file1", "file2" }; delegateTransformerMock.ExpectAndReturn("Transform", "transformed", "logContents", fileNames, null); Assert.AreEqual("transformed", requestTransformer.Transform(buildSpecifier, fileNames, null, null)); buildRetrieverMock.Verify(); delegateTransformerMock.Verify(); }
public void PassesThroughLabelSourceControl() { //// SETUP IntegrationResult result = new IntegrationResult(); DynamicMock mockSC1 = new DynamicMock(typeof (ISourceControl)); mockSC1.Expect("LabelSourceControl", result); DynamicMock mockSC2 = new DynamicMock(typeof (ISourceControl)); mockSC2.Expect("LabelSourceControl", result); ISourceControl[] sourceControls = new ISourceControl[] {(ISourceControl) mockSC1.MockInstance, (ISourceControl) mockSC2.MockInstance}; MultiSourceControl multiSourceControl = new MultiSourceControl(); multiSourceControl.SourceControls = sourceControls; //// EXECUTE multiSourceControl.LabelSourceControl(result); //// VERIFY mockSC1.Verify(); mockSC2.Verify(); }