Skip to content
This repository
Browse code

added remove link to the curated feed management page

  • Loading branch information...
commit 53904638fbd14319fb23b25053e2984e82d18d13 1 parent 1c7a82a
half-ogre authored
14 Facts/Commands/CreatedCuratedPackageCommandFacts.cs
@@ -12,7 +12,7 @@ public class TheExecuteMethod
12 12 [Fact]
13 13 public void WillThrowWhenCuratedFeedDoesNotExist()
14 14 {
15   - var cmd = new TestableCreatedCuratedPackageCommand();
  15 + var cmd = new TestableCreateCuratedPackageCommand();
16 16 cmd.StubCuratedFeedByKeyQry
17 17 .Setup(stub => stub.Execute(It.IsAny<int>(), It.IsAny<bool>()))
18 18 .Returns((CuratedFeed)null);
@@ -25,7 +25,7 @@ public void WillThrowWhenCuratedFeedDoesNotExist()
25 25 [Fact]
26 26 public void WillThrowWhenPackageRegistrationDoesNotExist()
27 27 {
28   - var cmd = new TestableCreatedCuratedPackageCommand();
  28 + var cmd = new TestableCreateCuratedPackageCommand();
29 29 cmd.StubPackageRegistrationByKeyQuery
30 30 .Setup(stub => stub.Execute(It.IsAny<int>(), It.IsAny<bool>()))
31 31 .Returns((PackageRegistration)null);
@@ -38,7 +38,7 @@ public void WillThrowWhenPackageRegistrationDoesNotExist()
38 38 [Fact]
39 39 public void WillAddANewCuratedPackageToTheCuratedFeed()
40 40 {
41   - var cmd = new TestableCreatedCuratedPackageCommand();
  41 + var cmd = new TestableCreateCuratedPackageCommand();
42 42 cmd.StubPackageRegistration.Key = 1066;
43 43
44 44 cmd.Execute(
@@ -59,7 +59,7 @@ public void WillAddANewCuratedPackageToTheCuratedFeed()
59 59 [Fact]
60 60 public void WillSaveTheEntityChanges()
61 61 {
62   - var cmd = new TestableCreatedCuratedPackageCommand();
  62 + var cmd = new TestableCreateCuratedPackageCommand();
63 63
64 64 cmd.Execute(
65 65 0,
@@ -71,7 +71,7 @@ public void WillSaveTheEntityChanges()
71 71 [Fact]
72 72 public void WillReturnTheCreatedCuratedPackage()
73 73 {
74   - var cmd = new TestableCreatedCuratedPackageCommand();
  74 + var cmd = new TestableCreateCuratedPackageCommand();
75 75 cmd.StubPackageRegistration.Key = 1066;
76 76
77 77 var curatedPackage = cmd.Execute(
@@ -89,9 +89,9 @@ public void WillReturnTheCreatedCuratedPackage()
89 89 }
90 90 }
91 91
92   - public class TestableCreatedCuratedPackageCommand : CreatedCuratedPackageCommand
  92 + public class TestableCreateCuratedPackageCommand : CreateCuratedPackageCommand
93 93 {
94   - public TestableCreatedCuratedPackageCommand()
  94 + public TestableCreateCuratedPackageCommand()
95 95 : base(null)
96 96 {
97 97 StubCuratedFeed = new CuratedFeed { Key = 0, Name = "aName", };
86 Facts/Commands/DeleteCuratedPackageCommandFacts.cs
... ... @@ -0,0 +1,86 @@
  1 +using System;
  2 +using Moq;
  3 +using Xunit;
  4 +using System.Data.Entity;
  5 +
  6 +namespace NuGetGallery.Commands
  7 +{
  8 + public class DeleteCuratedPackageCommandFacts
  9 + {
  10 + public class TheExecuteMethod
  11 + {
  12 + [Fact]
  13 + public void WillThrowWhenCuratedFeedDoesNotExist()
  14 + {
  15 + var cmd = new TestableDeleteCuratedPackageCommand();
  16 + cmd.StubCuratedFeedByKeyQry
  17 + .Setup(stub => stub.Execute(It.IsAny<int>(), It.IsAny<bool>()))
  18 + .Returns((CuratedFeed)null);
  19 +
  20 + Assert.Throws<InvalidOperationException>(() => cmd.Execute(
  21 + 42,
  22 + 0));
  23 + }
  24 +
  25 + [Fact]
  26 + public void WillThrowWhenCuratedPackageDoesNotExist()
  27 + {
  28 + var cmd = new TestableDeleteCuratedPackageCommand();
  29 + cmd.StubCuratedFeed.Packages = new[] { new CuratedPackage() { Key = 0 } };
  30 +
  31 + Assert.Throws<InvalidOperationException>(() => cmd.Execute(
  32 + 0,
  33 + 1066));
  34 + }
  35 +
  36 + [Fact]
  37 + public void WillDeleteTheCuratedPackage()
  38 + {
  39 + var cmd = new TestableDeleteCuratedPackageCommand();
  40 + var stubCuratedPackage = new CuratedPackage { Key = 1066 };
  41 + cmd.StubCuratedFeed.Packages = new[] { stubCuratedPackage };
  42 +
  43 + cmd.Execute(
  44 + 0,
  45 + 1066);
  46 +
  47 + cmd.StubCuratedPackageDbSet.Verify(stub => stub.Remove(stubCuratedPackage));
  48 + cmd.StubEntitiesContext.Verify(stub => stub.SaveChanges());
  49 + }
  50 + }
  51 +
  52 + public class TestableDeleteCuratedPackageCommand : DeleteCuratedPackageCommand
  53 + {
  54 + public TestableDeleteCuratedPackageCommand()
  55 + : base(null)
  56 + {
  57 + StubCuratedFeed = new CuratedFeed { Key = 0, Name = "aName", };
  58 + StubCuratedPackageDbSet = new Mock<IDbSet<CuratedPackage>>();
  59 + StubCuratedFeedByKeyQry = new Mock<ICuratedFeedByKeyQuery>();
  60 + StubEntitiesContext = new Mock<IEntitiesContext>();
  61 +
  62 + StubCuratedFeedByKeyQry
  63 + .Setup(stub => stub.Execute(It.IsAny<int>(), It.IsAny<bool>()))
  64 + .Returns(StubCuratedFeed);
  65 + StubEntitiesContext
  66 + .Setup(stub => stub.CuratedPackages)
  67 + .Returns(StubCuratedPackageDbSet.Object);
  68 +
  69 + Entities = StubEntitiesContext.Object;
  70 + }
  71 +
  72 + public CuratedFeed StubCuratedFeed { get; set; }
  73 + public Mock<IDbSet<CuratedPackage>> StubCuratedPackageDbSet { get; private set; }
  74 + public Mock<ICuratedFeedByKeyQuery> StubCuratedFeedByKeyQry { get; set; }
  75 + public Mock<IEntitiesContext> StubEntitiesContext { get; private set; }
  76 +
  77 + protected override T GetService<T>()
  78 + {
  79 + if (typeof(T) == typeof(ICuratedFeedByKeyQuery))
  80 + return (T)StubCuratedFeedByKeyQry.Object;
  81 +
  82 + throw new Exception("Tried to get unexpected service");
  83 + }
  84 + }
  85 + }
  86 +}
109 Facts/Controllers/CuratedPackagesControllerFacts.cs
@@ -17,7 +17,7 @@ public void WillReturn404IfTheCuratedFeedDoesNotExist()
17 17 var controller = new TestableCuratedPackagesController();
18 18 controller.StubCuratedFeedByNameQry.Setup(stub => stub.Execute(It.IsAny<string>(), It.IsAny<bool>())).Returns((CuratedFeed)null);
19 19
20   - var result = controller.CreateCuratedPackageForm("aFeedName");
  20 + var result = controller.GetCreateCuratedPackageForm("aFeedName");
21 21
22 22 Assert.IsType<HttpNotFoundResult>(result);
23 23 }
@@ -28,7 +28,7 @@ public void WillReturn403IfTheCurrentUsersIsNotAManagerOfTheCuratedFeed()
28 28 var controller = new TestableCuratedPackagesController();
29 29 controller.StubIdentity.Setup(stub => stub.Name).Returns("notAManager");
30 30
31   - var result = controller.CreateCuratedPackageForm("aFeedName") as HttpStatusCodeResult;
  31 + var result = controller.GetCreateCuratedPackageForm("aFeedName") as HttpStatusCodeResult;
32 32
33 33 Assert.NotNull(result);
34 34 Assert.Equal(403, result.StatusCode);
@@ -40,7 +40,7 @@ public void WillPushTheCuratedFeedNameIntoTheViewBag()
40 40 var controller = new TestableCuratedPackagesController();
41 41 controller.StubCuratedFeed.Name = "theCuratedFeedName";
42 42
43   - var result = controller.CreateCuratedPackageForm("aFeedName") as ViewResult;
  43 + var result = controller.GetCreateCuratedPackageForm("aFeedName") as ViewResult;
44 44
45 45 Assert.NotNull(result);
46 46 Assert.Equal("theCuratedFeedName", result.ViewBag.CuratedFeedName);
@@ -65,7 +65,7 @@ public void WillReturn404IfTheCuratedFeedDoesNotExist()
65 65 var controller = new TestableCuratedPackagesController();
66 66 controller.StubCuratedFeedByNameQry.Setup(stub => stub.Execute(It.IsAny<string>(), It.IsAny<bool>())).Returns((CuratedFeed)null);
67 67
68   - var result = controller.CuratedPackages("aFeedName", new CreatedCuratedPackageRequest());
  68 + var result = controller.PostCuratedPackages("aFeedName", new CreateCuratedPackageRequest());
69 69
70 70 Assert.IsType<HttpNotFoundResult>(result);
71 71 }
@@ -76,7 +76,7 @@ public void WillReturn403IfTheCurrentUsersIsNotAManagerOfTheCuratedFeed()
76 76 var controller = new TestableCuratedPackagesController();
77 77 controller.StubIdentity.Setup(stub => stub.Name).Returns("notAManager");
78 78
79   - var result = controller.CuratedPackages("aFeedName", new CreatedCuratedPackageRequest()) as HttpStatusCodeResult;
  79 + var result = controller.PostCuratedPackages("aFeedName", new CreateCuratedPackageRequest()) as HttpStatusCodeResult;
80 80
81 81 Assert.NotNull(result);
82 82 Assert.Equal(403, result.StatusCode);
@@ -89,7 +89,7 @@ public void WillPushTheCuratedFeedNameIntoTheViewBagAndShowTheCreateCuratedPacka
89 89 controller.StubCuratedFeed.Name = "theCuratedFeedName";
90 90 controller.ModelState.AddModelError("", "anError");
91 91
92   - var result = controller.CuratedPackages("aFeedName", new CreatedCuratedPackageRequest()) as ViewResult;
  92 + var result = controller.PostCuratedPackages("aFeedName", new CreateCuratedPackageRequest()) as ViewResult;
93 93
94 94 Assert.NotNull(result);
95 95 Assert.Equal("theCuratedFeedName", result.ViewBag.CuratedFeedName);
@@ -103,7 +103,7 @@ public void WillPushTheCuratedFeedNameIntoTheViewBagAndShowTheCreateCuratedPacka
103 103 controller.StubCuratedFeed.Name = "theCuratedFeedName";
104 104 controller.StubPackageRegistrationByIdQry.Setup(stub => stub.Execute(It.IsAny<string>(), It.IsAny<bool>())).Returns((PackageRegistration)null);
105 105
106   - var result = controller.CuratedPackages("aFeedName", new CreatedCuratedPackageRequest()) as ViewResult;
  106 + var result = controller.PostCuratedPackages("aFeedName", new CreateCuratedPackageRequest()) as ViewResult;
107 107
108 108 Assert.NotNull(result);
109 109 Assert.Equal("theCuratedFeedName", result.ViewBag.CuratedFeedName);
@@ -118,9 +118,9 @@ public void WillCreateTheCuratedPackage()
118 118 controller.StubCuratedFeed.Key = 42;
119 119 controller.StubPackageRegistration.Key = 1066;
120 120
121   - controller.CuratedPackages(
  121 + controller.PostCuratedPackages(
122 122 "aFeedName",
123   - new CreatedCuratedPackageRequest
  123 + new CreateCuratedPackageRequest
124 124 {
125 125 PackageId = "thePackageId", Notes = "theNotes"
126 126 });
@@ -138,7 +138,7 @@ public void WillRedirectToTheCuratedFeedRouteAfterCreatingTheCuratedPackage()
138 138 {
139 139 var controller = new TestableCuratedPackagesController();
140 140
141   - var result = controller.CuratedPackages("aFeedName", new CreatedCuratedPackageRequest()) as RedirectToRouteResult;
  141 + var result = controller.PostCuratedPackages("aFeedName", new CreateCuratedPackageRequest()) as RedirectToRouteResult;
142 142
143 143 Assert.NotNull(result);
144 144 Assert.Equal(RouteName.CuratedFeed, result.RouteName);
@@ -166,7 +166,7 @@ public void WillReturn404IfTheCuratedFeedDoesNotExist()
166 166 var controller = new TestableCuratedPackagesController();
167 167 controller.StubCuratedFeedByNameQry.Setup(stub => stub.Execute(It.IsAny<string>(), It.IsAny<bool>())).Returns((CuratedFeed)null);
168 168
169   - var result = controller.CuratedPackage("aCuratedFeedName", "aCuratedPackageId", new ModifyCuratedPackageRequest());
  169 + var result = controller.PatchCuratedPackage("aCuratedFeedName", "aCuratedPackageId", new ModifyCuratedPackageRequest());
170 170
171 171 Assert.IsType<HttpNotFoundResult>(result);
172 172 }
@@ -177,7 +177,7 @@ public void WillReturn404IfTheCuratedPackageDoesNotExist()
177 177 var controller = new TestableCuratedPackagesController();
178 178 controller.StubCuratedFeed.Packages = new[] { new CuratedPackage { PackageRegistration = new PackageRegistration() } };
179 179
180   - var result = controller.CuratedPackage("aCuratedFeedName", "aCuratedPackageId", new ModifyCuratedPackageRequest());
  180 + var result = controller.PatchCuratedPackage("aCuratedFeedName", "aCuratedPackageId", new ModifyCuratedPackageRequest());
181 181
182 182 Assert.IsType<HttpNotFoundResult>(result);
183 183 }
@@ -188,7 +188,7 @@ public void WillReturn403IfTheCuratedPackageDoesNotExist()
188 188 var controller = new TestableCuratedPackagesController();
189 189 controller.StubCuratedFeed.Managers = new[] {new User {Username = "notAManager"}};
190 190
191   - var result = controller.CuratedPackage("aCuratedFeedName", "aCuratedPackageId", new ModifyCuratedPackageRequest()) as HttpStatusCodeResult;
  191 + var result = controller.PatchCuratedPackage("aCuratedFeedName", "aCuratedPackageId", new ModifyCuratedPackageRequest()) as HttpStatusCodeResult;
192 192
193 193 Assert.NotNull(result);
194 194 Assert.Equal(403, result.StatusCode);
@@ -200,7 +200,7 @@ public void WillReturn400IfTheModelStateIsInvalid()
200 200 var controller = new TestableCuratedPackagesController();
201 201 controller.ModelState.AddModelError("", "anError");
202 202
203   - var result = controller.CuratedPackage("aCuratedFeedName", "aCuratedPackageId", new ModifyCuratedPackageRequest()) as HttpStatusCodeResult;
  203 + var result = controller.PatchCuratedPackage("aCuratedFeedName", "aCuratedPackageId", new ModifyCuratedPackageRequest()) as HttpStatusCodeResult;
204 204
205 205 Assert.NotNull(result);
206 206 Assert.Equal(400, result.StatusCode);
@@ -213,7 +213,7 @@ public void WillModifyTheCuratedPackageWhenRequestIsValid()
213 213 controller.StubCuratedFeed.Key = 42;
214 214 controller.StubCuratedFeed.Packages = new[] { new CuratedPackage { Key = 1066, PackageRegistration = new PackageRegistration { Id = "theCuratedPackageId" } } };
215 215
216   - controller.CuratedPackage("theCuratedFeedName", "theCuratedPackageId", new ModifyCuratedPackageRequest{ Included = true});
  216 + controller.PatchCuratedPackage("theCuratedFeedName", "theCuratedPackageId", new ModifyCuratedPackageRequest{ Included = true});
217 217
218 218 controller.StubModifyCuratedPackageCommand.Verify(stub => stub.Execute(
219 219 42,
@@ -234,6 +234,80 @@ public TestableCuratedPackagesController()
234 234 }
235 235 }
236 236
  237 + public class TheDeleteCuratedPackageAction
  238 + {
  239 + [Fact]
  240 + public void WillReturn404IfTheCuratedFeedDoesNotExist()
  241 + {
  242 + var controller = new TestableCuratedPackagesController();
  243 + controller.StubCuratedFeedByNameQry.Setup(stub => stub.Execute(It.IsAny<string>(), It.IsAny<bool>())).Returns((CuratedFeed)null);
  244 +
  245 + var result = controller.DeleteCuratedPackage("aCuratedFeedName", "aCuratedPackageId");
  246 +
  247 + Assert.IsType<HttpNotFoundResult>(result);
  248 + }
  249 +
  250 + [Fact]
  251 + public void WillReturn404IfTheCuratedPackageDoesNotExist()
  252 + {
  253 + var controller = new TestableCuratedPackagesController();
  254 + controller.StubCuratedFeed.Packages = new[] { new CuratedPackage { PackageRegistration = new PackageRegistration() } };
  255 +
  256 + var result = controller.DeleteCuratedPackage("aCuratedFeedName", "aCuratedPackageId");
  257 +
  258 + Assert.IsType<HttpNotFoundResult>(result);
  259 + }
  260 +
  261 + [Fact]
  262 + public void WillReturn403IfTheCuratedPackageDoesNotExist()
  263 + {
  264 + var controller = new TestableCuratedPackagesController();
  265 + controller.StubCuratedFeed.Managers = new[] { new User { Username = "notAManager" } };
  266 +
  267 + var result = controller.DeleteCuratedPackage("aCuratedFeedName", "aCuratedPackageId") as HttpStatusCodeResult;
  268 +
  269 + Assert.NotNull(result);
  270 + Assert.Equal(403, result.StatusCode);
  271 + }
  272 +
  273 + [Fact]
  274 + public void WillDeleteTheCuratedPackageWhenRequestIsValid()
  275 + {
  276 + var controller = new TestableCuratedPackagesController();
  277 + controller.StubCuratedFeed.Key = 42;
  278 + controller.StubCuratedFeed.Packages = new[] { new CuratedPackage { Key = 1066, PackageRegistration = new PackageRegistration { Id = "theCuratedPackageId" } } };
  279 +
  280 + controller.DeleteCuratedPackage("theCuratedFeedName", "theCuratedPackageId");
  281 +
  282 + controller.StubDeleteCuratedPackageCommand.Verify(stub => stub.Execute(
  283 + 42,
  284 + 1066));
  285 + }
  286 +
  287 + [Fact]
  288 + public void WillReturn204AfterDeletingTheCuratedPackage()
  289 + {
  290 + var controller = new TestableCuratedPackagesController();
  291 +
  292 + var result = controller.DeleteCuratedPackage("aCuratedFeedName", "aCuratedPackageId") as HttpStatusCodeResult;
  293 +
  294 + Assert.NotNull(result);
  295 + Assert.Equal(204, result.StatusCode);
  296 + }
  297 +
  298 + public class TestableCuratedPackagesController : TestableCuratedPackagesControllerBase
  299 + {
  300 + public TestableCuratedPackagesController()
  301 + {
  302 + StubCuratedFeed.Managers = new[] { new User { Username = "aUsername" } };
  303 + StubCuratedFeed.Packages = new[] { new CuratedPackage { PackageRegistration = new PackageRegistration { Id = "aCuratedPackageId" } } };
  304 + StubCuratedFeedByNameQry
  305 + .Setup(stub => stub.Execute(It.IsAny<string>(), It.IsAny<bool>()))
  306 + .Returns(StubCuratedFeed);
  307 + }
  308 + }
  309 + }
  310 +
237 311 public abstract class TestableCuratedPackagesControllerBase : CuratedPackagesController
238 312 {
239 313 protected TestableCuratedPackagesControllerBase()
@@ -241,6 +315,7 @@ protected TestableCuratedPackagesControllerBase()
241 315 StubCreatedCuratedPackageCmd = new Mock<ICreatedCuratedPackageCommand>();
242 316 StubCuratedFeed = new CuratedFeed { Key = 0, Name = "aName", Managers = new HashSet<User>( new []{ new User { Username = "aUsername" } }) };
243 317 StubCuratedFeedByNameQry = new Mock<ICuratedFeedByNameQuery>();
  318 + StubDeleteCuratedPackageCommand = new Mock<IDeleteCuratedPackageCommand>();
244 319 StubIdentity = new Mock<IIdentity>();
245 320 StubModifyCuratedPackageCommand = new Mock<IModifyCuratedPackageCommand>();
246 321 StubPackageRegistration = new PackageRegistration { Key = 0, Id = "anId" };
@@ -253,6 +328,7 @@ protected TestableCuratedPackagesControllerBase()
253 328 public Mock<ICreatedCuratedPackageCommand> StubCreatedCuratedPackageCmd { get; set; }
254 329 public CuratedFeed StubCuratedFeed { get; set; }
255 330 public Mock<ICuratedFeedByNameQuery> StubCuratedFeedByNameQry { get; private set; }
  331 + public Mock<IDeleteCuratedPackageCommand> StubDeleteCuratedPackageCommand { get; private set; }
256 332 public Mock<IIdentity> StubIdentity { get; private set; }
257 333 public Mock<IModifyCuratedPackageCommand> StubModifyCuratedPackageCommand { get; private set; }
258 334 public PackageRegistration StubPackageRegistration { get; private set; }
@@ -271,6 +347,9 @@ protected override T GetService<T>()
271 347 if (typeof(T) == typeof(ICuratedFeedByNameQuery))
272 348 return (T)StubCuratedFeedByNameQry.Object;
273 349
  350 + if (typeof(T) == typeof(IDeleteCuratedPackageCommand))
  351 + return (T)StubDeleteCuratedPackageCommand.Object;
  352 +
274 353 if (typeof(T) == typeof(IModifyCuratedPackageCommand))
275 354 return (T)StubModifyCuratedPackageCommand.Object;
276 355
1  Facts/Facts.csproj
@@ -93,6 +93,7 @@
93 93 <ItemGroup>
94 94 <Compile Include="Commands\AutomaticallyCuratePackageCommandFacts.cs" />
95 95 <Compile Include="Commands\CreatedCuratedPackageCommandFacts.cs" />
  96 + <Compile Include="Commands\DeleteCuratedPackageCommandFacts.cs" />
96 97 <Compile Include="Commands\ModifyCuratedPackageCommandFacts.cs" />
97 98 <Compile Include="Controllers\AuthenticationControllerFacts.cs" />
98 99 <Compile Include="Controllers\ApiControllerFacts.cs" />
5 Website/App_Start/ContainerBindings.cs
@@ -174,7 +174,10 @@ public override void Load()
174 174 .To<AutomaticallyCuratePackageCommand>()
175 175 .InRequestScope();
176 176 Bind<ICreatedCuratedPackageCommand>()
177   - .To<CreatedCuratedPackageCommand>()
  177 + .To<CreateCuratedPackageCommand>()
  178 + .InRequestScope();
  179 + Bind<IDeleteCuratedPackageCommand>()
  180 + .To<DeleteCuratedPackageCommand>()
178 181 .InRequestScope();
179 182 Bind<IModifyCuratedPackageCommand>()
180 183 .To<ModifyCuratedPackageCommand>()
4 Website/Commands/CreatedCuratedPackageCommand.cs → Website/Commands/CreateCuratedPackageCommand.cs
@@ -12,9 +12,9 @@ public interface ICreatedCuratedPackageCommand
12 12 string notes = null);
13 13 }
14 14
15   - public class CreatedCuratedPackageCommand : AppCommand, ICreatedCuratedPackageCommand
  15 + public class CreateCuratedPackageCommand : AppCommand, ICreatedCuratedPackageCommand
16 16 {
17   - public CreatedCuratedPackageCommand(IEntitiesContext entities)
  17 + public CreateCuratedPackageCommand(IEntitiesContext entities)
18 18 : base(entities)
19 19 {
20 20 }
37 Website/Commands/DeleteCuratedPackageCommand.cs
... ... @@ -0,0 +1,37 @@
  1 +using System;
  2 +using System.Linq;
  3 +
  4 +namespace NuGetGallery
  5 +{
  6 + public interface IDeleteCuratedPackageCommand
  7 + {
  8 + void Execute(
  9 + int curatedFeedKey,
  10 + int curatedPackageKey);
  11 + }
  12 +
  13 + public class DeleteCuratedPackageCommand : AppCommand, IDeleteCuratedPackageCommand
  14 + {
  15 + public DeleteCuratedPackageCommand(IEntitiesContext entities)
  16 + : base(entities)
  17 + {
  18 + }
  19 +
  20 + public void Execute(
  21 + int curatedFeedKey,
  22 + int curatedPackageKey)
  23 + {
  24 + var curatedFeed = GetService<ICuratedFeedByKeyQuery>().Execute(curatedFeedKey);
  25 + if (curatedFeed == null)
  26 + throw new InvalidOperationException("The curated feed does not exist.");
  27 +
  28 + var curatedPackage = curatedFeed.Packages.SingleOrDefault(cp => cp.Key == curatedPackageKey);
  29 + if (curatedPackage == null)
  30 + throw new InvalidOperationException("The curated package does not exist.");
  31 +
  32 + Entities.CuratedPackages.Remove(curatedPackage);
  33 +
  34 + Entities.SaveChanges();
  35 + }
  36 + }
  37 +}
73 Website/Controllers/CuratedPackagesController.cs
@@ -8,8 +8,8 @@ public class CuratedPackagesController : AppController
8 8 {
9 9 public const string Name = "CuratedPackages";
10 10
11   - [HttpGet]
12   - public ActionResult CreateCuratedPackageForm(string curatedFeedName)
  11 + [ActionName("CreateCuratedPackageForm"), HttpGet]
  12 + public ActionResult GetCreateCuratedPackageForm(string curatedFeedName)
13 13 {
14 14 var curatedFeed = GetService<ICuratedFeedByNameQuery>().Execute(curatedFeedName);
15 15 if (curatedFeed == null)
@@ -22,42 +22,31 @@ public ActionResult CreateCuratedPackageForm(string curatedFeedName)
22 22 return View();
23 23 }
24 24
25   - [HttpPost]
26   - public ActionResult CuratedPackages(
  25 + [ActionName("CuratedPackage"), HttpDelete]
  26 + public ActionResult DeleteCuratedPackage(
27 27 string curatedFeedName,
28   - CreatedCuratedPackageRequest request)
  28 + string curatedPackageId)
29 29 {
30 30 var curatedFeed = GetService<ICuratedFeedByNameQuery>().Execute(curatedFeedName, includePackages: true);
31 31 if (curatedFeed == null)
32 32 return HttpNotFound();
33 33
  34 + var curatedPackage = curatedFeed.Packages.SingleOrDefault(cp => cp.PackageRegistration.Id == curatedPackageId);
  35 + if (curatedPackage == null)
  36 + return HttpNotFound();
  37 +
34 38 if (!curatedFeed.Managers.Any(manager => manager.Username == Identity.Name))
35 39 return new HttpStatusCodeResult(403);
36 40
37   - if (!ModelState.IsValid)
38   - {
39   - ViewBag.CuratedFeedName = curatedFeed.Name;
40   - return View("CreateCuratedPackageForm");
41   - }
42   -
43   - var packageRegistration = GetService<IPackageRegistrationByIdQuery>().Execute(request.PackageId);
44   - if (packageRegistration == null)
45   - {
46   - ModelState.AddModelError("PackageId", Strings.PackageWithIdDoesNotExist);
47   - ViewBag.CuratedFeedName = curatedFeed.Name;
48   - return View("CreateCuratedPackageForm");
49   - }
50   -
51   - GetService<ICreatedCuratedPackageCommand>().Execute(
  41 + GetService<IDeleteCuratedPackageCommand>().Execute(
52 42 curatedFeed.Key,
53   - packageRegistration.Key,
54   - notes: request.Notes);
  43 + curatedPackage.Key);
55 44
56   - return RedirectToRoute(RouteName.CuratedFeed, new { name = curatedFeed.Name });
  45 + return new HttpStatusCodeResult(204);
57 46 }
58 47
59   - [AcceptVerbs("patch")]
60   - public ActionResult CuratedPackage(
  48 + [ActionName("CuratedPackage"), AcceptVerbs("patch")]
  49 + public ActionResult PatchCuratedPackage(
61 50 string curatedFeedName,
62 51 string curatedPackageId,
63 52 ModifyCuratedPackageRequest request)
@@ -83,5 +72,39 @@ public ActionResult CreateCuratedPackageForm(string curatedFeedName)
83 72
84 73 return new HttpStatusCodeResult(200);
85 74 }
  75 +
  76 + [ActionName("CuratedPackages"), HttpPost]
  77 + public ActionResult PostCuratedPackages(
  78 + string curatedFeedName,
  79 + CreateCuratedPackageRequest request)
  80 + {
  81 + var curatedFeed = GetService<ICuratedFeedByNameQuery>().Execute(curatedFeedName, includePackages: true);
  82 + if (curatedFeed == null)
  83 + return HttpNotFound();
  84 +
  85 + if (!curatedFeed.Managers.Any(manager => manager.Username == Identity.Name))
  86 + return new HttpStatusCodeResult(403);
  87 +
  88 + if (!ModelState.IsValid)
  89 + {
  90 + ViewBag.CuratedFeedName = curatedFeed.Name;
  91 + return View("CreateCuratedPackageForm");
  92 + }
  93 +
  94 + var packageRegistration = GetService<IPackageRegistrationByIdQuery>().Execute(request.PackageId);
  95 + if (packageRegistration == null)
  96 + {
  97 + ModelState.AddModelError("PackageId", Strings.PackageWithIdDoesNotExist);
  98 + ViewBag.CuratedFeedName = curatedFeed.Name;
  99 + return View("CreateCuratedPackageForm");
  100 + }
  101 +
  102 + GetService<ICreatedCuratedPackageCommand>().Execute(
  103 + curatedFeed.Key,
  104 + packageRegistration.Key,
  105 + notes: request.Notes);
  106 +
  107 + return RedirectToRoute(RouteName.CuratedFeed, new { name = curatedFeed.Name });
  108 + }
86 109 }
87 110 }
3  Website/Entities/EntitiesContext.cs
@@ -10,6 +10,7 @@ public interface IEntitiesContext
10 10 DbSet<T> Set<T>() where T : class;
11 11
12 12 IDbSet<CuratedFeed> CuratedFeeds { get; set; }
  13 + IDbSet<CuratedPackage> CuratedPackages { get; set; }
13 14 IDbSet<PackageRegistration> PackageRegistrations { get; set; }
14 15 IDbSet<User> Users { get; set; }
15 16 }
@@ -23,7 +24,6 @@ public EntitiesContext()
23 24
24 25 protected override void OnModelCreating(DbModelBuilder modelBuilder)
25 26 {
26   -
27 27 modelBuilder.Entity<User>()
28 28 .HasKey(u => u.Key);
29 29
@@ -127,6 +127,7 @@ protected override void OnModelCreating(DbModelBuilder modelBuilder)
127 127 }
128 128
129 129 public IDbSet<CuratedFeed> CuratedFeeds { get; set; }
  130 + public IDbSet<CuratedPackage> CuratedPackages { get; set; }
130 131 public IDbSet<PackageRegistration> PackageRegistrations { get; set; }
131 132 public IDbSet<User> Users { get; set; }
132 133 public IDbSet<WorkItem> WorkItems
2  ...ite/RequestModels/CreatedCuratedPackageRequest.cs → Website/RequestModels/CreateCuratedPackageRequest.cs
@@ -3,7 +3,7 @@
3 3
4 4 namespace NuGetGallery
5 5 {
6   - public class CreatedCuratedPackageRequest
  6 + public class CreateCuratedPackageRequest
7 7 {
8 8 [Required]
9 9 [DisplayName("Package ID")]
22 Website/Views/CuratedFeeds/CuratedFeed.cshtml
@@ -5,6 +5,20 @@
5 5 @section TopScripts {
6 6 <script>
7 7 var urlFormat = "@Url.RouteUrl(RouteName.CuratedPackage, new { curatedFeedName = Model.Name, curatedPackageId = "PACKAGE_ID" })";
  8 +
  9 + function deleteCuratedPackage(packageId) {
  10 + $.ajax({
  11 + type: 'delete',
  12 + url: urlFormat.replace("PACKAGE_ID", packageId)
  13 + })
  14 + .error(function(jqXhr, textStatus, errorThrown) {
  15 + alert("Error: " + errorThrown);
  16 + })
  17 + .complete(function () {
  18 + location.reload();
  19 + });
  20 + }
  21 +
8 22 function patchCuratedPackage(packageId, included) {
9 23 $.ajax({
10 24 type: 'patch',
@@ -21,6 +35,12 @@
21 35 }
22 36
23 37 $(document).ready(function() {
  38 + $(".remove-link").click(function() {
  39 + deleteCuratedPackage($(this).data("package-id"));
  40 + });
  41 + });
  42 +
  43 + $(document).ready(function() {
24 44 $(".exclude-link").click(function() {
25 45 patchCuratedPackage($(this).data("package-id"), false);
26 46 });
@@ -57,7 +77,7 @@
57 77 }
58 78 else
59 79 {
60   -
  80 + <a href="#" class="remove-link" data-package-id="@package.Id">Remove</a>
61 81 }
62 82 </li>
63 83 }
2  Website/Views/CuratedPackages/CreateCuratedPackageForm.cshtml
... ... @@ -1,4 +1,4 @@
1   -@model CreatedCuratedPackageRequest
  1 +@model CreateCuratedPackageRequest
2 2 @{
3 3 Layout = "~/Views/Shared/TwoColumnLayout.cshtml";
4 4 }
5 Website/Website.csproj
@@ -165,8 +165,9 @@
165 165 </Compile>
166 166 <Compile Include="App_Start\PackageStoreType.cs" />
167 167 <Compile Include="Commands\AppCommand.cs" />
  168 + <Compile Include="Commands\DeleteCuratedPackageCommand.cs" />
168 169 <Compile Include="Commands\ModifyCuratedPackageCommand.cs" />
169   - <Compile Include="Commands\CreatedCuratedPackageCommand.cs" />
  170 + <Compile Include="Commands\CreateCuratedPackageCommand.cs" />
170 171 <Compile Include="Commands\AutomaticallyCuratePackageCommand.cs" />
171 172 <Compile Include="Controllers\AppController.cs" />
172 173 <Compile Include="Controllers\CuratedFeedsController.cs" />
@@ -313,7 +314,7 @@
313 314 <Compile Include="Queries\PackageRegistrationByKeyQuery.cs" />
314 315 <Compile Include="Queries\UserByUsernameQuery.cs" />
315 316 <Compile Include="RequestModels\ModifyCuratedPackageRequest.cs" />
316   - <Compile Include="RequestModels\CreatedCuratedPackageRequest.cs" />
  317 + <Compile Include="RequestModels\CreateCuratedPackageRequest.cs" />
317 318 <Compile Include="Services\CloudBlobClientWrapper.cs" />
318 319 <Compile Include="Services\CloudBlobContainerWrapper.cs" />
319 320 <Compile Include="Services\CloudBlobFileStorageService.cs" />

0 comments on commit 5390463

Please sign in to comment.
Something went wrong with that request. Please try again.