Permalink
Browse files

fixed bug where you could curate the same package twice for a given feed

  • Loading branch information...
1 parent 5d28d5f commit ab5ca5fcd51aade66d19cc1d0793e792f9aeaaeb @half-ogre half-ogre committed Mar 23, 2012
@@ -143,7 +143,23 @@ public void WillRedirectToTheCuratedFeedRouteAfterCreatingTheCuratedPackage()
Assert.NotNull(result);
Assert.Equal(RouteName.CuratedFeed, result.RouteName);
}
-
+
+ [Fact]
+ public void WillShowAnErrorWhenThePackageHasAlreadyBeenCurated()
+ {
+ var controller = new TestableCuratedPackagesController();
+ controller.StubCuratedFeed.Name = "theCuratedFeedName";
+ controller.StubCuratedFeed.Packages.Add(new CuratedPackage{ PackageRegistration = new PackageRegistration{ Key = 42 } });
+ controller.StubPackageRegistrationByIdQry.Setup(stub => stub.Execute(It.IsAny<string>(), It.IsAny<bool>())).Returns((new PackageRegistration{ Key = 42 }));
+
+ var result = controller.PostCuratedPackages("theCuratedFeedName", new CreateCuratedPackageRequest()) as ViewResult;
+
+ Assert.NotNull(result);
+ Assert.Equal("theCuratedFeedName", result.ViewBag.CuratedFeedName);
+ Assert.Equal(Strings.PackageIsAlreadyCurated, controller.ModelState["PackageId"].Errors[0].ErrorMessage);
+ Assert.Equal("CreateCuratedPackageForm", result.ViewName);
+ }
+
public class TestableCuratedPackagesController : TestableCuratedPackagesControllerBase
{
public TestableCuratedPackagesController()
@@ -99,6 +99,13 @@ public ActionResult GetCreateCuratedPackageForm(string curatedFeedName)
return View("CreateCuratedPackageForm");
}
+ if (curatedFeed.Packages.Any(cp => cp.PackageRegistration.Key == packageRegistration.Key))
+ {
+ ModelState.AddModelError("PackageId", Strings.PackageIsAlreadyCurated);
+ ViewBag.CuratedFeedName = curatedFeed.Name;
+ return View("CreateCuratedPackageForm");
+ }
+
GetService<ICreateCuratedPackageCommand>().Execute(
curatedFeed.Key,
packageRegistration.Key,

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -165,4 +165,7 @@
<data name="PackageWithIdDoesNotExist" xml:space="preserve">
<value>No package with this ID exists.</value>
</data>
+ <data name="PackageIsAlreadyCurated" xml:space="preserve">
+ <value>The package is already curated.</value>
+ </data>
</root>

0 comments on commit ab5ca5f

Please sign in to comment.