public void Correctly_constructs_action_executors()
		{
			DatabaseAction[] actions = new DatabaseAction[] { DatabaseAction.Create, DatabaseAction.Update };

			MockRepository mocks = new MockRepository();
			IDatabaseActionResolver resolver = mocks.CreateMock<IDatabaseActionResolver>();
            IDataBaseActionLocator locator = mocks.CreateMock<IDataBaseActionLocator>();

			IDatabaseActionExecutor creator = mocks.CreateMock<IDatabaseActionExecutor>();
			IDatabaseActionExecutor updater = mocks.CreateMock<IDatabaseActionExecutor>();

			using (mocks.Record())
			{
				Expect.Call(resolver.GetActions(RequestedDatabaseAction.Create)).Return(actions);
				Expect.Call(locator.CreateInstance(DatabaseAction.Create)).Return(creator);
				Expect.Call(locator.CreateInstance(DatabaseAction.Update)).Return(updater);
			}

			using (mocks.Playback())
			{
				IDatabaseActionExecutorFactory factory = new DatabaseActionExecutorFactory(resolver, locator);
				IEnumerable<IDatabaseActionExecutor> executors = factory.GetExecutors(RequestedDatabaseAction.Create);
				IList<IDatabaseActionExecutor> executorList = new List<IDatabaseActionExecutor>(executors);

				Assert.That(executorList, Is.EqualTo(new IDatabaseActionExecutor[]{ creator, updater }));		
			}

			mocks.VerifyAll();
		}
		public void Constructs_deployment()
		{
			var mocks = new MockRepository();
			var clock = mocks.CreateMock<ISystemClock>();
			var resultCalculator = mocks.CreateMock<IDeploymentResultCalculator>();

			using (mocks.Record())
			{
				Expect.Call(clock.GetCurrentDateTime()).Return(new DateTime(2007, 4, 15));
			}

			using (mocks.Playback())
			{
				IDeploymentFactory factory = new DeploymentFactory(clock, resultCalculator);
				Deployment deployment = factory.CreateDeployment("A1", "E1", "jsmith", "Output...", "1.0", true);

				Assert.That(deployment.Application, Is.EqualTo("A1"));
				Assert.That(deployment.Environment, Is.EqualTo("E1"));
				Assert.That(deployment.DeployedBy, Is.EqualTo("jsmith"));
				Assert.That(deployment.DeployedOn, Is.EqualTo(new DateTime(2007, 4, 15)));
				Assert.That(deployment.Version, Is.EqualTo("1.0"));
				Assert.That(deployment.Output.Output, Is.EqualTo("Output..."));
				Assert.That(deployment.Result, Is.SameAs(DeploymentResult.Failure));
				Assert.That(deployment.Output.Deployment, Is.SameAs(deployment));
			}

			mocks.VerifyAll();
		}
		public void Creates_new_application_instance()
		{
			MockRepository mocks = new MockRepository();
			ISystemEnvironment systemEnvironment = mocks.CreateMock<ISystemEnvironment>();
			IAssemblyContext context = mocks.CreateMock<IAssemblyContext>();
			IConfigurationReader configurationReader = mocks.CreateMock<IConfigurationReader>();

			using (mocks.Record())
			{
				Expect.Call(context.GetAssemblyVersion()).Return("1.0");
				Expect.Call(systemEnvironment.GetMachineName()).Return("MyMachine");
				Expect.Call(configurationReader.GetRequiredSetting("TarantinoWebManagementHttpHost")).Return("www.myapp.com");
			}

			using (mocks.Playback())
			{
				IApplicationInstanceFactory factory = new ApplicationInstanceFactory(systemEnvironment, context, configurationReader);
				ApplicationInstance instance = factory.Create();

				Assert.That(instance.AvailableForLoadBalancing, Is.True);
				Assert.That(instance.MachineName, Is.EqualTo("MyMachine"));
				Assert.That(instance.Version, Is.EqualTo("1.0"));
				Assert.That(instance.MaintenanceHostHeader, Is.EqualTo("www.myapp.com"));
				Assert.That(instance.ApplicationDomain, Is.EqualTo("www.myapp.com"));
			}

			mocks.VerifyAll();
		}
		public void Can_read_worksheet_from_excel_workbook()
		{
			string excelFile = "MyWorkbook.xls";
			MemoryStream excelFileStream = new MemoryStream();

			DataSet workbook = createWorkbook();

			MockRepository mocks = new MockRepository();
			IFileSystem fileSystem = mocks.CreateMock<IFileSystem>();
			IExcelWorkbookReader workbookReader = mocks.CreateMock<IExcelWorkbookReader>();

			Expect.Call(fileSystem.ReadIntoFileStream(excelFile)).Return(excelFileStream);
			Expect.Call(workbookReader.GetWorkbookData(excelFileStream)).Return(workbook);

			mocks.ReplayAll();

			IExcelWorksheetReader worksheetReader = new ExcelWorksheetReader(fileSystem, workbookReader);
			DataTable myWorksheet = worksheetReader.GetWorksheet(excelFile, "MyWorksheet");

			Assert.That(myWorksheet, Is.Not.Null);
			Assert.That(myWorksheet.Columns.Count, Is.EqualTo(2));
			Assert.That(myWorksheet.Columns[0].ColumnName, Is.EqualTo("First Column"));
			Assert.That(myWorksheet.Columns[1].ColumnName, Is.EqualTo("Second Column"));

			Assert.That(myWorksheet.Rows.Count, Is.EqualTo(2));
			Assert.That(myWorksheet.Rows[0]["First Column"], Is.EqualTo("Row 1 - First Column Value"));
			Assert.That(myWorksheet.Rows[0]["Second Column"], Is.EqualTo("Row 1 - Second Column Value"));
			Assert.That(myWorksheet.Rows[1]["First Column"], Is.EqualTo("Row 2 - First Column Value"));
			Assert.That(myWorksheet.Rows[1]["Second Column"], Is.EqualTo("Row 2 - Second Column Value"));

			mocks.VerifyAll();
		}
