Exemple #1
0
        /// <summary>
        /// Run all methods in each of the listed assemblies
        /// </summary>
        public void Run(IORMToolServices services, IORMToolTestSuiteReport suiteReport)
        {
            suiteReport.BeginSuite(myName);
            IList <ReportAssembly> allAssemblies = myAssemblies;

            if (allAssemblies == null)
            {
                return;
            }
            int assemblyCount = allAssemblies.Count;

            for (int i = 0; i < assemblyCount; ++i)
            {
                ReportAssembly testAssembly     = allAssemblies[i];
                Assembly       resolvedAssembly = testAssembly.Assembly;
                suiteReport.BeginTestAssembly(testAssembly.Location, resolvedAssembly == null);
                if (resolvedAssembly != null)
                {
                    Type[] types     = resolvedAssembly.GetTypes();
                    int    typeCount = types.Length;
                    for (int j = 0; j < typeCount; ++j)
                    {
                        Type type = types[j];
                        if (0 != type.GetCustomAttributes(typeof(ORMTestFixtureAttribute), true).Length)
                        {
                            RunTests(type, services, suiteReport);
                        }
                    }
                }
            }
        }
Exemple #2
0
		public Tests(IORMToolServices services)
		{
			// Cache the services for future use
			myServices = services;
			// The services from the test tool can be retrieved
			// from the code services service provider.
			myTestServices = (IORMToolTestServices)services.ServiceProvider.GetService(typeof(IORMToolTestServices));
		}
Exemple #3
0
 public Tests(IORMToolServices services)
 {
     // Cache the services for future use
     myServices = services;
     // The services from the test tool can be retrieved
     // from the code services service provider.
     myTestServices = (IORMToolTestServices)services.ServiceProvider.GetService(typeof(IORMToolTestServices));
 }
Exemple #4
0
        private static int Main(string[] args)
        {
            string   suiteFile     = args[0];
            FileInfo suiteFileInfo = new FileInfo(suiteFile);
            string   fullName      = suiteFileInfo.FullName;
            string   extension     = suiteFileInfo.Extension;

            XmlReaderSettings readerSettings = new XmlReaderSettings();

            readerSettings.CloseInput = false;

            using (FileStream fileStream = suiteFileInfo.OpenRead())
            {
                XmlTextReader suitesReader = new XmlTextReader(new StreamReader(fileStream));
                using (XmlReader reader = XmlReader.Create(suitesReader, readerSettings))
                {
                    reader.MoveToContent();
                    string LoadingSchemaNamespace = reader.NamespaceURI;
                    ORMSuiteReportResult result   = ORMSuiteReportResult.NoFailure;
                    if (LoadingSchemaNamespace == SchemaNamespace)
                    {
                        //If the suite is not a report then we need to generate a report.
                        IList <Suite> suites = Suite.LoadSuiteFile(suiteFile);
                        if (suites != null)
                        {
                            int suiteCount                   = suites.Count;
                            IORMToolServices  services       = Suite.CreateServices();
                            XmlWriterSettings reportSettings = new XmlWriterSettings();
                            reportSettings.Indent      = true;
                            reportSettings.IndentChars = "\t";
                            using (XmlWriter reportWriter = XmlTextWriter.Create(string.Concat(fullName.Substring(0, fullName.Length - extension.Length), ".Report", extension), reportSettings))
                            {
                                IORMToolTestSuiteReport report = ((IORMToolTestSuiteReportFactory)services.ServiceProvider.GetService(typeof(IORMToolTestSuiteReportFactory))).Create(reportWriter);
                                try
                                {
                                    for (int i = 0; i < suiteCount; ++i)
                                    {
                                        suites[i].Run(services, report);
                                    }
                                }
                                finally
                                {
                                    result = report.CloseSuiteReport();
                                }
                            }
                        }
                    }
                    else if (LoadingSchemaNamespace == ReportSchemaNamespace)
                    {
                        //TODO:  where to go with a report
                    }
                    return((int)result);
                }
            }
        }
