public void FiltersAutoReferencedPackages()
            {
                // Arrange
                Func <InstalledPackageReference, bool> filter = ListPackageHelper.TopLevelPackagesFilterForOutdated;
                var installedPackageReference = ListPackageTestHelper.CreateInstalledPackageReference(autoReference: true);

                // Act
                bool result = filter.Invoke(installedPackageReference);

                // Assert
                Assert.False(result);
            }
            public void FiltersPackagesWithoutDeprecationMetadata()
            {
                // Arrange
                Func <InstalledPackageReference, bool> filter = ListPackageHelper.PackagesFilterForDeprecated;
                var installedPackageReference = ListPackageTestHelper.CreateInstalledPackageReference();

                // Act
                bool result = filter.Invoke(installedPackageReference);

                // Assert
                Assert.False(result);
            }
            public void DoesNotFilterPackagesWithVulnerableMetadata()
            {
                // Arrange
                Func <InstalledPackageReference, bool> filter = ListPackageHelper.PackagesFilterForVulnerable;
                var installedPackageReference = ListPackageTestHelper.CreateInstalledPackageReference(vulnerabilityCount: 1);

                // Act
                bool result = filter.Invoke(installedPackageReference);

                // Assert
                Assert.True(result);
            }
            public void DoesNotFilterPackagesWithDeprecationMetadata()
            {
                // Arrange
                Func <InstalledPackageReference, bool> filter = ListPackageHelper.PackagesFilterForDeprecated;
                var installedPackageReference = ListPackageTestHelper.CreateInstalledPackageReference(isDeprecated: true);

                // Act
                bool result = filter.Invoke(installedPackageReference);

                // Assert
                Assert.True(result);
            }
            public void DoesNotFilterPackagesWithNewerVersionAvailable()
            {
                // Arrange
                Func <InstalledPackageReference, bool> filter = ListPackageHelper.TransitivePackagesFilterForOutdated;
                var installedPackageReference = ListPackageTestHelper.CreateInstalledPackageReference(
                    latestPackageVersionString: "2.0.0");

                // Act
                bool result = filter.Invoke(installedPackageReference);

                // Assert
                Assert.True(result);
            }
            public void FiltersFrameworkPackagesCollectionWithOutdatedMetadata(
                bool includeTopLevelPositives,
                bool includeTransitivePositives)
            {
                // Arrange
                var packages         = new FrameworkPackages("net40");
                var topLevelPackages =
                    new List <InstalledPackageReference>
                {
                    ListPackageTestHelper.CreateInstalledPackageReference(resolvedPackageVersionString: "2.0.0",
                                                                          latestPackageVersionString: "2.0.0")
                };
                var transitivePackages =
                    new List <InstalledPackageReference>
                {
                    ListPackageTestHelper.CreateInstalledPackageReference(resolvedPackageVersionString: "2.0.0",
                                                                          latestPackageVersionString: "2.0.0")
                };

                if (includeTopLevelPositives)
                {
                    topLevelPackages.Add(ListPackageTestHelper.CreateInstalledPackageReference(
                                             resolvedPackageVersionString: "2.0.0", latestPackageVersionString: "3.0.0"));
                }

                if (includeTransitivePositives)
                {
                    transitivePackages.Add(ListPackageTestHelper.CreateInstalledPackageReference(
                                               resolvedPackageVersionString: "2.0.0", latestPackageVersionString: "3.0.0"));
                }

                packages.TopLevelPackages   = topLevelPackages;
                packages.TransitivePackages = transitivePackages;
                var allPackages = new List <FrameworkPackages> {
                    packages
                };
                var listPackageArgs = new ListPackageArgs(path: "", packageSources: Enumerable.Empty <PackageSource>(),
                                                          frameworks: Enumerable.Empty <string>(),
                                                          ReportType.Outdated,
                                                          includeTransitive: true, prerelease: false, highestPatch: false, highestMinor: false,
                                                          logger: new Mock <ILogger>().Object,
                                                          CancellationToken.None);

                // Act
                var isFilteredSetNonEmpty = ListPackageCommandRunner.FilterPackages(allPackages, listPackageArgs);

                // Assert
                Assert.Equal(includeTopLevelPositives || includeTransitivePositives, isFilteredSetNonEmpty);
                Assert.Equal(includeTopLevelPositives ? 1 : 0, allPackages.First().TopLevelPackages.Count());
                Assert.Equal(includeTransitivePositives ? 1 : 0, allPackages.First().TransitivePackages.Count());
            }
            public void DoesNotFilterPackagesWithLatestMetadataNull()
            {
                // Arrange
                Func <InstalledPackageReference, bool> filter = ListPackageHelper.TransitivePackagesFilterForOutdated;
                var installedPackageReference = ListPackageTestHelper.CreateInstalledPackageReference();

                installedPackageReference.LatestPackageMetadata = null;

                // Act
                bool result = filter.Invoke(installedPackageReference);

                // Assert
                Assert.True(result);
            }