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);
        }
        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);
        }
        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();
        }
Пример #4
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();
        }
Пример #5
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();
        }
        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();
        }
Пример #7
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();
        }
Пример #8
0
		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);
		}
        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();
        }
Пример #10
0
        public void TestLoad()
        {
            Document dm = new Document();

            dm.FileName = @"c:\abc.wordo";

            DynamicMock fs = new DynamicMock(typeof (IFileSystem));

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

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

            fs.Verify();

            Assert.AreEqual("abc", dm.Text);
        }
        public void estimatePreference()
        {
            var dataModelMock = new DynamicMock( typeof( IDataModel) );
            var factorizerMock = new DynamicMock( typeof(IFactorizer) );
            var factorization = new Factorization_estimatePreference_TestMock();

            factorizerMock.ExpectAndReturn("Factorize", factorization);

             //EasyMock.replay(dataModel, factorizer, factorization);

            SVDRecommender svdRecommender = new SVDRecommender( (IDataModel)dataModelMock.MockInstance, (IFactorizer)factorizerMock.MockInstance);

            float estimate = svdRecommender.EstimatePreference(1L, 5L);
            Assert.AreEqual(1, estimate, EPSILON);

            factorizerMock.Verify();
            Assert.AreEqual(1, factorization.getItemFeaturesCallCount );
            Assert.AreEqual(1, factorization.getUserFeaturesCallCount);
            //EasyMock.verify(dataModel, factorizer, factorization);
        }
        public void TestPersist()
        {
            //Gateway
            DynamicMock mockGateway = new DynamicMock(typeof(IUserGateway));
            IUserGateway gateway = (IUserGateway) mockGateway.MockInstance;

            //Validator
            DynamicMock mockValidator = new DynamicMock(typeof(IUserValidator));
            IUserValidator validator = (IUserValidator)mockValidator.MockInstance;

            //User
            User user = new User(gateway);

            //Expectations
            mockValidator.ExpectAndReturn("Validate", true, user);
            mockGateway.ExpectAndReturn("Persist", true, user);

            Assert.AreEqual(true, user.Persist(validator));
            mockValidator.Verify();
            mockGateway.Verify();
        }
        public void preferencesFetchedOnlyOnce()
        {
            var dataModelMock = new DynamicMock( typeof( IDataModel) );

            var itemSimilarityMock = new DynamicMock( typeof(IItemSimilarity) );
            var candidateItemsStrategyMock = new DynamicMock( typeof (ICandidateItemsStrategy) );
            var mostSimilarItemsCandidateItemsStrategyMock =
            new DynamicMock( typeof(IMostSimilarItemsCandidateItemsStrategy) );

            IPreferenceArray preferencesFromUser = new GenericUserPreferenceArray(
            new List<IPreference>() {new GenericPreference(1L, 1L, 5.0f), new GenericPreference(1L, 2L, 4.0f)});

            dataModelMock.ExpectAndReturn("GetMinPreference", float.NaN);
            dataModelMock.ExpectAndReturn("GetMaxPreference", float.NaN);
            dataModelMock.ExpectAndReturn("GetPreferencesFromUser", preferencesFromUser, 1L);
            var dataModel = (IDataModel)dataModelMock.MockInstance;

            candidateItemsStrategyMock.ExpectAndReturn("GetCandidateItems", new FastIDSet(new long[] { 3L, 4L }),
            1L, preferencesFromUser, dataModel);

            itemSimilarityMock.ExpectAndReturn("ItemSimilarities", new double[] { 0.5, 0.3 },
            3L, preferencesFromUser.GetIDs());
            itemSimilarityMock.ExpectAndReturn("ItemSimilarities", new double[] { 0.4, 0.1 },
            4L, preferencesFromUser.GetIDs());

            //EasyMock.replay(dataModel, itemSimilarity, candidateItemsStrategy, mostSimilarItemsCandidateItemsStrategy);

            IRecommender recommender = new GenericItemBasedRecommender((IDataModel)dataModel,
            (IItemSimilarity)itemSimilarityMock.MockInstance,
            (ICandidateItemsStrategy)candidateItemsStrategyMock.MockInstance,
            (IMostSimilarItemsCandidateItemsStrategy)mostSimilarItemsCandidateItemsStrategyMock.MockInstance);

            recommender.Recommend(1L, 3);

            dataModelMock.Verify();
            itemSimilarityMock.Verify();
            candidateItemsStrategyMock.Verify();
            mostSimilarItemsCandidateItemsStrategyMock.Verify();
            //EasyMock.verify(dataModel, itemSimilarity, candidateItemsStrategy, mostSimilarItemsCandidateItemsStrategy);
        }
