Ejemplo n.º 1
0
        public void WhenAddingInterceptor_ThenCanInterceptIdeOperation()
        {
            this.OpenSolution("SampleSolution\\SampleSolution.sln");

            var interceptor = new Mock <ICommandInterceptor>();
            var commands    = this.ServiceLocator.GetInstance <ICommandManager>();

            commands.AddInterceptor(interceptor.Object, new CommandInterceptorAttribute(
                                        Constants.PackageGuid, "{5efc7975-14bc-11cf-9b2b-00aa00573819}", 0x372));

            var mre    = new ManualResetEventSlim();
            var events = this.Dte.Events.BuildEvents;

            EnvDTE._dispBuildEvents_OnBuildDoneEventHandler done = (scope, action) => mre.Set();
            events.OnBuildDone += done;

            this.Dte.ExecuteCommand("Build.BuildSolution");

            mre.Wait();

            Assert.True(BuildCommandInterceptor.BeforeExecuteCalled);
            Assert.True(BuildCommandInterceptor.AfterExecuteCalled);

            interceptor.Verify(x => x.BeforeExecute());
            interceptor.Verify(x => x.AfterExecute());
        }
        public void WhenSolutionIsOpened_ThenCanGetProjectReferencedAssemblies()
        {
            var slnFile = base.OpenSolution("SampleSolution\\SampleSolution.sln");

            var proj = XDocument.Load(GetFullPath(Path.GetDirectoryName(slnFile), "ClassLibrary\\ClassLibrary.csproj"));
            var refs = proj.Descendants(XName.Get("{http://schemas.microsoft.com/developer/msbuild/2003}Reference"))
                       .Select(e => e.Attribute("Include").Value)
                       .ToList();

            var explorer = base.ServiceLocator.GetInstance <ISolutionExplorer>();

            var lib = new ITreeNode[] { explorer.Solution }.Traverse(TraverseKind.BreadthFirst, node => node.Nodes)
            .OfType <IProjectNode>()
            .FirstOrDefault(node => node.DisplayName == "ClassLibrary");

            Assert.NotNull(lib);

            var asm = lib.GetReferencedAssemblies().ToList();

            //asm.ForEach(a => Console.WriteLine(a.FullName));

            // 7 actual references + mscorlib which is always added automatically.
            Assert.Equal(1 + refs.Count, asm.Count);
            Assert.True(refs.All(r => asm.Any(a => a.GetName().Name == r)));
        }
Ejemplo n.º 3
0
        public void WhenCreated_ThenEvaluatesToTrue()
        {
            var value   = new object();
            var binding = FixedBinding.Create(value);

            Assert.True(binding.Evaluate());
        }
Ejemplo n.º 4
0
            public void WhenGettingCustomizableExtensions_ThenGotItemsMarkedAsIsCustomizableOrInDocumentsFolder()
            {
                var contents = this.target.GetCustomizableExtensions();

                Assert.Equal(2, contents.Count());
                Assert.True(contents.Any(c => c.RelativePath.Equals(@"Documentation\Other.docx", StringComparison.OrdinalIgnoreCase)));
                Assert.True(contents.Any(c => c.RelativePath.Equals(@"Sample.file", StringComparison.OrdinalIgnoreCase)));
            }
        public void WhenCreatingAnPatternElementSchema_ThenInjectsExtensionElements()
        {
            ElementSchema element = null;

            this.store.TransactionManager.DoWithinTransaction(() =>
            {
                element = this.store.ElementFactory.CreateElement <ElementSchema>();
            });

            Assert.True(element.GetExtensions <IGuidanceExtension>().Any());
            Assert.True(element.GetExtensions <IArtifactExtension>().Any());
        }
Ejemplo n.º 6
0
        public void WhenSolutionOpened_ThenRaisesOpenedEvent()
        {
            var explorer = this.ServiceLocator.GetInstance <ISolutionExplorer>();

            var called = false;

            explorer.Solution.SolutionOpened += (sender, args) => called = true;

            explorer.Solution.Open(GetFullPath(TestContext.TestDeploymentDir, "SampleSolution\\SampleSolution.sln"));

            Assert.True(called);
        }
Ejemplo n.º 7
0
        public void WhenRetrievingExportedMultipleComponents_ThenSucceeds()
        {
            var devEnv = DevEnv.Get(this.ServiceProvider);
            var result = devEnv.ServiceLocator.GetAllInstances <ICompletionSourceProvider>().ToList();

            Assert.True(result.Any());
        }
