public void ErrorShouldReturnView() => MyMvc .Pipeline() .ShouldMap("/Home/Error") .To <HomeController>(c => c.Error()) .Which() .ShouldReturn() .View();
public void GetPrivacyShouldReturnDefaultView() => MyMvc .Pipeline() .ShouldMap("/Home/Privacy") .To <HomeController>(c => c.Privacy()) .Which() .ShouldReturn() .View();
public void PrivacyShouldReturnPrivacyPage() { MyMvc .Pipeline() .ShouldMap("/Home/Privacy") .To <HomeController>(c => c.Privacy()) .Which() .ShouldReturn() .View(); }
public void IndexShouldReturnHomePage() { MyMvc .Pipeline() .ShouldMap("/") .To <HomeController>(c => c.Index()) .Which() .ShouldReturn() .View(); }
public void GetErrorShouldReturnCorrectView() { MyMvc .Pipeline() .ShouldMap("/Home/Error") .To <HomeController>(c => c.Error()) .Which() .ShouldReturn() .View("~/Views/Shared/Error.cshtml"); }
public void GetCreateShouldShouldReturnView() => MyMvc .Pipeline() .ShouldMap(request => request .WithLocation("/Articles/Create") .WithUser()) .To <ArticlesController>(c => c.Create()) .Which() .ShouldReturn() .View();
public void IndexShouldReturnViewWithCorrectModelAndData() => MyMvc .Pipeline() .ShouldMap("/") .To <HomeController>(c => c.Index()) .Which(controller => controller .WithData(TenPublicCars)) .ShouldReturn() .View(view => view .WithModelOfType <List <LatestCarServiceModel> >() .Passing(m => m.Should().HaveCount(3)));
public void GetIndexShouldReturnDefaultViewWithCorrectModel(int total, bool arePublic, int expected) => MyMvc .Pipeline() .ShouldMap("/") .To <HomeController>(c => c.Index()) .Which(controller => controller .WithData(ArticleTestData.GetArticles(total, arePublic))) .ShouldReturn() .View(view => view .WithModelOfType <List <ArticleListingServiceModel> >() .Passing(articles => articles.Count.ShouldBe(expected)));
public void IndexShouldReturnViewWithCorrectModelAndData() => MyMvc .Pipeline() .ShouldMap("/") .To <HomeController>(c => c.Index()) .Which(controller => controller .WithData(GetCars())) .ShouldReturn() .View(view => view .WithModelOfType <IndexViewModel>() .Passing(m => m.Cars.Should().HaveCount(3)));
public void GetDetailsShouldReturnViewWithCorrectModelWhenPublicArticleAndAnonymousUser() => MyMvc .Pipeline() .ShouldMap("/Articles/Details/1") .To <ArticlesController>(c => c.Details(1)) .Which(controller => controller .WithData(ArticleTestData.GetArticles(1))) .ShouldReturn() .View(view => view .WithModelOfType <ArticleDetailsServiceModel>() .Passing(article => article.Id == 1));
public void DrinksWorksCorrectly() { MyMvc .Pipeline() .ShouldMap(request => request .WithLocation("/Menu/Drinks") .WithMethod(HttpMethod.Get)) .To <MenuController>(c => c.Drinks()) .Which() .ShouldReturn() .View(v => v.Passing(x => Assert.IsType <List <MenuItemViewModel> >(x.Model))); }
public void GetAllShouldReturnViewWithAllArticles() => MyMvc .Pipeline() .ShouldMap(request => request .WithLocation("/Admin/Articles/All") .WithUser(new[] { ControllerConstants.AdministratorRole })) .To <ArticlesController>(c => c.All()) .Which(controller => controller .WithData(ArticleTestData.GetArticles(1, isPublic: false))) .ShouldReturn() .View(view => view .WithModelOfType <List <ArticleNonPublicListingServiceModel> >() .Passing(articles => articles.ShouldNotBeEmpty()));
public void IndexWorksCorrectly() { MyMvc .Pipeline() .ShouldMap(request => request .WithLocation("/Order/Index/id") .WithMethod(HttpMethod.Get) .WithUser()) .To <OrderController>(c => c.Index("id")) .Which() .ShouldReturn() .View(v => v.Passing(x => Assert.True(x.Model is OrderInfoViewModel || x.Model == null))); }
public void IndexWorksCorrectly() { MyMvc .Pipeline() .ShouldMap(request => request .WithLocation("/Waiter/Index") .WithMethod(HttpMethod.Get) .WithUser(x => x.InRole(GlobalConstants.AdministratorRoleName))) .To <WaiterController>(c => c.Index()) .Which() .ShouldReturn() .View(v => v.Passing(x => Assert.IsType <WaiterViewModel>(x.Model))); }
public void IndexWorksCorrectly() { MyMvc .Pipeline() .ShouldMap(request => request .WithLocation("/Manage/Index") .WithMethod(HttpMethod.Get) .WithUser(u => u.InRole(GlobalConstants.AdministratorRoleName))) .To <ManageController>(c => c.Index()) .Which() .ShouldReturn() .View(); }
public void SearchWorksCorrectlyWhenSearchTermIsNotNull() { var searchTerm = "a"; MyMvc .Pipeline() .ShouldMap(request => request .WithLocation("/Menu/Search") .WithQuery("searchTerm", searchTerm) .WithMethod(HttpMethod.Get)) .To <MenuController>(c => c.Search(searchTerm)) .Which() .ShouldReturn() .View(v => v.Passing(x => Assert.IsType <SearchViewModel>(x.Model))); }
public void AllWorksCorrectly() { string userId = "userId"; MyMvc .Pipeline() .ShouldMap(request => request .WithLocation("/Order/All/" + userId + "/1") .WithMethod(HttpMethod.Get) .WithUser()) .To <OrderController>(c => c.All(userId, 1)) .Which() .ShouldReturn() .View(v => v.Passing(x => Assert.IsType <OrderViewModel>(x.Model))); }
public void SearchWorksCorrectlyWhenSearchTermIsNull() { string searchTerm = null; MyMvc .Pipeline() .ShouldMap(request => request .WithLocation("/Menu/Search") .WithQuery("searchTerm", searchTerm) .WithMethod(HttpMethod.Get)) .To <MenuController>(c => c.Search(searchTerm)) .Which() .ShouldReturn() .RedirectToAction("Index"); }
public void GetAllWithPageShouldReturnDefaultViewWithCorrectModel(int total, int page, int expectedCount) => MyMvc .Pipeline() .ShouldMap($"/Articles/All?page={page}") .To <ArticlesController>(c => c.All(page)) .Which(controller => controller .WithData(ArticleTestData.GetArticles(total))) .ShouldReturn() .View(view => view .WithModelOfType <ArticleListingViewModel>() .Passing(articleListing => { articleListing.Articles.Count().ShouldBe(expectedCount); articleListing.Total.ShouldBe(total); articleListing.Page.ShouldBe(page); }));
public void GetIndexShouldReturnNoCartItemsWhenSessionIsEmpty() { MyMvc .Pipeline() .ShouldMap("/ShoppingCart/Index") .To <ShoppingCartController>(c => c.Index()) .Which() .ShouldReturn() .View(view => view .WithModelOfType <ShoppingCartViewModel>() .Passing(model => { Assert.Empty(model.CartItems); Assert.Equal(0, model.CartTotal); })); }
public void GetMineShouldReturnViewWithCorrectModel() => MyMvc .Pipeline() .ShouldMap(request => request .WithLocation("/Articles/Mine") .WithUser("Author Id 1", "Author 1")) .To <ArticlesController>(c => c.Mine()) .Which(controller => controller .WithData(ArticleTestData.GetArticles(2, sameUser: false))) .ShouldReturn() .View(view => view .WithModelOfType <List <ArticleForUserListingServiceModel> >() .Passing(articles => { articles.ShouldNotBeEmpty(); articles.SingleOrDefault(a => a.Author == "Author 1").ShouldNotBeNull(); }));
public void IndexWorksCorrectly() { MyMvc .Pipeline() .ShouldMap(request => request .WithLocation("/Chef/Index") .WithMethod(HttpMethod.Get) .WithUser(x => x.InRole(GlobalConstants.AdministratorRoleName))) .To <ChefController>(c => c.Index()) .Which() .ShouldHave() .ValidModelState() .AndAlso() .ShouldReturn() .View(result => result .WithModelOfType <ChefViewModel>()); }
public void SalesShouldWorkCorrectly() { MyMvc .Pipeline() .ShouldMap(request => request .WithLocation("/Analyse/Sales") .WithMethod(HttpMethod.Get) .WithUser()) .To <AnalyseController>(c => c.Sales()) .Which() .ShouldHave() .ActionAttributes(attr => attr .RestrictingForAuthorizedRequests()) .ValidModelState() .AndAlso() .ShouldReturn() .View(result => result .WithModelOfType <SalesViewModel>()); }
public void IndexWorksCorrectly() { MyMvc .Pipeline() .ShouldMap(request => request .WithLocation("/Basket/Index") .WithMethod(HttpMethod.Get) .WithUser()) .To <BasketController>(c => c.Index()) .Which() .ShouldHave() .ActionAttributes(attr => attr .RestrictingForAuthorizedRequests()) .ValidModelState() .AndAlso() .ShouldReturn() .View(result => result .WithModelOfType <BasketViewModel>() .AndAlso()); }
public void AddShouldWorkCorrectly(string type, string expectedViewType) { MyMvc .Pipeline() .ShouldMap(request => request .WithLocation("/Manage/Add") .WithFormFields(new { type = type, }) .WithMethod(HttpMethod.Post) .WithUser(u => u.InRole(GlobalConstants.AdministratorRoleName)) .WithAntiForgeryToken()) .To <ManageController>(c => c.Add(type)) .Which() .ShouldHave() .ValidModelState() .AndAlso() .ShouldReturn() .View(result => result.Passing(x => Assert.True(expectedViewType == null || expectedViewType == x.Model.GetType().Name))); }
public void DisplayDrinkWorksCorrectly(string id, string viewName) { var type = "Dish"; MyMvc .Pipeline() .ShouldMap(request => request .WithLocation("/Menu/DisplayDrink") .WithFormFields(new { type = type, id = id, }) .WithMethod(HttpMethod.Get)) .To <MenuController>(c => c.DisplayDrink(type, id)) .Which() .ShouldHave() .ValidModelState() .AndAlso() .ShouldReturn() .View(viewName); }
public void GetIndexShouldReturnTopSellingAlbumsAndSaveThenIntoCache() { MyMvc .Pipeline() .ShouldMap("/Home/Index") .To <HomeController>(c => c.Index( From.Services <MusicStoreContext>(), From.Services <IMemoryCache>())) .Which() .WithOptions(options => options .For <AppSettings>(settings => settings.CacheDbResults = true)) .WithData(data => data .WithSet <Album>(albums => albums .AddRange(TestAlbumDataProvider.GetAlbums()))) .ShouldHave() .MemoryCache(cache => cache .ContainingEntryOfType <List <Album> >("topselling")) .AndAlso() .ShouldReturn() .View(view => view .WithModelOfType <List <Album> >() .Passing(albums => Assert.Equal(6, albums.Count)));; }
public void GetMineShouldChangeArticleAndRedirectToAll() => MyMvc .Pipeline() .ShouldMap(request => request .WithLocation("/Admin/Articles/ChangeVisibility/1") .WithUser(new[] { ControllerConstants.AdministratorRole })) .To <ArticlesController>(c => c.ChangeVisibility(1)) .Which(controller => controller .WithData(ArticleTestData.GetArticles(1, isPublic: false))) .ShouldHave() .Data(data => data .WithSet <Article>(set => { var article = set.FirstOrDefault(a => a.IsPublic); article.ShouldNotBeNull(); article.PublishedOn.ShouldNotBeNull(); article.PublishedOn.ShouldBe(new DateTime(1, 1, 1)); })) .AndAlso() .ShouldReturn() .Redirect(redirect => redirect .To <ArticlesController>(c => c.All()));
public void PostCreateShouldSaveArticleHaveValidModelStateAndRedirect(string title, string content) => MyMvc .Pipeline() .ShouldMap(request => request .WithMethod(HttpMethod.Post) .WithLocation("/Articles/Create") .WithFormFields(new { Title = title, Content = content }) .WithUser() .WithAntiForgeryToken()) .To <ArticlesController>(c => c.Create(new ArticleFormModel { Title = title, Content = content })) .Which() .ShouldHave() .ValidModelState() .AndAlso() .ShouldHave() .Data(data => data .WithSet <Article>(set => { set.ShouldNotBeEmpty(); set.SingleOrDefault(a => a.Title == title).ShouldNotBeNull(); })) .AndAlso() .ShouldHave() .TempData(tempData => tempData .ContainingEntryWithKey(ControllerConstants.SuccessMessage)) .AndAlso() .ShouldReturn() .Redirect(redirect => redirect .To <ArticlesController>(c => c.Mine()));
public void GetIncomesWorksCorrectly() { var incomesViewModel = new GetIncomesViewModel() { StartDate = DateTime.Now.AddDays(-5).ToShortDateString(), EndDate = DateTime.Now.ToShortDateString(), Period = "daily", }; MyMvc .Pipeline() .ShouldMap(request => request .WithLocation("/api/Analyse/Incomes") .WithQuery(incomesViewModel) .WithMethod(HttpMethod.Get) .WithUser()) .To <AnalyseController>(c => c.GetIncomes(incomesViewModel)) .Which() .ShouldHave() .ValidModelState() .AndAlso() .ShouldReturn() .ResultOfType <SalesViewModel>(); }