Exemple #5
0
        /// <summary>See <see cref="RolePlayerElementPropertyDescriptor.SetValue"/>.</summary>
        public override void SetValue(object component, object value)
        {
            FactType factType;

            if (null == (factType = EditorUtility.ResolveContextInstance(component, false) as FactType))
            {
                return;
            }
            IORMToolServices toolServices           = null;
            AutomatedElementFilterCallback callback = null;
            Store store = factType.Store;

            if (null != (toolServices = store as IORMToolServices))
            {
                callback = delegate(ModelElement filterElement)
                {
                    FactType filterFactType;
                    return(filterElement is ObjectType || (null != (filterFactType = filterElement as FactType) && null == filterFactType.ImpliedByObjectification) ?
                           AutomatedElementDirective.NeverIgnore :
                           AutomatedElementDirective.None);
                };
                toolServices.AutomatedElementFilter += callback;
            }
            try
            {
                using (Transaction transaction = BeginTransaction(store))
                {
                    Objectification.CreateExplicitObjectification(factType, value as ObjectType);
                    if (transaction.HasPendingChanges)
                    {
                        transaction.Commit();
                    }
                }
            }
            finally
            {
                if (toolServices != null)
                {
                    toolServices.AutomatedElementFilter -= callback;
                }
            }
        }
                    LabelEditResult IBranch.CommitLabelEdit(int row, int column, string newText)
                    {
                        newText = newText.Trim();
                        switch ((Columns)column)
                        {
                        case Columns.Name:
                            return(LabelEditResult.CancelEdit);

                        case Columns.FormatString:
                            if (newText.Length == 0)
                            {
                                return(LabelEditResult.CancelEdit);
                            }
                            IORMToolServices toolServices = (IORMToolServices)myStore;
                            toolServices.AutomatedElementFilter += FilterAllElements;
                            try
                            {
                                using (Transaction t = myStore.TransactionManager.BeginTransaction(ResourceStrings.ModelReferenceModeEditorChangeFormatStringTransaction))
                                {
                                    myReferenceModeKindsList[row].FormatString = UglyFormatString(newText);
                                    if (t.HasPendingChanges)
                                    {
                                        t.Commit();
                                    }
                                }
                            }
                            finally
                            {
                                toolServices.AutomatedElementFilter -= FilterAllElements;
                            }
                            break;

                        case Columns.ReferenceModeKind:
                            return(LabelEditResult.CancelEdit);
                        }
                        return(LabelEditResult.AcceptEdit);
                    }
        /// <summary>
        /// Set a value with a filter in place
        /// </summary>
        public override void SetValue(object component, object value)
        {
            IORMToolServices toolServices = null;
            ModelElement     element;
            AutomatedElementFilterCallback callback = null;

            if (null != (element = component as ModelElement) &&
                null != (toolServices = element.Store as IORMToolServices))
            {
                callback = FilterAutomatedElement;
                toolServices.AutomatedElementFilter += callback;
            }
            try
            {
                base.SetValue(component, value);
            }
            finally
            {
                if (toolServices != null)
                {
                    toolServices.AutomatedElementFilter -= callback;
                }
            }
        }
 public DTBlankTests(IORMToolServices services)
 {
     myServices     = services;
     myTestServices = (IORMToolTestServices)services.ServiceProvider.GetService(typeof(IORMToolTestServices));
 }
		public ImplicationErrorTests(IORMToolServices services)
		{
			myServices = services;
			myTestServices = (IORMToolTestServices)services.ServiceProvider.GetService(typeof(IORMToolTestServices));
		}
                    LabelEditResult IBranch.CommitLabelEdit(int row, int column, string newText)
                    {
                        newText = newText.Trim();
                        IORMToolServices toolServices = (IORMToolServices)myStore;

                        toolServices.AutomatedElementFilter += FilterAllElements;
                        try
                        {
                            if (row < myCustomReferenceModesList.Count)
                            {
                                switch ((Columns)column)
                                {
                                case Columns.Name:
                                    string changeNameTransaction = ResourceStrings.ModelReferenceModeEditorChangeNameTransaction;
                                    using (Transaction t = myStore.TransactionManager.BeginTransaction(changeNameTransaction))
                                    {
                                        if (newText.Length != 0)
                                        {
                                            myCustomReferenceModesList[row].Name = newText;
                                        }
                                        else
                                        {
                                            myCustomReferenceModesList[row].Delete();
                                        }
                                        if (t.HasPendingChanges)
                                        {
                                            t.Commit();
                                        }
                                    }
                                    break;

                                case Columns.FormatString:
                                    using (Transaction t = myStore.TransactionManager.BeginTransaction(ResourceStrings.ModelReferenceModeEditorChangeFormatStringTransaction))
                                    {
                                        myCustomReferenceModesList[row].CustomFormatString = UglyFormatString(newText);
                                        if (t.HasPendingChanges)
                                        {
                                            t.Commit();
                                        }
                                    }
                                    break;

                                case Columns.ReferenceModeKind:
                                    break;
                                }
                            }
                            else
                            {
                                bool success = false;
                                using (Transaction t = myStore.TransactionManager.BeginTransaction(ResourceStrings.ModelReferenceModeEditorAddCustomReferenceModeTransaction))
                                {
                                    new CustomReferenceMode(this.myStore, new PropertyAssignment(CustomReferenceMode.NameDomainPropertyId, newText)).Model = this.myModel;
                                    // Note that the Kind is automatically set to General on Commit

                                    if (t.HasPendingChanges)
                                    {
                                        try
                                        {
                                            myIDidIt = true;
                                            t.Commit();
                                            success = true;
                                        }
                                        finally
                                        {
                                            myIDidIt = false;
                                        }
                                    }
                                }
                                if (success)
                                {
                                    // We want to activate the kind dropdown for the new row.
                                    // However, if we begin a label edit now before the current
                                    // one is finished, then the control gets really confused, so
                                    // we wait until the control is officially done--it will tell us
                                    // via an event--so we can open the new dropdown.
                                    VirtualTreeControl control = ORMDesignerPackage.ReferenceModeEditorWindow.TreeControl;
                                    control.LabelEditControlChanged += new EventHandler(DelayActivateKindDropdown);
                                }
                            }
                        }
                        finally
                        {
                            toolServices.AutomatedElementFilter -= FilterAllElements;
                        }
                        return(LabelEditResult.AcceptEdit);
                    }
		public ConstraintContradictionTests(IORMToolServices services)
		{
			myServices = services;
			myTestServices = (IORMToolTestServices)services.ServiceProvider.GetService(typeof(IORMToolTestServices));
		}
 public FCExactlyOneTests(IORMToolServices services)
 {
     myServices     = services;
     myTestServices = (IORMToolTestServices)services.ServiceProvider.GetService(typeof(IORMToolTestServices));
 }