Пример #14
0
        public void TestExport()
        {
            m_FileSystem = new DynamicMock(typeof(IFileSystem));

            List<Context> selected = new List<Context>();

            Context result = new Context();
            result.Tokens.Add("a");
            result.Tokens.Add("b");
            result.Tokens.Add("c");

            Context branch = result.Branch("b1");
            branch.Tokens.Add("d");

            selected.Add(result);

            IExporter exporter = new CsvExporter();

            m_FileSystem.Expect("WriteAllText", @"c:\abc.csv", string.Format(".Word.;b1{0}abc;abcd{0}", Environment.NewLine));

            exporter.Export(selected, @"c:\abc.csv", (IFileSystem)m_FileSystem.MockInstance);

            m_FileSystem.Verify();
        }
        public void testCommitTransactionCalled()
        {
            //STOP -- check with instructor before beginning this test~
            //now go break your code -- don't call the 'commit transaction' or the 'update account' methods.  Does the test above fail?
            //use dynamic mocks to verify that these methods are called.

            //here's an example of creating the credit card service.  You'll need another thing just like this for
            //the account update.  These mocks will replace the stub code from the happyPathTest
            DynamicMock mockCreditCardService = new DynamicMock(typeof (ICreditCardService));
            //some expectations
            int token = 42;
            String ccNum = "4324 3924 4382 3888";
            Decimal amount = 199.99M;
            mockCreditCardService.ExpectAndReturn("ReserveFunds", token, new Object[2] { ccNum, amount });
            mockCreditCardService.Expect("CommitTransaction", new Object[1] { token });
            ICreditCardService creditCardServiceInstance = (ICreditCardService) mockCreditCardService.MockInstance;

            //calls to the actual class under test goes here
            AccountUpdater au = new AccountUpdater(new StubBalanceService(), creditCardServiceInstance);
            au.UpdateAccount(ccNum, amount, 3982834);

            //this should be the last line.
            mockCreditCardService.Verify();
        }
Пример #16
0
        public void ShouldNotApplyBackgroundToRunningStreams()
        {
            const string units = "V";
            const MultiClampInterop.OperatingMode vclampMode = MultiClampInterop.OperatingMode.VClamp;
            const MultiClampInterop.OperatingMode iclampMode = MultiClampInterop.OperatingMode.IClamp;

            var c = new Controller();
            var mc = new FakeMulticlampCommander();

            var vclampBackground = new Measurement(2, -3, units);

            var background = new Dictionary<MultiClampInterop.OperatingMode, IMeasurement>()
                                 {
                                     { vclampMode, vclampBackground }
                                 };

            var dataVClamp = new MultiClampInterop.MulticlampData()
            {
                OperatingMode = vclampMode,
                ExternalCommandSensitivity = 2.5,
                ExternalCommandSensitivityUnits = MultiClampInterop.ExternalCommandSensitivityUnits.V_V
            };

            var daq = new DynamicMock(typeof(IDAQController));
            var s = new DAQOutputStream("test", daq.MockInstance as IDAQController);

            var mcd = new MultiClampDevice(mc, c, background);
            mcd.BindStream(s);

            daq.ExpectAndReturn("get_Running", true);
            daq.ExpectNoCall("ApplyStreamBackground");

            mc.FireParametersChanged(DateTimeOffset.Now, dataVClamp);

            daq.Verify();
        }
Пример #17
0
		public void GetParametersFor_CallsParameterSetFilter()
		{
			DynamicMock parameterSetFilterMock = new DynamicMock(typeof(IParameterSetFilter));
			IParameterSetFilter parameterSetFilter = (IParameterSetFilter) parameterSetFilterMock.MockInstance;
			parameterProvider.AddParameterSetFilter(parameterSetFilter);
			
			parameterSetFilterMock.Expect("Filter", Is.TypeOf(typeof(ParameterSet)), Is.Not.Null);
			parameterSetFilterMock.Expect("Filter", Is.TypeOf(typeof(ParameterSet)), Is.Not.Null);
			
			parameterProvider.GetTestCasesFor(GetTestClassMethod("RowTestMethodWith2Rows"));
			
			parameterSetFilterMock.Verify();
		}
