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 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 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 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 ShouldNotGetSourceIfAutoGetSourceFalse() { DynamicMock executor = new DynamicMock(typeof(ProcessExecutor)); ExternalSourceControl externalSC = new ExternalSourceControl((ProcessExecutor)executor.MockInstance); externalSC.AutoGetSource = false; executor.ExpectNoCall("Execute", typeof(ProcessInfo)); externalSC.GetSource(new IntegrationResult()); executor.Verify(); }
public void ShouldStopBuildIfTaskFails() { IntegrationResult result = IntegrationResultMother.CreateFailed(); mockTask.Expect("Run", result); IMock secondTask = new DynamicMock(typeof (ITask)); secondTask.ExpectNoCall("Run", typeof (IntegrationResult)); project.Tasks = new ITask[] {(ITask) mockTask.MockInstance, (ITask) secondTask.MockInstance}; project.Run(result); VerifyAll(); secondTask.Verify(); }
public void IfRequireChangesFromAllTrueAndFirstSourceControlHasEmptyChangesThenReturnEmpty() { //// SETUP IntegrationResult from = IntegrationResultMother.CreateSuccessful(DateTime.Now); IntegrationResult to = IntegrationResultMother.CreateSuccessful(DateTime.Now.AddDays(10)); Modification mod1 = new Modification(); mod1.Comment = "Testing Multi"; ArrayList mocks = new ArrayList(); mocks.Add(CreateModificationsSourceControlMock(new Modification[0], from, to)); DynamicMock nonCalledMock = new DynamicMock(typeof (ISourceControl)); nonCalledMock.ExpectNoCall("GetModifications", typeof(IIntegrationResult), typeof(IIntegrationResult)); mocks.Add(nonCalledMock); ArrayList scList = new ArrayList(); foreach (DynamicMock mock in mocks) { scList.Add(mock.MockInstance); } MultiSourceControl multiSourceControl = new MultiSourceControl(); multiSourceControl.SourceControls = (ISourceControl[]) scList.ToArray(typeof (ISourceControl)); multiSourceControl.RequireChangesFromAll = true; //// EXECUTE ArrayList returnedMods = new ArrayList(multiSourceControl.GetModifications(from, to)); //// VERIFY foreach (DynamicMock mock in mocks) { mock.Verify(); } Assert.AreEqual(0, returnedMods.Count); }
public void ShouldNotGetSourceIfAutoGetSourceFalse() { DynamicMock executor = new DynamicMock(typeof(ProcessExecutor)); ClearCase clearCase = new ClearCase((ProcessExecutor) executor.MockInstance); clearCase.Executable = EXECUTABLE; clearCase.ViewPath = VIEWPATH; clearCase.AutoGetSource = false; executor.ExpectNoCall("Execute", typeof(ProcessInfo)); clearCase.GetSource(new IntegrationResult()); executor.Verify(); }