Пример #1
0
        public static void Verify(Project view, Project real, ValidationContext context = null)
        {
            if (view == null && real == null)
            {
                return;
            }
            var pair = new ProjectPair(view, real);

            Verify(pair, context);
        }
Пример #2
0
        public void ProjectPropertyModify()
        {
            var pcLocal  = this.StdGroup.Local;
            var pcRemote = this.StdGroup.Remote[0];

            var proj1Path = this.StdGroup.StdProjectFiles[0];
            var realProj  = pcRemote.LoadProject(proj1Path);

            pcLocal.Importing = true;
            var viewProj = pcLocal.Collection.GetLoadedProjects(proj1Path).FirstOrDefault();

            ProjectPair pair = new ProjectPair(viewProj, realProj);

            ViewValidation.Verify(pair);

            pair.ValidatePropertyValue("fooProp", string.Empty);

            var fooView = pair.SetPropertyWithVerify(ObjectType.View, "fooProp", "fooValue$(xxx)");
            var fooReal = pair.Real.GetProperty("fooProp");

            Assert.Equal("fooValue", fooView.EvaluatedValue);
            pair.Real.SetGlobalProperty("xxx", "XXX");
            Assert.Equal("fooValue", fooView.EvaluatedValue);
            pair.Real.ReevaluateIfNecessary();
            // note msbuild create a new property objects on reevaluation.
            Assert.Equal("fooValue", fooView.EvaluatedValue);
            Assert.Equal("fooValue", fooReal.EvaluatedValue);
            var fooRealNew = pair.Real.GetProperty("fooProp");
            var fooViewNew = pair.View.GetProperty("fooProp");

            Assert.NotSame(fooReal, fooRealNew);
            Assert.NotSame(fooView, fooViewNew);

            Assert.Equal("fooValueXXX", fooViewNew.EvaluatedValue);

            fooViewNew.UnevaluatedValue = "fooValueChanged$(xxx)";
            Assert.Equal("fooValueChanged$(xxx)", fooRealNew.UnevaluatedValue);
            // but when changing the Unevaluate via ProjectProp element it does update the live object.
            Assert.Equal("fooValueChangedXXX", fooViewNew.EvaluatedValue);
            Assert.Equal("fooValueChangedXXX", fooRealNew.EvaluatedValue);

            ViewValidation.Verify(pair);

            // note this should work even though the fooView is recycled.
            Assert.True(pair.View.RemoveProperty(fooView));
            Assert.Null(pair.View.GetProperty("fooProp"));
        }
Пример #3
0
            public void ResetBeforeTests()
            {
                this.Clear();
                this.Local.Importing = true;
                {
                    var targetView = this.Local.GetLoadedProjects(this.TargetBigPath).FirstOrDefault();
                    Assert.NotNull(targetView);
                    var targetPair = new ProjectPair(targetView, this.TargetBig);
                    this.TargetXmlPair = new ProjectXmlPair(targetPair);
                }

                {
                    var guestView = this.Local.GetLoadedProjects(this.GuestBigPath).FirstOrDefault();
                    Assert.NotNull(guestView);
                    var guestPair = new ProjectPair(guestView, this.GuestBig);
                    this.GuestXmlPair = new ProjectXmlPair(guestPair);
                }
            }
Пример #4
0
        public void ProjectGlobalPropertyModify()
        {
            var pcLocal  = this.StdGroup.Local;
            var pcRemote = this.StdGroup.Remote[0];

            var proj1Path = this.StdGroup.StdProjectFiles[0];
            var realProj  = pcRemote.LoadProject(proj1Path);

            pcLocal.Importing = true;
            var viewProj = pcLocal.Collection.GetLoadedProjects(proj1Path).FirstOrDefault();

            ProjectPair pair = new ProjectPair(viewProj, realProj);

            ViewValidation.Verify(pair);

            Assert.False(pair.View.GlobalProperties.ContainsKey("gp1"));
            Assert.False(pair.View.GlobalProperties.ContainsKey("Configuration"));
            // at this point Configuration is not set and gp1 is not set.
            pair.ValidatePropertyValue("gpt1", "NotFoo");

            pair.View.SetGlobalProperty("gp1", "GP1V");
            Assert.True(pair.View.GlobalProperties.ContainsKey("gp1"));
            Assert.True(pair.Real.GlobalProperties.ContainsKey("gp1"));

            // not evaluated yet.
            pair.ValidatePropertyValue("gpt1", "NotFoo");
            pair.View.ReevaluateIfNecessary();
            pair.ValidatePropertyValue("gpt1", "NotFooGP1V");


            pair.Real.SetGlobalProperty("Configuration", "Foo");
            Assert.True(pair.View.GlobalProperties.ContainsKey("Configuration"));
            pair.ValidatePropertyValue("gpt1", "NotFooGP1V");
            pair.View.ReevaluateIfNecessary();
            pair.ValidatePropertyValue("gpt1", "FooGP1V");
        }