Ejemplo n.º 8
0
        public void ReferenceLinkIsAdded()
        {
            var uriProvider = VsIdeTestHostContext.ServiceProvider.GetService <IUriReferenceService>();
            var project     = solution.Items.OfType <IProject>().First().Id;

            Assert.True(this.pattern.References.Any(r => r.Value == string.Format("solution://{0}/", project)));
        }
        private static void AssertDictionaryValue(IDictionary <string, string> dictionary, string propertyName, string propertyValue)
        {
            Assert.True(dictionary.Keys.Contains(propertyName), string.Format(CultureInfo.CurrentCulture, "{0} key not found in dictionary.", propertyName));
            Assert.Equal(propertyValue, dictionary[propertyName]);

            //Remove item from dictionary
            dictionary.Remove(propertyName);
        }
Ejemplo n.º 10
0
        public void WhenSelectingProjects_ThenSelectionReturnsOnlyProjectNodes()
        {
            var projects = explorer.Solution.Nodes.Traverse(TraverseKind.DepthFirst, node => node.Nodes)
                           .OfType <IProjectNode>()
                           .ToList();

            projects.First().Select(false);
            projects.Skip(1).ToList().ForEach(project => project.Select(true));

            Assert.True(projects.TrueForAll(project => project.IsSelected));

            var selection = explorer.SelectedNodes.ToList();

            Assert.Equal(projects.Count, selection.Count);
            Assert.True(selection.TrueForAll(node => node is IProjectNode));
            Assert.True(projects.TrueForAll(project => selection.OfType <IProjectNode>().Any(sel => sel.PhysicalPath == project.PhysicalPath)));
        }
Ejemplo n.º 11
0
        public void WhenEnvironmentInitialized_ThenRaisesInitializedEvent()
        {
            var devenv = ServiceLocator.GetInstance <IDevEnv>();

            var called = false;

            devenv.Initialized += (sender, args) => called = true;

            var maxWait = DateTime.Now.AddSeconds(5);

            while (!devenv.IsInitialized && DateTime.Now < maxWait)
            {
                Thread.Sleep(50);
            }

            Assert.True(devenv.IsInitialized);
            Assert.True(called);
        }
Ejemplo n.º 12
0
        public void WhenCreatingUri_ThenCanRoundTrip()
        {
            var service = VsIdeTestHostContext.ServiceProvider.GetService <IUriReferenceService>();

            Assert.NotNull(service);
            var installed = VsIdeTestHostContext.ServiceProvider.GetService <IExtensionManager>()
                            .GetInstalledExtensions().First(e => e.Header.Name.Contains("NuPattern"));

            Assert.True(service.CanCreateUri(installed));
            Assert.True(service.CanCreateUri <IExtension>(installed));

            var uri       = service.CreateUri(installed);
            var resolved  = service.ResolveUri <IExtension>(uri);
            var resolved2 = service.ResolveUri <IInstalledExtension>(uri);

            Assert.Equal(installed.Header.Identifier, resolved.Header.Identifier);
            Assert.Equal(installed.Header.Identifier, resolved2.Header.Identifier);
        }
Ejemplo n.º 13
0
        public void WhenRetrievingPropertyNames_ThenFindsDteAndMsBuild()
        {
            var explorer = base.ServiceLocator.GetInstance <ISolutionExplorer>();

            this.OpenSolution("SampleSolution\\SampleSolution.sln");

            var project = explorer.Solution.Nodes.Traverse(TraverseKind.DepthFirst, node => node.Nodes)
                          .OfType <ProjectNode>()
                          .First(node => node.DisplayName == "ClassLibrary");

            var names = ((DynamicObject)project.Properties).GetDynamicMemberNames().ToList();

            Console.WriteLine(string.Join(Environment.NewLine, names));

            Assert.True(names.Contains("OfflineURL"));
            Assert.True(names.Contains("StartupObject"));
            Assert.True(names.Contains("BuildingInsideVisualStudio"));
        }
Ejemplo n.º 14
0
        public void WhenTypeIdChanged_ThenBindingRaisesChanged()
        {
            var binding = new BindingSettings();
            var raised  = false;

            binding.PropertyChanged += (sender, args) => raised = true;

            binding.TypeId = "foo";

            Assert.True(raised);
        }
            public void WhenGettingUniqueNameWithExistentBaseName_ThenActualNameIsReturned()
            {
                var view1 = this.product.Create <ViewSchema>();
                var view2 = this.product.Create <ViewSchema>();

                view1.Name = "Foo";
                view2.Name = "Foo1";

                Assert.True(view1.GetUniqueName("Foo").Equals("Foo2"));
            }
