Skip to content
This repository has been archived by the owner on Jul 30, 2024. It is now read-only.
/ NuGet.Jobs Public archive

Commit

Permalink
Remove InternalsVisibleTo
Browse files Browse the repository at this point in the history
  • Loading branch information
chenriksson committed Aug 3, 2018
1 parent 8c03cf5 commit 96c33f0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 19 deletions.
13 changes: 12 additions & 1 deletion src/NuGet.Jobs.Common/JobBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,17 @@ private async Task TestConnection(string name, ISqlConnectionFactory connectionF
}
}

public SqlConnectionStringBuilder GetDatabaseRegistration<T>()
where T : IDbConfiguration
{
if (SqlConnectionFactories.TryGetValue(GetDatabaseKey<T>(), out var connectionFactory))
{
return ((AzureSqlConnectionFactory)connectionFactory).SqlConnectionStringBuilder;
}

return null;
}

/// <summary>
/// Initializes an <see cref="ISqlConnectionFactory"/>, for use by validation jobs.
/// </summary>
Expand Down Expand Up @@ -154,7 +165,7 @@ private SqlConnectionStringBuilder RegisterDatabase(
return connectionFactory.SqlConnectionStringBuilder;
}

internal static string GetDatabaseKey<T>()
private static string GetDatabaseKey<T>()
{
return typeof(T).Name;
}
Expand Down
6 changes: 0 additions & 6 deletions src/NuGet.Jobs.Common/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,3 @@
[assembly: AssemblyCopyright("Copyright © .NET Foundation 2015")]
[assembly: ComVisible(false)]
[assembly: Guid("6dc01e18-81b0-49b4-9976-4a3548c6a959")]

#if SIGNED_BUILD
[assembly: InternalsVisibleTo("NuGet.Jobs.Common.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")]
#else
[assembly: InternalsVisibleTo("NuGet.Jobs.Common.Tests")]
#endif
38 changes: 26 additions & 12 deletions tests/NuGet.Jobs.Common.Tests/JobBaseFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,6 @@ public class JobBaseFacts
private const string DefaultValidationDbConnectionString =
"Data Source=(localdb)\\mssqllocaldb; Initial Catalog=Validation; Integrated Security=True; MultipleActiveResultSets=True";

public class TheGetDatabaseKeyMethod
{
[Fact]
public void UsesDistinctCacheKeys()
{
var galleryKey = JobBase.GetDatabaseKey<GalleryDbConfiguration>();
var validationKey = JobBase.GetDatabaseKey<ValidationDbConfiguration>();

Assert.NotEqual(galleryKey, validationKey);
}
}

public class TheRegisterDatabaseMethod
{
[Fact]
Expand Down Expand Up @@ -66,6 +54,32 @@ private void ReturnsConnectionStringBuilder_ValidationDb()
Assert.Equal("(localdb)\\mssqllocaldb", csBuilder.DataSource);
Assert.Equal("Validation", csBuilder.InitialCatalog);
}

[Fact]
private void DoesNotOverriteRegistrations()
{
// Arrange
var job = new TestJob();

// Act
job.RegisterDatabase<GalleryDbConfiguration>(
job.ServiceContainer,
testConnection: false);

job.RegisterDatabase<ValidationDbConfiguration>(
job.ServiceContainer,
testConnection: false);

// Assert
var galleryDb = job.GetDatabaseRegistration<GalleryDbConfiguration>();
var validationDb = job.GetDatabaseRegistration<ValidationDbConfiguration>();

Assert.NotNull(galleryDb);
Assert.Equal("NuGetGallery", galleryDb.InitialCatalog);

Assert.NotNull(validationDb);
Assert.Equal("Validation", validationDb.InitialCatalog);
}
}

public class TestJob : JobBase
Expand Down

0 comments on commit 96c33f0

Please sign in to comment.