Exemplo n.º 5
0
		public void Correctly_handles_when_service_agent_aggregator_throws_exception()
		{
			ApplicationException exception = new ApplicationException();

			MockRepository mocks = new MockRepository();
			IApplicationSettings settings = mocks.CreateMock<IApplicationSettings>();
			IServiceAgentAggregator aggregator = mocks.CreateMock<IServiceAgentAggregator>();

			IServiceRunner runner = new ServiceRunner(aggregator, settings);

			using (mocks.Record())
			{

				aggregator.ExecuteServiceAgentCycle();
				LastCall.Throw(exception);

			}

			using (mocks.Playback())
			{
				runner.Start();
				Thread.Sleep(500);
				runner.Stop();
			}

			mocks.VerifyAll();
		}
Exemplo n.º 6
0
		public void Run_service()
		{
			MockRepository mocks = new MockRepository();
			IApplicationSettings settings = mocks.CreateMock<IApplicationSettings>();
			IServiceAgentAggregator aggregator = mocks.CreateMock<IServiceAgentAggregator>();

			IServiceRunner runner = new ServiceRunner(aggregator, settings);

			using (mocks.Record())
			{


				aggregator.ExecuteServiceAgentCycle();
				LastCall.Repeat.Times(2, int.MaxValue);

				Expect.Call(settings.GetServiceSleepTime()).Return(10);
				LastCall.Repeat.Times(2, int.MaxValue);

			}

			using (mocks.Playback())
			{
				runner.Start();
				Thread.Sleep(500);
				runner.Stop();
			}

			mocks.VerifyAll();
		}