Пример #18
0
        public void TestAddCondition_CreateNewCondition()
        {
            //set up environment
            IPolicy policy = PolicyFactory.CreatePolicy("TestPolicy", m_policySet, PolicyStatus.Active, "None");
            IConditionGroup rootConditionGroup = (IConditionGroup)policy.Conditions[0];
            DynamicMock conditionsResourceSelectForm = new DynamicMock(typeof(IConditionsResourceSelectorForm));

            //set up test object
            AddConditionState state1 = new AddConditionStateTester();
            state1.Policy = policy;
            state1.StateMachine = (IStateMachine)m_stateMachine.MockInstance;
            state1.ConditionGroup = rootConditionGroup;
            //state1.ConditionMethodDisplay = new ConditionDisplayContentInFileContext();
            state1.Source = AddConditionState.ConditionSource.New;
            state1.SelectionUI = conditionsResourceSelectForm.MockInstance;

            IPolicyObjectCollection<IPolicyObject> selectedConditions = new PolicyObjectCollection<IPolicyObject>();
            ICondition condition1 = ConditionUnitFactory.CreateCondition(ConditionUnitFactory.PreDefinedConditionType.ContentInFileContext);
            selectedConditions.Add(condition1);
            conditionsResourceSelectForm.ExpectAndReturn("get_SelectedConditions", selectedConditions, new object[0]);

            //test conditions group is empty
            Assert.AreEqual(0, rootConditionGroup.Conditions.Count, "Unexpected number of conditions in conditionGroup.Conditions");

            //add new condition
            IState showConditionsState = new ShowConditionsState();
            m_stateMachine.ExpectAndReturn("GetState", showConditionsState, StateTypeEnum.ShowConditions);
            m_stateMachine.Expect("SetState", showConditionsState);
            state1.Enter();

            //test condition group
            Assert.AreEqual(1, rootConditionGroup.Conditions.Count, "Unexpected number of conditions in conditionGroup.Conditions");

            //test condition
            ICondition condition = rootConditionGroup.Conditions[0] as ICondition;
            Assert.IsNotNull(condition, "unexpected object type in condition");
            Assert.AreSame(rootConditionGroup, condition.Parent, "Unexpected object in condition.Parent");
            Assert.AreEqual("", condition.Name.Value, "unexpected condition name");
            Assert.AreEqual(OperatorType.GreaterThan, condition.Operator, "unexpected name in condition");
            Assert.AreEqual("IDataLengthComparer", condition.Class, "unexpected class in condition");
            Assert.AreEqual(Guid.Empty, condition["Ignore"].Identifier, "unexpected identifier on Ignore attribute on condition");
            Assert.AreEqual(Boolean.FalseString, condition["Ignore"].Value, "unexpected value on Ignore attribute on condition");

            //condition.dataleft
            IDataElement dataElement = condition.DataLeft as IDataElement;
            Assert.IsNotNull(dataElement, "unexpected object type in condition.dataleft");
            Assert.AreEqual(Guid.Empty, dataElement.DisplayName.Identifier, "unexpected displayname identifier in condition.dataleft");
            Assert.AreEqual("", dataElement.DisplayName.Value, "unexpected display name in condition.dataleft");
            Assert.AreEqual(Guid.Empty, dataElement.Name.Identifier, "unexpected name identifier in condition.dataleft");
            Assert.AreEqual("contentInFileContext", dataElement.Name.Value, "unexpected name in condition.dataleft");
            Assert.AreEqual(false, dataElement.ReadOnly, "unexpected readonly in condition.dataleft");
            Assert.AreEqual(DataType.Object, dataElement.Type, "unexpected type in condition.dataleft");

            //condition.dataleft.data 
            IDataSource dataSource = dataElement.Data as IDataSource;
            Assert.IsNotNull(dataSource, "unexpected object type in condition.dataleft.data");
            Assert.AreEqual("Workshare.Policy.Condition.ContentAnalysis.dll", dataSource.Assembly, "unexpected assembly in condition.dataleft.data");
            Assert.AreEqual("Workshare.Policy.Condition.ContentAnalysis", dataSource.Class, "unexpected class in condition.dataleft.data");
            Assert.AreEqual(Guid.Empty, dataSource.Name.Identifier, "unexpected name identifier in condition.dataleft.data");
            Assert.AreEqual("Workshare.Policy.Condition.ContentAnalysis", dataSource.Name.Value, "unexpected name in condition.dataleft.data");

            //condition.dataleft.data.method 
            IDataMethod dataMethod = dataSource.Method as IDataMethod;
            Assert.IsNotNull(dataMethod, "unexpected object type in condition.dataleft.data.method");
            Assert.AreEqual(Guid.Empty, dataMethod.Name.Identifier, "unexpected name identifier in condition.dataleft.data.method");
            Assert.AreEqual("TextLookupInFileType", dataMethod.Name.Value, "unexpected name in condition.dataleft.data.method");
            Assert.AreEqual(5, dataMethod.Parameters.Count, "unexpected number of parameters in condition.dataleft.data.method");

            //condition.dataleft.data.method.parameters[0]
            IParameter parameter = dataMethod.Parameters[0];
            Assert.AreEqual(Guid.Empty, parameter.Name.Identifier, "unexpected name identifier in condition.dataleft.data.method.parameters[0]");
            Assert.AreEqual("file", parameter.Name.Value, "unexpected name in condition.dataleft.data.method.parameters[0]");

            //condition.dataleft.data.method.parameters[0].value
            dataElement = dataMethod.Parameters[0].Value as IDataElement;
            Assert.IsNotNull(dataElement, "unexpected object type in condition.dataleft.data.method.parameters[0].value");
            Assert.AreEqual(Guid.Empty, dataElement.Name.Identifier, "unexpected name identifier in condition.dataleft.data.method.parameters[0].value");
            Assert.AreEqual("file", dataElement.Name.Value, "unexpected name in condition.dataleft.data.method.parameters[0].value");
            Assert.AreEqual(Guid.Empty, dataElement.DisplayName.Identifier, "unexpected displayname identifier in condition.dataleft.data.method.parameters[0].value");
            Assert.AreEqual("", dataElement.DisplayName.Value, "unexpected displayname in condition.dataleft.data.method.parameters[0].value");
            Assert.AreEqual(false, dataElement.ReadOnly, "unexpected readonly in condition.dataleft.data.method.parameters[0].value");
            Assert.AreEqual(DataType.Object, dataElement.Type, "unexpected datatype in condition.dataleft.data.method.parameters[0].value");

            //condition.dataleft.data.method.parameters[0].value.data
            dataSource = dataElement.Data as IDataSource;
            Assert.IsNotNull(dataSource, "unexpected object type in condition.dataleft.data.method.parameters[0].value.data");
            Assert.AreEqual("this", dataSource.Assembly, "unexpected assembly in condition.dataleft.data.method.parameters[0].value.data");
            Assert.AreEqual("this", dataSource.Class, "unexpected class in condition.dataleft.data.method.parameters[0].value.data");
            Assert.AreEqual(Guid.Empty, dataSource.Name.Identifier, "unexpected name identifier in condition.dataleft.data.method.parameters[0].value.data");
            Assert.AreEqual("this", dataSource.Name.Value, "unexpected name in condition.dataleft.data.method.parameters[0].value.data");

            //condition.dataleft.data.method.parameters[0].value.data.method
            IDataMethod fileDataMethod = dataSource.Method as IDataMethod;
            Assert.IsNotNull(fileDataMethod, "unexpected object type in condition.dataleft.data.method.parameters[0].value.data.method");
            Assert.AreEqual(Guid.Empty, fileDataMethod.Name.Identifier, "unexpected name identifier in condition.dataleft.data.method.parameters[0].value.data.method");
            Assert.AreEqual("CurrentFile", fileDataMethod.Name.Value, "unexpected name in condition.dataleft.data.method.parameters[0].value.data.method");
            Assert.AreEqual(0, fileDataMethod.Parameters.Count, "unexpected number of parameters in condition.dataleft.data.method.parameters[0].value.data.method");

            //condition1copy.dataleft.data.method.parameters[1]
            parameter = dataMethod.Parameters[1];
            Assert.AreEqual(Guid.Empty, parameter.Name.Identifier, "unexpected name identifier in condition1copy.dataleft.data.method.parameters[1]");
            Assert.AreEqual("fileTypes", parameter.Name.Value, "unexpected name in condition1copy.dataleft.data.method.parameters[1]");

            //condition1copy.dataleft.data.method.parameters[1].value
            dataElement = dataMethod.Parameters[1].Value as IDataElement;
            Assert.IsNotNull(dataElement, "unexpected object type in condition1copy.dataleft.data.method.parameters[1].value");
            Assert.AreEqual(Guid.Empty, dataElement.Name.Identifier, "unexpected name identifier in condition1copy.dataleft.data.method.parameters[1].value");
            Assert.AreEqual("fileTypes", dataElement.Name.Value, "unexpected name in condition1copy.dataleft.data.method.parameters[1].value");
            Assert.AreEqual(Guid.Empty, dataElement.DisplayName.Identifier, "unexpected displayname identifier in condition1copy.dataleft.data.method.parameters[1].value");
            Assert.AreEqual("", dataElement.DisplayName.Value, "unexpected displayname in condition1copy.dataleft.data.method.parameters[1].value");
            Assert.AreEqual(false, dataElement.ReadOnly, "unexpected readonly in condition1copy.dataleft.data.method.parameters[1].value");
            Assert.AreEqual(DataType.StringArray, dataElement.Type, "unexpected datatype in condition1copy.dataleft.data.method.parameters[1].value");

            //condition.dataleft.data.method.parameters[1].value.data
            IPolicyObjectCollection<IDataItem> collection = dataElement.Data as IPolicyObjectCollection<IDataItem>;
            Assert.IsNotNull(collection, "unexpected object type in condition.dataleft.data.method.parameters[1].value.data");
            Assert.AreEqual(5, collection.Count, "unexpected number of items in condition.dataleft.data.method.parameters[1].value.data");

            //condition.dataleft.data.method.parameters[1].value.data[0]
            IDataItem dataItem = collection[0] as IDataItem;
            Assert.IsNotNull(dataItem, "unexpected object type in condition.dataleft.data.method.parameters[1].value.data[0]");
            Assert.AreEqual(Guid.Empty, dataItem.Name.Identifier, "unexpected displayname identifier in condition.dataleft.data.method.parameters[1].value");
            Assert.AreEqual("", dataItem.Name.Value, "unexpected name in condition.dataleft.data.method.parameters[1].value.data[0]");
            Assert.AreEqual(false, dataItem.ReadOnly, "unexpected readonly in condition.dataleft.data.method.parameters[1].value.data[0]");
            Assert.AreEqual(Enum.GetName(typeof(Workshare.Policy.FileType), Workshare.Policy.FileType.WordDocument), dataItem.Value, "unexpected value in condition.dataleft.data.method.parameters[1].value.data[0]");

            //condition.dataleft.data.method.parameters[2]
            parameter = dataMethod.Parameters[2];
            Assert.AreEqual(Guid.Empty, parameter.Name.Identifier, "unexpected name identifier in condition.dataleft.data.method.parameters[2]");
            Assert.AreEqual("content", parameter.Name.Value, "unexpected name in condition.dataleft.data.method.parameters[2]");

            //condition.dataleft.data.method.parameters[2].value
            dataElement = dataMethod.Parameters[2].Value as IDataElement;
            Assert.IsNotNull(dataElement, "unexpected object type in condition.dataleft.data.method.parameters[2].value");
            Assert.AreEqual(Guid.Empty, dataElement.Name.Identifier, "unexpected name identifier in condition.dataleft.data.method.parameters[2].value");
            Assert.AreEqual("content", dataElement.Name.Value, "unexpected name in condition.dataleft.data.method.parameters[2].value");
            Assert.AreEqual(Guid.Empty, dataElement.DisplayName.Identifier, "unexpected displayname identifier in condition.dataleft.data.method.parameters[2].value");
            Assert.AreEqual("word or phrase", dataElement.DisplayName.Value, "unexpected displayname in condition.dataleft.data.method.parameters[2].value");
            Assert.AreEqual(false, dataElement.ReadOnly, "unexpected readonly in condition.dataleft.data.method.parameters[2].value");
            Assert.AreEqual(DataType.StringArray, dataElement.Type, "unexpected datatype in condition.dataleft.data.method.parameters[2].value");

            //condition.dataleft.data.method.parameters[2].value.data
            collection = dataElement.Data as IPolicyObjectCollection<IDataItem>;
            Assert.IsNotNull(collection, "unexpected object type in condition.dataleft.data.method.parameters[2].value.data");
            Assert.AreEqual(0, collection.Count, "unexpected number of items in condition.dataleft.data.method.parameters[2].value.data");

            //condition.dataleft.data.method.parameters[3]
            parameter = dataMethod.Parameters[3];
            Assert.AreEqual(Guid.Empty, parameter.Name.Identifier, "unexpected name identifier in condition.dataleft.data.method.parameters[3]");
            Assert.AreEqual("context", parameter.Name.Value, "unexpected name in condition.dataleft.data.method.parameters[3]");

            //condition.dataleft.data.method.parameters[3].value
            dataElement = dataMethod.Parameters[3].Value as IDataElement;
            Assert.IsNotNull(dataElement, "unexpected object type in condition.dataleft.data.method.parameters[3].value");
            Assert.AreEqual(Guid.Empty, dataElement.Name.Identifier, "unexpected name identifier in condition.dataleft.data.method.parameters[3].value");
            Assert.AreEqual("context", dataElement.Name.Value, "unexpected name in condition.dataleft.data.method.parameters[3].value");
            Assert.AreEqual(Guid.Empty, dataElement.DisplayName.Identifier, "unexpected displayname identifier in condition.dataleft.data.method.parameters[3].value");
            Assert.AreEqual("", dataElement.DisplayName.Value, "unexpected displayname in condition.dataleft.data.method.parameters[3].value");
            Assert.AreEqual(false, dataElement.ReadOnly, "unexpected readonly in condition.dataleft.data.method.parameters[3].value");
            Assert.AreEqual(DataType.StringArray, dataElement.Type, "unexpected datatype in condition.dataleft.data.method.parameters[3].value");

            //condition.dataleft.data.method.parameters[3].value.data
            collection = dataElement.Data as IPolicyObjectCollection<IDataItem>;
            Assert.IsNotNull(collection, "unexpected object type in condition.dataleft.data.method.parameters[3].value.data");
            Assert.AreEqual(1, collection.Count, "unexpected number of items in condition.dataleft.data.method.parameters[3].value.data");

            //condition.dataleft.data.method.parameters[3].value.data[0]
            dataItem = collection[0] as IDataItem;
            Assert.IsNotNull(dataItem, "unexpected object type in condition.dataleft.data.method.parameters[3].value.data[0]");
            Assert.AreEqual(Guid.Empty, dataItem.Name.Identifier, "unexpected name identifier in condition.dataleft.data.method.parameters[3].value.data[0]");
            Assert.AreEqual("", dataItem.Name.Value, "unexpected name in condition.dataleft.data.method.parameters[3].value.data[0]");
            Assert.AreEqual(false, dataItem.ReadOnly, "unexpected readonly in condition.dataleft.data.method.parameters[3].value.data[0]");
            Assert.AreEqual("Paragraph", dataItem.Value, "unexpected value in condition.dataleft.data.method.parameters[3].value.data[0]");

            //condition.dataleft.data.method.parameters[4].value
            dataElement = dataMethod.Parameters[4].Value as IDataElement;
            Assert.IsNotNull(dataElement, "unexpected object type in condition.dataleft.data.method.parameters[4].value");
            Assert.AreEqual(Guid.Empty, dataElement.Name.Identifier, "unexpected name identifier in condition.dataleft.data.method.parameters[4].value");
            Assert.AreEqual("matchWholeWords", dataElement.Name.Value, "unexpected name in condition.dataleft.data.method.parameters[4].value");
            Assert.AreEqual(Guid.Empty, dataElement.DisplayName.Identifier, "unexpected displayname identifier in condition.dataleft.data.method.parameters[4].value");
            Assert.AreEqual("", dataElement.DisplayName.Value, "unexpected displayname in condition.dataleft.data.method.parameters[4].value");
            Assert.AreEqual(false, dataElement.ReadOnly, "unexpected readonly in condition.dataleft.data.method.parameters[4].value");
            Assert.AreEqual(DataType.BooleanArray, dataElement.Type, "unexpected datatype in condition.dataleft.data.method.parameters[4].value");

            //condition.dataleft.data.method.parameters[4].value.data
            collection = dataElement.Data as IPolicyObjectCollection<IDataItem>;
            Assert.IsNotNull(collection, "unexpected object type in condition.dataleft.data.method.parameters[4].value.data");
            Assert.AreEqual(1, collection.Count, "unexpected number of items in condition.dataleft.data.method.parameters[4].value.data");

            //condition.dataleft.data.method.parameters[4].value.data[0]
            dataItem = collection[0] as IDataItem;
            Assert.IsNotNull(dataItem, "unexpected object type in condition.dataleft.data.method.parameters[4].value.data[0]");
            Assert.AreEqual(Guid.Empty, dataItem.Name.Identifier, "unexpected name identifier in condition.dataleft.data.method.parameters[4].value.data[0]");
            Assert.AreEqual("", dataItem.Name.Value, "unexpected name in condition.dataleft.data.method.parameters[4].value.data[0]");
            Assert.AreEqual(false, dataItem.ReadOnly, "unexpected readonly in condition.dataleft.data.method.parameters[4].value.data[0]");
            Assert.AreEqual(true, dataItem.Value, "unexpected value in condition.dataleft.data.method.parameters[4].value.data[0]");

            //condition.dataright
            dataElement = condition.DataRight as IDataElement;
            Assert.IsNotNull(dataElement, "unexpected object type in condition.dataright");
            Assert.AreEqual(Guid.Empty, dataElement.Name.Identifier, "unexpected name identifier in condition.dataright");
            Assert.AreEqual("", dataElement.DisplayName.Value, "unexpected display name in condition.dataright");
            Assert.AreEqual(Guid.Empty, dataElement.Name.Identifier, "unexpected name identifier in condition.dataright");
            Assert.AreEqual("numberOfOccurrences", dataElement.Name.Value, "unexpected name in condition.dataright");
            Assert.AreEqual(false, dataElement.ReadOnly, "unexpected readonly in condition.dataright");
            Assert.AreEqual(DataType.Long, dataElement.Type, "unexpected type in condition.dataright");

            //condition.dataright.data
            dataItem = dataElement.Data as IDataItem;
            Assert.IsNotNull(dataItem, "unexpected object type in condition.dataright.data");
            Assert.AreEqual(Guid.Empty, dataItem.Name.Identifier, "unexpected name identifier in condition.dataright.data");
            Assert.AreEqual("", dataItem.Name.Value, "unexpected name in condition.dataright.data");
            Assert.AreEqual(false, dataItem.ReadOnly, "unexpected readonly in condition.dataright.data");
            Assert.AreEqual(0, dataItem.Value, "unexpected value in condition.dataright");

            //test state machine state
            m_stateMachine.Verify();
            conditionsResourceSelectForm.Verify();

            //set up another test object
            AddConditionState state2 = new AddConditionStateTester();
            state2.Policy = policy;
            state2.StateMachine = (IStateMachine)m_stateMachine.MockInstance;
            state2.ConditionGroup = rootConditionGroup;
            //state2.ConditionMethodDisplay = new ConditionDisplayFileSize();
            state2.SelectionUI = conditionsResourceSelectForm.MockInstance;
            state2.Source = AddConditionState.ConditionSource.New;

            condition1 = ConditionUnitFactory.CreateCondition(ConditionUnitFactory.PreDefinedConditionType.FileSize);
            selectedConditions.Add(condition1);
            conditionsResourceSelectForm.ExpectAndReturn("get_SelectedConditions", selectedConditions, new object[0]);

            //add another new condition
            m_stateMachine.ExpectAndReturn("GetState", showConditionsState, StateTypeEnum.ShowConditions);
            m_stateMachine.Expect("SetState", showConditionsState);
            state2.Enter();

            //test condition group
            Assert.AreEqual(2, rootConditionGroup.Conditions.Count, "Unexpected number of conditions in conditionGroup.Conditions");

            //test condition
            ICondition condition2 = rootConditionGroup.Conditions[1] as ICondition;
            Assert.IsNotNull(condition2, "Unexpected object type in condition");
            Assert.AreSame(rootConditionGroup, condition2.Parent, "Unexpected object in condition.Parent");

            //test state machine state
            m_stateMachine.Verify();
            conditionsResourceSelectForm.Verify();
        }
        public void recommend()
        {
            var dataModelMock = new DynamicMock( typeof(IDataModel) );
            var preferencesFromUserMock = new DynamicMock( typeof(IPreferenceArray) );
            var candidateItemsStrategyMock = new DynamicMock( typeof(ICandidateItemsStrategy) );
            var factorizerMock = new DynamicMock( typeof(IFactorizer) );
            var factorization = new Factorization_recommend_TestMock();

            FastIDSet candidateItems = new FastIDSet();
            candidateItems.Add(5L);
            candidateItems.Add(3L);

            factorizerMock.ExpectAndReturn("Factorize", factorization);

            dataModelMock.ExpectAndReturn("GetPreferencesFromUser", preferencesFromUserMock.MockInstance, (1L));

            candidateItemsStrategyMock.ExpectAndReturn("GetCandidateItems", candidateItems,
            1L, preferencesFromUserMock.MockInstance, dataModelMock.MockInstance);

            //EasyMock.replay(dataModel, candidateItemsStrategy, factorizer, factorization);

            SVDRecommender svdRecommender = new SVDRecommender(
            (IDataModel)dataModelMock.MockInstance,
            (IFactorizer)factorizerMock.MockInstance,
            (ICandidateItemsStrategy)candidateItemsStrategyMock.MockInstance);

            IList<IRecommendedItem> recommendedItems = svdRecommender.Recommend(1L, 5);
            Assert.AreEqual(2, recommendedItems.Count);
            Assert.AreEqual(3L, recommendedItems[0].GetItemID());
            Assert.AreEqual(2.0f, recommendedItems[0].GetValue(), EPSILON);
            Assert.AreEqual(5L, recommendedItems[1].GetItemID());
            Assert.AreEqual(1.0f, recommendedItems[1].GetValue(), EPSILON);

            dataModelMock.Verify();
            candidateItemsStrategyMock.Verify();
            factorizerMock.Verify();

            Assert.AreEqual(2, factorization.getItemFeaturesCallCount);
            Assert.AreEqual(2, factorization.getUserFeaturesCallCount);
            //EasyMock.verify(dataModel, candidateItemsStrategy, factorizer, factorization);
        }