Exemple #13
0
 public ImplicationErrorTests(IORMToolServices services)
 {
     myServices     = services;
     myTestServices = (IORMToolTestServices)services.ServiceProvider.GetService(typeof(IORMToolTestServices));
 }
Exemple #14
0
 public PopulationTests(IORMToolServices services)
 {
     myServices     = services;
     myTestServices = (IORMToolTestServices)services.ServiceProvider.GetService(typeof(IORMToolTestServices));
 }
Exemple #15
0
		public FCMinMaxTests(IORMToolServices services)
		{
			myServices = services;
			myTestServices = (IORMToolTestServices)services.ServiceProvider.GetService(typeof(IORMToolTestServices));
		}
 public PreferredPathTests(IORMToolServices services)
 {
     myServices     = services;
     myTestServices = (IORMToolTestServices)services.ServiceProvider.GetService(typeof(IORMToolTestServices));
 }
Exemple #17
0
        /// <summary>
        /// Run all tests for the given type that match the
        /// category filters specified for this suite
        /// </summary>
        /// <param name="testType">A type with a Test attribute</param>
        /// <param name="services">Services used to run the test. IORMToolTestServices can
        /// be retrieved from services.ServiceProvider.</param>
        /// <param name="suiteReport">The suite report callback</param>
        private void RunTests(Type testType, IORMToolServices services, IORMToolTestSuiteReport suiteReport)
        {
            IORMToolTestServices testServices = (IORMToolTestServices)services.ServiceProvider.GetService(typeof(IORMToolTestServices));
            object testTypeInstance           = null;

            object[]     methodParams = null;
            MethodInfo[] methods      = testType.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly);
            int          methodCount  = methods.Length;

            for (int i = 0; i < methodCount; ++i)
            {
                MethodInfo method         = methods[i];
                object[]   testAttributes = method.GetCustomAttributes(typeof(ORMTestAttribute), false);
                Debug.Assert(testAttributes.Length < 2, "Single use attribute with inherit=false, should only pick up zero or one attributes");
                // Make sure that the method is flagged as a Test method that can be run per the current category settings
                if (testAttributes.Length == 0 || !CheckCategoryFilters((ORMTestAttribute)testAttributes[0]))
                {
                    continue;
                }

                // Make sure we've instantiated the test class
                if (testTypeInstance == null)
                {
                    ConstructorInfo constructor;
                    if (null != (constructor = testType.GetConstructor(new Type[] { typeof(IORMToolServices) })))
                    {
                        testTypeInstance = constructor.Invoke(new object[] { services });
                        methodParams     = new object[1];
                    }
                    bool loadFailure = null == testTypeInstance;
                    suiteReport.BeginTestClass(testType.Namespace, testType.Name, loadFailure);
                    if (loadFailure)
                    {
                        return;
                    }
                }

                ParameterInfo[] methodParamInfos = method.GetParameters();
                if (!(methodParamInfos.Length == 1 && typeof(Store).IsAssignableFrom(methodParamInfos[0].ParameterType)))
                {
                    // The test method does not match the signature we need, it should
                    // not have been marked with the Test attribute
                    suiteReport.ReportTestResults(method.Name, ORMTestResult.FailBind, null);
                }
                else
                {
                    Store store = null;
                    try
                    {
                        // Prepare the test services for a new test
                        testServices.OpenReport();

                        // Populate a store. Automatically loads the starting
                        // file from the test assembly if one is provided
                        store = testServices.Load(method, null, null);

                        // Run the method
                        methodParams[0] = store;
                        method.Invoke(testTypeInstance, methodParams);

                        // Compare the current contents of the store with the
                        // expected state
                        testServices.Compare(store, method, null);
                        testServices.LogValidationErrors(null);
                    }
                    finally
                    {
                        if (store != null)
                        {
                            ((IDisposable)store).Dispose();
                        }

                        // Close the report and see if the report matches the expected results
                        using (XmlReader reportReader = testServices.CloseReport(method))
                        {
                            string methodName     = method.Name;
                            string resourceName   = string.Concat(testType.FullName, ".", methodName, ".Report.xml");
                            Stream baselineStream = null;
                            try
                            {
                                Assembly testAssembly = testType.Assembly;
                                // Get the baseline that we're comparing to
                                if (null != testAssembly.GetManifestResourceInfo(resourceName))
                                {
                                    baselineStream = testAssembly.GetManifestResourceStream(resourceName);
                                }
                                if (baselineStream != null)
                                {
                                    bool hasDiff = false;

                                    // See if the data is different.
                                    XmlDiff           diff           = DiffEngine;
                                    XmlReaderSettings readerSettings = DetachableReaderSettings;
                                    XmlWriterSettings writerSettings = DetachableWriterSettings;
                                    using (MemoryStream diffStream = new MemoryStream())
                                    {
                                        using (XmlReader baselineReader = XmlReader.Create(baselineStream, readerSettings))
                                        {
                                            using (XmlWriter diffWriter = XmlWriter.Create(diffStream, writerSettings))
                                            {
                                                hasDiff = !diff.Compare(baselineReader, reportReader, diffWriter);
                                            }
                                        }
                                        if (hasDiff)
                                        {
                                            // Record the diffgram in the suite report
                                            diffStream.Seek(0, SeekOrigin.Begin);
                                            using (XmlReader diffReader = XmlTextReader.Create(diffStream, readerSettings))
                                            {
                                                suiteReport.ReportTestResults(methodName, ORMTestResult.FailReportDiffgram, diffReader);
                                            }
                                        }
                                        else
                                        {
                                            // Record a passing result
                                            suiteReport.ReportTestResults(methodName, ORMTestResult.Pass, null);
                                        }
                                    }
                                }
                                else
                                {
                                    // Record the full report, we have no baseline to compare against
                                    suiteReport.ReportTestResults(methodName, ORMTestResult.FailReportBaseline, reportReader);
                                }
                            }
                            finally
                            {
                                if (baselineStream != null)
                                {
                                    ((IDisposable)baselineStream).Dispose();
                                }
                            }
                        }
                    }
                }
            }
        }