Exemplo n.º 7
0
		public void Correctly_build_menu_view()
		{
			MockRepository mocks = new MockRepository();
			IResourceFileLocator locator = mocks.CreateMock<IResourceFileLocator>();
			ITokenReplacer replacer = mocks.CreateMock<ITokenReplacer>();

			using (mocks.Record())
			{
				string htmlTemplate = "||APPLICATION_URL|| ||CACHE_URL|| ||ASSEMBLY_URL|| ||LOADBALANCER_URL|| ||DISABLE_URL||";
				Expect.Call(locator.ReadTextFile("Tarantino.Core", MenuView.MenuTemplate)).Return(htmlTemplate);
				replacer.Text = htmlTemplate;

				replacer.Replace("APPLICATION_URL", "Tarantino.WebManagement.Application.axd");
				replacer.Replace("CACHE_URL", "Tarantino.WebManagement.Cache.axd");
				replacer.Replace("ASSEMBLY_URL", "Tarantino.WebManagement.Assemblies.axd");
				replacer.Replace("LOADBALANCER_URL", "Tarantino.WebManagement.LoadBalancer.axd");
				replacer.Replace("DISABLE_URL", "Tarantino.WebManagement.DisableSSL.axd");

				Expect.Call(replacer.Text).Return("fully formatted html");
			}

			using (mocks.Playback())
			{
				IMenuView menuView = new MenuView(locator, replacer);
				string html = menuView.BuildHtml();

				Assert.That(html, Is.EqualTo("fully formatted html"));
			}
		}
 public void SetUp()
 {
     mocker = new MockRepository();
     service = mocker.PartialMock<HarvestService>();
     harvestor = mocker.CreateMock<IHarvester>();
     scripter = mocker.CreateMock<ISqlScripter>();
 }
		public void Records_deployment()
		{
			var deployment = new Deployment{ Version = "1.0"};

			var mocks = new MockRepository();
			var factory = mocks.CreateMock<IDeploymentFactory>();
			var repository = mocks.CreateMock<IDeploymentRepository>();
			var context = mocks.CreateMock<ISecurityContext>();

			using (mocks.Record())
			{
				Expect.Call(context.GetCurrentUsername()).Return("jsmith");
				Expect.Call(factory.CreateDeployment("application", "environment", "jsmith", "Output...", "1.0", false)).Return(deployment);
				repository.Save(deployment);
			}

			using (mocks.Playback())
			{
				IDeploymentRecorder recorder = new DeploymentRecorder(context, factory, repository);
				var version = recorder.RecordDeployment("application", "environment", "Output...", "1.0", false);

				Assert.That(version, Is.EqualTo("1.0"));
			}

			mocks.VerifyAll();
		}
		public void JustPassesAfterReturningAdviceExceptionUpWithoutAnyWrapping()
		{

            MockRepository repository = new MockRepository();
            IMethodInvocation mockInvocation = (IMethodInvocation)repository.CreateMock(typeof(IMethodInvocation));
		    IAfterReturningAdvice mockAdvice = (IAfterReturningAdvice) repository.CreateMock(typeof (IAfterReturningAdvice));
		    mockAdvice.AfterReturning(null,null,null,null);
		    LastCall.IgnoreArguments();
		    LastCall.Throw(new FormatException());

            Expect.Call(mockInvocation.Method).Return(ReflectionUtils.GetMethod(typeof(object), "HashCode", new Type[] { }));
            Expect.Call(mockInvocation.Arguments).Return(null);
            Expect.Call(mockInvocation.This).Return(new object());           
		    Expect.Call(mockInvocation.Proceed()).Return(null);

            repository.ReplayAll();

            try
            {
                AfterReturningAdviceInterceptor interceptor = new AfterReturningAdviceInterceptor(mockAdvice);
                interceptor.Invoke(mockInvocation);
                Assert.Fail("Must have thrown a FormatException by this point.");
            }
            catch (FormatException)
            {
            }
            repository.VerifyAll();





		}
		public void Correctly_drops_connections()
		{
			string assembly = SqlDatabaseManager.SQL_FILE_ASSEMBLY;
			string sqlFile = string.Format(SqlDatabaseManager.SQL_FILE_TEMPLATE, "DropConnections");

			ConnectionSettings settings = new ConnectionSettings("server", "MyDatabase", true, null, null);

			MockRepository mocks = new MockRepository();

			ITaskObserver taskObserver = mocks.CreateMock<ITaskObserver>();			
			IResourceFileLocator fileLocator = mocks.CreateMock<IResourceFileLocator>();
			ITokenReplacer replacer = mocks.CreateMock<ITokenReplacer>();
			IQueryExecutor queryExecutor = mocks.CreateMock<IQueryExecutor>();

			using (mocks.Record())
			{
				taskObserver.Log("Dropping connections for database MyDatabase\n");
				Expect.Call(fileLocator.ReadTextFile(assembly, sqlFile)).Return("Unformatted SQL");
				replacer.Text = "Unformatted SQL";
				replacer.Replace("DatabaseName", "MyDatabase");
				Expect.Call(replacer.Text).Return("Formatted SQL");
				queryExecutor.ExecuteNonQuery(settings, "Formatted SQL", false);
			}

			using (mocks.Playback())
			{
				IDatabaseConnectionDropper dropper = new DatabaseConnectionDropper(fileLocator, replacer, queryExecutor);
				dropper.Drop(settings, taskObserver);
			}

			mocks.VerifyAll();
		}
		public void Manages_database()
		{
			var settings = new ConnectionSettings("server", "db", true, null, null);
            var scriptDirectory = @"c:\scripts"; 
            var taskAttributes = new TaskAttributes(settings, scriptDirectory);

			var mocks = new MockRepository();
			var taskObserver = mocks.CreateMock<ITaskObserver>();
			var generator = mocks.CreateMock<ILogMessageGenerator>();
			var factory = mocks.CreateMock<IDatabaseActionExecutorFactory>();

			var creator = mocks.CreateMock<IDatabaseActionExecutor>();
			var updater = mocks.CreateMock<IDatabaseActionExecutor>();

			var executors = new IDatabaseActionExecutor[] { creator, updater };

			using (mocks.Record())
			{
				Expect.Call(generator.GetInitialMessage(taskAttributes)).Return("starting...");
				taskObserver.Log("starting...");
				Expect.Call(factory.GetExecutors(RequestedDatabaseAction.Create)).Return(executors);

                creator.Execute(taskAttributes, taskObserver);
                updater.Execute(taskAttributes, taskObserver);
			}

			using (mocks.Playback())
			{
				ISqlDatabaseManager manager = new SqlDatabaseManager(generator, factory);

				manager.Upgrade(taskAttributes, taskObserver);
			}

			mocks.VerifyAll();
		}
		public void Should_enable_load_balancing_when_requested()
		{
			ApplicationInstance instance = new ApplicationInstance();
			instance.AvailableForLoadBalancing = false;

			MockRepository mocks = new MockRepository();
			IApplicationInstanceContext instanceContext = mocks.CreateMock<IApplicationInstanceContext>();
			IWebContext context = mocks.CreateMock<IWebContext>();
			ISecureAvailabilityStatusUpdater updater = mocks.CreateMock<ISecureAvailabilityStatusUpdater>();			

			using (mocks.Record())
			{
				Expect.Call(instanceContext.GetCurrent()).Return(instance);
				Expect.Call(context.GetRequestItem(LoadBalanceStatusManager.ENABLED_PARAM)).Return("True");
				Expect.Call(updater.SetStatus(true)).Return("My error message");
			}

			using (mocks.Playback())
			{
				ILoadBalanceStatusManager manager = new LoadBalanceStatusManager(instanceContext, context, updater);
				string errorMessage = manager.HandleLoadBalanceRequest();

				Assert.That(errorMessage, Is.EqualTo("My error message"));
			}
		}
		public void Versions_database()
		{
			string assembly = SqlDatabaseManager.SQL_FILE_ASSEMBLY;
			string sqlFile = string.Format(SqlDatabaseManager.SQL_FILE_TEMPLATE, "VersionDatabase");

			ConnectionSettings settings = new ConnectionSettings(String.Empty, String.Empty, false, String.Empty, String.Empty);
			string sqlScript = "SQL script...";

			MockRepository mocks = new MockRepository();
			IResourceFileLocator fileLocator = mocks.CreateMock<IResourceFileLocator>();
			IQueryExecutor queryExecutor = mocks.CreateMock<IQueryExecutor>();
			ITaskObserver taskObserver = mocks.CreateMock<ITaskObserver>();

			using (mocks.Record())
			{
				Expect.Call(fileLocator.ReadTextFile(assembly, sqlFile)).Return(sqlScript);
				Expect.Call(queryExecutor.ExecuteScalarInteger(settings, sqlScript)).Return(7);
				taskObserver.SetVariable("usdDatabaseVersion", "7");
			}

			using (mocks.Playback())
			{
				IDatabaseVersioner versioner = new DatabaseVersioner(fileLocator, queryExecutor);
				versioner.VersionDatabase(settings, taskObserver);
			}

			mocks.VerifyAll();
		}
		public void Should_send_forgotten_password_email_when_email_address_exists()
		{
			MailMessage forgottenPasswordEmail = new MailMessage();

			MockRepository mocks = new MockRepository();
			ISystemUser user = mocks.CreateMock<ISystemUser>();
			IForgottenPasswordMailFactory mailFactory = mocks.CreateMock<IForgottenPasswordMailFactory>();
			ISystemUserRepository repository = mocks.CreateMock<ISystemUserRepository>();
			IEncryptionEngine encryptionEngine = mocks.CreateMock<IEncryptionEngine>();
			IMailSender sender = mocks.CreateMock<IMailSender>();

			using (mocks.Record())
			{
				Expect.Call(repository.GetByEmailAddress("*****@*****.**")).Return(user);
				Expect.Call(user.Password).Return("encryptedPassword");
				Expect.Call(encryptionEngine.Decrypt("encryptedPassword")).Return("clearTextPassword");

				Expect.Call(mailFactory.CreateEmail("*****@*****.**", "clearTextPassword")).Return(forgottenPasswordEmail);

				sender.SendMail(forgottenPasswordEmail);
			}

			using (mocks.Playback())
			{
				IForgottenPasswordMailer mailer = new ForgottenPasswordMailer(encryptionEngine, mailFactory, sender);
				bool emailWasSent = mailer.SendForgottenPasswordEmail("*****@*****.**", repository);
				Assert.That(emailWasSent);
			}

			mocks.VerifyAll();
		}
		public void Correctly_executes_service_agents()
		{
			MockRepository mocks = new MockRepository();

			IApplicationSettings settings = mocks.CreateMock<IApplicationSettings>();
			ITypeActivator activator = mocks.CreateMock<ITypeActivator>();
			IServiceAgentFactory factory = mocks.CreateMock<IServiceAgentFactory>();
			IServiceAgent serviceAgent1 = mocks.CreateMock<IServiceAgent>();
			IServiceAgent serviceAgent2 = mocks.CreateMock<IServiceAgent>();
			IServiceAgent[] serviceAgents = new IServiceAgent[] { serviceAgent1, serviceAgent2 };

			IServiceAgentAggregator aggregator = new ServiceAgentAggregator(settings, activator);

			using (mocks.Record())
			{
				Expect.Call(settings.GetServiceAgentFactory()).Return("serviceAgentType");
				Expect.Call(activator.ActivateType<IServiceAgentFactory>("serviceAgentType")).Return(factory);
				Expect.Call(factory.GetServiceAgents()).Return(serviceAgents);

				Expect.Call(serviceAgent1.AgentName).Return("FirstAgent").Repeat.Any();
				serviceAgent1.Run();

				Expect.Call(serviceAgent2.AgentName).Return("SecondAgent").Repeat.Any();
				serviceAgent2.Run();
			}

			using (mocks.Playback())
			{
				aggregator.ExecuteServiceAgentCycle();
			}

			mocks.VerifyAll();
		}
		public void Correctly_creates_new_application_instance_if_existing_instance_does_not_exist()
		{
			ApplicationInstance instance = new ApplicationInstance();

			MockRepository mocks = new MockRepository();
			ISystemEnvironment environment = mocks.CreateMock<ISystemEnvironment>();
			IConfigurationReader configurationReader = mocks.CreateMock<IConfigurationReader>();
			IApplicationInstanceRepository repository = mocks.CreateMock<IApplicationInstanceRepository>();
			IApplicationInstanceFactory factory = mocks.CreateMock<IApplicationInstanceFactory>();

			using (mocks.Record())
			{
				Expect.Call(environment.GetMachineName()).Return("MyMachine");
				Expect.Call(configurationReader.GetRequiredSetting("TarantinoWebManagementHttpHost")).Return("www.myapp.com");
				Expect.Call(repository.GetByMaintenanceHostHeaderAndMachineName("www.myapp.com", "MyMachine")).Return(null);
				Expect.Call(factory.Create()).Return(instance);
				repository.Save(instance);
			}

			using (mocks.Playback())
			{
				ICurrentApplicationInstanceRetriever retriever = new CurrentApplicationInstanceRetriever(environment, configurationReader, repository, factory);
				Assert.That(retriever.GetApplicationInstance(), Is.SameAs(instance));
			}

			mocks.VerifyAll();
		}
        public void CanCreateFromExplicitConfiguration()
        {
            string SESSIONFACTORY_OBJECTNAME = "SessionFactory";
            string ENTITYINTERCEPTOR_OBJECTNAME = "EntityInterceptor";

            MockRepository mocks = new MockRepository();
            ISessionFactory expectedSessionFactory =  (ISessionFactory) mocks.CreateMock(typeof(ISessionFactory));
            IInterceptor expectedEntityInterceptor = (IInterceptor) mocks.CreateMock(typeof(IInterceptor));
            bool expectedSingleSession = false;
            FlushMode expectedDefaultFlushMode = FlushMode.Auto;

            // create and register context
            StaticApplicationContext appCtx = new StaticApplicationContext();
            appCtx.Name = AbstractApplicationContext.DefaultRootContextName;
            appCtx.ObjectFactory.RegisterSingleton(SESSIONFACTORY_OBJECTNAME, expectedSessionFactory);
            appCtx.ObjectFactory.RegisterSingleton(ENTITYINTERCEPTOR_OBJECTNAME, expectedEntityInterceptor);
            ContextRegistry.Clear();
            ContextRegistry.RegisterContext(appCtx);

            // simulate config section
            string thisTypeName = this.GetType().FullName;
            DictionaryVariableSource variableSource = new DictionaryVariableSource()
                .Add(thisTypeName + ".SessionFactoryObjectName", SESSIONFACTORY_OBJECTNAME)
                .Add(thisTypeName + ".EntityInterceptorObjectName", ENTITYINTERCEPTOR_OBJECTNAME)
                .Add(thisTypeName + ".SingleSession", expectedSingleSession.ToString().ToLower() ) // case insensitive!
                .Add(thisTypeName + ".DefaultFlushMode", expectedDefaultFlushMode.ToString().ToLower() ) // case insensitive!
                ;

            ConfigSectionSessionScopeSettings settings = new ConfigSectionSessionScopeSettings(this.GetType(), variableSource);

            Assert.AreEqual( expectedSessionFactory, settings.SessionFactory );
            Assert.AreEqual( expectedEntityInterceptor, settings.EntityInterceptor );
            Assert.AreEqual( expectedSingleSession, settings.SingleSession );
            Assert.AreEqual( expectedDefaultFlushMode, settings.DefaultFlushMode );
        }
