Skip to content

Commit

Permalink
Fixed: Unit Test for NuGet Security Policy Migration
Browse files Browse the repository at this point in the history
  • Loading branch information
Sewer56 committed Jun 11, 2022
1 parent 4fd8997 commit 484e4f8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@ public void Migrate_MigratesNuSpecIntoMainConfig()
}

[Fact]
public void GetResolver_RespectsMainConfigUrls()
public void GetResolver_UsesMainConfigUrls_BeforeSecurityPolicyMigrationDate()
{
// Arrange
var mod = _testEnvironmoent.TestModConfigATuple;

// Act
var resolverFactory = new NuGetUpdateResolverFactory();
NuGetUpdateResolverFactory.SetNowTime(NuGetUpdateResolverFactory.MigrationDate.AddMinutes(-1));
var resolvers = (AggregatePackageResolver) resolverFactory.GetResolver(mod, null, new UpdaterData(new List<string>() { "Sample NuGet Feed" }, new CommonPackageResolverSettings()));

// Assert
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class NuGetUpdateResolverFactory : IUpdateResolverFactory
/// <summary>
/// Today's date and time.
/// </summary>
public static readonly DateTime Now = DateTime.UtcNow;
public static DateTime Now { get; private set; } = DateTime.UtcNow;

/// <summary>
/// Date of migration to new security policy disallowing NuGet packages from unknown sources by default.
Expand Down Expand Up @@ -161,4 +161,10 @@ public class NuGetConfig : IConfig<NuGetConfig>
"Right click to add and remove items.")]
public ObservableCollection<StringWrapper> DefaultRepositoryUrls { get; set; } = new ObservableCollection<StringWrapper>();
}

/// <summary>
/// [Test use only. Sets the new time to use as 'now' in the program]
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public static void SetNowTime(DateTime newNowTime) => Now = newNowTime;
}

0 comments on commit 484e4f8

Please sign in to comment.