public virtual ActionResult ConfirmOwner(string id, string username, string token) { if (String.IsNullOrEmpty(token)) { return(HttpNotFound()); } if (!String.Equals(username, User.Identity.Name, StringComparison.OrdinalIgnoreCase)) { return(View(new PackageOwnerConfirmationModel() { Username = username, Result = ConfirmOwnershipResult.NotYourRequest })); } var package = _packageService.FindPackageRegistrationById(id); if (package == null) { return(HttpNotFound()); } var user = GetCurrentUser(); ConfirmOwnershipResult result = _packageService.ConfirmPackageOwner(package, user, token); var model = new PackageOwnerConfirmationModel { Result = result, PackageId = package.Id }; return(View(model)); }
public void AcceptsResultOfPackageServiceIfOtherwiseValid(ConfirmOwnershipResult confirmationResult) { var package = new PackageRegistration { Id = "foo" }; var user = new User { Username = "******" }; var packageService = new Mock<IPackageService>(); packageService.Setup(p => p.FindPackageRegistrationById("foo")).Returns(package); packageService.Setup(p => p.ConfirmPackageOwner(package, user, "token")).Returns(confirmationResult); var userService = new Mock<IUserService>(); userService.Setup(u => u.FindByUsername("username")).Returns(user); var httpContext = new Mock<HttpContextBase>(); httpContext.Setup(c => c.User.Identity.Name).Returns("username"); var controller = CreateController(packageService: packageService, userService: userService, httpContext: httpContext); var result = controller.ConfirmOwner("foo", "username", "token"); var model = ResultAssert.IsView<PackageOwnerConfirmationModel>(result); Assert.Equal(confirmationResult, model.Result); Assert.Equal("foo", model.PackageId); }
public async Task AcceptsResultOfPackageServiceIfOtherwiseValid(ConfirmOwnershipResult confirmationResult) { var package = new PackageRegistration { Id = "foo" }; var user = new User { Username = "******" }; var packageService = new Mock<IPackageService>(); packageService.Setup(p => p.FindPackageRegistrationById("foo")).Returns(package); packageService.Setup(p => p.ConfirmPackageOwnerAsync(package, user, "token")).Returns(Task.FromResult(confirmationResult)); var controller = CreateController(packageService: packageService); controller.SetCurrentUser(user); var result = await controller.ConfirmOwner("foo", "username", "token"); var model = ResultAssert.IsView<PackageOwnerConfirmationModel>(result); Assert.Equal(confirmationResult, model.Result); Assert.Equal("foo", model.PackageId); }
public PackageOwnerConfirmationModel(string packageId, string username, ConfirmOwnershipResult result) { Result = result; PackageId = packageId; Username = username; }