Exemplo n.º 19
0
 public void Setup()
 {
     _mockery = new MockRepository();
     //            _dataAccessMock = _mockery.CreateMock<DataAccess>();
     _batchMock = _mockery.CreateMock<Batch>();
     _userMock = _mockery.CreateMock<User>(11951, "IPDuncan");
 }
Exemplo n.º 20
0
        public void ShouldOnlyExecuteActionsQueuedWhileNotStopped()
        {
            var mockery = new MockRepository();
            var action1 = mockery.CreateMock<Action>();
            var action2 = mockery.CreateMock<Action>();
            var action3 = mockery.CreateMock<Action>();

            using (mockery.Record())
            {
                action1();
                action2();
            }

            using (mockery.Playback())
            {
                var queue = new DefaultQueue();
                queue.Enqueue(action1);

                var run = new Thread(queue.Run);

                run.Start();
                Thread.Sleep(100);
                queue.Enqueue(action2);
                queue.Stop();
                queue.Enqueue(action3);
                Thread.Sleep(100);
                run.Join();
            }
        }
Exemplo n.º 21
0
		public void Correctly_assigns_current_user_to_role()
		{
			MockRepository mocks = new MockRepository();

			IPrincipal principal = mocks.CreateMock<IPrincipal>();
			IIdentity identity = mocks.CreateMock<IIdentity>();
			IWebContext context = mocks.CreateMock<IWebContext>();
			IPrincipalFactory principalFactory = mocks.CreateMock<IPrincipalFactory>();

			using (mocks.Record())
			{
				Expect.Call(context.GetUserIdentity()).Return(identity);
				Expect.Call(principalFactory.CreatePrincipal(identity, "Administrator", "Other Role")).Return(principal);
				context.SetUser(principal);
			}

			mocks.ReplayAll();

			using (mocks.Playback())
			{
				IRoleAssigner assigner = new RoleAssigner(context, principalFactory);
				assigner.AssignCurrentUserToRoles("Administrator", "Other Role");
			}

			mocks.VerifyAll();
		}
		public void CorrectlyExecutesScriptIfItHasntAlreadyBeenExecuted()
		{
			ConnectionSettings settings = getConnectionSettings();
			string scriptFile = @"c:\scripts\Update\01_Test.sql";
			string fileContents = "file contents...";

			MockRepository mocks = new MockRepository();
			IScriptExecutionTracker executionTracker = mocks.CreateMock<IScriptExecutionTracker>();
			IFileSystem fileSystem = mocks.CreateMock<IFileSystem>();
			IQueryExecutor queryExecutor = mocks.CreateMock<IQueryExecutor>();
			ITaskObserver taskObserver = mocks.CreateMock<ITaskObserver>();

			Expect.Call(executionTracker.ScriptAlreadyExecuted(settings, "01_Test.sql")).Return(false);
			taskObserver.Log("Executing: 01_Test.sql");
			Expect.Call(fileSystem.ReadTextFile(scriptFile)).Return(fileContents);
			queryExecutor.ExecuteNonQuery(settings, fileContents, true);
			executionTracker.MarkScriptAsExecuted(settings, "01_Test.sql", taskObserver);

			mocks.ReplayAll();

			IChangeScriptExecutor executor = new ChangeScriptExecutor(executionTracker, queryExecutor, fileSystem);
			executor.Execute(scriptFile, settings, taskObserver);

			mocks.VerifyAll();
		}
