public void DependencyGraphSpec_Save_SerializesMembersAsJson()
        {
            var expectedJson        = ResourceTestUtility.GetResource("NuGet.ProjectModel.Test.compiler.resources.DependencyGraphSpec_Save_SerializesMembersAsJson.json", typeof(DependencyGraphSpecTests));
            var dependencyGraphSpec = CreateDependencyGraphSpec();
            var actualJson          = GetJson(dependencyGraphSpec);

            Assert.Equal(expectedJson, actualJson);
        }
Beispiel #2
0
        public void Write_SerializesMembersAsJson()
        {
            var expectedJson = ResourceTestUtility.GetResource("NuGet.ProjectModel.Test.compiler.resources.PackageSpecWriter_Write_SerializesMembersAsJson.json", typeof(PackageSpecWriterTests));
            var packageSpec  = CreatePackageSpec();
            var actualJson   = GetJson(packageSpec);

            Assert.Equal(expectedJson, actualJson);
        }
        public void Write_SerializesMembersAsJsonWithoutRestoreSettings()
        {
            // Arrange && Act
            var expectedJson = ResourceTestUtility.GetResource("NuGet.ProjectModel.Test.compiler.resources.PackageSpecWriter_Write_SerializesMembersAsJsonWithoutRestoreSettings.json", typeof(PackageSpecWriterTests));
            var packageSpec  = CreatePackageSpec(withRestoreSettings: false);
            var actualJson   = GetJsonString(packageSpec);

            // Assert
            Assert.Equal(expectedJson, actualJson);
        }
        public void DependencyGraphSpec_Save_SerializesMembersAsJson_CentralVersionDependencies()
        {
            // Arrange
            var expectedJson = ResourceTestUtility.GetResource("NuGet.ProjectModel.Test.compiler.resources.DependencyGraphSpec_CentralVersionDependencies.json", typeof(DependencyGraphSpecTests));

            // Act
            var dependencyGraphSpec = CreateDependencyGraphSpecWithCentralDependencies();
            var actualJson          = GetJson(dependencyGraphSpec);

            // Assert
            Assert.Equal(expectedJson, actualJson);
        }
        public void LockFile_GetTarget_WithAlias_ReturnsCorrectLockFileTarget()
        {
            // Arrange
            var            expectedJson   = ResourceTestUtility.GetResource("NuGet.ProjectModel.Test.compiler.resources.sample.assets.json", typeof(LockFileTests));
            var            lockFile       = new LockFileFormat().Parse(expectedJson, Path.GetTempPath());
            NuGetFramework nuGetFramework = NuGetFramework.ParseComponents(".NETCoreApp,Version=v5.0", "Windows,Version=7.0");

            // Act
            var target = lockFile.GetTarget("net5.0", runtimeIdentifier: null);

            // Assert
            target.TargetFramework.Should().Be(nuGetFramework);
        }
        public void DependencyGraphSpec_ReadFileWithProjects_CaseInsensitive_GetClosures()
        {
            // Arrange
            var json = JObject.Parse(ResourceTestUtility.GetResource("NuGet.ProjectModel.Test.compiler.resources.test3.dg", typeof(DependencyGraphSpecTests)));

            // Act
            var dg = DependencyGraphSpec.Load(json);

            var xClosure = dg.GetClosure("A55205E7-4D08-4672-8011-0925467CC45F").OrderBy(e => e.RestoreMetadata.ProjectUniqueName, StringComparer.OrdinalIgnoreCase).ToList();
            var yClosure = dg.GetClosure("78A6AD3F-9FA5-47F6-A54E-84B46A48CB2F").OrderBy(e => e.RestoreMetadata.ProjectUniqueName, StringComparer.OrdinalIgnoreCase).ToList();

            // Assert
            Assert.Equal(3, xClosure.Count);
            Assert.Equal("44B29B8D-8413-42D2-8DF4-72225659619B", xClosure[0].RestoreMetadata.ProjectUniqueName);
            Assert.Equal("78A6AD3F-9FA5-47F6-A54E-84B46A48CB2F", xClosure[1].RestoreMetadata.ProjectUniqueName);
            Assert.Equal("A55205E7-4D08-4672-8011-0925467CC45F", xClosure[2].RestoreMetadata.ProjectUniqueName);

            Assert.Equal(1, yClosure.Count);
            Assert.Equal("78A6AD3F-9FA5-47F6-A54E-84B46A48CB2F", yClosure.Single().RestoreMetadata.ProjectUniqueName);
        }
        public void DependencyGraphSpec_GetParents()
        {
            // Arrange
            var json = JObject.Parse(ResourceTestUtility.GetResource("NuGet.ProjectModel.Test.compiler.resources.test1.dg", typeof(DependencyGraphSpecTests)));

            // Act
            var dg = DependencyGraphSpec.Load(json);

            var xParents = dg.GetParents("A55205E7-4D08-4672-8011-0925467CC45F");
            var yParents = dg.GetParents("78A6AD3F-9FA5-47F6-A54E-84B46A48CB2F");
            var zParents = dg.GetParents("44B29B8D-8413-42D2-8DF4-72225659619B");

            // Assert
            Assert.Equal(0, xParents.Count);
            Assert.Equal(1, yParents.Count);
            Assert.Equal("A55205E7-4D08-4672-8011-0925467CC45F", yParents.Single());

            Assert.Equal(1, zParents.Count);
            Assert.Equal("A55205E7-4D08-4672-8011-0925467CC45F", zParents.Single());
        }
        public void IsValid_ReturnsFalseForInvalidFile()
        {
            using (var testDirectory = TestDirectory.Create())
            {
                // This is the build output from a default class library project.
                // There is nothing special about it; any unsigned DLL would work just as well.
                // This is a better test than an arbitrary file (e.g.:  file.txt) because
                // this is a portable executable (PE) file.  Authenticode signatures are
                // expected in PE files.
                var fileName     = "DefaultClassLibrary.dll";
                var resourceName = $"NuGet.Protocol.Tests.compiler.resources.{fileName}";
                var filePath     = Path.Combine(testDirectory.Path, fileName);

                ResourceTestUtility.CopyResourceToFile(resourceName, GetType(), filePath);

                var actualResult = _verifier.IsValid(filePath);

                Assert.False(actualResult);
            }
        }
        public void DependencyGraphSpec_ReadMSBuildMetadata()
        {
            // Arrange
            var json = ResourceTestUtility.GetResource("NuGet.ProjectModel.Test.compiler.resources.project1.json", typeof(DependencyGraphSpecTests));

            // Act
            var spec            = JsonPackageSpecReader.GetPackageSpec(json, "x", "c:\\fake\\project.json");
            var msbuildMetadata = spec.RestoreMetadata;

            // Assert
            Assert.NotNull(msbuildMetadata);
            Assert.Equal("A55205E7-4D08-4672-8011-0925467CC45F", msbuildMetadata.ProjectUniqueName);
            Assert.Equal("c:\\x\\x.csproj", msbuildMetadata.ProjectPath);
            Assert.Equal("x", msbuildMetadata.ProjectName);
            Assert.Equal("c:\\x\\project.json", msbuildMetadata.ProjectJsonPath);
            Assert.Equal(ProjectStyle.PackageReference, msbuildMetadata.ProjectStyle);
            Assert.Equal("c:\\packages", msbuildMetadata.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("|", msbuildMetadata.FallbackFolders));
            Assert.Equal("44B29B8D-8413-42D2-8DF4-72225659619B|c:\\a\\a.csproj|78A6AD3F-9FA5-47F6-A54E-84B46A48CB2F|c:\\b\\b.csproj", string.Join("|", msbuildMetadata.TargetFrameworks.Single().ProjectReferences.Select(e => $"{e.ProjectUniqueName}|{e.ProjectPath}")));
            Assert.True(msbuildMetadata.CrossTargeting);
            Assert.True(msbuildMetadata.LegacyPackagesDirectory);
        }
