public SendPackageOwnerRequest ( User fromUser, User toUser, PackageRegistration package, string confirmationUrl, string message ) : void | ||
fromUser | User | |
toUser | User | |
package | PackageRegistration | |
confirmationUrl | string | |
message | string | |
return | void |
public void DoesNotSendRequestIfUserDoesNotAllowEmails() { var to = new User { Username = "******", EmailAddress = "*****@*****.**", EmailAllowed = false }; var from = new User { Username = "******", EmailAddress = "*****@*****.**" }; var mailSender = new Mock <IMailSender>(); mailSender.Setup(s => s.Send(It.IsAny <MailMessage>())).Throws(new InvalidOperationException("Should not be called")); var config = new Mock <IAppConfiguration>(); config.Setup(x => x.GalleryOwner).Returns(TestGalleryOwner); var messageService = new MessageService(mailSender.Object, config.Object); var package = new PackageRegistration { Id = "CoolStuff" }; const string confirmationUrl = "http://example.com/confirmation-token-url"; MailMessage message = null; mailSender.Setup(m => m.Send(It.IsAny <MailMessage>())).Callback <MailMessage>(m => { message = m; }); messageService.SendPackageOwnerRequest(from, to, package, confirmationUrl); Assert.Null(message); }
public void SendsPackageOwnerRequestConfirmationUrl() { var to = new User { Username = "******", EmailAddress = "*****@*****.**", EmailAllowed = true }; var from = new User { Username = "******", EmailAddress = "*****@*****.**" }; var mailSender = new Mock <IMailSender>(); var config = new Mock <IAppConfiguration>(); config.Setup(x => x.GalleryOwner).Returns(TestGalleryOwner); var messageService = new MessageService(mailSender.Object, config.Object); var package = new PackageRegistration { Id = "CoolStuff" }; const string confirmationUrl = "http://example.com/confirmation-token-url"; MailMessage message = null; mailSender.Setup(m => m.Send(It.IsAny <MailMessage>())).Callback <MailMessage>(m => { message = m; }); messageService.SendPackageOwnerRequest(from, to, package, confirmationUrl); Assert.Equal("*****@*****.**", message.To[0].Address); Assert.Equal(TestGalleryOwner.Address, message.From.Address); Assert.Equal("*****@*****.**", message.ReplyToList.Single().Address); Assert.Equal("[Joe Shmoe] The user 'Existing' wants to add you as an owner of the package 'CoolStuff'.", message.Subject); Assert.Contains(confirmationUrl, message.Body); Assert.Contains("The user 'Existing' wants to add you as an owner of the package 'CoolStuff'.", message.Body); }
public void DoesNotSendRequestIfUserDoesNotAllowEmails() { var to = new User { Username = "******", EmailAddress = "*****@*****.**", EmailAllowed = false }; var from = new User { Username = "******", EmailAddress = "*****@*****.**" }; var mailSender = new Mock<IMailSender>(); mailSender.Setup(s => s.Send(It.IsAny<MailMessage>())).Throws(new InvalidOperationException("Should not be called")); var setting = new GallerySetting { GalleryOwnerName = "NuGet Gallery", GalleryOwnerEmail = "*****@*****.**" }; var messageService = new MessageService(mailSender.Object, setting); var package = new PackageRegistration { Id = "CoolStuff" }; const string confirmationUrl = "http://example.com/confirmation-token-url"; MailMessage message = null; mailSender.Setup(m => m.Send(It.IsAny<MailMessage>())).Callback<MailMessage>(m => { message = m; }); messageService.SendPackageOwnerRequest(from, to, package, confirmationUrl); Assert.Null(message); }
public void SendsPackageOwnerRequestConfirmationUrl() { var to = new User { Username = "******", EmailAddress = "*****@*****.**", EmailAllowed = true }; var from = new User { Username = "******", EmailAddress = "*****@*****.**" }; var mailSender = new Mock<IMailSender>(); var setting = new GallerySetting { GalleryOwnerName = "NuGet Gallery", GalleryOwnerEmail = "*****@*****.**" }; var messageService = new MessageService(mailSender.Object, setting); var package = new PackageRegistration { Id = "CoolStuff" }; const string confirmationUrl = "http://example.com/confirmation-token-url"; MailMessage message = null; mailSender.Setup(m => m.Send(It.IsAny<MailMessage>())).Callback<MailMessage>(m => { message = m; }); messageService.SendPackageOwnerRequest(from, to, package, confirmationUrl); Assert.Equal("*****@*****.**", message.To[0].Address); Assert.Equal("*****@*****.**", message.From.Address); Assert.Equal("[NuGet Gallery] The user 'Existing' wants to add you as an owner of the package 'CoolStuff'.", message.Subject); Assert.Contains(confirmationUrl, message.Body); Assert.Contains("The user 'Existing' wants to add you as an owner of the package 'CoolStuff'.", message.Body); }