Exemplo n.º 23
0
		public void Certifies_deployment()
		{
			var deployment = new Deployment();

			var mocks = new MockRepository();
			var clock = mocks.CreateMock<ISystemClock>();
			var securityContext = mocks.CreateMock<ISecurityContext>();
			var repository = mocks.CreateMock<IDeploymentRepository>();

			using (mocks.Record())
			{
				Expect.Call(clock.GetCurrentDateTime()).Return(new DateTime(2007, 4, 15));
				Expect.Call(securityContext.GetCurrentUsername()).Return("khurwitz");
				repository.Save(deployment);
			}

			using (mocks.Playback())
			{
				IVersionCertifier certifier = new VersionCertifier(clock, securityContext, repository);
				certifier.Certify(deployment);
				
				Assert.That(deployment.CertifiedBy, Is.EqualTo("khurwitz"));
				Assert.That(deployment.CertifiedOn, Is.EqualTo(new DateTime(2007, 4, 15)));
			}

			mocks.VerifyAll();
		}
Exemplo n.º 24
0
		public void Should_not_fail_if_datebase_does_not_exist()
		{
			var settings = new ConnectionSettings("server", "db", true, null, null);
            var taskAttributes = new TaskAttributes(settings, null);

			var mocks = new MockRepository();
			var connectionDropper = mocks.DynamicMock<IDatabaseConnectionDropper>();
			var taskObserver = mocks.CreateMock<ITaskObserver>();
			var queryExecutor = mocks.CreateMock<IQueryExecutor>();

			using (mocks.Record())
			{
                Expect.Call(() => queryExecutor.ExecuteNonQuery(settings, "ALTER DATABASE [db] SET SINGLE_USER WITH ROLLBACK IMMEDIATE drop database [db]", false))
					.Throw(new Exception("foo message"));
				Expect.Call(() => taskObserver.Log("Database 'db' could not be dropped."));
			}

			using (mocks.Playback())
			{
				IDatabaseActionExecutor dropper = new DatabaseDropper(connectionDropper, queryExecutor);
                dropper.Execute(taskAttributes, taskObserver);
			}

			mocks.VerifyAll();
		}