Пример #5
0
 public ProjectXmlPair(ProjectPair pair) : base(null, pair.View.Xml, pair.Real.Xml)
 {
     this.Project = pair; this.PRE = this;
 }
Пример #6
0
 public ValidationContext(ProjectPair pair)
 {
     this.Pair = pair;
 }
Пример #7
0
        public static void Verify(ProjectPair pair, ValidationContext context = null)
        {
            if (pair == null)
            {
                return;
            }
            var real = pair.Real;
            var view = pair.View;

            context      = context ?? new ValidationContext();
            context.Pair = pair;


            Verify(view.Xml, real.Xml);

            Verify(view.ItemsIgnoringCondition, real.ItemsIgnoringCondition, Verify, context);
            Verify(view.Items, real.Items, Verify, context);
            Verify(view.ItemDefinitions, real.ItemDefinitions, Verify, context);
            Verify(view.ConditionedProperties, real.ConditionedProperties, Verify, context);
            Verify(view.Properties, real.Properties, Verify, context);
            Verify(view.GlobalProperties, real.GlobalProperties, (a, b, p) => Assert.Equal(b, a), context);
            Verify(view.Imports, real.Imports, Verify, context);
            Verify(view.ItemTypes, real.ItemTypes, (a, b, p) => Assert.Equal(b, a), context);

            // this can only be used if project is loaded with ProjectLoadSettings.RecordDuplicateButNotCircularImports
            // or it throws otherwise. Slightly odd and inconvenient API design, but thats how it is.
            bool isImportsIncludingDuplicatesAvailable = false;

            try
            {
                var testLoadSettings = real.ImportsIncludingDuplicates;
                isImportsIncludingDuplicatesAvailable = true;
            }
            catch { }

            if (isImportsIncludingDuplicatesAvailable)
            {
                Verify(view.ImportsIncludingDuplicates, real.ImportsIncludingDuplicates, Verify, context);
            }


            Verify(view.AllEvaluatedProperties, real.AllEvaluatedProperties, Verify, context);
            Verify(view.AllEvaluatedItemDefinitionMetadata, real.AllEvaluatedItemDefinitionMetadata, Verify, context);
            Verify(view.AllEvaluatedItems, real.AllEvaluatedItems, Verify, context);

            Assert.NotSame(view.ProjectCollection, real.ProjectCollection);
            Assert.Equal(real.ToolsVersion, view.ToolsVersion);
            Assert.Equal(real.SubToolsetVersion, view.SubToolsetVersion);
            Assert.Equal(real.DirectoryPath, view.DirectoryPath);
            Assert.Equal(real.FullPath, view.FullPath);
            Assert.Equal(real.SkipEvaluation, view.SkipEvaluation);
            Assert.Equal(real.ThrowInsteadOfSplittingItemElement, view.ThrowInsteadOfSplittingItemElement);
            Assert.Equal(real.IsDirty, view.IsDirty);
            Assert.Equal(real.DisableMarkDirty, view.DisableMarkDirty);
            Assert.Equal(real.IsBuildEnabled, view.IsBuildEnabled);

            VerifySameLocation(real.ProjectFileLocation, view.ProjectFileLocation, context);

            // we currently dont support "Execution" remoting.
            // Verify(view.Targets, real.Targets, Verify, view, real);
            Assert.Equal(real.EvaluationCounter, view.EvaluationCounter);
            Assert.Equal(real.LastEvaluationId, view.LastEvaluationId);
        }
