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 WillReturn404IfTheCuratedFeedDoesNotExist()
            {
                var controller = new TestableCuratedPackagesController();
                controller.SetCurrentUser(controller.Fakes.User);

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

                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 void WillReturn404IfTheCuratedFeedDoesNotExist()
            {
                var controller = new TestableCuratedPackagesController();

                controller.SetCurrentUser(controller.Fakes.User);

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

                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);
            }
            public async Task WillReturn404IfTheCuratedPackageDoesNotExist()
            {
                var controller = new TestableCuratedPackagesController();
                controller.SetCurrentUser(controller.Fakes.User);
                controller.StubCuratedFeed.Packages = new[] { new CuratedPackage { PackageRegistration = new PackageRegistration() } };

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

                Assert.IsType<HttpNotFoundResult>(result);
            }
            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 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);
            }
            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 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 async Task WillReturn404IfTheCuratedPackageDoesNotExist()
            {
                var controller = new TestableCuratedPackagesController();

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

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

                Assert.IsType <HttpNotFoundResult>(result);
            }
            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 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 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 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);
            }
            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"));
            }
Ejemplo n.º 17
0
            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);
            }
Ejemplo n.º 18
0
            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 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);
            }
Ejemplo n.º 20
0
            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 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 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 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);
            }
Ejemplo n.º 24
0
            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 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 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 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 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 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 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 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 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 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 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 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 WillReturn404IfTheCuratedPackageDoesNotExist()
            {
                var controller = new TestableCuratedPackagesController();
                controller.SetCurrentUser(controller.Fakes.User);

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

                Assert.IsType<HttpNotFoundResult>(result);
            }
            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);
            }
            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 WillReturn404IfTheCuratedFeedDoesNotExist()
            {
                var controller = new TestableCuratedPackagesController();
                controller.SetCurrentUser(controller.Fakes.User);

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

                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);
            }
            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 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 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 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);
            }