diff --git a/src/CopyAzureContainer/CopyAzureContainer.csproj b/src/CopyAzureContainer/CopyAzureContainer.csproj index a1781bf5c..d460d4776 100644 --- a/src/CopyAzureContainer/CopyAzureContainer.csproj +++ b/src/CopyAzureContainer/CopyAzureContainer.csproj @@ -59,9 +59,6 @@ - - 1.0.0 - 4.0.11 diff --git a/src/Gallery.CredentialExpiration/Configuration/InitializationConfiguration.cs b/src/Gallery.CredentialExpiration/Configuration/InitializationConfiguration.cs index d1f870222..e63b04db4 100644 --- a/src/Gallery.CredentialExpiration/Configuration/InitializationConfiguration.cs +++ b/src/Gallery.CredentialExpiration/Configuration/InitializationConfiguration.cs @@ -1,9 +1,11 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using NuGet.Jobs.Configuration; + namespace Gallery.CredentialExpiration { - public class InitializationConfiguration + public class InitializationConfiguration : MessageServiceConfiguration { public string ContainerName { get; set; } diff --git a/src/Gallery.CredentialExpiration/Gallery.CredentialExpiration.csproj b/src/Gallery.CredentialExpiration/Gallery.CredentialExpiration.csproj index 11a191f4e..a92140af7 100644 --- a/src/Gallery.CredentialExpiration/Gallery.CredentialExpiration.csproj +++ b/src/Gallery.CredentialExpiration/Gallery.CredentialExpiration.csproj @@ -102,11 +102,8 @@ 9.0.1 - - 2.39.0 - - 2.1.3 + 2.46.0 4.3.3 diff --git a/src/Gallery.CredentialExpiration/Job.cs b/src/Gallery.CredentialExpiration/Job.cs index 4cd6d4b3d..ec1e0c26c 100644 --- a/src/Gallery.CredentialExpiration/Job.cs +++ b/src/Gallery.CredentialExpiration/Job.cs @@ -45,12 +45,18 @@ public override void Init(IServiceContainer serviceContainer, IDictionary()); - EmailService = new AsynchronousEmailMessageService(enqueuer, LoggerFactory.CreateLogger()); + EmailService = new AsynchronousEmailMessageService( + enqueuer, + LoggerFactory.CreateLogger(), + InitializationConfiguration); FromAddress = new MailAddress(InitializationConfiguration.MailFrom); var storageAccount = CloudStorageAccount.Parse(InitializationConfiguration.DataStorageAccount); - var storageFactory = new AzureStorageFactory(storageAccount, InitializationConfiguration.ContainerName, LoggerFactory); + var storageFactory = new AzureStorageFactory( + storageAccount, + InitializationConfiguration.ContainerName, + LoggerFactory.CreateLogger()); Storage = storageFactory.Create(); } @@ -120,7 +126,11 @@ public override async Task Run() string json = JsonConvert.SerializeObject(newCursor); var content = new StringStorageContent(json, "application/json"); - await Storage.Save(Storage.ResolveUri(_cursorFile), content, CancellationToken.None); + await Storage.Save( + Storage.ResolveUri(_cursorFile), + content, + overwrite: true, + cancellationToken: CancellationToken.None); } } diff --git a/src/Gallery.Maintenance/Gallery.Maintenance.csproj b/src/Gallery.Maintenance/Gallery.Maintenance.csproj index 02574e4fb..50fc47d67 100644 --- a/src/Gallery.Maintenance/Gallery.Maintenance.csproj +++ b/src/Gallery.Maintenance/Gallery.Maintenance.csproj @@ -69,9 +69,6 @@ runtime; build; native; contentfiles; analyzers all - - 1.0.0 - 9.0.1 diff --git a/src/NuGet.Jobs.Common/Configuration/MessageServiceConfiguration.cs b/src/NuGet.Jobs.Common/Configuration/MessageServiceConfiguration.cs new file mode 100644 index 000000000..d0cb2ab4a --- /dev/null +++ b/src/NuGet.Jobs.Common/Configuration/MessageServiceConfiguration.cs @@ -0,0 +1,49 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Net.Mail; +using NuGet.Services.Messaging.Email; + +namespace NuGet.Jobs.Configuration +{ + public class MessageServiceConfiguration : IMessageServiceConfiguration + { + private static readonly string DefaultMailAddress = "NuGet Gallery "; + + public string GalleryOwner { get; set; } = DefaultMailAddress; + + public string GalleryNoReplyAddress { get; set; } = DefaultMailAddress; + + MailAddress IMessageServiceConfiguration.GalleryOwner + { + get => StringToMailAddress(GalleryOwner); + set => GalleryOwner = MailAddressToString(value); + } + + MailAddress IMessageServiceConfiguration.GalleryNoReplyAddress + { + get => StringToMailAddress(GalleryNoReplyAddress); + set => GalleryNoReplyAddress = MailAddressToString(value); + } + + private static MailAddress StringToMailAddress(string input) + { + if (input == null) + { + return null; + } + + return new MailAddress(input); + } + + private static string MailAddressToString(MailAddress mailAddress) + { + if (mailAddress == null) + { + return null; + } + + return $"{mailAddress.DisplayName} <{mailAddress.Address}>"; + } + } +} diff --git a/src/NuGet.Jobs.Common/NuGet.Jobs.Common.csproj b/src/NuGet.Jobs.Common/NuGet.Jobs.Common.csproj index 472bef139..fb8a1d410 100644 --- a/src/NuGet.Jobs.Common/NuGet.Jobs.Common.csproj +++ b/src/NuGet.Jobs.Common/NuGet.Jobs.Common.csproj @@ -50,6 +50,7 @@ + @@ -105,13 +106,16 @@ all - 2.40.0 + 2.46.0 - 2.40.0 + 2.46.0 + + + 2.46.0 - 2.40.0 + 2.46.0 4.3.3 diff --git a/src/NuGet.Services.Revalidate/NuGet.Services.Revalidate.csproj b/src/NuGet.Services.Revalidate/NuGet.Services.Revalidate.csproj index ea66a805b..c89a5ec59 100644 --- a/src/NuGet.Services.Revalidate/NuGet.Services.Revalidate.csproj +++ b/src/NuGet.Services.Revalidate/NuGet.Services.Revalidate.csproj @@ -123,7 +123,7 @@ all - 2.40.0 + 2.46.0 diff --git a/src/NuGet.Services.Validation.Orchestrator/NuGet.Services.Validation.Orchestrator.csproj b/src/NuGet.Services.Validation.Orchestrator/NuGet.Services.Validation.Orchestrator.csproj index f37c16d5e..5d6c3afec 100644 --- a/src/NuGet.Services.Validation.Orchestrator/NuGet.Services.Validation.Orchestrator.csproj +++ b/src/NuGet.Services.Validation.Orchestrator/NuGet.Services.Validation.Orchestrator.csproj @@ -169,9 +169,6 @@ runtime; build; native; contentfiles; analyzers all - - 2.40.0 - diff --git a/src/NuGet.SupportRequests.Notifications/Configuration/InitializationConfiguration.cs b/src/NuGet.SupportRequests.Notifications/Configuration/InitializationConfiguration.cs index 0d19747f7..4659b00fc 100644 --- a/src/NuGet.SupportRequests.Notifications/Configuration/InitializationConfiguration.cs +++ b/src/NuGet.SupportRequests.Notifications/Configuration/InitializationConfiguration.cs @@ -1,9 +1,11 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using NuGet.Jobs.Configuration; + namespace NuGet.SupportRequests.Notifications { - public class InitializationConfiguration + public class InitializationConfiguration : MessageServiceConfiguration { /// /// Connection string to email publisher job's service bus. diff --git a/src/NuGet.SupportRequests.Notifications/NuGet.SupportRequests.Notifications.csproj b/src/NuGet.SupportRequests.Notifications/NuGet.SupportRequests.Notifications.csproj index 00047d83e..e21487317 100644 --- a/src/NuGet.SupportRequests.Notifications/NuGet.SupportRequests.Notifications.csproj +++ b/src/NuGet.SupportRequests.Notifications/NuGet.SupportRequests.Notifications.csproj @@ -110,9 +110,6 @@ 9.0.1 - - 2.39.0 - diff --git a/src/NuGet.SupportRequests.Notifications/Tasks/SupportRequestsNotificationScheduledTask.cs b/src/NuGet.SupportRequests.Notifications/Tasks/SupportRequestsNotificationScheduledTask.cs index 55ff0b89e..ec0c809c8 100644 --- a/src/NuGet.SupportRequests.Notifications/Tasks/SupportRequestsNotificationScheduledTask.cs +++ b/src/NuGet.SupportRequests.Notifications/Tasks/SupportRequestsNotificationScheduledTask.cs @@ -39,7 +39,10 @@ protected SupportRequestsNotificationScheduledTask( var serializer = new ServiceBusMessageSerializer(); var topicClient = new TopicClientWrapper(configuration.EmailPublisherConnectionString, configuration.EmailPublisherTopicName); var enqueuer = new EmailMessageEnqueuer(topicClient, serializer, loggerFactory.CreateLogger()); - var messageService = new AsynchronousEmailMessageService(enqueuer, loggerFactory.CreateLogger()); + var messageService = new AsynchronousEmailMessageService( + enqueuer, + loggerFactory.CreateLogger(), + configuration); _messagingService = new MessagingService(messageService, loggerFactory.CreateLogger()); _supportRequestRepository = new SupportRequestRepository(loggerFactory, openSupportRequestSqlConnectionAsync); diff --git a/src/PackageHash/PackageHash.csproj b/src/PackageHash/PackageHash.csproj index 171e8e0cc..6886d7a77 100644 --- a/src/PackageHash/PackageHash.csproj +++ b/src/PackageHash/PackageHash.csproj @@ -77,11 +77,8 @@ - - 1.1.2 - - 2.40.0 + 2.46.0 diff --git a/src/PackageLagMonitor/Monitoring.PackageLag.csproj b/src/PackageLagMonitor/Monitoring.PackageLag.csproj index 7db850ccb..81170d4c5 100644 --- a/src/PackageLagMonitor/Monitoring.PackageLag.csproj +++ b/src/PackageLagMonitor/Monitoring.PackageLag.csproj @@ -96,9 +96,6 @@ 1.1.1 - - 1.1.2 - 1.1.2 @@ -112,7 +109,7 @@ 0.5.0-CI-20180510-012541 - 2.40.0 + 2.46.0 4.3.3 diff --git a/src/Search.GenerateAuxiliaryData/Search.GenerateAuxiliaryData.csproj b/src/Search.GenerateAuxiliaryData/Search.GenerateAuxiliaryData.csproj index b73a3e1fc..26cd363b0 100644 --- a/src/Search.GenerateAuxiliaryData/Search.GenerateAuxiliaryData.csproj +++ b/src/Search.GenerateAuxiliaryData/Search.GenerateAuxiliaryData.csproj @@ -92,9 +92,6 @@ 5.7.0 - - 1.0.0 - 9.0.1 diff --git a/src/SnapshotAzureBlob/SnapshotAzureBlob.csproj b/src/SnapshotAzureBlob/SnapshotAzureBlob.csproj index 2fa5dc3df..af92f621d 100644 --- a/src/SnapshotAzureBlob/SnapshotAzureBlob.csproj +++ b/src/SnapshotAzureBlob/SnapshotAzureBlob.csproj @@ -54,9 +54,6 @@ - - 1.0.0 - 4.0.11 diff --git a/src/Stats.AggregateCdnDownloadsInGallery/Stats.AggregateCdnDownloadsInGallery.csproj b/src/Stats.AggregateCdnDownloadsInGallery/Stats.AggregateCdnDownloadsInGallery.csproj index 8e9699245..cb466c9c5 100644 --- a/src/Stats.AggregateCdnDownloadsInGallery/Stats.AggregateCdnDownloadsInGallery.csproj +++ b/src/Stats.AggregateCdnDownloadsInGallery/Stats.AggregateCdnDownloadsInGallery.csproj @@ -76,9 +76,6 @@ 5.7.0 - - 1.0.0 - 9.0.1 diff --git a/src/Stats.AzureCdnLogs.Common/Stats.AzureCdnLogs.Common.csproj b/src/Stats.AzureCdnLogs.Common/Stats.AzureCdnLogs.Common.csproj index d6f80e69b..79f2e9848 100644 --- a/src/Stats.AzureCdnLogs.Common/Stats.AzureCdnLogs.Common.csproj +++ b/src/Stats.AzureCdnLogs.Common/Stats.AzureCdnLogs.Common.csproj @@ -92,7 +92,7 @@ all - 1.0.0 + 1.1.2 9.0.1 diff --git a/src/Stats.CollectAzureCdnLogs/Stats.CollectAzureCdnLogs.csproj b/src/Stats.CollectAzureCdnLogs/Stats.CollectAzureCdnLogs.csproj index c96e6974b..84954c490 100644 --- a/src/Stats.CollectAzureCdnLogs/Stats.CollectAzureCdnLogs.csproj +++ b/src/Stats.CollectAzureCdnLogs/Stats.CollectAzureCdnLogs.csproj @@ -107,9 +107,6 @@ 5.7.0 - - 1.0.0 - 7.1.2 diff --git a/src/Stats.CollectAzureChinaCDNLogs/Stats.CollectAzureChinaCDNLogs.csproj b/src/Stats.CollectAzureChinaCDNLogs/Stats.CollectAzureChinaCDNLogs.csproj index c2e867581..783403ae6 100644 --- a/src/Stats.CollectAzureChinaCDNLogs/Stats.CollectAzureChinaCDNLogs.csproj +++ b/src/Stats.CollectAzureChinaCDNLogs/Stats.CollectAzureChinaCDNLogs.csproj @@ -83,9 +83,6 @@ 5.7.0 - - 1.0.0 - 7.1.2 diff --git a/src/Stats.CreateAzureCdnWarehouseReports/Stats.CreateAzureCdnWarehouseReports.csproj b/src/Stats.CreateAzureCdnWarehouseReports/Stats.CreateAzureCdnWarehouseReports.csproj index 251ac11a1..30688e24a 100644 --- a/src/Stats.CreateAzureCdnWarehouseReports/Stats.CreateAzureCdnWarehouseReports.csproj +++ b/src/Stats.CreateAzureCdnWarehouseReports/Stats.CreateAzureCdnWarehouseReports.csproj @@ -92,12 +92,6 @@ 5.7.0 - - 1.0.0 - - - 1.0.0 - 9.0.1 diff --git a/src/Stats.ImportAzureCdnStatistics/Stats.ImportAzureCdnStatistics.csproj b/src/Stats.ImportAzureCdnStatistics/Stats.ImportAzureCdnStatistics.csproj index ca430c87d..bc51cd540 100644 --- a/src/Stats.ImportAzureCdnStatistics/Stats.ImportAzureCdnStatistics.csproj +++ b/src/Stats.ImportAzureCdnStatistics/Stats.ImportAzureCdnStatistics.csproj @@ -120,12 +120,6 @@ 5.7.0 - - 1.0.0 - - - 1.0.0 - 4.3.0-preview1-2524 diff --git a/src/Stats.RefreshClientDimension/Stats.RefreshClientDimension.csproj b/src/Stats.RefreshClientDimension/Stats.RefreshClientDimension.csproj index 009f6564b..518ecef29 100644 --- a/src/Stats.RefreshClientDimension/Stats.RefreshClientDimension.csproj +++ b/src/Stats.RefreshClientDimension/Stats.RefreshClientDimension.csproj @@ -77,9 +77,6 @@ - - 1.0.0 - 9.0.1 diff --git a/src/Stats.RollUpDownloadFacts/Stats.RollUpDownloadFacts.csproj b/src/Stats.RollUpDownloadFacts/Stats.RollUpDownloadFacts.csproj index f7c43281c..b4b4497c2 100644 --- a/src/Stats.RollUpDownloadFacts/Stats.RollUpDownloadFacts.csproj +++ b/src/Stats.RollUpDownloadFacts/Stats.RollUpDownloadFacts.csproj @@ -79,12 +79,6 @@ 5.7.0 - - 1.0.0 - - - 1.0.0 - 0.3.0 runtime; build; native; contentfiles; analyzers diff --git a/src/StatusAggregator/StatusAggregator.csproj b/src/StatusAggregator/StatusAggregator.csproj index d63eaeef5..75abbf37b 100644 --- a/src/StatusAggregator/StatusAggregator.csproj +++ b/src/StatusAggregator/StatusAggregator.csproj @@ -157,13 +157,13 @@ 1.1.1 - 2.40.0 + 2.46.0 - 2.40.0 + 2.46.0 - 2.40.0 + 2.46.0 9.2.0 diff --git a/src/UpdateLicenseReports/UpdateLicenseReports.csproj b/src/UpdateLicenseReports/UpdateLicenseReports.csproj index d6c476a75..2bfa519e0 100644 --- a/src/UpdateLicenseReports/UpdateLicenseReports.csproj +++ b/src/UpdateLicenseReports/UpdateLicenseReports.csproj @@ -73,9 +73,6 @@ 1.50.2 - - 1.0.0 - 9.0.1 diff --git a/src/Validation.Common.Job/Validation.Common.Job.csproj b/src/Validation.Common.Job/Validation.Common.Job.csproj index d7bc7594d..d55f5d016 100644 --- a/src/Validation.Common.Job/Validation.Common.Job.csproj +++ b/src/Validation.Common.Job/Validation.Common.Job.csproj @@ -104,19 +104,19 @@ 5.0.0-preview1.5707 - 2.44.0 + 2.46.0 - 2.44.0 + 2.46.0 - 2.44.0 + 2.46.0 - 2.44.0 + 2.46.0 - 4.4.5-dev-2323501 + 4.4.5-dev-2571542 2.5.0 diff --git a/src/Validation.ScanAndSign.Core/Validation.ScanAndSign.Core.csproj b/src/Validation.ScanAndSign.Core/Validation.ScanAndSign.Core.csproj index 4ab76c755..64eb4bae3 100644 --- a/src/Validation.ScanAndSign.Core/Validation.ScanAndSign.Core.csproj +++ b/src/Validation.ScanAndSign.Core/Validation.ScanAndSign.Core.csproj @@ -64,7 +64,7 @@ all - 2.40.0 + 2.46.0 0.3.0 diff --git a/tests/NuGet.Jobs.Common.Tests/Configuration/MessageServiceConfigurationFacts.cs b/tests/NuGet.Jobs.Common.Tests/Configuration/MessageServiceConfigurationFacts.cs new file mode 100644 index 000000000..ff5a26e40 --- /dev/null +++ b/tests/NuGet.Jobs.Common.Tests/Configuration/MessageServiceConfigurationFacts.cs @@ -0,0 +1,47 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Net.Mail; +using NuGet.Jobs.Configuration; +using NuGet.Services.Messaging.Email; +using Xunit; + +namespace NuGet.Jobs.Common.Tests.Configuration +{ + public class MessageServiceConfigurationFacts + { + public MessageServiceConfigurationFacts() + { + Target = new MessageServiceConfiguration(); + } + + public MessageServiceConfiguration Target { get; } + + [Fact] + public void ParsesStringToMailAddress() + { + Target.GalleryOwner = "Test Person "; + + var casted = (IMessageServiceConfiguration)Target; + Assert.Equal("Test Person", casted.GalleryOwner.DisplayName); + Assert.Equal("me@example.com", casted.GalleryOwner.Address); + } + + [Fact] + public void ParsesMailAddressToString() + { + var casted = (IMessageServiceConfiguration)Target; + + casted.GalleryOwner = new MailAddress("me@example.com", "Test Person"); + + Assert.Equal("Test Person ", Target.GalleryOwner); + } + + [Fact] + public void MailAddressesHaveDefaultValue() + { + Assert.Equal("NuGet Gallery ", Target.GalleryOwner); + Assert.Equal("NuGet Gallery ", Target.GalleryNoReplyAddress); + } + } +} diff --git a/tests/NuGet.Jobs.Common.Tests/NuGet.Jobs.Common.Tests.csproj b/tests/NuGet.Jobs.Common.Tests/NuGet.Jobs.Common.Tests.csproj index 8331c5a89..fb19b711c 100644 --- a/tests/NuGet.Jobs.Common.Tests/NuGet.Jobs.Common.Tests.csproj +++ b/tests/NuGet.Jobs.Common.Tests/NuGet.Jobs.Common.Tests.csproj @@ -40,6 +40,7 @@ + diff --git a/tests/NuGet.Services.Revalidate.Tests/NuGet.Services.Revalidate.Tests.csproj b/tests/NuGet.Services.Revalidate.Tests/NuGet.Services.Revalidate.Tests.csproj index 6d80b1611..d91c9bae0 100644 --- a/tests/NuGet.Services.Revalidate.Tests/NuGet.Services.Revalidate.Tests.csproj +++ b/tests/NuGet.Services.Revalidate.Tests/NuGet.Services.Revalidate.Tests.csproj @@ -45,9 +45,6 @@ 6.1.3 - - 1.1.2 - 4.7.145 diff --git a/tests/NuGet.Services.Validation.Orchestrator.Tests/NuGet.Services.Validation.Orchestrator.Tests.csproj b/tests/NuGet.Services.Validation.Orchestrator.Tests/NuGet.Services.Validation.Orchestrator.Tests.csproj index 42bd9cd5f..6ed26efab 100644 --- a/tests/NuGet.Services.Validation.Orchestrator.Tests/NuGet.Services.Validation.Orchestrator.Tests.csproj +++ b/tests/NuGet.Services.Validation.Orchestrator.Tests/NuGet.Services.Validation.Orchestrator.Tests.csproj @@ -81,9 +81,6 @@ 6.1.3 - - 1.1.2 - 4.7.145 diff --git a/tests/Tests.Gallery.Maintenance/GalleryMaintenanceJobTests.cs b/tests/Tests.Gallery.Maintenance/GalleryMaintenanceJobTests.cs index 227b6fe7c..1006013ef 100644 --- a/tests/Tests.Gallery.Maintenance/GalleryMaintenanceJobTests.cs +++ b/tests/Tests.Gallery.Maintenance/GalleryMaintenanceJobTests.cs @@ -1,4 +1,7 @@ -using Gallery.Maintenance; +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Gallery.Maintenance; using Microsoft.Extensions.Logging; using Xunit; diff --git a/tests/Tests.Gallery.Maintenance/Tests.Gallery.Maintenance.csproj b/tests/Tests.Gallery.Maintenance/Tests.Gallery.Maintenance.csproj index d557ff469..acf734e54 100644 --- a/tests/Tests.Gallery.Maintenance/Tests.Gallery.Maintenance.csproj +++ b/tests/Tests.Gallery.Maintenance/Tests.Gallery.Maintenance.csproj @@ -65,12 +65,6 @@ - - 1.0.0 - - - 1.0.0 - 2.3.1 diff --git a/tests/Tests.Search.GenerateAuxiliaryData/Tests.Search.GenerateAuxiliaryData.csproj b/tests/Tests.Search.GenerateAuxiliaryData/Tests.Search.GenerateAuxiliaryData.csproj index cc00843e1..25849a3b8 100644 --- a/tests/Tests.Search.GenerateAuxiliaryData/Tests.Search.GenerateAuxiliaryData.csproj +++ b/tests/Tests.Search.GenerateAuxiliaryData/Tests.Search.GenerateAuxiliaryData.csproj @@ -66,12 +66,6 @@ 5.7.0 - - 1.0.0 - - - 1.0.0 - 4.8.2 diff --git a/tests/Tests.Stats.ImportAzureCdnStatistics/Tests.Stats.ImportAzureCdnStatistics.csproj b/tests/Tests.Stats.ImportAzureCdnStatistics/Tests.Stats.ImportAzureCdnStatistics.csproj index ea10a18fc..2403a7253 100644 --- a/tests/Tests.Stats.ImportAzureCdnStatistics/Tests.Stats.ImportAzureCdnStatistics.csproj +++ b/tests/Tests.Stats.ImportAzureCdnStatistics/Tests.Stats.ImportAzureCdnStatistics.csproj @@ -89,12 +89,6 @@ - - 1.0.0 - - - 1.0.0 - 4.8.2 diff --git a/tests/Validation.PackageSigning.Core.Tests/Support/DbSetMockFactory.cs b/tests/Validation.PackageSigning.Core.Tests/Support/DbSetMockFactory.cs index 8aa21ea8f..418b9334b 100644 --- a/tests/Validation.PackageSigning.Core.Tests/Support/DbSetMockFactory.cs +++ b/tests/Validation.PackageSigning.Core.Tests/Support/DbSetMockFactory.cs @@ -1,28 +1,17 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.Collections.Generic; using System.Data.Entity; -using System.Linq; using Moq; +using Tests.ContextHelpers; namespace Validation.PackageSigning.Core.Tests.Support { public static class DbSetMockFactory { - public static Mock> CreateMock(params T[] sourceList) where T : class + public static Mock> CreateMock(params TEntity[] sourceList) where TEntity : class { - var list = new List(sourceList); - - var dbSet = new Mock>(); - dbSet.As>().Setup(m => m.Provider).Returns(() => new TestDbAsyncQueryProvider(list.AsQueryable().Provider)); - dbSet.As>().Setup(m => m.Expression).Returns(() => list.AsQueryable().Expression); - dbSet.As>().Setup(m => m.ElementType).Returns(() => list.AsQueryable().ElementType); - dbSet.As>().Setup(m => m.GetEnumerator()).Returns(() => list.GetEnumerator()); - dbSet.Setup(m => m.Add(It.IsAny())).Callback(e => list.Add(e)); - dbSet.Setup(m => m.Remove(It.IsAny())).Callback(e => list.Remove(e)); - - return dbSet; + return new Mock>().SetupDbSet(sourceList); } public static IDbSet Create(params T[] sourceList) where T : class diff --git a/tests/Validation.PackageSigning.Core.Tests/Support/TestDbAsyncEnumerable.cs b/tests/Validation.PackageSigning.Core.Tests/Support/TestDbAsyncEnumerable.cs deleted file mode 100644 index fac682d6e..000000000 --- a/tests/Validation.PackageSigning.Core.Tests/Support/TestDbAsyncEnumerable.cs +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Collections.Generic; -using System.Data.Entity.Infrastructure; -using System.Linq; -using System.Linq.Expressions; - -namespace Validation.PackageSigning.Core.Tests.Support -{ - /// - /// Source: https://msdn.microsoft.com/en-us/data/dn314429 - /// - public class TestDbAsyncEnumerable : EnumerableQuery, IDbAsyncEnumerable, IQueryable - { - public TestDbAsyncEnumerable(IEnumerable enumerable) : base(enumerable) - { - } - - public TestDbAsyncEnumerable(Expression expression) : base(expression) - { - } - - public IDbAsyncEnumerator GetAsyncEnumerator() - { - return new TestDbAsyncEnumerator(this.AsEnumerable().GetEnumerator()); - } - - IDbAsyncEnumerator IDbAsyncEnumerable.GetAsyncEnumerator() - { - return GetAsyncEnumerator(); - } - - IQueryProvider IQueryable.Provider - { - get { return new TestDbAsyncQueryProvider(this); } - } - } -} \ No newline at end of file diff --git a/tests/Validation.PackageSigning.Core.Tests/Support/TestDbAsyncEnumerator.cs b/tests/Validation.PackageSigning.Core.Tests/Support/TestDbAsyncEnumerator.cs deleted file mode 100644 index d20f61e84..000000000 --- a/tests/Validation.PackageSigning.Core.Tests/Support/TestDbAsyncEnumerator.cs +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Collections.Generic; -using System.Data.Entity.Infrastructure; -using System.Threading; -using System.Threading.Tasks; - -namespace Validation.PackageSigning.Core.Tests.Support -{ - /// - /// Source: https://msdn.microsoft.com/en-us/data/dn314429 - /// - public class TestDbAsyncEnumerator : IDbAsyncEnumerator - { - private readonly IEnumerator _inner; - - public TestDbAsyncEnumerator(IEnumerator inner) - { - _inner = inner; - } - - public void Dispose() - { - _inner.Dispose(); - } - - public Task MoveNextAsync(CancellationToken cancellationToken) - { - return Task.FromResult(_inner.MoveNext()); - } - - public T Current - { - get { return _inner.Current; } - } - - object IDbAsyncEnumerator.Current - { - get { return Current; } - } - } -} \ No newline at end of file diff --git a/tests/Validation.PackageSigning.Core.Tests/Support/TestDbAsyncQueryProvider.cs b/tests/Validation.PackageSigning.Core.Tests/Support/TestDbAsyncQueryProvider.cs deleted file mode 100644 index e6f2f3cd0..000000000 --- a/tests/Validation.PackageSigning.Core.Tests/Support/TestDbAsyncQueryProvider.cs +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Data.Entity.Infrastructure; -using System.Linq; -using System.Linq.Expressions; -using System.Threading; -using System.Threading.Tasks; - -namespace Validation.PackageSigning.Core.Tests.Support -{ - /// - /// Source: https://msdn.microsoft.com/en-us/data/dn314429 - /// - public class TestDbAsyncQueryProvider : IDbAsyncQueryProvider - { - private readonly IQueryProvider _inner; - - internal TestDbAsyncQueryProvider(IQueryProvider inner) - { - _inner = inner; - } - - public IQueryable CreateQuery(Expression expression) - { - return new TestDbAsyncEnumerable(expression); - } - - public IQueryable CreateQuery(Expression expression) - { - return new TestDbAsyncEnumerable(expression); - } - - public object Execute(Expression expression) - { - return _inner.Execute(expression); - } - - public TResult Execute(Expression expression) - { - return _inner.Execute(expression); - } - - public Task ExecuteAsync(Expression expression, CancellationToken cancellationToken) - { - return Task.FromResult(Execute(expression)); - } - - public Task ExecuteAsync(Expression expression, CancellationToken cancellationToken) - { - return Task.FromResult(Execute(expression)); - } - } -} \ No newline at end of file diff --git a/tests/Validation.PackageSigning.Core.Tests/Validation.PackageSigning.Core.Tests.csproj b/tests/Validation.PackageSigning.Core.Tests/Validation.PackageSigning.Core.Tests.csproj index 10294e475..f0a07d89b 100644 --- a/tests/Validation.PackageSigning.Core.Tests/Validation.PackageSigning.Core.Tests.csproj +++ b/tests/Validation.PackageSigning.Core.Tests/Validation.PackageSigning.Core.Tests.csproj @@ -45,9 +45,6 @@ - - - @@ -63,6 +60,10 @@ {91c060da-736f-4da9-a57f-cb3ac0e6cb10} Validation.PackageSigning.Core + + {2c5be067-adfd-49e3-ba9f-13a74436e5db} + Tests.ContextHelpers + diff --git a/tests/Validation.PackageSigning.Helpers/ContextExtensions.cs b/tests/Validation.PackageSigning.Helpers/ContextExtensions.cs index 2818beea5..38888746f 100644 --- a/tests/Validation.PackageSigning.Helpers/ContextExtensions.cs +++ b/tests/Validation.PackageSigning.Helpers/ContextExtensions.cs @@ -19,16 +19,19 @@ public static class ContextExtensions { public static void Mock( this Mock context, - Mock> packageRegistrationsMock = null, - Mock> packageDependenciesMock = null, - Mock> packagesMock = null, + Mock> packageRegistrationsMock = null, + Mock> packageDependenciesMock = null, + Mock> packagesMock = null, + Mock> certificatesMock = null, IEnumerable packageRegistrations = null, IEnumerable packageDependencies = null, - IEnumerable packages = null) + IEnumerable packages = null, + IEnumerable certificates = null) { context.SetupDbSet(c => c.PackageRegistrations, packageRegistrationsMock, packageRegistrations); context.SetupDbSet(c => c.Set(), packageDependenciesMock, packageDependencies); context.SetupDbSet(c => c.Set(), packagesMock, packages); + context.SetupDbSet(c => c.Certificates, certificatesMock, certificates); } public static void Mock( @@ -40,13 +43,17 @@ public static void Mock( Mock> endCertificatesMock = null, Mock> certificateValidationsMock = null, Mock> packageRevalidationsMock = null, + Mock> parentCertificatesMock = null, + Mock> certificateChainLinksMock = null, IEnumerable validatorStatuses = null, IEnumerable packageSigningStates = null, IEnumerable packageSignatures = null, IEnumerable trustedTimestamps = null, IEnumerable endCertificates = null, IEnumerable certificateValidations = null, - IEnumerable packageRevalidations = null) + IEnumerable packageRevalidations = null, + IEnumerable parentCertificates = null, + IEnumerable certificateChainLinks = null) { validationContext.SetupDbSet(c => c.ValidatorStatuses, validatorStatusesMock, validatorStatuses); validationContext.SetupDbSet(c => c.PackageSigningStates, packageSigningStatesMock, packageSigningStates); @@ -55,17 +62,30 @@ public static void Mock( validationContext.SetupDbSet(c => c.EndCertificates, endCertificatesMock, endCertificates); validationContext.SetupDbSet(c => c.CertificateValidations, certificateValidationsMock, certificateValidations); validationContext.SetupDbSet(c => c.PackageRevalidations, packageRevalidationsMock, packageRevalidations); + validationContext.SetupDbSet(c => c.ParentCertificates, parentCertificatesMock, parentCertificates); + validationContext.SetupDbSet(c => c.CertificateChainLinks, certificateChainLinksMock, certificateChainLinks); } - private static void SetupDbSet( + public static void SetupDbSet( this Mock validationContext, - Expression>> dbSetAccessor, - Mock> dbSet, + Expression> dbSetAccessor, + Mock dbSet, IEnumerable dataEnumerable) where TContext : class + where TDbSet : class, IDbSet where TEntity : class { - dbSet = dbSet ?? new Mock>(); + dbSet = SetupDbSet(dbSet, dataEnumerable); + validationContext.Setup(dbSetAccessor).Returns(dbSet.Object); + } + + public static Mock SetupDbSet( + this Mock dbSet, + IEnumerable dataEnumerable) + where TDbSet : class, IDbSet + where TEntity : class + { + dbSet = dbSet ?? new Mock(); dataEnumerable = dataEnumerable ?? new TEntity[0]; var data = dataEnumerable.AsQueryable(); @@ -92,7 +112,7 @@ private static void SetupDbSet( dbSet.As>().Setup(m => m.ElementType).Returns(() => data.ElementType); dbSet.As>().Setup(m => m.GetEnumerator()).Returns(() => data.GetEnumerator()); - validationContext.Setup(dbSetAccessor).Returns(dbSet.Object); + return dbSet; } } } diff --git a/tests/Validation.PackageSigning.Helpers/TestDbAsyncQueryProvider.cs b/tests/Validation.PackageSigning.Helpers/TestDbAsyncQueryProvider.cs index e1134cd39..f4bac1a4a 100644 --- a/tests/Validation.PackageSigning.Helpers/TestDbAsyncQueryProvider.cs +++ b/tests/Validation.PackageSigning.Helpers/TestDbAsyncQueryProvider.cs @@ -11,11 +11,11 @@ namespace Tests.ContextHelpers { // Copied from https://msdn.microsoft.com/en-us/library/dn314429.aspx - internal class TestDbAsyncQueryProvider : IDbAsyncQueryProvider + public class TestDbAsyncQueryProvider : IDbAsyncQueryProvider { private readonly IQueryProvider _inner; - internal TestDbAsyncQueryProvider(IQueryProvider inner) + public TestDbAsyncQueryProvider(IQueryProvider inner) { _inner = inner; } @@ -51,7 +51,7 @@ public Task ExecuteAsync(Expression expression, CancellationTo } } - internal class TestDbAsyncEnumerable : EnumerableQuery, IDbAsyncEnumerable, IQueryable + public class TestDbAsyncEnumerable : EnumerableQuery, IDbAsyncEnumerable, IQueryable { public TestDbAsyncEnumerable(IEnumerable enumerable) : base(enumerable) @@ -77,7 +77,7 @@ IQueryProvider IQueryable.Provider } } - internal class TestDbAsyncEnumerator : IDbAsyncEnumerator + public class TestDbAsyncEnumerator : IDbAsyncEnumerator { private readonly IEnumerator _inner; diff --git a/tests/Validation.PackageSigning.ProcessSignature.Tests/SignaturePartsExtractorFacts.cs b/tests/Validation.PackageSigning.ProcessSignature.Tests/SignaturePartsExtractorFacts.cs index c7254bf13..1e8913055 100644 --- a/tests/Validation.PackageSigning.ProcessSignature.Tests/SignaturePartsExtractorFacts.cs +++ b/tests/Validation.PackageSigning.ProcessSignature.Tests/SignaturePartsExtractorFacts.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Data.Entity; using System.IO; using System.Linq; using System.Security.Cryptography.Pkcs; @@ -21,6 +22,7 @@ using NuGetGallery; using Org.BouncyCastle.Cms; using Org.BouncyCastle.X509.Store; +using Tests.ContextHelpers; using Validation.PackageSigning.Core.Tests.Support; using Xunit; @@ -146,26 +148,10 @@ public ExtractAsync() .Callback((cert, _) => _savedCertificates.Add(new X509Certificate2(cert.RawData))); _validationEntitiesContext = new Mock(); - _validationEntitiesContext - .Setup(x => x.ParentCertificates) - .Returns(DbSetMockFactory.Create()); - _validationEntitiesContext - .Setup(x => x.EndCertificates) - .Returns(DbSetMockFactory.Create()); - _validationEntitiesContext - .Setup(x => x.CertificateChainLinks) - .Returns(DbSetMockFactory.Create()); - _validationEntitiesContext - .Setup(x => x.PackageSignatures) - .Returns(DbSetMockFactory.Create()); - _validationEntitiesContext - .Setup(x => x.TrustedTimestamps) - .Returns(DbSetMockFactory.Create()); + _validationEntitiesContext.Mock(); _galleryEntitiesContext = new Mock(); - _galleryEntitiesContext - .Setup(x => x.Certificates) - .Returns(DbSetMockFactory.Create()); + _galleryEntitiesContext.Mock(); _configAccessor = new Mock>(); _config = new ProcessSignatureConfiguration diff --git a/tests/Validation.PackageSigning.ProcessSignature.Tests/SignatureValidatorIntegrationTests.cs b/tests/Validation.PackageSigning.ProcessSignature.Tests/SignatureValidatorIntegrationTests.cs index 6bf86c2f6..4bb46876a 100644 --- a/tests/Validation.PackageSigning.ProcessSignature.Tests/SignatureValidatorIntegrationTests.cs +++ b/tests/Validation.PackageSigning.ProcessSignature.Tests/SignatureValidatorIntegrationTests.cs @@ -29,6 +29,7 @@ using NuGet.Services.Validation.Issues; using NuGetGallery; using Test.Utility.Signing; +using Tests.ContextHelpers; using Validation.PackageSigning.Core.Tests.Support; using Xunit; using Xunit.Abstractions; @@ -93,29 +94,10 @@ public SignatureValidatorIntegrationTests(CertificateIntegrationTestFixture fixt _output = output ?? throw new ArgumentNullException(nameof(output)); _validationEntitiesContext = new Mock(); - _validationEntitiesContext - .Setup(x => x.PackageSigningStates) - .Returns(DbSetMockFactory.Create()); - _validationEntitiesContext - .Setup(x => x.ParentCertificates) - .Returns(DbSetMockFactory.Create()); - _validationEntitiesContext - .Setup(x => x.EndCertificates) - .Returns(DbSetMockFactory.Create()); - _validationEntitiesContext - .Setup(x => x.CertificateChainLinks) - .Returns(DbSetMockFactory.Create()); - _validationEntitiesContext - .Setup(x => x.PackageSignatures) - .Returns(DbSetMockFactory.Create()); - _validationEntitiesContext - .Setup(x => x.TrustedTimestamps) - .Returns(DbSetMockFactory.Create()); + _validationEntitiesContext.Mock(); _galleryEntitiesContext = new Mock(); - _galleryEntitiesContext - .Setup(x => x.Certificates) - .Returns(DbSetMockFactory.Create()); + _galleryEntitiesContext.Mock(); var loggerFactory = new LoggerFactory(); loggerFactory.AddXunit(output); diff --git a/tests/Validation.PackageSigning.ProcessSignature.Tests/Validation.PackageSigning.ProcessSignature.Tests.csproj b/tests/Validation.PackageSigning.ProcessSignature.Tests/Validation.PackageSigning.ProcessSignature.Tests.csproj index d456f3b94..105229242 100644 --- a/tests/Validation.PackageSigning.ProcessSignature.Tests/Validation.PackageSigning.ProcessSignature.Tests.csproj +++ b/tests/Validation.PackageSigning.ProcessSignature.Tests/Validation.PackageSigning.ProcessSignature.Tests.csproj @@ -53,9 +53,6 @@ - - 1.1.2 - 4.7.145 @@ -89,6 +86,10 @@ {b4b7564a-965b-447b-927f-6749e2c08880} Validation.PackageSigning.Core.Tests + + {2c5be067-adfd-49e3-ba9f-13a74436e5db} + Tests.ContextHelpers + diff --git a/tests/Validation.PackageSigning.RevalidateCertificate.Tests/Validation.PackageSigning.RevalidateCertificate.Tests.csproj b/tests/Validation.PackageSigning.RevalidateCertificate.Tests/Validation.PackageSigning.RevalidateCertificate.Tests.csproj index 45cf07f79..97db21444 100644 --- a/tests/Validation.PackageSigning.RevalidateCertificate.Tests/Validation.PackageSigning.RevalidateCertificate.Tests.csproj +++ b/tests/Validation.PackageSigning.RevalidateCertificate.Tests/Validation.PackageSigning.RevalidateCertificate.Tests.csproj @@ -41,9 +41,6 @@ - - 1.1.2 - 4.7.145 diff --git a/tests/Validation.PackageSigning.ValidateCertificate.Tests/Validation.PackageSigning.ValidateCertificate.Tests.csproj b/tests/Validation.PackageSigning.ValidateCertificate.Tests/Validation.PackageSigning.ValidateCertificate.Tests.csproj index 441fb1dfd..9075a79c6 100644 --- a/tests/Validation.PackageSigning.ValidateCertificate.Tests/Validation.PackageSigning.ValidateCertificate.Tests.csproj +++ b/tests/Validation.PackageSigning.ValidateCertificate.Tests/Validation.PackageSigning.ValidateCertificate.Tests.csproj @@ -73,9 +73,6 @@ - - 1.1.2 - 4.7.145