Exemple #18
0
		/// <summary>
		/// Run all methods in each of the listed assemblies
		/// </summary>
		public void Run(IORMToolServices services, IORMToolTestSuiteReport suiteReport)
		{

			suiteReport.BeginSuite(myName);
			IList<ReportAssembly> allAssemblies = myAssemblies;
			if (allAssemblies == null)
			{
				return;
			}
			int assemblyCount = allAssemblies.Count;
			for (int i = 0; i < assemblyCount; ++i)
			{
				ReportAssembly testAssembly = allAssemblies[i];
				Assembly resolvedAssembly = testAssembly.Assembly;
				suiteReport.BeginTestAssembly(testAssembly.Location, resolvedAssembly == null);
				if (resolvedAssembly != null)
				{
					Type[] types = resolvedAssembly.GetTypes();
					int typeCount = types.Length;
					for (int j = 0; j < typeCount; ++j)
					{
						Type type = types[j];
						if (0 != type.GetCustomAttributes(typeof(ORMTestFixtureAttribute), true).Length)
						{
							RunTests(type, services, suiteReport);
						}
					}
				}
			}
			 
		}
Exemple #19
0
 public ConstraintContradictionTests(IORMToolServices services)
 {
     myServices     = services;
     myTestServices = (IORMToolTestServices)services.ServiceProvider.GetService(typeof(IORMToolTestServices));
 }
