Skip to content

Commit

Permalink
SendValidationTakingTooLongNotice method with tests (#5402)
Browse files Browse the repository at this point in the history
* Added SendValidationTakingTooLongNotice method and tests.

* Updated with the new message

* Removed the signature from the validation taking too long message.
Removed the unused argument from the `SendValidationTakingTooLongNotice` method
  • Loading branch information
agr authored Feb 6, 2018
1 parent 743616f commit 93d5307
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/NuGetGallery.Core/Services/CoreMessageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,44 @@ public void SendSignedPackageNotAllowedNotice(Package package, string packageUrl
}
}

public void SendValidationTakingTooLongNotice(Package package, string packageUrl)
{
string subject = "[{0}] Package validation taking longer than expected - {1} {2}";
string body = "It is taking longer than expected for your package [{1} {2}]({3}) to get published.\n\n" +
"We are looking into it and there is no action on you at this time. We’ll send you an email notification when your package has been published.\n\n" +
"Thank you for your patience.";

body = string.Format(
CultureInfo.CurrentCulture,
body,
CoreConfiguration.GalleryOwner.DisplayName,
package.PackageRegistration.Id,
package.Version,
packageUrl);

subject = string.Format(
CultureInfo.CurrentCulture,
subject,
CoreConfiguration.GalleryOwner.DisplayName,
package.PackageRegistration.Id,
package.Version);

using (var mailMessage = new MailMessage())
{
mailMessage.Subject = subject;
mailMessage.Body = body;
mailMessage.From = CoreConfiguration.GalleryNoReplyAddress;

AddAllOwnersToMailMessage(package.PackageRegistration, mailMessage);

if (mailMessage.To.Any())
{
SendMessage(mailMessage, copySender: false);
}
}
}


protected static void AddAllOwnersToMailMessage(PackageRegistration packageRegistration, MailMessage mailMessage)
{
foreach (var owner in packageRegistration.Owners)
Expand Down
1 change: 1 addition & 0 deletions src/NuGetGallery.Core/Services/ICoreMessageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ public interface ICoreMessageService
void SendPackageAddedNotice(Package package, string packageUrl, string packageSupportUrl, string emailSettingsUrl);
void SendPackageValidationFailedNotice(Package package, string packageUrl, string packageSupportUrl);
void SendSignedPackageNotAllowedNotice(Package package, string packageUrl, string announcementsUrl, string twitterUrl);
void SendValidationTakingTooLongNotice(Package package, string packageUrl);
}
}
89 changes: 89 additions & 0 deletions tests/NuGetGallery.Facts/Services/MessageServiceFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,95 @@ public void WillSendEmailToOwnersRegardlessOfSettings(bool user1PushAllowed, boo
}
}

public class TheSendValidationTakingTooLongNoticeMethod
: TestContainer
{
[Theory]
[InlineData("1.2.3")]
[InlineData("1.2.3-alpha")]
[InlineData("1.2.3-alpha.1")]
[InlineData("1.2.3+metadata")]
[InlineData("1.2.3-alpha+metadata")]
[InlineData("1.2.3-alpha.1+metadata")]
public void WillSendEmailToAllOwners(string version)
{
// Arrange
var nugetVersion = new NuGetVersion(version);
var packageRegistration = new PackageRegistration
{
Id = "smangit",
Owners = new[]
{
new User { EmailAddress = "[email protected]", NotifyPackagePushed = true },
new User { EmailAddress = "[email protected]", NotifyPackagePushed = true }
}
};
var package = new Package
{
Version = version,
PackageRegistration = packageRegistration
};
packageRegistration.Packages.Add(package);

// Act
var messageService = TestableMessageService.Create(GetConfigurationService());
var packageUrl = $"https://localhost/packages/{packageRegistration.Id}/{nugetVersion.ToNormalizedString()}";
messageService.SendValidationTakingTooLongNotice(package, packageUrl);

// Assert
var message = messageService.MockMailSender.Sent.Last();

Assert.Equal("[email protected]", message.To[0].Address);
Assert.Equal("[email protected]", message.To[1].Address);
Assert.Equal(TestGalleryNoReplyAddress, message.From);
Assert.Contains($"[Joe Shmoe] Package validation taking longer than expected - {packageRegistration.Id} {nugetVersion.ToNormalizedString()}", message.Subject);
Assert.Contains(
$"It is taking longer than expected for your package [{packageRegistration.Id} {nugetVersion.ToFullString()}]({packageUrl}) to get published.\n\n" +
$"We are looking into it and there is no action on you at this time. We’ll send you an email notification when your package has been published.\n\n" +
$"Thank you for your patience.", message.Body);
}

public static IEnumerable<object[]> EmailSettingsCombinations
=> from u1pa in new[] { true, false }
from u2pa in new[] { true, false }
from u1ea in new[] { true, false }
from u2ea in new[] { true, false }
select new object[] { u1pa, u2pa, u1ea, u2ea };

[Theory]
[MemberData(nameof(EmailSettingsCombinations))]
public void WillSendEmailToOwnersRegardlessOfSettings(bool user1PushAllowed, bool user2PushAllowed, bool user1EmailAllowed, bool user2EmailAllowed)
{
// Arrange
var packageRegistration = new PackageRegistration
{
Id = "smangit",
Owners = new[]
{
new User { EmailAddress = "[email protected]", NotifyPackagePushed = user1PushAllowed, EmailAllowed = user1EmailAllowed },
new User { EmailAddress = "[email protected]", NotifyPackagePushed = user2PushAllowed, EmailAllowed = user2EmailAllowed }
}
};
var package = new Package
{
Version = "1.2.3",
PackageRegistration = packageRegistration
};
packageRegistration.Packages.Add(package);

// Act
var messageService = TestableMessageService.Create(GetConfigurationService());
messageService.SendValidationTakingTooLongNotice(package, "http://dummy1");

// Assert
var message = messageService.MockMailSender.Sent.Last();

Assert.Equal("[email protected]", message.To[0].Address);
Assert.Equal("[email protected]", message.To[1].Address);
Assert.Equal(2, message.To.Count);
}
}

public class TheSendPackageUploadedNoticeMethod
: TestContainer
{
Expand Down

0 comments on commit 93d5307

Please sign in to comment.