Exemple #1
0
            public void WillModifyTheCuratedPackageWhenRequestIsValid()
            {
                var controller = new TestableCuratedPackagesController();

                controller.StubCuratedFeed.Packages.Add(
                    new CuratedPackage
                {
                    CuratedFeed            = controller.StubCuratedFeed,
                    CuratedFeedKey         = controller.StubCuratedFeed.Key,
                    PackageRegistration    = controller.StubPackageRegistration,
                    PackageRegistrationKey = controller.StubPackageRegistration.Key,
                    Included = true,
                });

                Assert.False(controller.StubCuratedFeed.Packages.Any(
                                 cp => cp.Included == false));

                var result = controller.PatchCuratedPackage(
                    "aFeedName",
                    "anId",
                    new ModifyCuratedPackageRequest {
                    Included = false
                }) as HttpStatusCodeResult;

                Assert.True(controller.StubCuratedFeed.Packages.Any(
                                cp => cp.Included == false));
            }
            public void WillCreateTheCuratedPackage()
            {
                var controller = new TestableCuratedPackagesController();

                controller.StubPackageRegistrationByIdQry
                .Setup(stub => stub.Execute(It.IsAny <string>(), It.IsAny <bool>(), It.IsAny <bool>()))
                .Returns(controller.StubPackageRegistration);

                controller.PostCuratedPackages(
                    "aFeedName",
                    new CreateCuratedPackageRequest
                {
                    PackageId = "thePackageId",
                    Notes     = "theNotes"
                });

                controller.StubCuratedFeedService.Verify(
                    stub => stub.CreatedCuratedPackage(
                        controller.StubCuratedFeed,
                        controller.StubPackageRegistration,
                        true,
                        false,
                        "theNotes",
                        true));
            }
Exemple #3
0
            public void WillModifyTheCuratedPackageWhenRequestIsValid()
            {
                var controller = new TestableCuratedPackagesController();

                controller.StubCuratedFeed.Key      = 42;
                controller.StubCuratedFeed.Packages = new[]
                {
                    new CuratedPackage
                    {
                        Key = 1066,
                        PackageRegistration = new PackageRegistration {
                            Id = "theCuratedPackageId"
                        }
                    }
                };

                controller.PatchCuratedPackage("theCuratedFeedName", "theCuratedPackageId", new ModifyCuratedPackageRequest {
                    Included = true
                });

                controller.StubModifyCuratedPackageCmd.Verify(
                    stub => stub.Execute(
                        42,
                        1066,
                        true));
            }
Exemple #4
0
            public void WillReturn404IfTheCuratedFeedDoesNotExist()
            {
                var controller = new TestableCuratedPackagesController();

                var result = controller.GetCreateCuratedPackageForm("aWrongFeedName");

                Assert.IsType <HttpNotFoundResult>(result);
            }
Exemple #5
0
            public void WillReturn404IfTheCuratedPackageDoesNotExist()
            {
                var controller = new TestableCuratedPackagesController();

                var result = controller.PatchCuratedPackage("aFeedName", "aWrongId", new ModifyCuratedPackageRequest());

                Assert.IsType <HttpNotFoundResult>(result);
            }
Exemple #6
0
            public void WillReturn404IfTheCuratedFeedDoesNotExist()
            {
                var controller = new TestableCuratedPackagesController();

                var result = controller.DeleteCuratedPackage("aStrangeCuratedFeedName", "anId");

                Assert.IsType <HttpNotFoundResult>(result);
            }
            public void WillReturn404IfTheCuratedFeedDoesNotExist()
            {
                var controller = new TestableCuratedPackagesController();
                
                var result = controller.DeleteCuratedPackage("aStrangeCuratedFeedName", "anId");

                Assert.IsType<HttpNotFoundResult>(result);
            }
Exemple #8
0
            public void WillReturn204AfterDeletingTheCuratedPackage()
            {
                var controller = new TestableCuratedPackagesController();

                var result = controller.DeleteCuratedPackage("aCuratedFeedName", "aCuratedPackageId") as HttpStatusCodeResult;

                Assert.NotNull(result);
                Assert.Equal(204, result.StatusCode);
            }
            public void WillReturn404IfTheCuratedPackageDoesNotExist()
            {
                var controller = new TestableCuratedPackagesController();
                controller.StubCuratedFeed.Packages = new[] { new CuratedPackage { PackageRegistration = new PackageRegistration() } };

                var result = controller.DeleteCuratedPackage("aFeedName", "aStrangeCuratedPackageId");

                Assert.IsType<HttpNotFoundResult>(result);
            }