Beispiel #10
0
 public static byte[] GetResourceBytes(string name)
 {
     return(ResourceTestUtility.GetResourceBytes($"Test.Utility.compiler.resources.{name}", typeof(SigningTestUtility)));
 }
Beispiel #11
0
 private static byte[] GetResource(string name)
 {
     return(ResourceTestUtility.GetResourceBytes(
                $"Dotnet.Integration.Test.compiler.resources.{name}",
                typeof(DotnetRestoreTests)));
 }
Beispiel #12
0
 private static byte[] GetResource(string name)
 {
     return(ResourceTestUtility.GetResourceBytes(
                $"NuGet.Commands.Test.compiler.resources.{name}",
                typeof(SignCommandRunnerTests)));
 }
Beispiel #13
0
 private static byte[] GetResource(string name)
 {
     return(ResourceTestUtility.GetResourceBytes(
                $"NuGet.CommandLine.Test.compiler.resources.{name}",
                typeof(NuGetVerifyCommandTest)));
 }
Beispiel #14
0
 internal static byte[] GetResourceBytes(string name)
 {
     return(ResourceTestUtility.GetResourceBytes($"NuGet.Packaging.Test.compiler.resources.{name}", typeof(SignTestUtility)));
 }
 private static byte[] GetResource(string name)
 {
     return(ResourceTestUtility.GetResourceBytes(
                $"NuGet.Packaging.Test.compiler.resources.{name}",
                typeof(SignedPackageArchiveUtilityTests)));
 }
Beispiel #16
0
        private static X509Certificate2 GetCertificate(string name)
        {
            var bytes = ResourceTestUtility.GetResourceBytes($"NuGet.Packaging.Test.compiler.resources.{name}", typeof(SigningUtilityTests));

            return(new X509Certificate2(bytes));
        }
 private static byte[] GetResource(string name)
 {
     return(ResourceTestUtility.GetResourceBytes(
                $"NuGet.Packaging.FuncTest.compiler.resources.{name}",
                typeof(PackageSignatureVerifierTests)));
 }
Beispiel #18
0
        private static string GetResourceAsJson(string fileName)
        {
            var resourceName = $"NuGet.ProjectModel.Test.compiler.resources.{fileName}";

            return(ResourceTestUtility.GetResource(resourceName, typeof(DependencyGraphSpecTests)));
        }
 private static byte[] GetResource(string name)
 {
     return(ResourceTestUtility.GetResourceBytes(
                $"NuGet.Packaging.FuncTest.compiler.resources.{name}",
                typeof(SignatureTrustAndValidityVerificationProviderTests)));
 }
Beispiel #20
0
 private static byte[] GetTestUtilityResource(string name)
 {
     return(ResourceTestUtility.GetResourceBytes(
                $"Test.Utility.compiler.resources.{name}",
                typeof(ResourceTestUtility)));
 }