public void BeforeAddOrUpdate_WhenSdk_ShouldFindMatchingPackageAndSetProperties()
        {
            var dependencyIDs = ImmutableArray.Create("id1", "id2");

            var targetFramework = new TargetFramework("tfm");

            const string sdkName = "sdkName";

            var sdkDependency = new TestDependency
            {
                Id       = "dependency1Id",
                Name     = sdkName,
                TopLevel = true,
                Resolved = false,
                Flags    = DependencyTreeFlags.SdkDependency
            };

            var packageDependency = new TestDependency
            {
                Id            = Dependency.GetID(targetFramework, PackageRuleHandler.ProviderTypeString, sdkName),
                Resolved      = true,
                DependencyIDs = dependencyIDs,
                Flags         = DependencyTreeFlags.NuGetPackageDependency
            };

            var worldBuilder = new IDependency[] { sdkDependency, packageDependency }.ToImmutableDictionary(d => d.Id).ToBuilder();

            var context = new AddDependencyContext(worldBuilder);

            var filter = new SdkAndPackagesDependenciesSnapshotFilter();

            filter.BeforeAddOrUpdate(
                targetFramework,
                sdkDependency,
                null,
                null,
                context);

            var acceptedDependency = context.GetResult(filter);

            // Dependency should be accepted, but converted to resolved state
            Assert.NotNull(acceptedDependency);
            Assert.NotSame(sdkDependency, acceptedDependency);
            acceptedDependency.AssertEqualTo(
                sdkDependency.ToResolved(
                    schemaName: ResolvedSdkReference.SchemaName,
                    dependencyIDs: dependencyIDs));

            // No changes other than the filtered dependency
            Assert.False(context.Changed);
        }
        public void BeforeAddOrUpdate_WhenPackage_ShouldFindMatchingSdkAndSetProperties()
        {
            var dependencyIDs = ImmutableArray.Create("id1", "id2");

            var targetFramework = new TargetFramework("tfm");

            const string packageName = "packageName";

            var sdkDependency = new TestDependency
            {
                Id       = Dependency.GetID(targetFramework, SdkRuleHandler.ProviderTypeString, packageName),
                TopLevel = false,
                Resolved = true,
                Flags    = DependencyTreeFlags.NuGetPackageDependency.Union(DependencyTreeFlags.Unresolved) // to see if unresolved is fixed
            };

            var packageDependency = new TestDependency
            {
                Id            = "packageId",
                Name          = packageName,
                Flags         = DependencyTreeFlags.NuGetPackageDependency,
                TopLevel      = true,
                Resolved      = true,
                DependencyIDs = dependencyIDs
            };

            var worldBuilder = new IDependency[] { packageDependency, sdkDependency }.ToImmutableDictionary(d => d.Id).ToBuilder();

            var context = new AddDependencyContext(worldBuilder);

            var filter = new SdkAndPackagesDependenciesSnapshotFilter();

            filter.BeforeAddOrUpdate(
                targetFramework,
                packageDependency,
                null,
                null,
                context);

            // Accepts unchanged dependency
            Assert.Same(packageDependency, context.GetResult(filter));

            // Other changes made
            Assert.True(context.Changed);

            Assert.True(context.TryGetDependency(sdkDependency.Id, out IDependency sdkDependencyAfter));
            sdkDependencyAfter.AssertEqualTo(
                sdkDependency.ToResolved(
                    schemaName: ResolvedSdkReference.SchemaName,
                    dependencyIDs: dependencyIDs));
        }