Exemple #10
0
            public void WillRedirectToTheCuratedFeedRouteAfterCreatingTheCuratedPackage()
            {
                var controller = new TestableCuratedPackagesController();

                var result = controller.PostCuratedPackages("aFeedName", new CreateCuratedPackageRequest()) as RedirectToRouteResult;

                Assert.NotNull(result);
                Assert.Equal(RouteName.CuratedFeed, result.RouteName);
            }
            public async Task WillReturn404IfTheCuratedFeedDoesNotExist()
            {
                var controller = new TestableCuratedPackagesController();
                controller.SetCurrentUser(controller.Fakes.User);

                var result = await controller.DeleteCuratedPackage("aStrangeCuratedFeedName", "anId");

                Assert.IsType<HttpNotFoundResult>(result);
            }
            public void WillReturn204AfterModifyingTheCuratedPackage()
            {
                var controller = new TestableCuratedPackagesController();

                var result = controller.PatchCuratedPackage("aCuratedFeedName", "aCuratedPackageId", new ModifyCuratedPackageRequest()) as HttpStatusCodeResult;

                Assert.NotNull(result);
                Assert.Equal(204, result.StatusCode);
            }
            public void WillReturn404IfTheCuratedFeedDoesNotExist()
            {
                var controller = new TestableCuratedPackagesController();

                controller.StubCuratedFeedService.Setup(stub => stub.GetFeedByName(It.IsAny <string>(), It.IsAny <bool>())).Returns((CuratedFeed)null);

                var result = controller.PatchCuratedPackage("aCuratedFeedName", "aCuratedPackageId", new ModifyCuratedPackageRequest());

                Assert.IsType <HttpNotFoundResult>(result);
            }
            public async Task WillReturn404IfTheCuratedPackageDoesNotExist()
            {
                var controller = new TestableCuratedPackagesController();

                controller.SetCurrentUser(controller.Fakes.User);

                var result = await controller.PatchCuratedPackage("aFeedName", "aWrongId", new ModifyCuratedPackageRequest());

                Assert.IsType <HttpNotFoundResult>(result);
            }
            public async Task WillReturn404IfTheCuratedFeedDoesNotExist()
            {
                var controller = new TestableCuratedPackagesController();

                controller.SetCurrentUser(controller.Fakes.User);

                var result = await controller.DeleteCuratedPackage("aStrangeCuratedFeedName", "anId");

                Assert.IsType <HttpNotFoundResult>(result);
            }
Exemple #16
0
            public void WillReturn404IfTheCuratedFeedDoesNotExist()
            {
                var controller = new TestableCuratedPackagesController();

                controller.StubCuratedFeedByNameQry.Setup(stub => stub.Execute(It.IsAny <string>(), It.IsAny <bool>())).Returns((CuratedFeed)null);

                var result = controller.DeleteCuratedPackage("aCuratedFeedName", "aCuratedPackageId");

                Assert.IsType <HttpNotFoundResult>(result);
            }
            public void WillReturn400IfTheModelStateIsInvalid()
            {
                var controller = new TestableCuratedPackagesController();

                controller.ModelState.AddModelError("", "anError");

                var result = controller.PatchCuratedPackage("aCuratedFeedName", "aCuratedPackageId", new ModifyCuratedPackageRequest()) as HttpStatusCodeResult;

                Assert.NotNull(result);
                Assert.Equal(400, result.StatusCode);
            }
Exemple #18
0
            public void WillReturn403IfTheCurrentUsersIsNotAManagerOfTheCuratedFeed()
            {
                var controller = new TestableCuratedPackagesController();

                controller.StubIdentity.Setup(stub => stub.Name).Returns("notAManager");

                var result = controller.GetCreateCuratedPackageForm("aFeedName") as HttpStatusCodeResult;

                Assert.NotNull(result);
                Assert.Equal(403, result.StatusCode);
            }