Пример #20
0
        public void OutputStreamShouldPropagateOutputConfiguration()
        {
            var s = new DAQOutputStream("test");
            var device = new DynamicMock(typeof (IExternalDevice));

            DateTimeOffset time = DateTime.Now;
            var config = new List<IPipelineNodeConfiguration>();
            device.Expect("DidOutputData", new object[] {s, time, TimeSpan.FromSeconds(0.1), config});

            s.Device = device.MockInstance as IExternalDevice;

            s.DidOutputData(time, TimeSpan.FromSeconds(0.1), config);

            device.Verify();
        }
Пример #21
0
        public void TestSave()
        {
            Document dm = new Document();
            dm.Text = "abc";

            dm.FileName = @"c:\abc.wordo";

            DynamicMock fs = new DynamicMock(typeof (IFileSystem));

            fs.Expect("WriteAllText", @"c:\abc.wordo", "abc");

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

            fs.Verify();
        }
Пример #22
0
        public void Install_Successful()
        {
            #if NMOCK2
            IExtensionHost extensionHostMock = (IExtensionHost)_mocks.NewMock(typeof(IExtensionHost));
            IExtensionPoint extensionPointMock = (IExtensionPoint)_mocks.NewMock(typeof(IExtensionPoint));
            RowTestAddIn addIn = new RowTestAddIn();

            NMock2.Expect.Once.On(extensionHostMock)
                    .Method("GetExtensionPoint").With("TestCaseBuilders")
                    .Will(NMock2.Return.Value(extensionPointMock));

            NMock2.Expect.Once.On(extensionPointMock)
                    .Method("Install").With(addIn);

            bool installed = addIn.Install(extensionHost);

            _mocks.VerifyAllExpectationsHaveBeenMet();
            Assert.That(installed, Is.True);
            #else
            DynamicMock extensionHostMock = new DynamicMock(typeof(IExtensionHost));
            IExtensionHost extensionHost = (IExtensionHost)extensionHostMock.MockInstance;
            DynamicMock extensionPointMock = new DynamicMock(typeof(IExtensionPoint));
            IExtensionPoint extensionPoint = (IExtensionPoint)extensionPointMock.MockInstance;
            RowTestAddIn addIn = new RowTestAddIn();

            extensionHostMock.ExpectAndReturn("GetExtensionPoint", extensionPointMock.MockInstance, "TestCaseBuilders");
            extensionPointMock.Expect("Install", addIn);

            bool installed = addIn.Install(extensionHost);

            extensionPointMock.Verify();
            extensionHostMock.Verify();
            Assert.That(installed, Is.True);
            #endif
        }
Пример #23
0
        public void OutputStreamShouldApplyBackground()
        {
            var controller = new DynamicMock(typeof (IDAQController));
            var s = new DAQOutputStream("test", controller.MockInstance as IDAQController);

            controller.Expect("ApplyStreamBackground", s);

            s.ApplyBackground();

            controller.Verify();
        }