Пример #8
0
        public void ProjectItemModify()
        {
            var pcLocal  = this.StdGroup.Local;
            var pcRemote = this.StdGroup.Remote[0];

            var proj1Path = this.StdGroup.StdProjectFiles[0];
            var realProj  = pcRemote.LoadProject(proj1Path);

            pcLocal.Importing = true;
            var viewProj = pcLocal.Collection.GetLoadedProjects(proj1Path).FirstOrDefault();

            ProjectPair pair = new ProjectPair(viewProj, realProj);

            ViewValidation.Verify(pair);


            List <KeyValuePair <string, string> > testMedatada = new List <KeyValuePair <string, string> >()
            {
                new KeyValuePair <string, string>("a", "aValue"),
                new KeyValuePair <string, string>("b", "bValue"),
            };

            /// test AddItems

            // add a new files in the view, ensure it is added correctly and also the real object will immediately reflect that add as well
            Assert.Null(pair.GetSingleItemWithVerify(ObjectType.View, "foo.cpp"));
            var fooView = pair.AddSingleItemWithVerify(ObjectType.View, "cpp", "foo.cpp");

            Assert.Null(pair.GetSingleItemWithVerify(ObjectType.View, "fooFast.cpp"));
            var fooViewFast = pair.AddSingleItemFastWithVerify(ObjectType.View, "cpp", "fooFast.cpp");

            Assert.Null(pair.GetSingleItemWithVerify(ObjectType.View, "fooWithMetadata.cpp"));
            var fooWithMetadataView = pair.AddSingleItemWithVerify(ObjectType.View, "cpp", "fooWithMetadata.cpp", testMedatada);

            Assert.Null(pair.GetSingleItemWithVerify(ObjectType.View, "fooWithMetadataFast.cpp"));
            var fooWithMetadataViewFast = pair.AddSingleItemWithVerify(ObjectType.View, "cpp", "fooWithMetadataFast.cpp", testMedatada);

            // add a new files in the real, ensure it is added correctly and also the view object will immediately reflect that add as well
            Assert.Null(pair.GetSingleItemWithVerify(ObjectType.Real, "bar.cpp"));
            var barReal = pair.AddSingleItemWithVerify(ObjectType.Real, "cpp", "bar.cpp");

            Assert.Null(pair.GetSingleItemWithVerify(ObjectType.Real, "barFast.cpp"));
            var barRealFast = pair.AddSingleItemFastWithVerify(ObjectType.Real, "cpp", "barFast.cpp");

            Assert.Null(pair.GetSingleItemWithVerify(ObjectType.Real, "barWithMetadata.cpp"));
            var barWithMetadataReal = pair.AddSingleItemWithVerify(ObjectType.Real, "cpp", "barWithMetadata.cpp", testMedatada);

            Assert.Null(pair.GetSingleItemWithVerify(ObjectType.Real, "barWithMetadataFast.cpp"));
            var barWithMetadataRealFast = pair.AddSingleItemWithVerify(ObjectType.Real, "cpp", "barWithMetadataFast.cpp", testMedatada);


            ViewValidation.Verify(pair);

            // Test remove items.

            var validationContext = new ValidationContext(pair);
            // remove single from view
            {
                Assert.NotNull(pair.GetSingleItemWithVerify(ObjectType.View, "barWithMetadataFast.cpp"));
                var barWithMetadataViewFast = pair.GetSingleItemWithVerify(ObjectType.View, "barWithMetadataFast.cpp");
                Assert.NotNull(barWithMetadataViewFast);

                ViewValidation.Verify(barWithMetadataViewFast, barWithMetadataRealFast, validationContext);
                Assert.Throws <ArgumentException>(() =>
                {
                    pair.Real.RemoveItem(barWithMetadataViewFast);
                });

                pair.View.RemoveItem(barWithMetadataViewFast);
                Assert.Null(pair.GetSingleItemWithVerify(ObjectType.View, "barWithMetadataFast.cpp"));
            }

            // remove multiple from view
            {
                Assert.NotNull(pair.GetSingleItemWithVerify(ObjectType.View, "fooWithMetadata.cpp"));
                var barWithMetadataView = pair.GetSingleItemWithVerify(ObjectType.View, "barWithMetadata.cpp");
                Assert.NotNull(barWithMetadataView);
                ViewValidation.Verify(barWithMetadataView, barWithMetadataReal, validationContext);
                var toRemoveView = new List <ProjectItem>()
                {
                    barWithMetadataView, fooWithMetadataView
                };

                Assert.Throws <ArgumentException>(() =>
                {
                    pair.Real.RemoveItems(toRemoveView);
                });

                pair.View.RemoveItems(toRemoveView);
                Assert.Null(pair.GetSingleItemWithVerify(ObjectType.View, "fooWithMetadata.cpp"));
                Assert.Null(pair.GetSingleItemWithVerify(ObjectType.View, "barWithMetadata.cpp"));
            }


            // remove single from real
            {
                Assert.NotNull(pair.GetSingleItemWithVerify(ObjectType.Real, "fooWithMetadataFast.cpp"));
                var fooWithMetadataRealFast = pair.GetSingleItemWithVerify(ObjectType.Real, "fooWithMetadataFast.cpp");
                Assert.NotNull(fooWithMetadataRealFast);
                ViewValidation.Verify(fooWithMetadataViewFast, fooWithMetadataRealFast, validationContext);

                // Note in reality we do not guarantee that the Export provider will re-throw exactly the same exception.
                // (some exception can be hard to marshal) Current mock does in fact forward exact exception.)
                Assert.Throws <ArgumentException>(() =>
                {
                    pair.View.RemoveItem(fooWithMetadataRealFast);
                });


                pair.Real.RemoveItem(fooWithMetadataRealFast);
                Assert.Null(pair.GetSingleItemWithVerify(ObjectType.Real, "fooWithMetadataFast.cpp"));
            }

            // remove multiple from real
            {
                Assert.NotNull(pair.GetSingleItemWithVerify(ObjectType.Real, "barFast.cpp"));
                var fooRealFast = pair.GetSingleItemWithVerify(ObjectType.Real, "fooFast.cpp");
                Assert.NotNull(fooRealFast);
                ViewValidation.Verify(fooViewFast, fooRealFast, validationContext);
                var toRemoveReal = new List <ProjectItem>()
                {
                    fooRealFast, barRealFast
                };

                Assert.Throws <ArgumentException>(() =>
                {
                    pair.View.RemoveItems(toRemoveReal);
                });

                pair.Real.RemoveItems(toRemoveReal);
                Assert.Null(pair.GetSingleItemWithVerify(ObjectType.Real, "fooFast.cpp"));
                Assert.Null(pair.GetSingleItemWithVerify(ObjectType.Real, "barFast.cpp"));
            }


            // Check metadata modify
            var fooReal = pair.GetSingleItemWithVerify(ObjectType.Real, "foo.cpp");

            ViewValidation.Verify(fooView, fooReal, validationContext);

            Assert.False(fooView.HasMetadata("xx"));
            fooView.SetMetadataValue("xx", "xxValue");
            Assert.True(fooView.HasMetadata("xx"));
            Assert.Equal("xxValue", fooView.GetMetadataValue("xx"));
            ViewValidation.Verify(fooView, fooReal, validationContext);


            Assert.False(fooView.RemoveMetadata("xxNone"));
            Assert.True(fooView.RemoveMetadata("xx"));
            Assert.False(fooView.HasMetadata("xx"));

            ViewValidation.Verify(fooView, fooReal, validationContext);
            // now check metadata modify via real also affect view.

            Assert.False(fooView.HasMetadata("xxReal"));
            fooReal.SetMetadataValue("xxReal", "xxRealValue");
            Assert.True(fooView.HasMetadata("xxReal"));
            Assert.Equal("xxRealValue", fooView.GetMetadataValue("xxReal"));
            ViewValidation.Verify(fooView, fooReal, validationContext);

            Assert.True(fooReal.RemoveMetadata("xxReal"));
            Assert.False(fooView.HasMetadata("xxReal"));

            ViewValidation.Verify(fooView, fooReal, validationContext);

            // TODO: test the boolean form (low value for linking really).

            // ItemType set.
            Assert.Equal("cpp", fooView.ItemType);
            fooView.ItemType = "cpp2";
            Assert.Equal("cpp2", fooView.ItemType);
            Assert.Equal("cpp2", fooReal.ItemType);
            fooReal.ItemType = "cpp3";
            Assert.Equal("cpp3", fooView.ItemType);
            Assert.Equal("cpp3", fooReal.ItemType);

            ViewValidation.Verify(fooView, fooReal, validationContext);

            // UnevaluatedInclude set

            Assert.Equal("foo.cpp", fooView.UnevaluatedInclude);
            fooView.UnevaluatedInclude = "fooRenamed.cpp";
            Assert.Equal("fooRenamed.cpp", fooView.UnevaluatedInclude);
            Assert.Equal("fooRenamed.cpp", fooReal.UnevaluatedInclude);

            fooReal.UnevaluatedInclude = "fooRenamedAgain.cpp";
            Assert.Equal("fooRenamedAgain.cpp", fooView.UnevaluatedInclude);
            Assert.Equal("fooRenamedAgain.cpp", fooReal.UnevaluatedInclude);
            ViewValidation.Verify(fooView, fooReal, validationContext);

            // Rename.
            fooView.Rename("fooRenamedOnceMore.cpp");
            Assert.Equal("fooRenamedOnceMore.cpp", fooView.UnevaluatedInclude);
            Assert.Equal("fooRenamedOnceMore.cpp", fooReal.UnevaluatedInclude);

            fooReal.Rename("fooRenamedLastTimeForSure.cpp");
            Assert.Equal("fooRenamedLastTimeForSure.cpp", fooView.UnevaluatedInclude);
            Assert.Equal("fooRenamedLastTimeForSure.cpp", fooReal.UnevaluatedInclude);
            ViewValidation.Verify(fooView, fooReal, validationContext);


            // and finally again verify the two projects are equivalent as a whole.
            ViewValidation.Verify(pair);
        }