public void RunSubmitAdRequest_Returns_Empty_List_If_No_Ads() { var mockery = new MockRepository(); var restClient = mockery.StrictMock<IRestClient>(); var restRequestFactory = mockery.StrictMock<IRestRequestFactory>(); var restRequest = mockery.StrictMock<IRestRequest>(); var serializer = mockery.Stub<ISerializer>(); var str = "some data"; var adRequest = new AdRequest { NetworkId = Guid.NewGuid().ToString() }; var advertisementResponse = new AdvertisementResponseMessage { advertisement = null }; var restResponse = new RestResponse<AdvertisementResponseMessage>(); restResponse.Data = advertisementResponse; using (mockery.Record()) { Expect.Call(restRequestFactory.Create(null, Method.POST)) .Constraints(Is.Anything(), Is.Equal(Method.POST)) .Return(restRequest); restRequest.RequestFormat = DataFormat.Json; Expect.Call(restRequest.JsonSerializer).Return(serializer); Expect.Call(serializer.Serialize(null)).Constraints( Rhino.Mocks.Constraints.Property.Value("network_id", adRequest.NetworkId) && Is.TypeOf<AdRequestMessage>() ).Return(str); Expect.Call(restRequest.AddParameter("text/json", str, ParameterType.RequestBody)).Return(new RestRequest()); Expect.Call(restClient.Execute<AdvertisementResponseMessage>(restRequest)).Return(restResponse); } using (mockery.Playback()) { var results = new AdRequestor(restClient, restRequestFactory).RunSubmitAdRequest(adRequest); Assert.IsEmpty(results); } }
public void DisplayProjectDetails_Should_Set_Bug_Count_From_BugService() { MockRepository repo = new MockRepository(); IBugListView mockBugView = repo.StrictMock<IBugListView>(); IBugService mockBugService = repo.StrictMock<IBugService>(); IProject mockProject = repo.StrictMock<IProject>(); IBug[] mockBugsArray = new IBug[] { repo.StrictMock<IBug>(), repo.StrictMock<IBug>() }; List<IBug> mockBugs = new List<IBug>(mockBugsArray); mockBugView.Expect(view => view.SelectedProject).Return(mockProject).Repeat.Twice(); mockBugService.Expect(svc => svc.GetBugCountForProject(mockProject)).Return(200); mockBugView.Expect(view => view.TotalBugs).SetPropertyWithArgument(200); mockBugView.Expect(view => view.FilterBy).Return(string.Empty).Repeat.Any(); mockBugView.Expect(view => view.FilterValue).Return(string.Empty).Repeat.Any(); mockBugView.Expect(view => view.IsBusy).Return(false).Repeat.Any(); mockBugView.Expect(view => view.IsBusy).SetPropertyAndIgnoreArgument().Repeat.Any(); repo.ReplayAll(); IBugListViewPresenter pres = new BugListViewPresenter(mockBugView, mockBugService); pres.DisplayProjectDetails(); mockBugService.VerifyAllExpectations(); mockBugView.VerifyAllExpectations(); }
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.StrictMock<IResourceFileLocator>(); IQueryExecutor queryExecutor = mocks.StrictMock<IQueryExecutor>(); ITaskObserver taskObserver = mocks.StrictMock<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 Manages_database() { var settings = new ConnectionSettings("server", "db", true, null, null); var scriptDirectory = @"c:\scripts"; var taskAttributes = new TaskAttributes(settings, scriptDirectory); taskAttributes.RequestedDatabaseAction= RequestedDatabaseAction.Create; var mocks = new MockRepository(); var taskObserver = mocks.StrictMock<ITaskObserver>(); var generator = mocks.StrictMock<ILogMessageGenerator>(); var factory = mocks.StrictMock<IDatabaseActionExecutorFactory>(); var creator = mocks.StrictMock<IDatabaseActionExecutor>(); var updater = mocks.StrictMock<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 Add() { var mocks = new MockRepository(); var connection = mocks.StrictMock<ISolrConnection>(); var executer = mocks.StrictMock<ISolrQueryExecuter<TestDocumentWithoutUniqueKey>>(); var headerParser = mocks.StrictMock<ISolrHeaderResponseParser>(); var docSerializer = new SolrDocumentSerializer<TestDocumentWithoutUniqueKey>(new AttributesMappingManager(), new DefaultFieldSerializer()); With.Mocks(mocks) .Expecting(() => { Expect.On(connection) .Call(connection.Post("/update", "<add><doc /></add>")) .Repeat.Once() .Return(EmbeddedResource.GetEmbeddedString(GetType(), "Resources.response.xml")); Expect.On(headerParser) .Call(headerParser.Parse(null)) .IgnoreArguments() .Return(new ResponseHeader()); }) .Verify(() => { var ops = new SolrBasicServer<TestDocumentWithoutUniqueKey>(connection, executer, docSerializer, null, headerParser, null, null, null); ops.AddWithBoost(new[] { new KeyValuePair<TestDocumentWithoutUniqueKey, double?>(new TestDocumentWithoutUniqueKey(), null), }, null); }); }
public void Setup() { this.mr = new MockRepository(); this.fsSvc = mr.StrictMock<IFileSystemService>(); this.tllSvc = mr.Stub<ITypeLibraryLoaderService>(); this.services = mr.StrictMock<IServiceProvider>(); var cfgSvc = mr.Stub<IConfigurationService>(); var env = mr.Stub<OperatingEnvironment>(); this.arch = new M68kArchitecture(); this.rtls = new List<RtlInstruction>(); this.m = new RtlEmitter(rtls); cfgSvc.Stub(c => c.GetEnvironment("amigaOS")).Return(env); env.Stub(e => e.TypeLibraries).Return(new List<ITypeLibraryElement>()); env.Stub(e => e.CharacteristicsLibraries).Return(new List<ITypeLibraryElement>()); env.Stub(e => e.Options).Return(new Dictionary<string, object> { { "versionDependentLibraries", new Dictionary<string,object> { { "33", new List<object> { "exec_v33", "dos_v33" } }, { "34", new List<object> { "exec_v34", "dos_v34" } }, } } }); this.services.Stub(s => s.GetService(typeof(IConfigurationService))).Return(cfgSvc); this.services.Stub(s => s.GetService(typeof(IFileSystemService))).Return(fsSvc); this.services.Stub(s => s.GetService(typeof(ITypeLibraryLoaderService))).Return(tllSvc); this.frame = new Frame(arch.FramePointerType); }
public MaintenanceManagerMockedTests() { mocks = new MockRepository(); countersManagerMock = mocks.StrictMock<ICoffeeCountersManager>(); serviceMock = mocks.StrictMock<ICoffeeMakerMaintenanceService>(); }
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.StrictMock<IScriptExecutionTracker>(); IFileSystem fileSystem = mocks.StrictMock<IFileSystem>(); IQueryExecutor queryExecutor = mocks.StrictMock<IQueryExecutor>(); ITaskObserver taskObserver = mocks.StrictMock<ITaskObserver>(); Expect.Call(executionTracker.ScriptAlreadyExecuted(settings, "01_Test.sql")).Return(false); taskObserver.Log("Executing: 01_Test.sql in a transaction"); Expect.Call(fileSystem.ReadTextFile(scriptFile)).Return(fileContents); queryExecutor.ExecuteNonQueryTransactional(settings, fileContents); executionTracker.MarkScriptAsExecuted(settings, "01_Test.sql", taskObserver); mocks.ReplayAll(); IChangeScriptExecutor executor = new ChangeScriptExecutor(executionTracker, queryExecutor, fileSystem); executor.Execute(scriptFile, settings, taskObserver); mocks.VerifyAll(); }
public void TestRefreshAmount() { var mock = new MockRepository(); var getAmountEventReceived = new AutoResetEvent(false); var accountServiceMock = mock.StrictMock<IAccountService>(); var getAmountResetEventMock = mock.StrictMock<AutoResetEvent>(); var expectedAccountId = new Random().Next(100); var accountInfoToTest = new AccountInfo(expectedAccountId, accountServiceMock, getAmountResetEventMock); var expectedReturnAmount = new Random().NextDouble(); Expect.Call(getAmountResetEventMock.WaitOne(0)).Return(true); Expect.Call(getAmountResetEventMock.WaitOne(0)).Return(false); Expect.Call(accountServiceMock.GetAccountAmount(expectedAccountId)).Return(expectedReturnAmount); Expect.Call(getAmountResetEventMock.Set()).Return(true).WhenCalled(MethodInvocation => getAmountEventReceived.Set()); mock.ReplayAll(); getAmountEventReceived.Reset(); accountInfoToTest.RefreshAmount(); accountInfoToTest.RefreshAmount(); Assert.IsTrue(getAmountEventReceived.WaitOne(1000)); Assert.AreEqual(expectedReturnAmount, accountInfoToTest.Amount); mock.VerifyAll(); }
public void MyTestInitialize() { var mocks = new MockRepository(); Func<IProbe> registryMethod = delegate() { return new RegistryProber(); }; Func<IProbe> familyProberWindowsMethod = delegate { return new FamilyProberWindows(); }; Func<IProbe> familyProberUnixMethod = delegate { return new FamilyProberUnix(); }; Func<IProbe> lineProberCiscoIosMethod = delegate { return new LineProber(); }; Func<ISystemInformationService> systemInformationMethod = delegate() { return new WindowsSystemInformationService(); }; var registryProbe = mocks.StrictMock<Lazy<IProbe, IProbeCapabilities>>( registryMethod, GetProbeCapability("registry", FamilyEnumeration.windows)); var familyProberWindows = mocks.StrictMock<Lazy<IProbe, IProbeCapabilities>>( familyProberWindowsMethod, GetProbeCapability("family", FamilyEnumeration.windows)); var familyProberUnix = mocks.StrictMock<Lazy<IProbe, IProbeCapabilities>>( familyProberUnixMethod, GetProbeCapability("family", FamilyEnumeration.unix)); var lineProberCiscoIOS = mocks.StrictMock<Lazy<IProbe, IProbeCapabilities>>( lineProberCiscoIosMethod, GetProbeCapability("line", FamilyEnumeration.ios)); var probes = GetProbeCapabilities(registryProbe, familyProberWindows, familyProberUnix, lineProberCiscoIOS); var windowsInformationService = mocks.StrictMock<Lazy<ISystemInformationService, ISystemInformationServicePlataform>>( systemInformationMethod, GetSystemInformationSvcForWindows()); var systemInformations = new Lazy<ISystemInformationService, ISystemInformationServicePlataform>[] { windowsInformationService }; ProbeManager = new ProbeManager() { probes = probes, systemInformationServices = systemInformations }; }
public void Search() { // Basic integration test: search algorithms are already extensively tested with InMemoryIndexBase MockRepository mocks = new MockRepository(); IIndexConnector conn = mocks.StrictMock<IIndexConnector>(); ScrewTurn.Wiki.SearchEngine.IWordFetcher fetcher = mocks.StrictMock<ScrewTurn.Wiki.SearchEngine.IWordFetcher>(); ScrewTurn.Wiki.SearchEngine.Word dummy = null; Expect.Call(fetcher.TryGetWord("test", out dummy)).Return(false); Expect.Call(fetcher.TryGetWord("query", out dummy)).Return(false); fetcher.Dispose(); LastCall.On(fetcher); Expect.Call(conn.GetWordFetcher()).Return(fetcher); mocks.ReplayAll(); SqlIndex index = new SqlIndex(conn); Assert.AreEqual(0, index.Search(new ScrewTurn.Wiki.SearchEngine.SearchParameters("test query")).Count, "Wrong search result count"); mocks.VerifyAll(); }
public void Drops_Azure_database_without_dropping_connections() { var settings = new ConnectionSettings("server", "db", true, null, null); var taskAttributes = new TaskAttributes(settings, null); var mocks = new MockRepository(); var connectionDropper = mocks.StrictMock<IDatabaseConnectionDropper>(); var taskObserver = mocks.StrictMock<ITaskObserver>(); var queryExecutor = mocks.StrictMock<IQueryExecutor>(); using (mocks.Record()) { Expect.Call(() => taskObserver.Log("Running against: SQL Azure")); Expect.Call(queryExecutor.ReadFirstColumnAsStringArray(settings, "select @@version")).Return(new string[] { "SQL Azure" }); queryExecutor.ExecuteNonQuery(settings, "drop database [db]"); Expect.Call(() => taskObserver.Log("Dropping database: db\n")); } using (mocks.Playback()) { IDatabaseActionExecutor dropper = new DatabaseDropper(connectionDropper, queryExecutor); dropper.Execute(taskAttributes, taskObserver); } mocks.VerifyAll(); }
public void ClassSetUp() { _repository = new MockRepository(); _httpContext = _repository.StrictMock<HttpContextBase>(); _httpRequest = _repository.StrictMock<HttpRequestBase>(); _httpResponse = _repository.StrictMock<HttpResponseBase>(); }
public void SetUp() { _mockRepository = new MockRepository(); _accountRepository = _mockRepository.StrictMock<IAccountRepository>(); _transactionsRepository = _mockRepository.StrictMock<ITransactionsRepository>(); _paymentGateway = _mockRepository.StrictMock<IPaymentGateway>(); }
public void Select_Finds_FirstToSatisfyAllConstraints() { var mockery = new MockRepository(); var constraint1 = mockery.StrictMock<IResidentConstraint>(); var constraint2 = mockery.StrictMock<IResidentConstraint>(); var selector = new ResidentSelector(); selector.Constraints.Clear(); selector.Constraints.Add(constraint1); selector.Constraints.Add(constraint2); var residents = new List<Resident> { new Resident(), new Resident(), new Resident() }; var shift = new Shift(DateTime.Today, DateTime.Today, DateTime.Today); using (mockery.Record()) { SetupResult.For(constraint1.Assignable(residents.First(), shift)).Return(false); SetupResult.For(constraint2.Assignable(residents.First(), shift)).Return(true); SetupResult.For(constraint1.Assignable(residents.Skip(1).First(), shift)).Return(true); SetupResult.For(constraint2.Assignable(residents.Skip(1).First(), shift)).Return(false); SetupResult.For(constraint1.Assignable(residents.Skip(2).First(), shift)).Return(true); SetupResult.For(constraint2.Assignable(residents.Skip(2).First(), shift)).Return(true); } using (mockery.Playback()) { Assert.AreEqual(residents.Skip(2).First(), selector.Select(residents, shift)); } }
public void BidirectionalConverter_Should_Convert_All_Items() { var mocks = new MockRepository(); var converter1 = mocks.StrictMock<IBidirectionalConverter<int, string>>(); Expect.Call(converter1.Convert(5)).Return("5"); Expect.Call(converter1.Convert(3)).Return("3"); Expect.Call(converter1.Convert(7)).Return("7"); var converter2 = mocks.StrictMock<IBidirectionalConverter<string, int>>(); Expect.Call(converter2.Convert("5")).Return(5); Expect.Call(converter2.Convert("3")).Return(3); Expect.Call(converter2.Convert("7")).Return(7); mocks.ReplayAll(); // Convert one way IList<int> input1 = new List<int> { 5, 3, 7 }; var output1 = converter1.ConvertAll(input1); Assert.IsTrue(output1.Contains("5")); Assert.IsTrue(output1.Contains("3")); Assert.IsTrue(output1.Contains("7")); // Convert the other way IList<string> input2 = new List<string> { "5", "3", "7" }; var output2 = converter2.ConvertAll(input2); Assert.IsTrue(output2.Contains(5)); Assert.IsTrue(output2.Contains(3)); Assert.IsTrue(output2.Contains(7)); mocks.VerifyAll(); }
public void SubmitAdRequestsAsync() { var mockery = new MockRepository(); var taskFactory = mockery.StrictMock<IVistarTaskFactory>(); var adRequestor = mockery.StrictMock<IAdRequestor>(); var adRequests = new List<AdRequest> { new AdRequest(), new AdRequest(), new AdRequest() }; var expectedTasks = new List<Task<List<Advertisement>>> { new Task<List<Advertisement>>(null), new Task<List<Advertisement>>(null), new Task<List<Advertisement>>(null) }; using (mockery.Record()) { Expect.Call(taskFactory.StartNew(adRequestor.RunSubmitAdRequest, adRequests[0])).Return(expectedTasks[0]); Expect.Call(taskFactory.StartNew(adRequestor.RunSubmitAdRequest, adRequests[1])).Return(expectedTasks[1]); Expect.Call(taskFactory.StartNew(adRequestor.RunSubmitAdRequest, adRequests[2])).Return(expectedTasks[2]); } using (mockery.Playback()) { var client = new ApiClientAsync(adRequestor, taskFactory); var tasks = client.SubmitAdRequestsAsync(adRequests); Assert.AreEqual(expectedTasks, tasks); } }
public void SetPort_three_locations() { var expectedPort = 1234; var mockRepository = new MockRepository(); // Arrange var fileManipulation = mockRepository.StrictMock<IFileManipulation>(); var paths = mockRepository.StrictMock<IPaths>(); var neo4JServerConfigSettings = mockRepository.StrictMock<INeo4jServerConfigSettings>(); neo4JServerConfigSettings.Expect(n => n.Port).Return("org.neo4j.server.webserver.port"); neo4JServerConfigSettings.Expect(n => n.WebAdminDataUri).Return("webadmindatauri"); neo4JServerConfigSettings.Expect(n => n.WebAdminManagementUri).Return("webadminmanagementuri"); var neo4JManager = new Neo4jManager(fileManipulation, null); paths.Expect(p => p.Neo4jServerConfigSettings).Return(neo4JServerConfigSettings); paths.Expect(p => p.Neo4jAdminDataUri).Return("Neo4jAdminDataUri"); paths.Expect(p => p.Neo4jAdminManagementUri).Return("Neo4jAdminManagementUri"); paths.Expect(p => p.Neo4jServerConfigPath).Return("Neo4jServerConfigPath"); fileManipulation.Expect(fm => fm.ReplaceConfigLine(null, null)).IgnoreArguments(); mockRepository.ReplayAll(); // Act neo4JManager.SetServerPortAndUrlConfig(paths, expectedPort); // Assert mockRepository.VerifyAll(); }
public void Correctly_constructs_action_executors() { DatabaseAction[] actions = new DatabaseAction[] { DatabaseAction.Create, DatabaseAction.Update }; MockRepository mocks = new MockRepository(); IDatabaseActionResolver resolver = mocks.StrictMock<IDatabaseActionResolver>(); IDataBaseActionLocator locator = mocks.StrictMock<IDataBaseActionLocator>(); IDatabaseActionExecutor creator = mocks.StrictMock<IDatabaseActionExecutor>(); IDatabaseActionExecutor updater = mocks.StrictMock<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 PublishDomainEvents() { var e = new TestEvent(); var mockRepository = new MockRepository(); IEnumerable<object> handlers; using (mockRepository.Record()) { var handler1 = mockRepository.StrictMock<IEventHandler<TestEvent>>(); handler1.Expect(h => h.Handle(e)).Repeat.Once(); var handler2 = mockRepository.StrictMock<IEventHandler<TestEvent>>(); handler2.Expect(h => h.Handle(e)).Repeat.Once(); handlers = new[] { handler1, handler2 }; } MultiInstanceFactory multiInstanceFactory = t => handlers; var publisher = new DomainEventsPublisher(multiInstanceFactory); DomainEvents.Raise(e); using (mockRepository.Playback()) publisher.Publish(); mockRepository.VerifyAll(); }
public void Do3Fluent() { var mockRepository = new MockRepository(); var view = mockRepository.StrictMock<IButtonView>(); var model = mockRepository.StrictMock<IToggleModel>(); var presenter = new ButtonPresenter(model); presenter.ConnectView(view); //IEventRaiser clicked = null; //view.Clicked += null; //clicked = LastCall.GetEventRaiser(); IEventSubscriber subscriber = mockRepository.StrictMock<IEventSubscriber>(); IWithEvents events = new WithEvents(); // This doesn't create an expectation because no method is called on subscriber!! events.Blah += subscriber.Handler; subscriber.Handler(VisibilityState.Visible); With.Mocks(mockRepository) .Expecting(delegate { Expect.Call(model.ToggleVisibility); Expect.Call(() => model.VisibilityStateChanged += null).IgnoreArguments(); Expect.Call(() => view.SetCheckedState(CheckedState.Checked)); }) .Verify(delegate { events.RaiseEvent(VisibilityState.Visible); //clicked.Raise(); }); }
public void CallAllTheInterceptors() { var mocks = new MockRepository(); var interceptor1 = mocks.StrictMock<InstanceInterceptor>(); var interceptor2 = mocks.StrictMock<InstanceInterceptor>(); var interceptor3 = mocks.StrictMock<InstanceInterceptor>(); var interceptor4 = mocks.StrictMock<InstanceInterceptor>(); Expect.Call(interceptor1.Process("0", null)).Return("1"); Expect.Call(interceptor2.Process("1", null)).Return("2"); Expect.Call(interceptor3.Process("2", null)).Return("3"); Expect.Call(interceptor4.Process("3", null)).Return("4"); mocks.ReplayAll(); var compoundInterceptor = new CompoundInterceptor(new[] { interceptor1, interceptor2, interceptor3, interceptor4 }); Assert.AreEqual("4", compoundInterceptor.Process("0", null)); mocks.VerifyAll(); }
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.StrictMock<ITaskObserver>(); var queryExecutor = mocks.StrictMock<IQueryExecutor>(); using (mocks.Record()) { Expect.Call(() => taskObserver.Log("Running against: SQL Server")); Expect.Call(queryExecutor.ReadFirstColumnAsStringArray(settings, "select @@version")).Return(new string[] { "SQL Server" }); Expect.Call(() => taskObserver.Log("Dropping database: db\n")); Expect.Call(() => queryExecutor.ExecuteNonQuery(settings, "ALTER DATABASE [db] SET SINGLE_USER WITH ROLLBACK IMMEDIATE drop database [db]")) .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(); }
public void Setup() { persistanceFilePath = Path.Combine(applicationDataPath, "ProjectsState.xml"); mocks = new MockRepository(); fileSystem = mocks.StrictMock<IFileSystem>(); executionEnvironment = mocks.StrictMock<IExecutionEnvironment>(); }
public void ShouldVerify_IsNotFriendly() { var mocks = new MockRepository(); var context = mocks.DynamicMock<HttpContextBase>(); SetupResult.For(context.Request).Return(MockedRequest(mocks)); var response = mocks.StrictMock<HttpResponseBase>(); SetupResult.For(response.StatusCode).PropertyBehavior(); SetupResult.For(context.Response).Return(response); var whoisService = mocks.StrictMock<IWhois>(); Expect.Call(whoisService.WhoisEnhancedXml(null, null, null)).IgnoreArguments().Return(new WhoisEnhancedRecord {IsFriendly = false}); mocks.ReplayAll(); var controller = new ContactController(whoisService, null); controller.ControllerContext = new ControllerContext(context, new RouteData(), controller); var result = controller.IsFriendly() as ContentResult; Assert.IsNotNull(result); Assert.AreNotEqual(MyWebPresence.EmailAccount, result.Content); Assert.IsTrue(controller.Response.StatusCode == (int) HttpStatusCode.BadRequest); mocks.VerifyAll(); }
public void SetJavaPath() { string expectedFileName = "config/wrapper.conf"; string expectedWrapperJavaSetting = "wrapper.java.setting"; string expectedLocalJavaExePath = "c:/localjavapath/java.exe"; var mockRepository = new MockRepository(); // Arrange var fileManipulation = mockRepository.StrictMock<IFileManipulation>(); var paths = mockRepository.StrictMock<IPaths>(); var neo4JManager = new Neo4jManager(fileManipulation, null); paths.Expect(p => p.LocalJavaExePath).Return(expectedLocalJavaExePath); paths.Expect(p => p.Neo4jWrapperSettingJavaCommand).Return(expectedWrapperJavaSetting); paths.Expect(p => p.Neo4jWrapperConfigPath).Return(expectedFileName); fileManipulation.Expect(fm => fm.ReplaceConfigLine(null, null)).IgnoreArguments(); mockRepository.ReplayAll(); // Act neo4JManager.SetJavaPath(paths); // Assert mockRepository.VerifyAll(); }
public void Creates_database() { var settings = new ConnectionSettings("server", "db", true, null, null); var taskAttributes = new TaskAttributes(settings, "c:\\scripts"); taskAttributes.RequestedDatabaseAction= RequestedDatabaseAction.Create; var mocks = new MockRepository(); var queryExecutor = mocks.StrictMock<IQueryExecutor>(); var executor = mocks.StrictMock<IScriptFolderExecutor>(); var taskObserver = mocks.StrictMock<ITaskObserver>(); using (mocks.Record()) { queryExecutor.ExecuteNonQuery(settings, "create database [db]"); taskObserver.Log(string.Format("Run scripts in Create folder.")); executor.ExecuteScriptsInFolder(taskAttributes, "Create", taskObserver); } using (mocks.Playback()) { IDatabaseActionExecutor creator = new DatabaseCreator(queryExecutor, executor); creator.Execute(taskAttributes, taskObserver); } mocks.VerifyAll(); }
public void withSyntaxeTest2() { // Prepare mock repository MockRepository mocks = new MockRepository(); IDependency dependency = mocks.StrictMock<IDependency>(); IAnotherDependency anotherDependency = mocks.StrictMock<IAnotherDependency>(); object result = null; With.Mocks(mocks).ExpectingInSameOrder(delegate { // Record expectations which must be met in the exact same order Expect.Call(dependency.SomeMethod()).Return(null); anotherDependency.SomeOtherMethod(); }) .Verify(delegate { // Replay and validate interaction ComponentImplementation underTest = new ComponentImplementation(dependency, anotherDependency); result = underTest.TestMethod(); }); // Post-interaction assertions Assert.IsNull(result); }
public void Do3Classic() { var mockRepository = new MockRepository(); var view = mockRepository.StrictMock<IButtonView>(); var model = mockRepository.StrictMock<IToggleModel>(); model.VisibilityStateChanged += null; IEventRaiser visibilityChanged = LastCall.GetEventRaiser(); view.Clicked += null; IEventRaiser clicked = LastCall.GetEventRaiser(); var presenter = new ButtonPresenter(model); presenter.ConnectView(view); mockRepository.BackToRecordAll(); //mockRepository.Playback(); Expect.Call(model.ToggleVisibility); Expect.Call(() => model.VisibilityStateChanged += null).IgnoreArguments(); Expect.Call(() => view.SetCheckedState(CheckedState.Checked)); mockRepository.ReplayAll(); clicked.Raise(); visibilityChanged.Raise(VisibilityState.Visible); mockRepository.VerifyAll(); }
public void Updates_database() { var settings = new ConnectionSettings("server", "db", true, null, null); var taskAttributes = new TaskAttributes(settings, "c:\\scripts"); taskAttributes.RequestedDatabaseAction = RequestedDatabaseAction.Update; var mocks = new MockRepository(); var scriptfolderexecutor = mocks.StrictMock<IScriptFolderExecutor>(); var queryexecutor = mocks.StrictMock<IQueryExecutor>(); queryexecutor.Stub(x => x.CheckDatabaseExists(taskAttributes.ConnectionSettings)).Return(true); var taskObserver = mocks.StrictMock<ITaskObserver>(); using (mocks.Record()) { taskObserver.Log(string.Format("Run scripts in Update folder.")); scriptfolderexecutor.ExecuteScriptsInFolder(taskAttributes, "Update", taskObserver); taskObserver.Log(string.Format("Run scripts in Everytime folder.")); scriptfolderexecutor.ExecuteChangedScriptsInFolder(taskAttributes, "Everytime", taskObserver); taskObserver.Log(string.Format("Run scripts in RunAlways folder.")); scriptfolderexecutor.ExecuteRunAlwaysScriptsInFolder(taskAttributes, "RunAlways", taskObserver); } using (mocks.Playback()) { IDatabaseActionExecutor updater = new DatabaseUpdater(scriptfolderexecutor, queryexecutor); updater.Execute(taskAttributes, taskObserver); } mocks.VerifyAll(); }
public void Setup() { _mockRepository = new MockRepository(); _cacheStore = _mockRepository.StrictMock <ICacheStore>(); _messageHandler = new DummyMessageHandler(); _cachingHandler = new CachingHandler(_cacheStore) { InnerHandler = _messageHandler }; _client = new HttpClient(_cachingHandler); }
public void About() { // Arrange var mockRepo = new Rhino.Mocks.MockRepository(); var mockTwitterService = mockRepo.StrictMock <ITwitterService>(); var controller = new HomeController(new InMemoryRepository(), null, mockTwitterService); // Act var result = controller.About() as ViewResult; // Assert Assert.IsNotNull(result); }