Exemplo n.º 25
0
		public void Drops_database()
		{
			var settings = new ConnectionSettings("server", "db", true, null, null);
            var taskAttributes = new TaskAttributes(settings, null);

			var mocks = new MockRepository();
			var connectionDropper = mocks.CreateMock<IDatabaseConnectionDropper>();
			var taskObserver = mocks.CreateMock<ITaskObserver>();
			var queryExecutor = mocks.CreateMock<IQueryExecutor>();
            
			using (mocks.Record())
			{
				connectionDropper.Drop(settings, taskObserver);
                
                queryExecutor.ExecuteNonQuery(settings, "ALTER DATABASE [db] SET SINGLE_USER WITH ROLLBACK IMMEDIATE drop database [db]", false);
			    
			}

			using (mocks.Playback())
			{
				IDatabaseActionExecutor dropper = new DatabaseDropper(connectionDropper, queryExecutor);
				dropper.Execute(taskAttributes, taskObserver);
			}

			mocks.VerifyAll();
		}
Exemplo n.º 26
0
 public void SetupResult()
 {
     _mockery = new MockRepository();
     _dataAccessMock = _mockery.CreateMock<DataAccess>();
     _batch = new Batch(_dataAccessMock);
     _batchHeaderDTO = _mockery.CreateMock<BatchHeaderDTO>();
 }
