Exemplo n.º 1
0
        public void PackagesConfigWriter_Basic()
        {
            MemoryStream stream = new MemoryStream();

            using (PackagesConfigWriter writer = new PackagesConfigWriter(stream))
            {
                writer.WriteMinClientVersion(NuGetVersion.Parse("3.0.1"));

                writer.WritePackageEntry("packageB", NuGetVersion.Parse("2.0.0"), NuGetFramework.Parse("portable-net45+win8"));

                writer.WritePackageEntry("packageA", NuGetVersion.Parse("1.0.1"), NuGetFramework.Parse("net45"));
            }

            stream.Seek(0, SeekOrigin.Begin);

            var xml = XDocument.Load(stream);

            Assert.Equal("utf-8", xml.Declaration.Encoding);

            PackagesConfigReader reader = new PackagesConfigReader(xml);

            Assert.Equal("3.0.1", reader.GetMinClientVersion().ToNormalizedString());

            var packages = reader.GetPackages().ToArray();

            Assert.Equal("packageA", packages[0].PackageIdentity.Id);
            Assert.Equal("packageB", packages[1].PackageIdentity.Id);

            Assert.Equal("1.0.1", packages[0].PackageIdentity.Version.ToNormalizedString());
            Assert.Equal("2.0.0", packages[1].PackageIdentity.Version.ToNormalizedString());

            Assert.Equal("net45", packages[0].TargetFramework.GetShortFolderName());
            Assert.Equal("portable-net45+win8", packages[1].TargetFramework.GetShortFolderName());
        }
Exemplo n.º 2
0
        public void PackagesConfigWriter_Basic()
        {
            var stream = new MemoryStream();

            using (PackagesConfigWriter writer = new PackagesConfigWriter(stream))
            {
                writer.WriteMinClientVersion(NuGetVersion.Parse("3.0.1"));

                writer.WritePackageEntry("packageB", NuGetVersion.Parse("2.0.0"), NuGetFramework.Parse("portable-net45+win8"));

                writer.WritePackageEntry("packageA", NuGetVersion.Parse("1.0.1"), NuGetFramework.Parse("net45"));
            }

            stream.Seek(0, SeekOrigin.Begin);

            var xml = XDocument.Load(stream);

            Assert.Equal("utf-8", xml.Declaration.Encoding);

            PackagesConfigReader reader = new PackagesConfigReader(xml);

            Assert.Equal("3.0.1", reader.GetMinClientVersion().ToNormalizedString());

            var packages = reader.GetPackages().ToArray();
            Assert.Equal("packageA", packages[0].PackageIdentity.Id);
            Assert.Equal("packageB", packages[1].PackageIdentity.Id);

            Assert.Equal("1.0.1", packages[0].PackageIdentity.Version.ToNormalizedString());
            Assert.Equal("2.0.0", packages[1].PackageIdentity.Version.ToNormalizedString());

            Assert.Equal("net45", packages[0].TargetFramework.GetShortFolderName());
            Assert.Equal("portable-net45+win8", packages[1].TargetFramework.GetShortFolderName());
        }
        public void PackagesConfigWriter_BasicWithDifferentCulture()
        {
            var currentCulture   = CultureInfo.CurrentCulture;
            var currentUICulture = CultureInfo.CurrentUICulture;

            try
            {
                var calendar = new CultureInfo("he-IL");
                calendar.DateTimeFormat.Calendar = new HebrewCalendar();

                CultureInfo.CurrentCulture   = calendar;
                CultureInfo.CurrentUICulture = calendar;

                // Arrange
                using (var testFolder = TestDirectory.Create())
                {
                    var path = Path.Combine(testFolder + "packages.config");

                    // Act
                    using (var writer = new PackagesConfigWriter(path, true))
                    {
                        writer.WriteMinClientVersion(NuGetVersion.Parse("3.0.1"));

                        writer.AddPackageEntry("packageB", NuGetVersion.Parse("2.0.0"), NuGetFramework.Parse("portable-net45+win8"));

                        writer.AddPackageEntry("packageA", NuGetVersion.Parse("1.0.1"), NuGetFramework.Parse("net45"));
                    }

                    // Assert
                    var xml = XDocument.Load(path);

                    // Assert
                    Assert.Equal("utf-8", xml.Declaration.Encoding);

                    var reader = new PackagesConfigReader(xml);

                    Assert.Equal("3.0.1", reader.GetMinClientVersion().ToNormalizedString());

                    var packages = reader.GetPackages().ToArray();
                    Assert.Equal("packageA", packages[0].PackageIdentity.Id);
                    Assert.Equal("packageB", packages[1].PackageIdentity.Id);

                    Assert.Equal("1.0.1", packages[0].PackageIdentity.Version.ToNormalizedString());
                    Assert.Equal("2.0.0", packages[1].PackageIdentity.Version.ToNormalizedString());

                    Assert.Equal("net45", packages[0].TargetFramework.GetShortFolderName());
                    Assert.Equal("portable-net45+win8", packages[1].TargetFramework.GetShortFolderName());
                }
            }
            finally
            {
                CultureInfo.CurrentCulture   = currentCulture;
                CultureInfo.CurrentUICulture = currentUICulture;
            }
        }