Exemple #19
0
            public void WillPushTheCuratedFeedNameIntoTheViewBag()
            {
                var controller = new TestableCuratedPackagesController();

                controller.StubCuratedFeed.Name = "theCuratedFeedName";

                var result = controller.GetCreateCuratedPackageForm("theCuratedFeedName") as ViewResult;

                Assert.NotNull(result);
                Assert.Equal("theCuratedFeedName", result.ViewBag.CuratedFeedName);
            }
            public void WillReturn403IfTheCurrentUsersIsNotAManagerOfTheCuratedFeed()
            {
                var controller = new TestableCuratedPackagesController();

                controller.SetCurrentUser(controller.Fakes.Owner);

                var result = controller.GetCreateCuratedPackageForm("aFeedName") as HttpStatusCodeResult;

                Assert.NotNull(result);
                Assert.Equal(403, result.StatusCode);
            }
Exemple #21
0
            public void WillReturn404IfTheCuratedPackageDoesNotExist()
            {
                var controller = new TestableCuratedPackagesController();

                controller.StubCuratedFeed.Packages = new[] { new CuratedPackage {
                                                                  PackageRegistration = new PackageRegistration()
                                                              } };

                var result = controller.DeleteCuratedPackage("aFeedName", "aStrangeCuratedPackageId");

                Assert.IsType <HttpNotFoundResult>(result);
            }
            public async Task WillReturn404IfTheCuratedFeedDoesNotExist()
            {
                var controller = new TestableCuratedPackagesController();

                controller.SetCurrentUser(controller.Fakes.User);

                var result = await controller.PostCuratedPackages(
                    "aWrongFeedName",
                    new CreateCuratedPackageRequest { PackageId = "AnId" });

                Assert.IsType <HttpNotFoundResult>(result);
            }
Exemple #23
0
            public void WillReturn404IfTheCuratedFeedDoesNotExist()
            {
                var controller = new TestableCuratedPackagesController();

                var result = controller.PostCuratedPackages(
                    "aWrongFeedName",
                    new CreateCuratedPackageRequest {
                    PackageId = "AnId"
                });

                Assert.IsType <HttpNotFoundResult>(result);
            }
Exemple #24
0
            public void WillReturn403IfTheCuratedPackageDoesNotExist()
            {
                var controller = new TestableCuratedPackagesController();

                controller.StubCuratedFeed.Managers = new[] { new User {
                                                                  Username = "******"
                                                              } };

                var result = controller.DeleteCuratedPackage("aCuratedFeedName", "aCuratedPackageId") as HttpStatusCodeResult;

                Assert.NotNull(result);
                Assert.Equal(403, result.StatusCode);
            }
            public async Task WillRedirectToTheCuratedFeedRouteAfterCreatingTheCuratedPackage()
            {
                var controller = new TestableCuratedPackagesController();

                controller.SetCurrentUser(controller.Fakes.User);

                var result = await controller.PostCuratedPackages(
                    "aFeedName", new CreateCuratedPackageRequest { PackageId = "anId" })
                             as RedirectToRouteResult;

                Assert.NotNull(result);
                Assert.Equal(RouteName.CuratedFeed, result.RouteName);
            }
