public void BeforeAddOrUpdate_WhenNeedToApplyImplicit_ShouldSetProperties() { const string providerType = "providerType"; const string projectItemSpec = "projectItemSpec"; var implicitIcon = KnownMonikers.Abbreviation; var dependency = new TestDependency { Id = "dependency1", ProviderType = providerType, Implicit = false, Resolved = true, Flags = DependencyTreeFlags.GenericResolvedDependencyFlags, OriginalItemSpec = projectItemSpec, IconSet = new DependencyIconSet(KnownMonikers.Reference, KnownMonikers.Reference, KnownMonikers.Reference, KnownMonikers.Reference) }; var dependencyById = new Dictionary <(string ProviderType, string ModelId), IDependency> { { (dependency.ProviderType, dependency.Id), dependency } }; var context = new AddDependencyContext(dependencyById); var filter = new ImplicitDependenciesSnapshotFilter(); var subTreeProvider = IProjectDependenciesSubTreeProviderFactory.ImplementInternal( providerType: providerType, implicitIcon: implicitIcon); filter.BeforeAddOrUpdate( dependency, new Dictionary <string, IProjectDependenciesSubTreeProvider> { { providerType, subTreeProvider } }, ImmutableHashSet <string> .Empty, context); var acceptedDependency = context.GetResult(filter); // Returns changed dependency Assert.NotNull(acceptedDependency); Assert.NotSame(dependency, acceptedDependency); DependencyAssert.Equal( new TestDependency { ClonePropertiesFrom = dependency, Implicit = true, IconSet = new DependencyIconSet( implicitIcon, implicitIcon, KnownMonikers.Reference, KnownMonikers.Reference), Flags = DependencyTreeFlags.GenericResolvedDependencyFlags.Except(DependencyTreeFlags.SupportsRemove) }, acceptedDependency !); // No other changes made Assert.False(context.Changed); }
public void BeforeAddOrUpdate_WhenThereIsMatchingDependencyWithAliasApplied_ShouldUpdateCaptionForCurrentDependency() { // Same provider type // Duplicate caption, though with parenthesized text after one instance // -> Changes caption of non-parenthesized const string providerType = "provider"; const string caption = "caption"; var dependency = new TestDependency { Id = "id1", OriginalItemSpec = "originalItemSpec1", ProviderType = providerType, Caption = caption }; var otherDependency = new TestDependency { ClonePropertiesFrom = dependency, Id = "id2", OriginalItemSpec = "originalItemSpec2", Caption = $"{caption} (originalItemSpec2)" // caption already includes alias }; var dependencyById = new IDependency[] { dependency, otherDependency }.ToDictionary(d => d.Id); var context = new AddDependencyContext(dependencyById); var filter = new DeduplicateCaptionsSnapshotFilter(); filter.BeforeAddOrUpdate( null !, dependency, null !, null, context); // The context was unchanged, beyond the filtered dependency Assert.False(context.Changed); // The filtered dependency had its caption changed to its alias var dependencyAfter = context.GetResult(filter); DependencyAssert.Equal(new TestDependency { ClonePropertiesFrom = dependency, Caption = "caption (originalItemSpec1)" }, dependencyAfter !); // The other dependency had its caption changed to its alias Assert.True(context.TryGetDependency(otherDependency.Id, out IDependency otherDependencyAfter)); DependencyAssert.Equal(new TestDependency { ClonePropertiesFrom = otherDependency, Caption = "caption (originalItemSpec2)" }, otherDependencyAfter); }
public void BeforeAddOrUpdate_WhenThereIsMatchingDependencies_ShouldUpdateCaptionForAll() { // Same provider type // Same captions // -> Changes caption for both to match alias const string providerType = "provider"; const string caption = "caption"; var dependency = new TestDependency { Id = "id1", OriginalItemSpec = "originalItemSpec1", ProviderType = providerType, Caption = caption }; var otherDependency = new TestDependency { ClonePropertiesFrom = dependency, // clone, with changes Id = "id2", OriginalItemSpec = "originalItemSpec2" }; var dependencyById = new IDependency[] { dependency, otherDependency }.ToDictionary(d => d.Id); var context = new AddDependencyContext(dependencyById); var filter = new DeduplicateCaptionsSnapshotFilter(); filter.BeforeAddOrUpdate( null !, dependency, null !, null, context); // The context changed, beyond just the filtered dependency Assert.True(context.Changed); // The filtered dependency had its caption changed to its alias var dependencyAfter = context.GetResult(filter); DependencyAssert.Equal(new TestDependency { ClonePropertiesFrom = dependency, Caption = "caption (originalItemSpec1)" }, dependencyAfter !); // The other dependency had its caption changed to its alias Assert.True(context.TryGetDependency(otherDependency.Id, out IDependency otherDependencyAfter)); DependencyAssert.Equal(new TestDependency { ClonePropertiesFrom = otherDependency, Caption = "caption (originalItemSpec2)" }, otherDependencyAfter); }
public void BeforeRemove_WhenPackageRemoving_ShouldCleanupSdk() { const string packageName = "packageName"; var targetFramework = new TargetFramework("tfm"); var sdkDependency = new TestDependency { Id = Dependency.GetID(targetFramework, SdkRuleHandler.ProviderTypeString, packageName), Resolved = true, Flags = DependencyTreeFlags.SdkDependency.Union(DependencyTreeFlags.Resolved) }; var packageDependency = new TestDependency { Id = "packageId", Name = packageName, Flags = DependencyTreeFlags.PackageDependency, Resolved = true }; var builder = new IDependency[] { packageDependency, sdkDependency }.ToDictionary(d => d.Id); var context = new RemoveDependencyContext(builder); var filter = new SdkAndPackagesDependenciesSnapshotFilter(); filter.BeforeRemove( targetFramework: targetFramework, dependency: packageDependency, context); // Accepts removal Assert.True(context.GetResult(filter)); // Makes other changes too Assert.True(context.Changed); Assert.True(builder.TryGetValue(packageDependency.Id, out var afterPackageDependency)); Assert.Same(packageDependency, afterPackageDependency); Assert.True(builder.TryGetValue(sdkDependency.Id, out var afterSdkDependency)); DependencyAssert.Equal( afterSdkDependency.ToUnresolved( SdkReference.SchemaName), afterSdkDependency); }
public void BeforeAddOrUpdate_WhenSdk_ShouldFindMatchingPackageAndSetProperties() { var targetFramework = new TargetFramework("tfm"); const string sdkName = "sdkName"; var sdkDependency = new TestDependency { Id = "dependency1Id", Name = sdkName, Resolved = false, Flags = DependencyTreeFlags.SdkDependency }; var packageDependency = new TestDependency { Id = Dependency.GetID(targetFramework, PackageRuleHandler.ProviderTypeString, sdkName), Resolved = true, Flags = DependencyTreeFlags.PackageDependency }; var builder = new IDependency[] { sdkDependency, packageDependency }.ToDictionary(d => d.Id); var context = new AddDependencyContext(builder); 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); DependencyAssert.Equal( sdkDependency.ToResolved( schemaName: ResolvedSdkReference.SchemaName), acceptedDependency !); // No changes other than the filtered dependency Assert.False(context.Changed); }
public void BeforeAddOrUpdate_WhenPackage_ShouldFindMatchingSdkAndSetProperties() { var targetFramework = new TargetFramework("tfm"); const string packageName = "packageName"; var sdkDependency = new TestDependency { Id = Dependency.GetID(targetFramework, SdkRuleHandler.ProviderTypeString, packageName), Resolved = true, Flags = DependencyTreeFlags.PackageDependency.Union(DependencyTreeFlags.Unresolved) // to see if unresolved is fixed }; var packageDependency = new TestDependency { Id = "packageId", Name = packageName, Flags = DependencyTreeFlags.PackageDependency, Resolved = true }; var builder = new IDependency[] { packageDependency, sdkDependency }.ToDictionary(d => d.Id); var context = new AddDependencyContext(builder); 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)); DependencyAssert.Equal( sdkDependency.ToResolved( schemaName: ResolvedSdkReference.SchemaName), sdkDependencyAfter); }
public void BeforeRemove_WhenPackageRemoving_ShouldCleanupSdk() { const string packageName = "packageName"; var sdkDependency = new TestDependency { Id = packageName, ProviderType = SdkRuleHandler.ProviderTypeString, Resolved = true, Flags = DependencyTreeFlags.SdkDependency.Union(ProjectTreeFlags.ResolvedReference) }; var packageDependency = new TestDependency { Id = packageName, ProviderType = PackageRuleHandler.ProviderTypeString, Flags = DependencyTreeFlags.PackageDependency, Resolved = true }; var builder = new IDependency[] { packageDependency, sdkDependency }.ToDictionary(IDependencyExtensions.GetDependencyId); var context = new RemoveDependencyContext(builder); var filter = new SdkAndPackagesDependenciesSnapshotFilter(); filter.BeforeRemove( dependency: packageDependency, context); // Accepts removal Assert.True(context.GetResult(filter)); // Makes other changes too Assert.True(context.Changed); Assert.True(builder.TryGetValue(packageDependency.GetDependencyId(), out var afterPackageDependency)); Assert.Same(packageDependency, afterPackageDependency); Assert.True(builder.TryGetValue(sdkDependency.GetDependencyId(), out var afterSdkDependency)); DependencyAssert.Equal( afterSdkDependency.ToUnresolved(SdkReference.SchemaName), afterSdkDependency); }
public void BeforeAddOrUpdate_WhenPackage_ShouldFindMatchingSdkAndSetProperties() { const string packageName = "packageName"; var sdkDependency = new TestDependency { Id = packageName, ProviderType = SdkRuleHandler.ProviderTypeString, Resolved = true, Flags = DependencyTreeFlags.PackageDependency.Union(ProjectTreeFlags.BrokenReference) // to see if unresolved is fixed }; var packageDependency = new TestDependency { Id = packageName, ProviderType = PackageRuleHandler.ProviderTypeString, Flags = DependencyTreeFlags.PackageDependency, Resolved = true }; var builder = new IDependency[] { packageDependency, sdkDependency }.ToDictionary(IDependencyExtensions.GetDependencyId); var context = new AddDependencyContext(builder); var filter = new SdkAndPackagesDependenciesSnapshotFilter(); filter.BeforeAddOrUpdate( 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.GetDependencyId(), out IDependency sdkDependencyAfter)); DependencyAssert.Equal( sdkDependency.ToResolved(schemaName: ResolvedSdkReference.SchemaName, diagnosticLevel: DiagnosticLevel.None), sdkDependencyAfter); }
public void BeforeAddOrUpdate_WhenSdk_ShouldFindMatchingPackageAndSetProperties() { const string sdkName = "sdkName"; var sdkDependency = new TestDependency { Id = sdkName, ProviderType = SdkRuleHandler.ProviderTypeString, Resolved = false, Flags = DependencyTreeFlags.SdkDependency }; var packageDependency = new TestDependency { Id = sdkName, ProviderType = PackageRuleHandler.ProviderTypeString, Resolved = true, Flags = DependencyTreeFlags.PackageDependency }; var builder = new IDependency[] { sdkDependency, packageDependency }.ToDictionary(IDependencyExtensions.GetDependencyId); var context = new AddDependencyContext(builder); var filter = new SdkAndPackagesDependenciesSnapshotFilter(); filter.BeforeAddOrUpdate( sdkDependency, context); var acceptedDependency = context.GetResult(filter); // Dependency should be accepted, but converted to resolved state Assert.NotNull(acceptedDependency); Assert.NotSame(sdkDependency, acceptedDependency); DependencyAssert.Equal( sdkDependency.ToResolved(schemaName: ResolvedSdkReference.SchemaName, diagnosticLevel: DiagnosticLevel.None), acceptedDependency !); // No changes other than the filtered dependency Assert.False(context.Changed); }