Exemple #20
0
        private void UpdateVerbalization()
        {
            if (CurrentORMSelectionContainer == null)
            {
                return;
            }
            if (myStringWriter != null)
            {
                myStringWriter.GetStringBuilder().Length = 0;

                ICollection selectedObjects = base.GetSelectedComponents();
                IDictionary <Type, IVerbalizationSets>            snippetsDictionary = null;
                IDictionary <string, object>                      options            = null;
                IVerbalizationSets <CoreVerbalizationSnippetType> snippets           = null;
                IExtensionVerbalizerService extensionVerbalizer = null;
                VerbalizationCallbackWriter callbackWriter      = null;
                bool showNegative     = ORMDesignerPackage.VerbalizationWindowSettings.ShowNegativeVerbalizations;
                bool firstCallPending = true;
                Dictionary <IVerbalize, IVerbalize> alreadyVerbalized = myAlreadyVerbalized;
                if (alreadyVerbalized == null)
                {
                    alreadyVerbalized   = new Dictionary <IVerbalize, IVerbalize>();
                    myAlreadyVerbalized = alreadyVerbalized;
                }
                else
                {
                    alreadyVerbalized.Clear();
                }
                Dictionary <object, object> locallyVerbalized = myLocallyVerbalized;
                if (locallyVerbalized == null)
                {
                    locallyVerbalized   = new Dictionary <object, object>();
                    myLocallyVerbalized = locallyVerbalized;
                }
                if (selectedObjects != null)
                {
                    foreach (object melIter in selectedObjects)
                    {
                        ModelElement        mel       = melIter as ModelElement;
                        PresentationElement pel       = mel as PresentationElement;
                        ModelElement        secondMel = null;
                        if (pel != null)
                        {
                            IRedirectVerbalization shapeRedirect = pel as IRedirectVerbalization;
                            bool redirected = null != (shapeRedirect = pel as IRedirectVerbalization) &&
                                              null != (mel = shapeRedirect.SurrogateVerbalizer as ModelElement);

                            if (!redirected)
                            {
                                mel = pel.ModelElement;
                            }

                            if (pel is IVerbalizeCustomChildren ||
                                (!redirected && pel is IVerbalize || pel is IVerbalizeChildren))
                            {
                                secondMel = mel;
                                mel       = pel;
                            }
                        }
                        while (mel != null && !mel.IsDeleted)
                        {
                            if (snippetsDictionary == null)
                            {
                                Store store = Utility.ValidateStore(mel.Store);
                                if (store == null)
                                {
                                    break;
                                }
                                IORMToolServices toolServices = (IORMToolServices)store;
                                extensionVerbalizer = toolServices.ExtensionVerbalizerService;
                                options             = toolServices.VerbalizationOptions;
                                snippetsDictionary  = toolServices.GetVerbalizationSnippetsDictionary(ORMCoreDomainModel.VerbalizationTargetName);
                                snippets            = (IVerbalizationSets <CoreVerbalizationSnippetType>)snippetsDictionary[typeof(CoreVerbalizationSnippetType)];
                                callbackWriter      = new VerbalizationCallbackWriter(snippets, myStringWriter, GetDocumentHeaderReplacementFields(mel, snippets));
                            }
                            locallyVerbalized.Clear();
                            VerbalizationHelper.VerbalizeElement(
                                mel,
                                snippetsDictionary,
                                extensionVerbalizer,
                                options,
                                ORMCoreDomainModel.VerbalizationTargetName,
                                alreadyVerbalized,
                                locallyVerbalized,
                                (showNegative ? VerbalizationSign.Negative : VerbalizationSign.Positive) | VerbalizationSign.AttemptOppositeSign,
                                callbackWriter,
                                true,
                                ref firstCallPending);

                            if (secondMel != null)
                            {
                                mel       = secondMel;
                                secondMel = null;
                            }
                            else
                            {
                                mel = null;
                            }
                        }
                    }
                }
                if (!firstCallPending)
                {
                    // Write footer
                    callbackWriter.WriteDocumentFooter();
                    // Clear cache
                    alreadyVerbalized.Clear();
                }
                else
                {
                    // Nothing happened, put in text for nothing happened
                }
                WebBrowser browser = myWebBrowser;
                if (browser != null)
                {
                    browser.DocumentText = myStringWriter.ToString();
                }
            }
        }