Exemple #26
0
            public void WillPushTheCuratedFeedNameIntoTheViewBagAndShowTheCreateCuratedPackageFormWithErrorsWhenModelStateIsInvalid()
            {
                var controller = new TestableCuratedPackagesController();

                controller.StubCuratedFeed.Name = "theCuratedFeedName";
                controller.ModelState.AddModelError("", "anError");

                var result = controller.PostCuratedPackages("aFeedName", new CreateCuratedPackageRequest()) as ViewResult;

                Assert.NotNull(result);
                Assert.Equal("theCuratedFeedName", result.ViewBag.CuratedFeedName);
                Assert.Equal("CreateCuratedPackageForm", result.ViewName);
            }
            public async Task WillReturn403IfTheCurrentUsersIsNotAManagerOfTheCuratedFeed()
            {
                var controller = new TestableCuratedPackagesController();

                controller.SetCurrentUser(controller.Fakes.Owner);

                var result = await controller.PostCuratedPackages(
                    "aFeedName",
                    new CreateCuratedPackageRequest { PackageId = "AnId" })
                             as HttpStatusCodeResult;

                Assert.NotNull(result);
                Assert.Equal(403, result.StatusCode);
            }
            public void WillPushTheCuratedFeedNameIntoTheViewBagAndShowTheCreateCuratedPackageFormWithErrorsWhenThePackageIdDoesNotExist()
            {
                var controller = new TestableCuratedPackagesController();

                controller.StubCuratedFeed.Name = "theCuratedFeedName";
                controller.StubPackageRegistrationByIdQry.Setup(stub => stub.Execute(It.IsAny <string>(), It.IsAny <bool>(), It.IsAny <bool>())).Returns((PackageRegistration)null);

                var result = controller.PostCuratedPackages("aFeedName", new CreateCuratedPackageRequest()) as ViewResult;

                Assert.NotNull(result);
                Assert.Equal("theCuratedFeedName", result.ViewBag.CuratedFeedName);
                Assert.Equal(Strings.PackageWithIdDoesNotExist, controller.ModelState["PackageId"].Errors[0].ErrorMessage);
                Assert.Equal("CreateCuratedPackageForm", result.ViewName);
            }
Exemple #29
0
            public void WillPushTheCuratedFeedNameIntoTheViewBagAndShowTheCreateCuratedPackageFormWithErrorsWhenThePackageIdDoesNotExist()
            {
                var controller = new TestableCuratedPackagesController();

                var result = controller.PostCuratedPackages("aFeedName",
                                                            new CreateCuratedPackageRequest {
                    PackageId = "aWrongId"
                }) as ViewResult;

                Assert.NotNull(result);
                Assert.Equal("aFeedName", result.ViewBag.CuratedFeedName);
                Assert.Equal(Strings.PackageWithIdDoesNotExist, controller.ModelState["PackageId"].Errors[0].ErrorMessage);
                Assert.Equal("CreateCuratedPackageForm", result.ViewName);
            }
            public void WillDeleteTheCuratedPackageWhenRequestIsValid()
            {
                var controller = new TestableCuratedPackagesController();

                controller.StubCuratedFeed.Key      = 42;
                controller.StubCuratedFeed.Packages = new[] { new CuratedPackage {
                                                                  Key = 1066, PackageRegistration = new PackageRegistration {
                                                                      Id = "theCuratedPackageId"
                                                                  }
                                                              } };

                controller.DeleteCuratedPackage("theCuratedFeedName", "theCuratedPackageId");

                controller.StubDeleteCuratedPackageCmd.Verify(stub => stub.Execute(
                                                                  42,
                                                                  1066));
            }
Exemple #31
0
            public void WillReturn204AfterDeletingTheCuratedPackage()
            {
                var controller = new TestableCuratedPackagesController();

                controller.StubCuratedFeed.Packages.Add(
                    new CuratedPackage
                {
                    CuratedFeed            = controller.StubCuratedFeed,
                    CuratedFeedKey         = controller.StubCuratedFeed.Key,
                    PackageRegistration    = controller.StubPackageRegistration,
                    PackageRegistrationKey = controller.StubPackageRegistration.Key,
                });

                var result = controller.DeleteCuratedPackage("aFeedName", "anId") as HttpStatusCodeResult;

                Assert.NotNull(result);
                Assert.Equal(204, result.StatusCode);
            }
Exemple #32
0
            public void WillCreateTheCuratedPackage()
            {
                var controller = new TestableCuratedPackagesController();

                controller.PostCuratedPackages(
                    "aFeedName",
                    new CreateCuratedPackageRequest
                {
                    PackageId = "anId",
                    Notes     = "theNotes"
                });

                Assert.True(controller.EntitiesContext.Set <CuratedPackage>()
                            .Any(cp => cp.PackageRegistration.Id == "anId"));

                Assert.True(controller.EntitiesContext.Set <CuratedPackage>()
                            .Any(cp => cp.Notes == "theNotes"));
            }
            public async Task WillReturn403IfTheUserNotAManager()
            {
                var controller = new TestableCuratedPackagesController();
                controller.SetCurrentUser(controller.Fakes.Owner);

                controller.StubCuratedFeed.Packages.Add(
                    new CuratedPackage
                    {
                        CuratedFeed = controller.StubCuratedFeed,
                        CuratedFeedKey = controller.StubCuratedFeed.Key,
                        PackageRegistration = controller.StubPackageRegistration,
                        PackageRegistrationKey = controller.StubPackageRegistration.Key,
                    });

                var result = await controller.DeleteCuratedPackage("aFeedName", "anId") as HttpStatusCodeResult;

                Assert.NotNull(result);
                Assert.Equal(403, result.StatusCode);
            }