Ejemplo n.º 16
0
        public void WhenDisposed_ThenInvokesAction()
        {
            var called = false;

            using (new AnonymousDisposable(() => called = true))
            {
            }

            Assert.True(called);
        }
        public void WhenCreatingAProduct_ThenSetsArtifactLinks()
        {
            IProduct product = null;

            UIThreadInvoker.Invoke((Action)(() =>
            {
                DoActionWithWait(4000, () => product = this.manager.CreateProduct(toolkit, "Foo"));
            }));

            Assert.NotNull(product);
            Assert.NotNull(product.TryGetReference(ReferenceKindConstants.SolutionItem));

            Assert.True(product.Views.Count() > 0);
            var view = product.Views.ElementAt(0);

            Assert.True(view.Elements.Count() > 0);
            var element = view.Elements.ElementAt(0);

            Assert.NotNull(element.TryGetReference(ReferenceKindConstants.SolutionItem));
        }
Ejemplo n.º 18
0
        public void WhenShellInitializeRaised_ThenShellIsInitializedIsTrue()
        {
            while (!this.initializeRaised &&
                   /* It might be too late for the test runner to catch the shell event */
                   !this.shellEvents.IsInitialized)
            {
                Thread.Sleep(100);
            }

            Assert.True(this.shellEvents.IsInitialized);
        }
Ejemplo n.º 19
0
        public void WhenCreateUriWithSolutionProjectItemWithoutItemGuid_TheReturnsResilientUri()
        {
            var result         = this.service.CreateUri(this.solution.Find(@"TopSolutionFolder\SecSolutionFolder\TrdSolutionFolder\TrdProject\TopProjectItem.cs").FirstOrDefault());
            var itemGuidString = result.ToString().ToLower(CultureInfo.InvariantCulture).Replace("solution://b13b408f-4969-48c0-85c2-227461953fa7/", string.Empty);

            itemGuidString = itemGuidString.Trim(SolutionUriProvider.UriPathDelimiter);

            Guid itemGuid;

            Assert.True(Guid.TryParse(itemGuidString, out itemGuid));
        }
Ejemplo n.º 20
0
        public void WhenEventArgsMatchesPropertyName_ThenEvaluateReturnsTrue()
        {
            var mockEvent = new Mock <IEvent <PropertyChangedEventArgs> >();

            mockEvent.Setup(x => x.EventArgs).Returns(new PropertyChangedEventArgs("Foo"));
            this.condition.Event        = mockEvent.Object;
            this.condition.PropertyName = "Foo";

            var result = this.condition.Evaluate();

            Assert.True(result);
        }
        public void WhenContextInitializerNotNull_ThenInvokesItOnEvaluation()
        {
            var settings = new PropertyBindingSettings {
                ValueProvider = new ValueProviderBindingSettings {
                }
            };
            bool invoked = false;

            settings.Evaluate(this.bindingFactory, this.tracer, c => invoked = true);

            Assert.True(invoked);
        }
Ejemplo n.º 22
0
        public void WhenEventsAreRaised_ThenStoreIsInATransaction()
        {
            var           store        = new DslTestStore <ProductStateStoreDomainModel>();
            IProductState productState = null;

            store.TransactionManager.DoWithinTransaction(() =>
            {
                productState = store.ElementFactory.CreateElement <ProductState>();
            });

            IProduct product       = null;
            bool     inTransaction = false;

            productState.ElementInstantiated += (sender, args) => inTransaction = store.Store.TransactionActive;

            store.TransactionManager.DoWithinTransaction(() =>
            {
                product = productState.CreateProduct();
            });

            Assert.True(inTransaction);
        }
Ejemplo n.º 23
0
        internal static void VerifyDocumentContent(string directoryPath, string fileName, string[] matchExpressions)
        {
            string fileText = File.ReadAllText(Path.Combine(directoryPath, fileName));

            foreach (var match in matchExpressions)
            {
                var regex = new Regex(match, RegexOptions.IgnoreCase);
                Assert.True(regex.IsMatch(fileText));
            }
        }
Ejemplo n.º 24
0
        public void when_writing_to_pane_writer_then_writes_to_output_pane()
        {
            var manager = ServiceLocator.GetInstance <IOutputWindowManager>();

            var writer = manager.GetPane(Guid.Empty, "test");

            writer.Write("foo");
            var pane = Dte.ToolWindows.OutputWindow.OutputWindowPanes.Item("test");

            Assert.True(SpinWait.SpinUntil(() =>
            {
                var start = pane.TextDocument.StartPoint.CreateEditPoint();
                var text  = start.GetText(pane.TextDocument.EndPoint);
                return(text == "foo");
            }, 3000), "Expected text was not written to the output window within the specified timeout.");
        }