Exemple #21
0
        /// <summary>
        /// Using the current verbalization settings, verbalize the specified
        /// elements into the output text writer.
        /// </summary>
        /// <param name="store">The context <see cref="Store"/> returned by <see cref="ModelLoader.Load(Stream)"/>.</param>
        /// <param name="writer">An externally allocated writer to receive the output.</param>
        /// <param name="target">The name of the target to verbalize. The target must match
        /// a known target as registered with the <see cref="VerbalizationTargetProviderAttribute"/> on
        /// a loaded core or extension model.</param>
        /// <param name="elements">One or more elements to verbalize.</param>
        /// <param name="showNegative">Generate a negative verbalization if available.</param>
        public void Verbalize(Store store, TextWriter writer, string target, ICollection elements, bool showNegative)
        {
            IDictionary <Type, IVerbalizationSets>            snippetsDictionary = null;
            IDictionary <string, object>                      options            = null;
            IVerbalizationSets <CoreVerbalizationSnippetType> snippets           = null;
            IExtensionVerbalizerService extensionVerbalizer = null;
            VerbalizationCallbackWriter callbackWriter      = null;
            bool firstCallPending = true;
            Dictionary <IVerbalize, IVerbalize> alreadyVerbalized = new Dictionary <IVerbalize, IVerbalize>();
            Dictionary <object, object>         locallyVerbalized = new Dictionary <object, object>();

            if (elements != null)
            {
                foreach (object elemIter in elements)
                {
                    if (snippetsDictionary == null)
                    {
                        IORMToolServices toolServices = (IORMToolServices)store;
                        extensionVerbalizer = toolServices.ExtensionVerbalizerService;
                        options             = toolServices.VerbalizationOptions;
                        snippetsDictionary  = toolServices.GetVerbalizationSnippetsDictionary(target);
                        snippets            = (IVerbalizationSets <CoreVerbalizationSnippetType>)snippetsDictionary[typeof(CoreVerbalizationSnippetType)];
                        callbackWriter      = new VerbalizationCallbackWriter(snippets, writer, VerbalizationHelper.GetDocumentHeaderReplacementFields(store, snippets));
                    }
                    object              elem = elemIter;
                    ModelElement        mel  = elem as ModelElement;
                    PresentationElement pel;
                    if ((mel != null) &&
                        null != (pel = mel as PresentationElement))
                    {
                        IRedirectVerbalization shapeRedirect = pel as IRedirectVerbalization;
                        if (null == (shapeRedirect = pel as IRedirectVerbalization) ||
                            null == (elem = shapeRedirect.SurrogateVerbalizer as ModelElement))
                        {
                            elem = mel = pel.ModelElement;
                        }
                    }
                    if (elem != null &&
                        (mel == null || !mel.IsDeleted))
                    {
                        locallyVerbalized.Clear();
                        VerbalizationHelper.VerbalizeElement(
                            elem,
                            snippetsDictionary,
                            extensionVerbalizer,
                            options,
                            target,
                            alreadyVerbalized,
                            locallyVerbalized,
                            (showNegative ? VerbalizationSign.Negative : VerbalizationSign.Positive) | VerbalizationSign.AttemptOppositeSign,
                            callbackWriter,
                            true,
                            ref firstCallPending);
                    }
                }
            }
            if (!firstCallPending)
            {
                // Write footer
                callbackWriter.WriteDocumentFooter();
                // Clear cache
                alreadyVerbalized.Clear();
            }
        }
