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));
            }
Beispiel #2
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);
            }
Beispiel #3
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.PostCuratedPackages("aFeedName", new CreateCuratedPackageRequest());

                Assert.IsType <HttpNotFoundResult>(result);
            }
Beispiel #4
0
            public void WillReturn403IfTheCurrentUsersIsNotAManagerOfTheCuratedFeed()
            {
                var controller = new TestableCuratedPackagesController();

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

                var result = controller.PostCuratedPackages("aFeedName", new CreateCuratedPackageRequest()) 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);
            }
Beispiel #6
0
            public void WillReturn404IfTheCuratedFeedDoesNotExist()
            {
                var controller = new TestableCuratedPackagesController();

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

                Assert.IsType <HttpNotFoundResult>(result);
            }
Beispiel #7
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 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 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);
            }
Beispiel #11
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);
            }
Beispiel #12
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"));
            }
Beispiel #13
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 void WillCreateTheCuratedPackage()
            {
                var controller = new TestableCuratedPackagesController();

                controller.StubCuratedFeed.Key         = 42;
                controller.StubPackageRegistration.Key = 1066;

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

                controller.StubCreatedCuratedPackageCmd.Verify(stub => stub.Execute(
                                                                   42,
                                                                   1066,
                                                                   true,
                                                                   false,
                                                                   "theNotes"));
            }
            public void WillShowAnErrorWhenThePackageHasAlreadyBeenCurated()
            {
                var controller = new TestableCuratedPackagesController();

                controller.StubCuratedFeed.Name = "theCuratedFeedName";
                controller.StubCuratedFeed.Packages.Add(new CuratedPackage {
                    PackageRegistration = new PackageRegistration {
                        Key = 42
                    }
                });
                controller.StubPackageRegistrationByIdQry.Setup(stub => stub.Execute(It.IsAny <string>(), It.IsAny <bool>(), It.IsAny <bool>())).Returns((new PackageRegistration {
                    Key = 42
                }));

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

                Assert.NotNull(result);
                Assert.Equal("theCuratedFeedName", result.ViewBag.CuratedFeedName);
                Assert.Equal(Strings.PackageIsAlreadyCurated, controller.ModelState["PackageId"].Errors[0].ErrorMessage);
                Assert.Equal("CreateCuratedPackageForm", result.ViewName);
            }
            public 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);
            }
Beispiel #17
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 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 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 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 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 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 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 WillReturn404IfTheCuratedFeedDoesNotExist()
            {
                var controller = new TestableCuratedPackagesController();

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

                Assert.IsType<HttpNotFoundResult>(result);
            }