Exemplo n.º 27
0
 public void ConstructorTest()
 {
     mocks = new MockRepository();
     TripleStore ts = mocks.CreateMock<TripleStore>("http://www.tempuri.com");
     IRdfContext context = mocks.CreateMock<RdfDataContext>(ts);
     QueryFactory<Track> factory = new QueryFactory<Track>(ts.QueryType, context);
     Assert.IsNotNull(factory);
 }
 public void SetUp()
 {
     mocker = new MockRepository();
     scripter = mocker.CreateMock<ISqlScripter>();
     database = mocker.CreateMock<IDataCommand>();
     factory = new SqlScripterFactory(database);
     //harvestor = new Harvestor(factory, );
 }
Exemplo n.º 29
0
 public void New_screen_containing_component()
 {
     MockRepository mocks = new MockRepository();
     Window window = mocks.CreateMock<Window>();
     ScreenRepository screenRepository = mocks.CreateMock<ScreenRepository>();
     mocks.ReplayAll();
     Class @class = new Class(typeof(ScreenClassContainingComponent));
     new ScreenClass(@class).New(window, screenRepository);
 }
        public void SetUpTest()
        {
            shipment = new Shipment();
            shipment.StateOrProvince = "Testville";
            shipment.Vendor = "Test";
            shipment.ShippingOption = "Carrier Pigeon";

            mocks = new MockRepository();
            service = mocks.CreateMock<IShippingService>();
            screen = mocks.CreateMock<IShippingScreen>();
            presenter = new ShippingScreenPresenter(screen, service, shipment);
        }