Exemple #22
0
		public PreferredPathTests(IORMToolServices services)
		{
			myServices = services;
			myTestServices = (IORMToolTestServices)services.ServiceProvider.GetService(typeof(IORMToolTestServices));
		}
		public PopulationTests(IORMToolServices services)
		{
			myServices = services;
			myTestServices = (IORMToolTestServices)services.ServiceProvider.GetService(typeof(IORMToolTestServices));
		}
Exemple #24
0
 /// <summary>
 /// Create a new store
 /// </summary>
 /// <param name="services">IORMToolServices to defer to</param>
 public ORMStore(IORMToolServices services)
 {
     myServices             = services;
     myModelingEventManager = new ModelingEventManagerImpl(this, (IORMToolTestServices)services);
 }
Exemple #25
0
		/// <summary>
		/// Run all tests for the given type that match the
		/// category filters specified for this suite
		/// </summary>
		/// <param name="testType">A type with a Test attribute</param>
		/// <param name="services">Services used to run the test. IORMToolTestServices can
		/// be retrieved from services.ServiceProvider.</param>
		/// <param name="suiteReport">The suite report callback</param>
		private void RunTests(Type testType, IORMToolServices services, IORMToolTestSuiteReport suiteReport)
		{
			IORMToolTestServices testServices = (IORMToolTestServices)services.ServiceProvider.GetService(typeof(IORMToolTestServices));
			object testTypeInstance = null;
			object[] methodParams = null;
			MethodInfo[] methods = testType.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly);
			int methodCount = methods.Length;
			for (int i = 0; i < methodCount; ++i)
			{
				MethodInfo method = methods[i];
				object[] testAttributes = method.GetCustomAttributes(typeof(ORMTestAttribute), false);
				Debug.Assert(testAttributes.Length < 2, "Single use attribute with inherit=false, should only pick up zero or one attributes");
				// Make sure that the method is flagged as a Test method that can be run per the current category settings
				if (testAttributes.Length == 0 || !CheckCategoryFilters((ORMTestAttribute)testAttributes[0]))
				{
					continue;
				}

				// Make sure we've instantiated the test class
				if (testTypeInstance == null)
				{
					ConstructorInfo constructor;
					if (null != (constructor = testType.GetConstructor(new Type[] { typeof(IORMToolServices) })))
					{
						testTypeInstance = constructor.Invoke(new object[] { services });
						methodParams = new object[1];
					}
					bool loadFailure = null == testTypeInstance;
					suiteReport.BeginTestClass(testType.Namespace, testType.Name, loadFailure);
					if (loadFailure)
					{
						return;
					}
				}

				ParameterInfo[] methodParamInfos = method.GetParameters();
				if (!(methodParamInfos.Length == 1 && typeof(Store).IsAssignableFrom(methodParamInfos[0].ParameterType)))
				{
					// The test method does not match the signature we need, it should
					// not have been marked with the Test attribute
					suiteReport.ReportTestResults(method.Name, ORMTestResult.FailBind, null);
				}
				else
				{
					Store store = null;
					try
					{
						// Prepare the test services for a new test
						testServices.OpenReport();

						// Populate a store. Automatically loads the starting
						// file from the test assembly if one is provided
						store = testServices.Load(method, null, null);

						// Run the method
						methodParams[0] = store;
						method.Invoke(testTypeInstance, methodParams);

						// Compare the current contents of the store with the
						// expected state
						testServices.Compare(store, method, null);
						testServices.LogValidationErrors(null);
					}
					finally
					{
						if (store != null)
						{
							((IDisposable)store).Dispose();
						}

						// Close the report and see if the report matches the expected results
						using (XmlReader reportReader = testServices.CloseReport(method))
						{
							string methodName = method.Name;
							string resourceName = string.Concat(testType.FullName, ".", methodName, ".Report.xml");
							Stream baselineStream = null;
							try
							{
								Assembly testAssembly = testType.Assembly;
								// Get the baseline that we're comparing to
								if (null != testAssembly.GetManifestResourceInfo(resourceName))
								{
									baselineStream = testAssembly.GetManifestResourceStream(resourceName);
								}
								if (baselineStream != null)
								{
									bool hasDiff = false;

									// See if the data is different.
									XmlDiff diff = DiffEngine;
									XmlReaderSettings readerSettings = DetachableReaderSettings;
									XmlWriterSettings writerSettings = DetachableWriterSettings;
									using (MemoryStream diffStream = new MemoryStream())
									{
										using (XmlReader baselineReader = XmlReader.Create(baselineStream, readerSettings))
										{
											using (XmlWriter diffWriter = XmlWriter.Create(diffStream, writerSettings))
											{
												hasDiff = !diff.Compare(baselineReader, reportReader, diffWriter);
											}
										}
										if (hasDiff)
										{
											// Record the diffgram in the suite report
											diffStream.Seek(0, SeekOrigin.Begin);
											using (XmlReader diffReader = XmlTextReader.Create(diffStream, readerSettings))
											{
												suiteReport.ReportTestResults(methodName, ORMTestResult.FailReportDiffgram, diffReader);
											}
										}
										else
										{
											// Record a passing result
											suiteReport.ReportTestResults(methodName, ORMTestResult.Pass, null);
										}
									}
								}
								else
								{
									// Record the full report, we have no baseline to compare against
									suiteReport.ReportTestResults(methodName, ORMTestResult.FailReportBaseline, reportReader);
								}
							}
							finally
							{
								if (baselineStream != null)
								{
									((IDisposable)baselineStream).Dispose();
								}
							}
						}
					}
				}
			}
		}