Ejemplo n.º 25
0
            public void WhenBuildingSolution_ThenBuildStartedRaised()
            {
                var called = false;

                this.buildStarted.Subscribe(e => called = true);

                VsIdeTestHostContext.Dte.Solution.Open("Library.IntegrationTests.Content\\ClassLibrary\\ClassLibrary.sln");
                VsIdeTestHostContext.Dte.Solution.SolutionBuild.Build(true);

                while (VsIdeTestHostContext.Dte.Solution.SolutionBuild.BuildState != EnvDTE.vsBuildState.vsBuildStateDone)
                {
                    Thread.Sleep(10);
                }

                Assert.True(called);
            }
Ejemplo n.º 26
0
        public void WhenRetrievingSettings_ThenSavesDefaultTracingLevelValue()
        {
            var devEnv = DevEnv.Get(Microsoft.VisualStudio.Shell.ServiceProvider.GlobalProvider);

            var settings = devEnv.ServiceLocator.GetInstance <ClideSettings>();

            Assert.NotNull(settings);

            var defaultValue = Reflect <ClideSettings> .GetProperty(x => x.TracingLevel)
                               .GetCustomAttributes(typeof(DefaultValueAttribute), true)
                               .OfType <DefaultValueAttribute>()
                               .Select(d => (SourceLevels)d.Value)
                               .First();

            var collection = SettingsManager.GetSettingsCollectionName(typeof(ClideSettings));

            Assert.True(settingsStore.CollectionExists(collection));
            Assert.Equal(defaultValue, (SourceLevels)Enum.Parse(typeof(SourceLevels), settingsStore.GetString(collection, Reflect <ClideSettings> .GetPropertyName(x => x.TracingLevel), "-1")));
        }
Ejemplo n.º 27
0
        public void WhenGettingLogicalPathOfItem_ThenSucceedsForSharedProject()
        {
            using (AutoCloseDialog("Developer License"))
            {
                base.OpenSolution("SampleShared\\SampleShared.sln");
            }

            var explorer = base.ServiceLocator.GetInstance <ISolutionExplorer>();

            var node = explorer.Solution.Traverse().OfType <IItemNode>().First(i => i.DisplayName == "Foo.cs");

            Assert.NotNull(node);

            Assert.Equal(node.OwningProject, node.OwningProject, "Retrieving owning project twice didn't return the same project.");
            Assert.Equal(node.OwningProject, node.OwningProject, "Retrieving owning project twice didn't return the same project.");

            var project   = node.OwningProject;
            var ancestors = node.Ancestors().ToList();

            Assert.True(ancestors.Contains(project), "Ancestors doesn't contain owning project.");

            Assert.Equal("Folder\\Foo.cs", node.LogicalPath);
        }
Ejemplo n.º 28
0
        public void WhenCreatingReference_ThenUsesAdapter()
        {
            var stateFile = this.solution.Find <IItem>(item => item.Name.EndsWith(StoreConstants.RuntimeStoreExtension)).First();

            var manager = this.modelBus.FindAdapterManagers(new object[] { stateFile.PhysicalPath }).FirstOrDefault();

            Assert.NotNull(manager);

            Assert.True(manager.CanCreateReference(new object[] { stateFile.PhysicalPath }));

            var mar = new ModelingAdapterReference(null, null, stateFile.PhysicalPath);
            var mbr = new ModelBusReference(this.modelBus, Adapter.AdapterId,
                                            Path.GetFileNameWithoutExtension(stateFile.Name),
                                            mar);

            using (var adapter = this.modelBus.CreateAdapter(mbr, VsIdeTestHostContext.ServiceProvider))
            {
                var withRoot   = adapter as IModelingAdapterWithRootedModel;
                var state      = ((IProductState)withRoot.ModelRoot).Products.First();
                var elementRef = adapter.GetElementReference(state);

                Assert.NotNull(elementRef);
            }
        }
Ejemplo n.º 29
0
 public void WhenTryingToConvertFromString_ThenReturnsTrue()
 {
     Assert.True(this.converter.CanConvertFrom(typeof(string)));
 }
        public void WhenTypeAttributeIsFound_ThenElementPropertyIsGenerated()
        {
            var processor = new ModelElementDirectiveProcessor();

            processor.StartProcessingRun(provider, null, new CompilerErrorCollection());
            processor.ProcessDirective("ModelElement", directiveAttributes);
            var result = processor.GetClassCodeForProcessingRun();

            Assert.NotNull(result);
            Assert.True(result.Contains("public new Foo.Bar Element"));
            Assert.True(result.Contains("return ((Foo.Bar)(base.Element));"));
        }