コード例 #1
0
ファイル: TestImportState.cs プロジェクト: killbug2004/WSProf
		public void TestEnterImportStateWithExclusiveLockedFile()
		{
			try
			{
				m_stateMachine = new DynamicMock(typeof(IStateMachine));

				ImportState import = new ImportState();
				import.StateMachine = (IStateMachine)m_stateMachine.MockInstance;

				string exclusivelyLockedFilePath = Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\XMLPolicyStore.Tests\TestFiles\Sample\en.csv");
				Assert.IsTrue(File.Exists(exclusivelyLockedFilePath), "The file should exist on disk.");

				XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance;
				IPolicyLanguageStore policyLanguageStore = catalogueStore.LanguageStore;
				string xmlLang = System.IO.File.ReadAllText(Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\XMLPolicyStore.Tests\TestFiles\Sample\Languages\SamplePolicy.Language.xml"));
				Guid guid = policyLanguageStore.AddLanguage(xmlLang);

				import.FileName = exclusivelyLockedFilePath;

				//open the file with no sharing permissions (as if the file was open in another editor)
				using (FileStream fs = new FileStream(exclusivelyLockedFilePath, FileMode.Open, FileAccess.ReadWrite, FileShare.None))
				{
					import.Enter();
				}

				Assert.IsFalse(String.IsNullOrEmpty(import.ErrorMessage), "After entering the import state, DoImport should have caught (and failed gracefully) with an error message, because the file was exclusively locked");
			}
			finally
			{
				PolicyLanguageCache.Instance.Reset();
				XmlPolicyLanguageStore.Instance.Reset();
			}
		}
        public void testStrategy()
        {
            FastIDSet itemIDsFromUser123 = new FastIDSet();
            itemIDsFromUser123.Add(1L);

            FastIDSet itemIDsFromUser456 = new FastIDSet();
            itemIDsFromUser456.Add(1L);
            itemIDsFromUser456.Add(2L);

            List<IPreference> prefs = new List<IPreference>();
            prefs.Add(new GenericPreference(123L, 1L, 1.0f));
            prefs.Add(new GenericPreference(456L, 1L, 1.0f));
            IPreferenceArray preferencesForItem1 = new GenericItemPreferenceArray(prefs);

            var dataModelMock = new DynamicMock(typeof(IDataModel));
            dataModelMock.ExpectAndReturn("GetPreferencesForItem", preferencesForItem1,  (1L));
            dataModelMock.ExpectAndReturn("GetItemIDsFromUser", itemIDsFromUser123, (123L));
            dataModelMock.ExpectAndReturn("GetItemIDsFromUser", itemIDsFromUser456, (456L));

            IPreferenceArray prefArrayOfUser123 =
            new GenericUserPreferenceArray( new List<IPreference>() {new GenericPreference(123L, 1L, 1.0f)} );

            ICandidateItemsStrategy strategy = new PreferredItemsNeighborhoodCandidateItemsStrategy();

            //EasyMock.replay(dataModel);

            FastIDSet candidateItems = strategy.GetCandidateItems(123L, prefArrayOfUser123, (IDataModel)dataModelMock.MockInstance);
            Assert.AreEqual(1, candidateItems.Count());
            Assert.True(candidateItems.Contains(2L));

            dataModelMock.Verify(); //  EasyMock.verify(dataModel);
        }
コード例 #3
0
ファイル: TestImportState.cs プロジェクト: killbug2004/WSProf
        public void TestImportWithEmptyFile()
        {
            try
            {
                m_stateMachine = new DynamicMock(typeof(IStateMachine));

                ImportState import = new ImportState();
                import.StateMachine = (IStateMachine)m_stateMachine.MockInstance;

                string pathToEmptyFile = Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\Projects\Hygiene\src\TestDocuments\empty.csv");
                Assert.IsTrue(File.Exists(pathToEmptyFile), "The file should exist on disk.");

                XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance;
                IPolicyLanguageStore policyLanguageStore = catalogueStore.LanguageStore;
                string xmlLang = System.IO.File.ReadAllText(Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\XMLPolicyStore.Tests\TestFiles\Sample\Languages\SamplePolicy.Language.xml"));
                Guid guid = policyLanguageStore.AddLanguage(xmlLang);

                import.FileName = pathToEmptyFile;

                Assert.IsTrue(string.IsNullOrEmpty(import.ErrorMessage), "set up failure - already an error message on the import state");
                import.Enter();
                Assert.AreEqual(Properties.Resources.INVALID_CSV_FILE, import.ErrorMessage, "Unexpected error message on the import state");
            }
            finally
            {
                PolicyLanguageCache.Instance.Reset();
                XmlPolicyLanguageStore.Instance.Reset();
            }
        }
        public void testStrategy()
        {
            FastIDSet allItemIDs = new FastIDSet();
            allItemIDs.AddAll(new long[] { 1L, 2L, 3L });

            FastIDSet preferredItemIDs = new FastIDSet(1);
            preferredItemIDs.Add(2L);

            var dataModelMock = new DynamicMock( typeof( IDataModel ));
            dataModelMock.ExpectAndReturn("GetNumItems", 3);
            dataModelMock.ExpectAndReturn("GetItemIDs", allItemIDs.GetEnumerator());

            IPreferenceArray prefArrayOfUser123 = new GenericUserPreferenceArray( new List<IPreference>() {
            new GenericPreference(123L, 2L, 1.0f) } );

            ICandidateItemsStrategy strategy = new AllUnknownItemsCandidateItemsStrategy();

            //EasyMock.replay(dataModel);

            FastIDSet candidateItems = strategy.GetCandidateItems(123L, prefArrayOfUser123, (IDataModel)dataModelMock.MockInstance);
            Assert.AreEqual(2, candidateItems.Count() );
            Assert.True(candidateItems.Contains(1L));
            Assert.True(candidateItems.Contains(3L));

            dataModelMock.Verify();
            //EasyMock.verify(dataModel);
        }
コード例 #5
0
 public void SetUp ()
 {
     mock1 = new DynamicMock (typeof (IMessage));
     msg1 = (IMessage) mock1.MockInstance;
     mock2 = new DynamicMock (typeof (IMessage));
     msg2 = (IMessage) mock2.MockInstance;
 }
コード例 #6
0
		void SetUpCurrentVersion(long version, List<long> appliedVersions, bool assertRollbackIsCalled, bool includeBad)
		{
			var providerMock = new DynamicMock(typeof (ITransformationProvider));

			providerMock.SetReturnValue("get_MaxVersion", version);
			providerMock.SetReturnValue("get_AppliedMigrations", appliedVersions);
			providerMock.SetReturnValue("get_Logger", new Logger(false));
			if (assertRollbackIsCalled)
				providerMock.Expect("Rollback");
			else
				providerMock.ExpectNoCall("Rollback");

			_migrator = new Migrator((ITransformationProvider) providerMock.MockInstance, Assembly.GetExecutingAssembly(), false);

			// Enlève toutes les migrations trouvée automatiquement
			_migrator.MigrationsTypes.Clear();
			_upCalled.Clear();
			_downCalled.Clear();

			_migrator.MigrationsTypes.Add(typeof (FirstMigration));
			_migrator.MigrationsTypes.Add(typeof (SecondMigration));
			_migrator.MigrationsTypes.Add(typeof (ThirdMigration));
			_migrator.MigrationsTypes.Add(typeof (FourthMigration));
			_migrator.MigrationsTypes.Add(typeof (SixthMigration));

			if (includeBad)
				_migrator.MigrationsTypes.Add(typeof (BadMigration));
		}
コード例 #7
0
ファイル: DocumentTest.cs プロジェクト: alfar/WordBuilder
        public void TestDirty()
        {
            Document dm = new Document();
            Assert.IsFalse(dm.Dirty);

            dm.Text = "abc";
            Assert.IsTrue(dm.Dirty);

            dm.FileName = @"c:\abc.wordo";
            DynamicMock fs = new DynamicMock(typeof (IFileSystem));
            dm.Save((IFileSystem)fs.MockInstance);

            Assert.IsFalse(dm.Dirty);

            dm.Text = "abc2";

            Assert.IsTrue(dm.Dirty);

            dm.Save((IFileSystem)fs.MockInstance);

            Assert.IsFalse(dm.Dirty);

            fs.ExpectAndReturn("ReadAllText", "abc3", @"c:\abc.wordo");

            dm.Load((IFileSystem)fs.MockInstance);

            Assert.AreEqual("abc3", dm.Text);
            Assert.IsFalse(dm.Dirty);
        }
コード例 #8
0
        public void SetUp()
        {
            _mock = new DynamicMock(typeof(IErrorListRenderer));

            _list = new TestingErrorList((IErrorListRenderer)_mock.MockInstance);

            _trace1 = 
                "à SomeClass.SomeMethod() dans C:\\folder\\file1.cs:ligne 20\r\n" +
                "à ExternClass.ExternMethod()\r\n" +
                "à AnotherExternClass.AnotherExternMethod()\r\n" +
                "à SomeClass2.SomeMethod2() dans C:\\folder\\file2.cs:ligne 42\r\n" +
                "à SomeClass3.SomeMethod3() dans C:\\folder\\AnotherFile2.cs:ligne 93\r\n";

            _trace2 =
                "à SomeClass.SomeMethod() dans C:\\folder\\file1.cs:ligne 20\r\n" +
                "à ExternClass.ExternMethod()\r\n" +
                "à AnotherExternClass.AnotherExternMethod()\r\n" +
                "à SomeClass2.SomeMethod2() dans C:\\folder\\file2.cs:ligne 42\r\n";

            _selectionNotification = false;

            _list.SelectedItemChanged += new EventHandler(_list_SelectedItemChanged);

            return;
        }
コード例 #9
0
ファイル: ByTest.cs プロジェクト: v4viveksharma90/selenium
        public void ShouldUseFindsByNameToLocateElementsByName()
        {
            DynamicMock driver = new DynamicMock(typeof(IAllDriver));

            driver.Expect("FindElementByName", new object[] { "cheese" });

            By by = By.Name("cheese");
            by.FindElement(driver.MockInstance as IAllDriver);
        }
コード例 #10
0
 public void Setup() {
     subTrigger1Mock = new DynamicMock(typeof(ITrigger));
     subTrigger2Mock = new DynamicMock(typeof(ITrigger));
     subTrigger1 = (ITrigger)subTrigger1Mock.MockInstance;
     subTrigger2 = (ITrigger)subTrigger2Mock.MockInstance;
     trigger = new MultipleTrigger();
     trigger.FirstTrigger = subTrigger1;
     trigger.SecondTrigger = subTrigger2;  
 }
コード例 #11
0
ファイル: MockHelper.cs プロジェクト: Phaiax/dotnetautoupdate
        public static DynamicMock NewMockIErrorRenderer(string name, int hashcode)
        {
            DynamicMock res;

            res = new DynamicMock(name, typeof(IErrorDisplay));
            res.SetReturnValue("Equals", true);
            res.SetReturnValue("GetHashCode", hashcode);

            return (res);
        }
コード例 #12
0
        public void SearchParameters_With_No_SelectedFilters_Return_Only_Actives_And_Visibles()
        {
            var searchParameterMock = new DynamicMock(typeof(ISearchParameters<Publication>));
            searchParameterMock.SetReturnValue("get_SelectedFilters", null);

            var solrQueryBuilder = new SolrQueryBuilder<Publication>((ISearchParameters<Publication>)searchParameterMock.MockInstance);
            var query = solrQueryBuilder.BuildQuery();

            Assert.IsTrue(query.Query.Equals("publication_state_id:Active AND publication_visible:true"));
        }
        public void IsLoginOK_WhenCalled_WritesToLog()
        {
            DynamicMock mockLog = new DynamicMock(typeof(ILogger));
            mockLog.Expect("Write","login ok: user: u");

            var loginManager = new LoginManagerWithMock((ILogger)mockLog.MockInstance);
            loginManager.IsLoginOK("", "");

            mockLog.Verify();
        }
コード例 #14
0
        public void GetProvincesWithoutResult()
        {
            DynamicMock dynamicMock = new DynamicMock(typeof(LocationsManager));
            dynamicMock.SetReturnValue("GetProvinces",new List<Province>());

            LocationsManager locationsManager = (LocationsManager)dynamicMock.MockInstance;
            LocationServices locationServices = new LocationServices(locationsManager);

            Assert.AreEqual(0,locationServices.GetProvinces().Count);
        }
コード例 #15
0
ファイル: ByTest.cs プロジェクト: v4viveksharma90/selenium
        // TODO (jimevan): This test is disabled in the Java implementation unit tests.
        // Is the functionality not implemented?
        public void ShouldUseXPathToFindByNameIfDriverDoesNotImplementFindsByName()
        {
            DynamicMock driver = new DynamicMock(typeof(IOnlyXPath));

            driver.Expect("FindElementByXPath", new object[] { "//*[@name='cheese']" });

            By by = By.Name("cheese");

            by.FindElement(driver.MockInstance as IOnlyXPath);
        }
コード例 #16
0
        public void CanAddDecorator()
        {
            DynamicMock mock = new DynamicMock( typeof(ITestDecorator) );
            mock.Expect( "Decorate" );

            IExtensionPoint ep = host.GetExtensionPoint("TestDecorators");
            ep.Install( mock.MockInstance );
            host.TestDecorators.Decorate( null, null );

            mock.Verify();
        }
コード例 #17
0
        public void CreateIntegrationRequestQueue() {
            queue = new ProcessorQueue();

            processorMock1 = new DynamicMock(typeof(IProcessor));
            processorMock1.SetReturnValue("get_Name", "Processor1");
            processor1 = (IProcessor)processorMock1.MockInstance;

            processorMock2 = new DynamicMock(typeof(IProcessor));
            processorMock2.SetReturnValue("get_Name", "Processor2");
            processor2 = (IProcessor)processorMock2.MockInstance;
        }
コード例 #18
0
 public void VerifyUserAgent(string expected)
 {
     var mock = new DynamicMock(typeof(IAndroidJavaClass));
     mock.ExpectAndReturn("CallStatic", "1.0.0", "GetSdkVersion");
     Assert.AreEqual(
         string.Format(
             CultureInfo.InvariantCulture,
             expected,
             FacebookSdkVersion.Build),
         Constants.GraphApiUserAgent);
 }
コード例 #19
0
        public void CanAddTestCaseBuilder()
        {
            DynamicMock mock = new DynamicMock( typeof(ITestCaseBuilder) );
            mock.ExpectAndReturn( "CanBuildFrom", true, null );
            mock.Expect( "BuildFrom" );

            IExtensionPoint ep = host.GetExtensionPoint("TestCaseBuilders");
            ep.Install( mock.MockInstance );
            host.TestBuilders.BuildFrom( null );

            mock.Verify();
        }
コード例 #20
0
        public void Details_Action_Should_Return_Correct_View_Model()
        {
            var agencyIndexServiceMock = new DynamicMock(typeof(IndexServiceAgencySolrImpl));
            var publicationIndexServiceMock = new DynamicMock(typeof(IndexServicePublicationSolrImpl));

            var agency = new Agency
                             {
                                 Address = "Direccion",
                                 Name = "agencia prueba",
                                 UserId = 1
                             };

            var agencysPublication1 = new Publication
                                          {
                                              VehicleMakeText = "Ford",
                                              UserUid = agency.UserId
                                          };

            var agencysPublication2 = new Publication
                                     {
                                         VehicleMakeText = "Peugeot",
                                         UserUid = agency.UserId
                                     };

            var listPublications = new List<Publication>
                                      {
                                          agencysPublication1,
                                          agencysPublication2
                                      };

            var listAgency = new List<Agency>
                                 {
                                     agency
                                 };

            agencyIndexServiceMock.SetReturnValue("Query", listAgency);
            publicationIndexServiceMock.SetReturnValue("Query",listPublications);

            var agencyController = new AgencyController
                                       {
                                           AgencyIndexService = (IndexServiceAgencySolrImpl)agencyIndexServiceMock.MockInstance,
                                           PublicationIndexService = (IndexServicePublicationSolrImpl)publicationIndexServiceMock.MockInstance,
                                       };

            var viewResult = agencyController.Details("abrahamautomotores");

            Assert.IsNotNull(viewResult);
            Assert.NotNull(viewResult.ViewData["Title"]);
            Assert.True(viewResult.ViewData["Title"].ToString() == "Concesionaria abrahamautomotores");
            Assert.NotNull(viewResult.ViewData["Publications"]);
            Assert.True(((List<Publication>)viewResult.ViewData["Publications"]).Count == listPublications.Count);
            Assert.True(((List<Publication>)viewResult.ViewData["Publications"])[0].VehicleMakeText == listPublications[0].VehicleMakeText);
        }
コード例 #21
0
        public void CanAddEventListener()
        {
            DynamicMock mock = new DynamicMock( typeof(EventListener) );
            mock.Expect( "RunStarted" );
            mock.Expect( "RunFinished" );

            IExtensionPoint ep = host.GetExtensionPoint("EventListeners");
            ep.Install( mock.MockInstance );
            host.Listeners.RunStarted( "test", 0 );
            host.Listeners.RunFinished( new TestSuiteResult(null, "test") );

            mock.Verify();
        }
コード例 #22
0
        public void SearchParameters_With__SelectedFilters_With_NoName_Return_SelectedFilterException()
        {
            var selectedFilters = new List<SelectedFilter>
                                      {
                                          new SelectedFilter(string.Empty, "val1", true, 1)
                                      };

            var searchParameterMock = new DynamicMock(typeof(ISearchParameters<Publication>));
            searchParameterMock.SetReturnValue("get_SelectedFilters", selectedFilters);

            var solrQueryBuilder = new SolrQueryBuilder<Publication>((ISearchParameters<Publication>)searchParameterMock.MockInstance);
            solrQueryBuilder.BuildQuery();
        }
コード例 #23
0
        public void Setup()
        {
            _errorBrowser = new TestingErrorBrowser();

            _mockStackDisplay = MockHelper.NewMockIErrorRenderer("StackTraceDisplay", 1);
            _mockStackDisplay.SetReturnValue("Text", "Display actual stack trace");

            _stackTraceChanged = false;

            _errorBrowser.StackTraceSourceChanged += new EventHandler(_errorBrowser_StackTraceSourceChanged);

            return;
        }
コード例 #24
0
        public void AddEconomicActivityWhenNameAlreadyExist()
        {
            _dynamicMock = new DynamicMock(typeof(EconomicActivityManager));
            EconomicActivity activity = new EconomicActivity { Name = "Services", Parent = new EconomicActivity { Id = 1 } };

            _dynamicMock.ExpectAndReturn("ThisActivityAlreadyExist", true, "Services", 1);
            _dynamicMock.ExpectAndReturn("AddEconomicActivity", 0, activity);

            _economicActivityManager = (EconomicActivityManager)_dynamicMock.MockInstance;
            _economicActivityServices = new EconomicActivityServices(_economicActivityManager);

            _economicActivityServices.AddEconomicActivity(activity);
        }
コード例 #25
0
        public void Analyze_TooShortFileName_CallsWebService()
        {
            DynamicMock mockController = new DynamicMock(typeof (IWebService));
            mockController.Expect("LogError", "Filename too short:abc.ext");

            IWebService mockService = mockController.MockInstance as IWebService;

            LogAnalyzer log = new LogAnalyzer(mockService);
            string tooShortFileName="abc.ext";
            log.Analyze(tooShortFileName);

            mockController.Verify();
        }
コード例 #26
0
        public void AddEconomicActivity()
        {
            _dynamicMock = new DynamicMock(typeof(EconomicActivityManager));
            EconomicActivity activity = new EconomicActivity { Name = "Services",Parent = new EconomicActivity {Id=1}};

            _dynamicMock.ExpectAndReturn("ThisActivityAlreadyExist", false, "Services", 1);
            _dynamicMock.ExpectAndReturn("AddEconomicActivity", 2, activity);

            _economicActivityManager = (EconomicActivityManager)_dynamicMock.MockInstance;
            _economicActivityServices = new EconomicActivityServices(_economicActivityManager);

            activity.Id = _economicActivityServices.AddEconomicActivity(activity);
            Assert.AreEqual(2,activity.Id);
        }
コード例 #27
0
ファイル: RowTestAddInTest.cs プロジェクト: kobida/nunitv2
		public void Install_Successful()
		{
			DynamicMock extensionPointMock = new DynamicMock(typeof(IExtensionPoint));
			IExtensionPoint extensionPoint = (IExtensionPoint) extensionPointMock.MockInstance;

			extensionHostMock.ExpectAndReturn("GetExtensionPoint", extensionPoint, "ParameterProviders");
			extensionPointMock.Expect("Install");

			bool installed = addIn.Install(extensionHost);
			
			extensionHostMock.Verify();
			extensionPointMock.Verify();
			Assert.That(installed, Is.True);
		}
コード例 #28
0
ファイル: BoardControllerTest.cs プロジェクト: rockem/reverci
 public void setUp()
 {
     m_PossibleMoves = new List<Point> {new Point(2, 3)};
     m_BoardView = new StubBoardView();
     m_MockModel = new DynamicMock(typeof (IBoardModel));
     m_BoardController = new BoardController(m_BoardView);
     m_MockModel.SetReturnValue("GetPossibleMovesFor", m_PossibleMoves);
     m_MockModel.SetReturnValue("GetBoard", r_ExpectedData);
     m_MockModel.SetReturnValue("GetCurrentColor", eCoinType.Black);
     m_EventListener = new DynamicMock(typeof (IBoardEventListener));
     m_BoardController.setEventListener((IBoardEventListener)m_EventListener.MockInstance);
     m_BoardController.SetModel((IBoardModel)m_MockModel.MockInstance);
     m_BoardController.setPlayers(new StubPlayer(), new StubPlayer());
 }
        public void IsLoginOK_LoggerThrowsException_WritesToWebService()
        {
            DynamicMock stubLog = new DynamicMock(typeof(ILogger));
            DynamicMock mockService = new DynamicMock(typeof(IWebService));

            stubLog.ExpectAndThrow("Write",new LoggerException("fake exception"),"yo" );
            mockService.Expect("Write","got exception");

            var loginManager =
                new LoginManagerWithMockAndStub((ILogger)stubLog.MockInstance,
                                                (IWebService) mockService.MockInstance);
            loginManager.IsLoginOK("", "");

            mockService.Verify();
        }
コード例 #30
0
ファイル: ProfitPerMonthTest.cs プロジェクト: sherman/onTSLab
        public void init()
        {
            sourceMock = new DynamicMock(typeof(ISecurity));
            positionMock = new DynamicMock(typeof(IPosition));
            positionListMock = new DynamicMock(typeof(IPositionsList));

            sourceMock.ExpectAndReturn(
                "get_Positions",
                (IPositionsList)positionListMock.MockInstance
            );
            positionListMock.ExpectAndReturn(
                "get_LastPositionClosed",
                (IPosition)positionMock.MockInstance
            );
        }