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 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 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");
			}
		}
        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");
        }
Exemple #5
0
 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 DefaultPowerShellShouldBe1IfNothingNewerInstalled()
        {
            IMock mockRegistry2 = new DynamicMock(typeof(IRegistry));

            PowerShellTask task = new PowerShellTask((IRegistry)mockRegistry2.MockInstance, (ProcessExecutor)mockProcessExecutor.MockInstance);
            mockRegistry2.ExpectAndReturn("GetLocalMachineSubKeyValue", null, PowerShellTask.regkeypowershell2, PowerShellTask.regkeyholder);
            mockRegistry2.ExpectAndReturn("GetLocalMachineSubKeyValue", POWERSHELL1_PATH,
                                         PowerShellTask.regkeypowershell1, PowerShellTask.regkeyholder);
            Assert.AreEqual(POWERSHELL1_PATH + "\\powershell.exe", task.Executable);
            mockRegistry2.Verify();
            mockProcessExecutor.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 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 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 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 ViewManagerCreateView()
        {
            DynamicMock useCase = new DynamicMock(typeof(IUseCase));
            IUseCase useCaseMockInstance = (IUseCase)useCase.MockInstance;

            IRegexEngine engine = new DotNetRegexEngine();
            IRegexView view = new ReplaceView();

            useCase.ExpectAndReturn("CreateNewView", view);
            useCase.ExpectAndReturn("CreateNewEngine", engine);

            ViewManager factory = new ViewManager();
            IRegexView newView = factory.CreateView(useCaseMockInstance);
            Form frm = (Form)newView;
            frm.ShowDialog();
        }
		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 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 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);


		}
		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 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 TestSimpleSmtpNegotiationWithAuth()
		{


			SmtpServer smtpserver=new SmtpServer("localhost");
			smtpserver.SmtpAuthToken=new SmtpAuthToken("test", "test");			
			
			
			Base64Encoder encoder=Base64Encoder.GetInstance();
			String base64Username=encoder.EncodeString(smtpserver.SmtpAuthToken.UserName, System.Text.Encoding.ASCII );
			String base64Password=encoder.EncodeString(smtpserver.SmtpAuthToken.Password, System.Text.Encoding.ASCII );

			EmailMessage emailMessage=GetTestHtmlAndTextMessage();

			IMock mockSmtpProxy = new DynamicMock(typeof(ISmtpProxy));
			mockSmtpProxy.ExpectAndReturn("Open", new SmtpResponse(220, "welcome to the mock object server"), null);

			EhloSmtpResponse ehloResponse=new EhloSmtpResponse();
			ehloResponse.AddAvailableAuthType("login");
			
			ehloResponse.Message="OK";
			ehloResponse.ResponseCode=250;
			mockSmtpProxy.ExpectAndReturn("Ehlo",ehloResponse , Dns.GetHostName());
			mockSmtpProxy.ExpectAndReturn("Auth", new SmtpResponse(334, encoder.EncodeString("Username:"******"login");
			mockSmtpProxy.ExpectAndReturn("SendString", new SmtpResponse(334, encoder.EncodeString("Password:"******"SendString", new SmtpResponse(235, "Hooray, Authenticated"), base64Password);
			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);
			
			try 
			{
				emailMessage.Send(smtpserver);
			}
			catch (SmtpException ex)
			{
				log.Debug("Exception was "+ex.Message);
				log.Debug(ex.StackTrace);
				throw ex;
			}

		}
		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();
		}	
Exemple #20
0
        [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 Setup()
		{
			serverSpecifier = new DefaultServerSpecifier(serverName);
			projectSpecifier = new DefaultProjectSpecifier(serverSpecifier, projectName);
			buildSpecifier = new DefaultBuildSpecifier(projectSpecifier, buildName);
			linkFactoryMock = new DynamicMock(typeof (ILinkFactory));
			configurationMock = new DynamicMock(typeof (IPluginConfiguration));
			Plugins = new DefaultPluginLinkCalculator((ILinkFactory) linkFactoryMock.MockInstance, (IPluginConfiguration) configurationMock.MockInstance);

			pluginMock1 = new DynamicMock(typeof (IPlugin));
			pluginMock2 = new DynamicMock(typeof (IPlugin));
			action1 = new ImmutableNamedAction("Action Name 1", null);
			action2 = new ImmutableNamedAction("Action Name 2", null);
			action3 = new ImmutableNamedAction("Action Name 3", null);
			pluginMock1.ExpectAndReturn("LinkDescription", "Description 1");
			pluginMock1.ExpectAndReturn("NamedActions", new INamedAction[] {action1});
			pluginMock2.ExpectAndReturn("LinkDescription", "Description 2");
			pluginMock2.ExpectAndReturn("NamedActions", new INamedAction[] {action2});
			link1 = (IAbsoluteLink) new DynamicMock(typeof (IAbsoluteLink)).MockInstance;
			link2 = (IAbsoluteLink) new DynamicMock(typeof (IAbsoluteLink)).MockInstance;
		}
Exemple #22
0
        [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 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();
		}
		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();
		}
		public void CanProvideASetOfProjectStatusMonitors()
		{
			CCTrayMultiConfiguration provider = CreateTestConfiguration(ConfigXml);
            DynamicMock mockCruiseServerManager = new DynamicMock(typeof(ICruiseServerManager));
		    mockCruiseServerManager.Strict = true;
            mockCruiseServerManager.ExpectAndReturn("Configuration", new BuildServer("tcp://blah1"));
            mockCruiseServerManager.ExpectAndReturn("Configuration", new BuildServer("tcp://blah2"));
		    ICruiseServerManager cruiseServerManagerInstance = (ICruiseServerManager) mockCruiseServerManager.MockInstance;

            mockServerConfigFactory.ExpectAndReturn("Create", cruiseServerManagerInstance, provider.GetUniqueBuildServerList()[0]);
            mockServerConfigFactory.ExpectAndReturn("Create", cruiseServerManagerInstance, provider.GetUniqueBuildServerList()[1]);
            ISingleServerMonitor[] serverMonitorList = provider.GetServerMonitors();

			mockProjectConfigFactory.ExpectAndReturn("Create", null, provider.Projects[0], null);
			mockProjectConfigFactory.ExpectAndReturn("Create", null, provider.Projects[1], null);

            IProjectMonitor[] monitorList = provider.GetProjectStatusMonitors(serverMonitorList);
			Assert.AreEqual(2, monitorList.Length);

			mockProjectConfigFactory.Verify();
            mockServerConfigFactory.Verify();
            mockCruiseServerManager.Verify();
		}
Exemple #26
0
        [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();
        }
Exemple #27
0
        [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();
        }
Exemple #28
0
        [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 ShouldInstantiateArrayOfStrings()
		{
			CollectionComponentParameter ccp = new CollectionComponentParameter();

			Mock componentAdapterMock = new DynamicMock(typeof (IComponentAdapter));
			componentAdapterMock.ExpectAndReturn("ComponentKey", "x", null);
			componentAdapterMock.ExpectAndReturn("ComponentKey", "x", null);

			Mock containerMock = new DynamicMock(typeof (IPicoContainer));
			containerMock.ExpectAndReturn("ComponentAdapters", new Hashtable(), null);

			IComponentAdapter[] adapters = new IComponentAdapter[]
				{
					new InstanceComponentAdapter("y", "Hello"),
					new InstanceComponentAdapter("z", "World")
				};

			containerMock.ExpectAndReturn("GetComponentAdaptersOfType", adapters, new IsEqual(typeof (string)));
			containerMock.ExpectAndReturn("GetComponentInstance", "World", new IsEqual("z"));
			containerMock.ExpectAndReturn("GetComponentInstance", "Hello", new IsEqual("y"));
			containerMock.ExpectAndReturn("Parent", null, null);

			ArrayList expected = new ArrayList(new string[] {"Hello", "World"});
			expected.Sort();

			object[] array = (object[]) ccp.ResolveInstance((IPicoContainer) containerMock.MockInstance,
                (IComponentAdapter) componentAdapterMock.MockInstance, 
				typeof (string[]));

			ArrayList actual = new ArrayList(array);
			actual.Sort();
			Assert.AreEqual(expected.ToArray(), actual.ToArray());

			// Verify mocks
			componentAdapterMock.Verify();
			containerMock.Verify();
		}
			public void ShouldGenerateAFileInTheArtifactDirectory()
			{
				IMock mockIntegrationResult = new DynamicMock(typeof (IIntegrationResult));
				mockIntegrationResult.ExpectAndReturn("ArtifactDirectory", artifactDirectory);
				IIntegrationResult mockIntegrationResultInstance = (IIntegrationResult) mockIntegrationResult.MockInstance;
				IMock mockProcessor = new DynamicMock(typeof(BuildStatisticsProcessor));
				IntegrationStatistics statistics = new IntegrationStatistics();
				mockProcessor.ExpectAndReturn("ProcessBuildResults", statistics, mockIntegrationResultInstance);
				publisher.Processor = (BuildStatisticsProcessor) mockProcessor.MockInstance;
				publisher.Run(mockIntegrationResultInstance);
				filePath = Path.Combine(artifactDirectory, publisher.FileName);
				bool fileExists = File.Exists(filePath);
				Assert.IsTrue(fileExists);
				if (fileExists) File.Delete(filePath);
			}
		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 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 ShouldHandleIncrementingLabelAfterInitialBuildFailsWithException()
		{
			IMock mockSourceControl = new DynamicMock(typeof (ISourceControl));
			mockSourceControl.ExpectAndThrow("GetModifications", new Exception("doh!"), new IsAnything(), new IsAnything());
			mockSourceControl.ExpectAndReturn("GetModifications", new Modification[] {new Modification()}, new IsAnything(), new IsAnything());

			Project project = new Project();
			project.Name = "test";
			project.SourceControl = (ISourceControl) mockSourceControl.MockInstance;
			project.StateManager = new StateManagerStub();
			try { project.Integrate(new IntegrationRequest(BuildCondition.ForceBuild, "test", null));}
			catch (Exception) { }

			project.Integrate(new IntegrationRequest(BuildCondition.ForceBuild, "test", null));
			Assert.AreEqual(IntegrationStatus.Success, project.CurrentResult.Status);
			Assert.AreEqual("1", project.CurrentResult.Label);
		}
		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 CurrentlyAddedProjectsAreIgnoredWhenServerIsSelected()
		{
			CCTrayProject[] allProjects = {
			                        	new CCTrayProject("tcp://localhost:123/blah", "proj1"),
			                        	new CCTrayProject("tcp://localhost:123/blah", "proj2"),
			                        	new CCTrayProject("tcp://localhost:123/blah", "proj3"),
			                        };

			CCTrayProject[] selectedProjects = {
			                             	new CCTrayProject("tcp://localhost:123/blah", "proj1"),
			                             	new CCTrayProject("tcp://localhost:123/blah", "proj2"),
			                             };

			DynamicMock mockCruiseManagerFactory = new DynamicMock(typeof (ICruiseProjectManagerFactory));
			mockCruiseManagerFactory.ExpectAndReturn("GetProjectList", allProjects, allProjects[0].BuildServer, false);
			AddProjects addProjects = new AddProjects(
                (ICruiseProjectManagerFactory)mockCruiseManagerFactory.MockInstance,
                null, 
                selectedProjects);
		}
Exemple #36
0
        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();
        }