public void GetTargetFramework(string targetFramework, string targetFrameworkIdentifier, string targetFrameworkVersion, string targetFrameworkProfile, string expectedTargetFramework)
        {
            var properties = new Dictionary <string, string>();

            if (targetFramework != null)
            {
                properties.Add("TargetFramework", targetFramework);
            }
            if (targetFrameworkIdentifier != null)
            {
                properties.Add("TargetFrameworkIdentifier", targetFrameworkIdentifier);
            }
            if (targetFrameworkVersion != null)
            {
                properties.Add("TargetFrameworkVersion", targetFrameworkVersion);
            }
            if (targetFrameworkProfile != null)
            {
                properties.Add("TargetFrameworkProfile", targetFrameworkProfile);
            }

            var project = IProjectFactory.Create(properties);
            var actualTargetFramework = ProjectExtensions.GetTargetFramework(project);

            Assert.Equal(expectedTargetFramework, actualTargetFramework);
        }
Esempio n. 2
0
        private static bool IsApplicableProject(CodeGenerationContext context)
        {
            FrameworkName targetFramework;
            bool          flag;

            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if ((object)ProjectLanguage.CSharp == (object)ProjectExtensions.GetCodeLanguage(context.ActiveProject) || (object)ProjectLanguage.VisualBasic == (object)ProjectExtensions.GetCodeLanguage(context.ActiveProject))
            {
                targetFramework = null;
                try
                {
                    targetFramework = ProjectExtensions.GetTargetFramework(context.ActiveProject);
                    goto Label0;
                }
                catch
                {
                    flag = false;
                }
                return(flag);
            }
            return(false);

Label0:
            if (targetFramework != null && targetFramework.Identifier == ".NETFramework" && targetFramework.Version >= new Version(4, 5))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 3
0
        public void GetTargetFrameworkForJSProjectReturnsCorrectPlatformVersion(string platformVersion, string platformIdentifier, string exptectedTargetFramework)
        {
            // Arrange
            var project = new Mock <Project>();

            project.Setup(p => p.Kind).Returns(VsConstants.JsProjectTypeGuid);

            var verProp = new Mock <Property>();

            verProp.Setup(x => x.Value).Returns(platformVersion);

            var idProp = new Mock <Property>();

            idProp.Setup(x => x.Value).Returns(platformIdentifier);

            project.Setup(p => p.Properties.Item(It.Is <object>(v => "TargetPlatformVersion".Equals(v))))
            .Returns(verProp.Object);

            project.Setup(p => p.Properties.Item(It.Is <object>(v => "TargetPlatformIdentifier".Equals(v))))
            .Returns(idProp.Object);

            // Act
            string targetFramework = ProjectExtensions.GetTargetFramework(project.Object);

            // Assert
            Assert.Equal(exptectedTargetFramework, targetFramework);
        }
Esempio n. 4
0
        public void GetTargetFrameworkForMissingXnaPropertyDoesNotReturnWindowsPhoneTargetFramework()
        {
            // Arrange
            var project = new Mock <Project>();

            var fxProperty = new Mock <Property>();

            fxProperty.Setup(x => x.Value).Returns(".NETFramework,Version=v4.0");
            project.Setup(p => p.Properties.Item(It.Is <object>(v => "TargetFrameworkMoniker".Equals(v))))
            .Returns(fxProperty.Object);

            // Act
            string targetFramework = ProjectExtensions.GetTargetFramework(project.Object);

            // Assert
            Assert.Equal(".NETFramework,Version=v4.0", targetFramework);
        }
        public void GetTargetFramework_Throws(string targetFramework, string targetFrameworkIdentifier, string targetFrameworkVersion)
        {
            var properties = new Dictionary <string, string>();

            if (targetFramework != null)
            {
                properties.Add("TargetFramework", targetFramework);
            }
            if (targetFrameworkIdentifier != null)
            {
                properties.Add("TargetFrameworkIdentifier", targetFrameworkIdentifier);
            }
            if (targetFrameworkVersion != null)
            {
                properties.Add("TargetFrameworkVersion", targetFrameworkVersion);
            }

            var project = IProjectFactory.Create(properties);

            Assert.Throws <InvalidOperationException>(() => ProjectExtensions.GetTargetFramework(project));
        }
Esempio n. 6
0
        public void GetTargetFrameworkForWrongXnaProjectDoesNotReturnWindowsPhoneTargetFramework()
        {
            // Arrange
            var project = new Mock <Project>();

            var xnaProperty = new Mock <Property>();

            xnaProperty.Setup(x => x.Value).Returns("Windows Phone OS 7.0");    // 7.0 is not recognized. Only 7.1 is.

            project.Setup(p => p.Properties.Item(It.Is <object>(v => "Microsoft.Xna.GameStudio.CodeProject.WindowsPhoneProjectPropertiesExtender.XnaRefreshLevel".Equals(v))))
            .Returns(xnaProperty.Object);

            var fxProperty = new Mock <Property>();

            fxProperty.Setup(x => x.Value).Returns(".NETFramework,Version=v4.0");
            project.Setup(p => p.Properties.Item(It.Is <object>(v => "TargetFrameworkMoniker".Equals(v))))
            .Returns(fxProperty.Object);

            // Act
            string targetFramework = ProjectExtensions.GetTargetFramework(project.Object);

            // Assert
            Assert.Equal(".NETFramework,Version=v4.0", targetFramework);
        }
Esempio n. 7
0
        public void GetTargetFrameworkForXnaProjectReturnsWindowsPhoneTargetFramework()
        {
            // Arrange
            var project = new Mock <Project>();

            var xnaProperty = new Mock <Property>();

            xnaProperty.Setup(x => x.Value).Returns("Windows Phone OS 7.1");

            project.Setup(p => p.Properties.Item(It.Is <object>(v => "Microsoft.Xna.GameStudio.CodeProject.WindowsPhoneProjectPropertiesExtender.XnaRefreshLevel".Equals(v))))
            .Returns(xnaProperty.Object);

            var fxProperty = new Mock <Property>();

            fxProperty.Setup(x => x.Value).Returns(".NETFramework,Version=v4.0");
            project.Setup(p => p.Properties.Item(It.Is <object>(v => "TargetFrameworkMoniker".Equals(v))))
            .Returns(fxProperty.Object);

            // Act
            string targetFramework = ProjectExtensions.GetTargetFramework(project.Object);

            // Assert
            Assert.Equal("Silverlight,Version=v4.0,Profile=WindowsPhone71", targetFramework);
        }