本文整理汇总了C#中NuGetGallery.ContactOwnersViewModel类的典型用法代码示例。如果您正苦于以下问题:C# ContactOwnersViewModel类的具体用法?C# ContactOwnersViewModel怎么用?C# ContactOwnersViewModel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ContactOwnersViewModel类属于NuGetGallery命名空间,在下文中一共展示了ContactOwnersViewModel类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CallsSendContactOwnersMessageWithUserInfo
public void CallsSendContactOwnersMessageWithUserInfo()
{
var messageService = new Mock<IMessageService>();
messageService.Setup(s => s.SendContactOwnersMessage(
It.IsAny<MailAddress>(),
It.IsAny<PackageRegistration>(),
"I like the cut of your jib", It.IsAny<string>()));
var package = new PackageRegistration { Id = "factory" };
var packageSvc = new Mock<IPackageService>();
packageSvc.Setup(p => p.FindPackageRegistrationById("factory")).Returns(package);
var httpContext = new Mock<HttpContextBase>();
httpContext.Setup(h => h.User.Identity.Name).Returns("Montgomery");
var userSvc = new Mock<IUserService>();
userSvc.Setup(u => u.FindByUsername("Montgomery")).Returns(new User { EmailAddress = "[email protected]", Username = "Montgomery" });
var controller = CreateController(packageSvc: packageSvc,
messageSvc: messageService,
userSvc: userSvc,
httpContext: httpContext);
var model = new ContactOwnersViewModel
{
Message = "I like the cut of your jib",
};
var result = controller.ContactOwners("factory", model) as RedirectToRouteResult;
Assert.NotNull(result);
}
示例2: ContactOwners
public virtual ActionResult ContactOwners(string id, ContactOwnersViewModel contactForm)
{
if (!ModelState.IsValid)
{
return ContactOwners(id);
}
var package = _packageService.FindPackageRegistrationById(id);
if (package == null)
{
return HttpNotFound();
}
var user = _userService.FindByUsername(HttpContext.User.Identity.Name);
var fromAddress = new MailAddress(user.EmailAddress, user.Username);
_messageService.SendContactOwnersMessage(
fromAddress, package, contactForm.Message, Url.Action(MVC.Users.Edit(), protocol: Request.Url.Scheme));
string message = String.Format(CultureInfo.CurrentCulture, "Your message has been sent to the owners of {0}.", id);
TempData["Message"] = message;
return RedirectToAction(MVC.Packages.DisplayPackage(id, null));
}
示例3: ContactOwners
public virtual ActionResult ContactOwners(string id, ContactOwnersViewModel contactForm)
{
// Html Encode the message
contactForm.Message = System.Web.HttpUtility.HtmlEncode(contactForm.Message);
if (!ModelState.IsValid)
{
return ContactOwners(id);
}
var package = _packageService.FindPackageRegistrationById(id);
if (package == null)
{
return HttpNotFound();
}
var user = GetCurrentUser();
var fromAddress = new MailAddress(user.EmailAddress, user.Username);
_messageService.SendContactOwnersMessage(
fromAddress,
package,
contactForm.Message,
Url.Action(
actionName: "Account",
controllerName: "Users",
routeValues: null,
protocol: Request.Url.Scheme),
contactForm.CopySender);
string message = String.Format(CultureInfo.CurrentCulture, "Your message has been sent to the owners of {0}.", id);
TempData["Message"] = message;
return RedirectToAction(
actionName: "DisplayPackage",
controllerName: "Packages",
routeValues: new
{
id,
version = (string)null
});
}
示例4: CallsSendContactOwnersMessageWithUserInfo
public void CallsSendContactOwnersMessageWithUserInfo()
{
var messageService = new Mock<IMessageService>();
messageService.Setup(
s => s.SendContactOwnersMessage(
It.IsAny<MailAddress>(),
It.IsAny<PackageRegistration>(),
"I like the cut of your jib",
It.IsAny<string>(), false));
var package = new PackageRegistration { Id = "factory" };
var packageService = new Mock<IPackageService>();
packageService.Setup(p => p.FindPackageRegistrationById("factory")).Returns(package);
var userService = new Mock<IUserService>();
var controller = CreateController(
packageService: packageService,
messageService: messageService);
controller.SetCurrentUser(new User { EmailAddress = "[email protected]", Username = "Montgomery" });
var model = new ContactOwnersViewModel
{
Message = "I like the cut of your jib",
};
var result = controller.ContactOwners("factory", model) as RedirectToRouteResult;
Assert.NotNull(result);
}
示例5: HtmlEncodesMessageContent
public void HtmlEncodesMessageContent()
{
var messageService = new Mock<IMessageService>();
string sentMessage = null;
messageService.Setup(
s => s.SendContactOwnersMessage(
It.IsAny<MailAddress>(),
It.IsAny<PackageRegistration>(),
It.IsAny<string>(),
It.IsAny<string>(),
false))
.Callback<MailAddress, PackageRegistration, string, string, bool>((_, __, msg, ___, ____) => sentMessage = msg);
var package = new PackageRegistration { Id = "factory" };
var packageService = new Mock<IPackageService>();
packageService.Setup(p => p.FindPackageRegistrationById("factory")).Returns(package);
var userService = new Mock<IUserService>();
var controller = CreateController(
packageService: packageService,
messageService: messageService);
controller.SetCurrentUser(new User { EmailAddress = "[email protected]", Username = "Montgomery" });
var model = new ContactOwnersViewModel
{
Message = "I like the cut of your jib. It's <b>bold</b>.",
};
var result = controller.ContactOwners("factory", model) as RedirectToRouteResult;
Assert.Equal("I like the cut of your jib. It's <b>bold</b>.", sentMessage);
}
示例6: ContactOwners
public virtual ActionResult ContactOwners(string id, ContactOwnersViewModel contactForm)
{
if (!ModelState.IsValid) return ContactOwners(id);
var package = packageSvc.FindPackageRegistrationById(id);
if (package == null) return PackageNotFound(id);
MailAddress from = null;
if (Request.IsAuthenticated)
{
var user = userSvc.FindByUsername(HttpContext.User.Identity.Name);
from = user.ToMailAddress();
} else from = new MailAddress(contactForm.Email);
var packageUrl = EnsureTrailingSlash(Configuration.GetSiteRoot(useHttps: false)) + RemoveStartingSlash(Url.Package(package));
messageService.SendContactOwnersMessage(from, package, contactForm.Message, Url.Action(MVC.Users.Edit(), protocol: Request.Url.Scheme), packageUrl, contactForm.CopySender);
string message = String.Format(CultureInfo.CurrentCulture, "Your message has been sent to the maintainers of {0}.", id);
TempData["Message"] = message;
return RedirectToAction(MVC.Packages.DisplayPackage(id, null));
}