Exemple #34
0
            public void WillReturn204AfterModifyingTheCuratedPackage()
            {
                var controller = new TestableCuratedPackagesController();

                controller.StubCuratedFeed.Packages.Add(
                    new CuratedPackage
                {
                    CuratedFeed            = controller.StubCuratedFeed,
                    CuratedFeedKey         = controller.StubCuratedFeed.Key,
                    PackageRegistration    = controller.StubPackageRegistration,
                    PackageRegistrationKey = controller.StubPackageRegistration.Key,
                    Included = true,
                });

                var result = controller.PatchCuratedPackage("aFeedName", "anId",
                                                            new ModifyCuratedPackageRequest()) as HttpStatusCodeResult;

                Assert.NotNull(result);
                Assert.Equal(204, result.StatusCode);
            }
            public void WillReturn403IfTheUserNotAManager()
            {
                var controller = new TestableCuratedPackagesController();
                controller.StubIdentity
                    .Setup(i => i.Name)
                    .Returns("notAManager");

                controller.StubCuratedFeed.Packages.Add(
                    new CuratedPackage
                    {
                        CuratedFeed = controller.StubCuratedFeed,
                        CuratedFeedKey = controller.StubCuratedFeed.Key,
                        PackageRegistration = controller.StubPackageRegistration,
                        PackageRegistrationKey = controller.StubPackageRegistration.Key,
                    });

                var result = controller.DeleteCuratedPackage("aFeedName", "anId") as HttpStatusCodeResult;

                Assert.NotNull(result);
                Assert.Equal(403, result.StatusCode);
            }
            public async Task WillReturn404IfTheCuratedFeedDoesNotExist()
            {
                var controller = new TestableCuratedPackagesController();
                controller.SetCurrentUser(controller.Fakes.User);

                var result = await controller.PostCuratedPackages(
                    "aWrongFeedName",
                    new CreateCuratedPackageRequest { PackageId = "AnId" });

                Assert.IsType<HttpNotFoundResult>(result);
            }
            public async Task WillReturn403IfTheCurrentUsersIsNotAManagerOfTheCuratedFeed()
            {
                var controller = new TestableCuratedPackagesController();
                controller.SetCurrentUser(controller.Fakes.Owner);

                var result = await controller.PostCuratedPackages(
                    "aFeedName",
                    new CreateCuratedPackageRequest { PackageId = "AnId" })
                    as HttpStatusCodeResult;

                Assert.NotNull(result);
                Assert.Equal(403, result.StatusCode);
            }
            public async Task WillModifyTheCuratedPackageWhenRequestIsValid()
            {
                var controller = new TestableCuratedPackagesController();
                controller.SetCurrentUser(controller.Fakes.User);
                controller.StubCuratedFeed.Packages.Add(
                    new CuratedPackage
                    {
                        CuratedFeed = controller.StubCuratedFeed,
                        CuratedFeedKey = controller.StubCuratedFeed.Key,
                        PackageRegistration = controller.StubPackageRegistration,
                        PackageRegistrationKey = controller.StubPackageRegistration.Key,
                        Included = true,
                    });

                Assert.False(controller.StubCuratedFeed.Packages.Any(
                    cp => cp.Included == false));

                var result = await controller.PatchCuratedPackage(
                    "aFeedName",
                    "anId",
                    new ModifyCuratedPackageRequest { Included = false }) as HttpStatusCodeResult;

                Assert.True(controller.StubCuratedFeed.Packages.Any(
                    cp => cp.Included == false));
            }
            public async Task WillReturn204AfterModifyingTheCuratedPackage()
            {
                var controller = new TestableCuratedPackagesController();
                controller.SetCurrentUser(controller.Fakes.User);
                controller.StubCuratedFeed.Packages.Add(
                    new CuratedPackage
                    {
                        CuratedFeed = controller.StubCuratedFeed,
                        CuratedFeedKey = controller.StubCuratedFeed.Key,
                        PackageRegistration = controller.StubPackageRegistration,
                        PackageRegistrationKey = controller.StubPackageRegistration.Key,
                        Included = true,
                    });

                var result = await controller.PatchCuratedPackage("aFeedName", "anId",
                    new ModifyCuratedPackageRequest()) as HttpStatusCodeResult;

                Assert.NotNull(result);
                Assert.Equal(204, result.StatusCode);
            }
            public void WillReturn403IfTheCurrentUsersIsNotAManagerOfTheCuratedFeed()
            {
                var controller = new TestableCuratedPackagesController();
                controller.StubIdentity.Setup(stub => stub.Name).Returns("notAManager");

                var result = controller.PostCuratedPackages(
                    "aFeedName",
                    new CreateCuratedPackageRequest { PackageId = "AnId" })
                    as HttpStatusCodeResult;

                Assert.NotNull(result);
                Assert.Equal(403, result.StatusCode);
            }
            public async Task WillReturn400IfTheModelStateIsInvalid()
            {
                var controller = new TestableCuratedPackagesController();
                controller.SetCurrentUser(controller.Fakes.User);
                controller.StubCuratedFeed.Packages.Add(
                    new CuratedPackage
                    {
                        CuratedFeed = controller.StubCuratedFeed,
                        CuratedFeedKey = controller.StubCuratedFeed.Key,
                        PackageRegistration = controller.StubPackageRegistration,
                        PackageRegistrationKey = controller.StubPackageRegistration.Key,
                    });
                controller.ModelState.AddModelError("", "anError");

                var result = await controller.PatchCuratedPackage(
                    "aFeedName",
                    "anId",
                    new ModifyCuratedPackageRequest()) as HttpStatusCodeResult;

                Assert.NotNull(result);
                Assert.Equal(400, result.StatusCode);
            }
            public async Task WillShowAnErrorWhenThePackageHasAlreadyBeenCurated()
            {
                var controller = new TestableCuratedPackagesController();
                controller.SetCurrentUser(controller.Fakes.User);
                controller.StubCuratedFeed.Packages.Add(
                    new CuratedPackage {
                        CuratedFeed = controller.StubCuratedFeed,
                        CuratedFeedKey = controller.StubCuratedFeed.Key,
                        PackageRegistration = controller.StubPackageRegistration,
                        PackageRegistrationKey = controller.StubPackageRegistration.Key
                    });

                var result = await controller.PostCuratedPackages(
                    "aFeedName", new CreateCuratedPackageRequest { PackageId = "anId" })
                    as ViewResult;

                Assert.NotNull(result);
                Assert.Equal("aFeedName", result.ViewBag.CuratedFeedName);
                Assert.Equal(Strings.PackageIsAlreadyCurated, controller.ModelState["PackageId"].Errors[0].ErrorMessage);
                Assert.Equal("CreateCuratedPackageForm", result.ViewName);
            }
            public async Task WillCreateTheCuratedPackage()
            {
                var controller = new TestableCuratedPackagesController();
                controller.SetCurrentUser(controller.Fakes.User);

                await controller.PostCuratedPackages(
                    "aFeedName",
                    new CreateCuratedPackageRequest
                        {
                            PackageId = "anId",
                            Notes = "theNotes"
                        });

                Assert.True(controller.EntitiesContext.Set<CuratedPackage>()
                    .Any(cp => cp.PackageRegistration.Id == "anId"));

                Assert.True(controller.EntitiesContext.Set<CuratedPackage>()
                    .Any(cp => cp.Notes == "theNotes"));
            }
            public void WillReturn403IfNotAFeedManager()
            {
                var controller = new TestableCuratedPackagesController();
                controller.SetCurrentUser(Fakes.Owner);
                controller.StubCuratedFeed.Packages.Add(
                    new CuratedPackage
                    {
                        CuratedFeed = controller.StubCuratedFeed,
                        CuratedFeedKey = controller.StubCuratedFeed.Key,
                        PackageRegistration = controller.StubPackageRegistration,
                        PackageRegistrationKey = controller.StubPackageRegistration.Key,
                    });

                var result = controller.PatchCuratedPackage("aFeedName", "anId", 
                        new ModifyCuratedPackageRequest()) as HttpStatusCodeResult;

                Assert.NotNull(result);
                Assert.Equal(403, result.StatusCode);
            }
            public void WillReturn404IfTheCuratedFeedDoesNotExist()
            {
                var controller = new TestableCuratedPackagesController();
                controller.SetCurrentUser(controller.Fakes.User);

                var result = controller.GetCreateCuratedPackageForm("aWrongFeedName");

                Assert.IsType<HttpNotFoundResult>(result);
            }
            public void WillReturn204AfterDeletingTheCuratedPackage()
            {
                var controller = new TestableCuratedPackagesController();
                controller.SetCurrentUser(Fakes.User);

                controller.StubCuratedFeed.Packages.Add(
                    new CuratedPackage
                    {
                        CuratedFeed = controller.StubCuratedFeed,
                        CuratedFeedKey = controller.StubCuratedFeed.Key,
                        PackageRegistration = controller.StubPackageRegistration,
                        PackageRegistrationKey = controller.StubPackageRegistration.Key,
                    });

                var result = controller.DeleteCuratedPackage("aFeedName", "anId") as HttpStatusCodeResult;

                Assert.NotNull(result);
                Assert.Equal(204, result.StatusCode);
            }
            public void WillReturn404IfTheCuratedPackageDoesNotExist()
            {
                var controller = new TestableCuratedPackagesController();

                var result = controller.PatchCuratedPackage("aFeedName", "aWrongId", new ModifyCuratedPackageRequest());

                Assert.IsType<HttpNotFoundResult>(result);
            }
            public void WillReturn404IfTheCuratedFeedDoesNotExist()
            {
                var controller = new TestableCuratedPackagesController();

                var result = controller.PostCuratedPackages(
                    "aWrongFeedName", 
                    new CreateCuratedPackageRequest { PackageId = "AnId" });

                Assert.IsType<HttpNotFoundResult>(result);
            }
            public async Task WillPushTheCuratedFeedNameIntoTheViewBagAndShowTheCreateCuratedPackageFormWithErrorsWhenModelStateIsInvalid()
            {
                var controller = new TestableCuratedPackagesController();
                controller.SetCurrentUser(controller.Fakes.User);
                controller.StubCuratedFeed.Name = "theCuratedFeedName";
                controller.ModelState.AddModelError("", "anError");

                var result = await controller.PostCuratedPackages(
                    "theCuratedFeedName", new CreateCuratedPackageRequest()) as ViewResult;

                Assert.NotNull(result);
                Assert.Equal("theCuratedFeedName", result.ViewBag.CuratedFeedName);
                Assert.Equal("CreateCuratedPackageForm", result.ViewName);
            }
            public void WillRedirectToTheCuratedFeedRouteAfterCreatingTheCuratedPackage()
            {
                var controller = new TestableCuratedPackagesController();

                var result = controller.PostCuratedPackages(
                    "aFeedName", new CreateCuratedPackageRequest { PackageId = "anId" }) 
                    as RedirectToRouteResult;

                Assert.NotNull(result);
                Assert.Equal(RouteName.CuratedFeed, result.RouteName);
            }
            public async Task WillPushTheCuratedFeedNameIntoTheViewBagAndShowTheCreateCuratedPackageFormWithErrorsWhenThePackageIdDoesNotExist()
            {
                var controller = new TestableCuratedPackagesController();
                controller.SetCurrentUser(controller.Fakes.User);

                var result = await controller.PostCuratedPackages("aFeedName",
                    new CreateCuratedPackageRequest { PackageId = "aWrongId" }) as ViewResult;

                Assert.NotNull(result);
                Assert.Equal("aFeedName", result.ViewBag.CuratedFeedName);
                Assert.Equal(Strings.PackageWithIdDoesNotExist, controller.ModelState["PackageId"].Errors[0].ErrorMessage);
                Assert.Equal("CreateCuratedPackageForm", result.ViewName);
            }
            public async Task WillReturn404IfTheCuratedPackageDoesNotExist()
            {
                var controller = new TestableCuratedPackagesController();
                controller.SetCurrentUser(controller.Fakes.User);

                var result = await controller.PatchCuratedPackage("aFeedName", "aWrongId", new ModifyCuratedPackageRequest());

                Assert.IsType<HttpNotFoundResult>(result);
            }
            public async Task WillRedirectToTheCuratedFeedRouteAfterCreatingTheCuratedPackage()
            {
                var controller = new TestableCuratedPackagesController();
                controller.SetCurrentUser(controller.Fakes.User);

                var result = await controller.PostCuratedPackages(
                    "aFeedName", new CreateCuratedPackageRequest { PackageId = "anId" })
                    as RedirectToRouteResult;

                Assert.NotNull(result);
                Assert.Equal(RouteName.CuratedFeed, result.RouteName);
            }
            public void WillAddAllPackageVersionsToTheCuratedFeed()
            {
                var controller = new TestableCuratedPackagesController();
                controller.SetCurrentUser(Fakes.User);

                controller.PostCuratedPackages(
                    "aFeedName",
                    new CreateCuratedPackageRequest
                    {
                        PackageId = "anId",
                        Notes = "theNotes"
                    });

                var packageVersions =
                    controller.StubCuratedFeed.Packages.First(cpr => cpr.PackageRegistration.Id == "anId")
                        .CuratedPackageVersions.Select(cpv => cpv.Package).ToList();
                Assert.Equal(3, packageVersions.Count);
                Assert.Contains(controller.StubPackage, packageVersions);
                Assert.Contains(controller.StubLatestPackage, packageVersions);
                Assert.Contains(controller.StubLatestStablePackage, packageVersions);
            }
            public void WillReturn403IfTheCurrentUsersIsNotAManagerOfTheCuratedFeed()
            {
                var controller = new TestableCuratedPackagesController();
                controller.SetCurrentUser(controller.Fakes.Owner);

                var result = controller.GetCreateCuratedPackageForm("aFeedName") as HttpStatusCodeResult;

                Assert.NotNull(result);
                Assert.Equal(403, result.StatusCode);
            }
            public void WillUpdateIsLatestFlags()
            {
                var controller = new TestableCuratedPackagesController();
                controller.SetCurrentUser(Fakes.User);

                controller.PostCuratedPackages(
                    "aFeedName",
                    new CreateCuratedPackageRequest
                    {
                        PackageId = "anId",
                        Notes = "theNotes"
                    });

                var curatedPackageRegistration = controller.EntitiesContext.Set<CuratedPackage>()
                    .First(cpr => cpr.PackageRegistration.Id == "anId");
                Assert.Same(controller.StubLatestPackage, curatedPackageRegistration.CuratedPackageVersions.Single(cpv => cpv.IsLatest).Package);
                Assert.Same(controller.StubLatestStablePackage, curatedPackageRegistration.CuratedPackageVersions.Single(cpv => cpv.IsLatestStable).Package);
            }
            public async Task WillDeleteTheCuratedPackageWhenRequestIsValid()
            {
                var controller = new TestableCuratedPackagesController();
                controller.SetCurrentUser(controller.Fakes.User);

                controller.StubCuratedFeed.Packages.Add(
                    new CuratedPackage
                    {
                        CuratedFeed = controller.StubCuratedFeed,
                        CuratedFeedKey = controller.StubCuratedFeed.Key,
                        PackageRegistration = controller.StubPackageRegistration ,
                        PackageRegistrationKey = controller.StubPackageRegistration.Key,
                    });

                Assert.True(controller.EntitiesContext.CuratedPackages.Any
                    (cp => cp.PackageRegistration.Id == "anId"));

                await controller.DeleteCuratedPackage("aFeedName", "anId");

                Assert.False(controller.EntitiesContext.CuratedPackages.Any
                    (cp => cp.PackageRegistration.Id == "anId"));
            }
            public void WillPushTheCuratedFeedNameIntoTheViewBag()
            {
                var controller = new TestableCuratedPackagesController();
                controller.SetCurrentUser(controller.Fakes.User);
                controller.StubCuratedFeed.Name = "theCuratedFeedName";

                var result = controller.GetCreateCuratedPackageForm("theCuratedFeedName") as ViewResult;

                Assert.NotNull(result);
                Assert.Equal("theCuratedFeedName", result.ViewBag.CuratedFeedName);
            }