Exemple #26
0
		public FCExactlyOneTests(IORMToolServices services)
		{
			myServices = services;
			myTestServices = (IORMToolTestServices)services.ServiceProvider.GetService(typeof(IORMToolTestServices));
		}
Exemple #27
0
        private void DrawDiagram(bool refresh, ModelElement element, IHierarchyContextEnabled hierarchyElement)
        {
            bool storeChange = false;
            if (hierarchyElement == null && (myDiagram == null || (element != null && (storeChange = (element.Store != myDiagram.Store)))))
            {
                ModelElement selectedElement = element;
                element = myCurrentlySelectedObject as ModelElement;
                if (element != null && ((element.IsDeleted || element.Store == null) || storeChange))
                {
                    myCurrentlySelectedObject = null;
                    mySelectedPartitionId = null;
                    RemoveDiagram();
                }
                hierarchyElement = myCurrentlySelectedObject;
                if (hierarchyElement == null && selectedElement != null && !selectedElement.IsDeleted && selectedElement.Store != null)
                {
                    ORMModel attachToModel = selectedElement as ORMModel;
                    if (attachToModel != null)
                    {
                        EnsureDiagram(attachToModel);
                    }
                }
            }
            else if (hierarchyElement == myCurrentlySelectedObject && hierarchyElement != null && !refresh && (myDiagram != null && myDiagram.HasChildren))
            {
                return;
            }
            if (hierarchyElement == null)
            {
                return;
            }
            myCurrentlySelectedObject = hierarchyElement;
            mySelectedPartitionId = ((ModelElement)hierarchyElement).Partition.AlternateId;
            ORMModel model = hierarchyElement.Model;
            if (model == null)
            {
                return;
            }
            this.EnsureDiagram(model);
            if (myDiagram == null)
            {
                return;
            }
            Store store = element.Store;
            IORMToolServices toolServices = (IORMToolServices)store;
            if (!toolServices.CanAddTransaction)
            {
                return;
            }
            using (Transaction t = store.TransactionManager.BeginTransaction("Draw Context Diagram"))
            {
                myDiagram.NestedChildShapes.Clear();
                myDiagram.AutoPopulateShapes = true;

                PlaceObject(hierarchyElement);
                LinkedElementCollection<ShapeElement> collection = myDiagram.NestedChildShapes;
                LayoutManager bl = new LayoutManager(myDiagram, toolServices.GetLayoutEngine(typeof(ORMRadialLayoutEngine)));
                foreach (ShapeElement shape in collection)
                {
                    bl.AddShape(shape, false);
                }
                bl.Layout(true);

                myDiagram.AutoPopulateShapes = false;
                if (t.HasPendingChanges)
                {
                    t.Commit();
                }
            }
            return;
        }
Exemple #28
0
		public NotWellModeledTests(IORMToolServices services)
		{
			myServices = services;
			myTestServices = (IORMToolTestServices)services.ServiceProvider.GetService(typeof(IORMToolTestServices));
		}
 public NotWellModeledTests(IORMToolServices services)
 {
     myServices     = services;
     myTestServices = (IORMToolTestServices)services.ServiceProvider.GetService(typeof(IORMToolTestServices));
 }