Пример #1
0
        public void Write_ThrowsForNullPackageSpec()
        {
            var writer = new JsonObjectWriter();

            // Assert
            Assert.Throws <ArgumentNullException>(() => PackageSpecWriter.Write(packageSpec: null, writer: writer));
        }
Пример #2
0
        //[InlineData("ModifyRestoreSettings", true)] = Not really included in the equals and hash code comparisons
        public void PackageSpecCloneTest(string methodName, bool validateJson)
        {
            // Set up
            var PackageSpec       = CreatePackageSpec();
            var clonedPackageSpec = PackageSpec.Clone();

            //Preconditions
            Assert.Equal(PackageSpec, clonedPackageSpec);
            var originalPackageSpecWriter = new JsonObjectWriter();
            var clonedPackageSpecWriter   = new JsonObjectWriter();

            PackageSpecWriter.Write(PackageSpec, originalPackageSpecWriter);
            PackageSpecWriter.Write(clonedPackageSpec, clonedPackageSpecWriter);
            Assert.Equal(originalPackageSpecWriter.GetJson().ToString(), clonedPackageSpecWriter.GetJson().ToString());
            Assert.False(object.ReferenceEquals(PackageSpec, clonedPackageSpec));

            // Act
            var methodInfo = typeof(PackageSpecModify).GetMethod(methodName);

            methodInfo.Invoke(null, new object[] { PackageSpec });

            // Assert

            Assert.NotEqual(PackageSpec, clonedPackageSpec);
            if (validateJson)
            {
                var oPackageSpecWriter = new JsonObjectWriter();
                var cPackageSpecWriter = new JsonObjectWriter();
                PackageSpecWriter.Write(PackageSpec, oPackageSpecWriter);
                PackageSpecWriter.Write(clonedPackageSpec, cPackageSpecWriter);
                Assert.NotEqual(oPackageSpecWriter.GetJson().ToString(), cPackageSpecWriter.GetJson().ToString());
            }
            Assert.False(object.ReferenceEquals(PackageSpec, clonedPackageSpec));
        }
 public void Write_ThrowsForNullPackageSpec()
 {
     using (var jsonWriter = new JTokenWriter())
         using (var writer = new JsonObjectWriter(jsonWriter))
         {
             Assert.Throws <ArgumentNullException>(() => PackageSpecWriter.Write(packageSpec: null, writer: writer));
         }
 }
Пример #4
0
        private static JObject GetJsonObject(PackageSpec packageSpec)
        {
            var writer = new JsonObjectWriter();

            PackageSpecWriter.Write(packageSpec, writer);

            return(writer.GetJObject());
        }
Пример #5
0
        private static string GetJsonString(PackageSpec packageSpec)
        {
            var writer = new JsonObjectWriter();

            PackageSpecWriter.Write(packageSpec, writer);

            return(writer.GetJson());
        }
Пример #6
0
        public static PackageSpec RoundTrip(this PackageSpec spec)
        {
            var writer = new JsonObjectWriter();

            PackageSpecWriter.Write(spec, writer);
            var json = writer.GetJObject();

            return(JsonPackageSpecReader.GetPackageSpec(json));
        }
Пример #7
0
        internal static JObject ToJObject(this PackageSpec spec)
        {
            using (var jsonWriter = new JTokenWriter())
                using (var writer = new JsonObjectWriter(jsonWriter))
                {
                    writer.WriteObjectStart();

                    PackageSpecWriter.Write(spec, writer);

                    writer.WriteObjectEnd();

                    return((JObject)jsonWriter.Token);
                }
        }
Пример #8
0
        internal static PackageSpec RoundTrip(this PackageSpec spec, string packageSpecName, string packageSpecPath)
        {
            using (var stringWriter = new StringWriter())
                using (var jsonWriter = new JsonTextWriter(stringWriter))
                    using (var writer = new JsonObjectWriter(jsonWriter))
                    {
                        writer.WriteObjectStart();

                        PackageSpecWriter.Write(spec, writer);

                        writer.WriteObjectEnd();

                        return(JsonPackageSpecReader.GetPackageSpec(stringWriter.ToString(), packageSpecName, packageSpecPath));
                    }
        }
Пример #9
0
        private static void VerifyJsonPackageSpecRoundTrip(string json)
        {
            // Arrange & Act
            var spec = JsonPackageSpecReader.GetPackageSpec(json, "testName", @"C:\fake\path");

            var writer = new JsonObjectWriter();

            PackageSpecWriter.Write(spec, writer);

            var actualResult = writer.GetJson();

            var expected = JObject.Parse(json).ToString();

            // Assert
            Assert.Equal(expected, actualResult);
        }
Пример #10
0
        public static PackageSpec RoundTrip(this PackageSpec spec)
        {
            using (var jsonWriter = new JTokenWriter())
                using (var writer = new JsonObjectWriter(jsonWriter))
                {
                    writer.WriteObjectStart();

                    PackageSpecWriter.Write(spec, writer);

                    writer.WriteObjectEnd();

#pragma warning disable CS0618
                    return(JsonPackageSpecReader.GetPackageSpec((JObject)jsonWriter.Token));

#pragma warning restore CS0618
                }
        }
        public void DependencyGraphSpec_RoundTripMSBuildMetadata_ProjectReferenceFlags()
        {
            // Arrange
            var frameworks = new List <TargetFrameworkInformation>();

            frameworks.Add(new TargetFrameworkInformation()
            {
                FrameworkName = NuGetFramework.Parse("net45")
            });

            var spec            = new PackageSpec(frameworks);
            var msbuildMetadata = new ProjectRestoreMetadata();

            spec.RestoreMetadata = msbuildMetadata;

            msbuildMetadata.ProjectUniqueName = "A55205E7-4D08-4672-8011-0925467CC45F";
            msbuildMetadata.ProjectPath       = "c:\\x\\x.csproj";
            msbuildMetadata.ProjectName       = "x";
            msbuildMetadata.ProjectStyle      = ProjectStyle.PackageReference;

            var tfmGroup  = new ProjectRestoreMetadataFrameworkInfo(NuGetFramework.Parse("net45"));
            var tfmGroup2 = new ProjectRestoreMetadataFrameworkInfo(NuGetFramework.Parse("netstandard1.3"));

            msbuildMetadata.TargetFrameworks.Add(tfmGroup);
            msbuildMetadata.TargetFrameworks.Add(tfmGroup2);

            var ref1 = new ProjectRestoreReference()
            {
                ProjectUniqueName = "44B29B8D-8413-42D2-8DF4-72225659619B",
                ProjectPath       = "c:\\a\\a.csproj",
                IncludeAssets     = LibraryIncludeFlags.Build,
                ExcludeAssets     = LibraryIncludeFlags.Compile,
                PrivateAssets     = LibraryIncludeFlags.Runtime
            };

            var ref2 = new ProjectRestoreReference()
            {
                ProjectUniqueName = "78A6AD3F-9FA5-47F6-A54E-84B46A48CB2F",
                ProjectPath       = "c:\\b\\b.csproj"
            };

            tfmGroup.ProjectReferences.Add(ref1);
            tfmGroup.ProjectReferences.Add(ref2);

            tfmGroup2.ProjectReferences.Add(ref1);
            tfmGroup2.ProjectReferences.Add(ref2);

            var writer = new RuntimeModel.JsonObjectWriter();

            // Act
            PackageSpecWriter.Write(spec, writer);
            var json     = writer.GetJson();
            var readSpec = JsonPackageSpecReader.GetPackageSpec(json, "x", "c:\\fake\\project.json");

            // Assert
            Assert.Equal(2, readSpec.RestoreMetadata.TargetFrameworks.Count);

            foreach (var framework in readSpec.RestoreMetadata.TargetFrameworks)
            {
                var references = framework.ProjectReferences.OrderBy(e => e.ProjectUniqueName).ToArray();
                Assert.Equal("44B29B8D-8413-42D2-8DF4-72225659619B", references[0].ProjectUniqueName);
                Assert.Equal(LibraryIncludeFlags.Build, references[0].IncludeAssets);
                Assert.Equal(LibraryIncludeFlags.Compile, references[0].ExcludeAssets);
                Assert.Equal(LibraryIncludeFlags.Runtime, references[0].PrivateAssets);

                Assert.Equal("78A6AD3F-9FA5-47F6-A54E-84B46A48CB2F", references[1].ProjectUniqueName);
                Assert.Equal(LibraryIncludeFlags.All, references[1].IncludeAssets);
                Assert.Equal(LibraryIncludeFlags.None, references[1].ExcludeAssets);
                Assert.Equal(LibraryIncludeFlagUtils.DefaultSuppressParent, references[1].PrivateAssets);
            }
        }
        public void DependencyGraphSpec_RoundTripMSBuildMetadata()
        {
            // Arrange
            var frameworks = new List <TargetFrameworkInformation>();

            frameworks.Add(new TargetFrameworkInformation()
            {
                FrameworkName = NuGetFramework.Parse("net45")
            });

            var spec = new PackageSpec(frameworks);

            spec.Version = NuGetVersion.Parse("24.5.1.2-alpha.1.2+a.b.c");
            var msbuildMetadata = new ProjectRestoreMetadata();

            spec.RestoreMetadata = msbuildMetadata;

            msbuildMetadata.ProjectUniqueName = "A55205E7-4D08-4672-8011-0925467CC45F";
            msbuildMetadata.ProjectPath       = "c:\\x\\x.csproj";
            msbuildMetadata.ProjectName       = "x";
            msbuildMetadata.ProjectJsonPath   = "c:\\x\\project.json";
            msbuildMetadata.ProjectStyle      = ProjectStyle.PackageReference;
            msbuildMetadata.PackagesPath      = "c:\\packages";
            msbuildMetadata.Sources           = new[] { new PackageSource("https://api.nuget.org/v3/index.json") };

            var tfmGroup = new ProjectRestoreMetadataFrameworkInfo(NuGetFramework.Parse("net45"));

            msbuildMetadata.TargetFrameworks.Add(tfmGroup);

            tfmGroup.ProjectReferences.Add(new ProjectRestoreReference()
            {
                ProjectUniqueName = "44B29B8D-8413-42D2-8DF4-72225659619B",
                ProjectPath       = "c:\\a\\a.csproj"
            });

            tfmGroup.ProjectReferences.Add(new ProjectRestoreReference()
            {
                ProjectUniqueName = "78A6AD3F-9FA5-47F6-A54E-84B46A48CB2F",
                ProjectPath       = "c:\\b\\b.csproj"
            });

            msbuildMetadata.FallbackFolders.Add("c:\\fallback1");
            msbuildMetadata.FallbackFolders.Add("c:\\fallback2");


            msbuildMetadata.ConfigFilePaths.Add("c:\\nuget.config");
            msbuildMetadata.ConfigFilePaths.Add("d:\\nuget.config");

            msbuildMetadata.CrossTargeting          = true;
            msbuildMetadata.LegacyPackagesDirectory = true;

            // Act
            var writer = new RuntimeModel.JsonObjectWriter();

            PackageSpecWriter.Write(spec, writer);
            var json             = writer.GetJson();
            var readSpec         = JsonPackageSpecReader.GetPackageSpec(json, "x", "c:\\fake\\project.json");
            var msbuildMetadata2 = readSpec.RestoreMetadata;

            // Assert
            Assert.NotNull(msbuildMetadata2);
            Assert.Equal("A55205E7-4D08-4672-8011-0925467CC45F", msbuildMetadata2.ProjectUniqueName);
            Assert.Equal("c:\\x\\x.csproj", msbuildMetadata2.ProjectPath);
            Assert.Equal("x", msbuildMetadata2.ProjectName);
            Assert.Equal("c:\\x\\project.json", msbuildMetadata2.ProjectJsonPath);
            Assert.Equal(ProjectStyle.PackageReference, msbuildMetadata2.ProjectStyle);
            Assert.Equal("c:\\packages", msbuildMetadata2.PackagesPath);
            Assert.Equal("https://api.nuget.org/v3/index.json", string.Join("|", msbuildMetadata.Sources.Select(s => s.Source)));
            Assert.Equal("c:\\fallback1|c:\\fallback2", string.Join("|", msbuildMetadata2.FallbackFolders));
            Assert.Equal("c:\\nuget.config|d:\\nuget.config", string.Join("|", msbuildMetadata.ConfigFilePaths));
            Assert.Equal("44B29B8D-8413-42D2-8DF4-72225659619B|c:\\a\\a.csproj|78A6AD3F-9FA5-47F6-A54E-84B46A48CB2F|c:\\b\\b.csproj", string.Join("|", msbuildMetadata2.TargetFrameworks.Single().ProjectReferences.Select(e => $"{e.ProjectUniqueName}|{e.ProjectPath}")));
            Assert.True(msbuildMetadata.CrossTargeting);
            Assert.True(msbuildMetadata.LegacyPackagesDirectory);

            // Verify build metadata is not lost.
            Assert.Equal("24.5.1.2-alpha.1.2+a.b.c", readSpec.Version.ToFullString());
        }
 public void Write_ThrowsForNullWriter()
 {
     // Assert
     Assert.Throws <ArgumentNullException>(() => PackageSpecWriter.Write(EmptyPackageSpec, writer: null));
 }