public void RestoreAlbumShouldHaveRestrictionsForHttpPostOnlyAndAuthorizedUsers() => MyController <DashboardController> .Calling(c => c.RestoreAlbum(With.Any <int>())) .ShouldHave() .ActionAttributes(attr => attr .RestrictingForHttpMethod(System.Net.Http.HttpMethod.Post) .RestrictingForAuthorizedRequests());
public void ErrorShouldReturnViewWithCorrectViewModel() => MyController <HomeController> .Calling(c => c.Error()) .ShouldReturn() .View(v => v .WithDefaultName() .WithModelOfType <ErrorViewModel>());
public void CreateShouldHaveRestrictionsForHttpPostOnlyAndAuthorizedUsers() => MyController <WallPostsController> .Calling(c => c.Create(With.Any <string>())) .ShouldHave() .ActionAttributes(attr => attr .RestrictingForHttpMethod(System.Net.Http.HttpMethod.Post) .RestrictingForAuthorizedRequests());
public void AddDrinkCategoryWorksCorrectly() { var addCategoryViewModel = new AddCategoryViewModel() { Name = "Test", Description = "testdescritption", Image = this.GetImageMock(), }; MyController <ManageController> .Calling(c => c.AddDrinkCategory(addCategoryViewModel)) .ShouldHave() .ValidModelState() .AndAlso() .ShouldReturn() .RedirectToAction("Index"); addCategoryViewModel.Name = null; MyController <ManageController> .Calling(c => c.AddDrinkCategory(addCategoryViewModel)) .ShouldReturn() .View(); }
public void EditPostShouldHaveRestrictionsForHttpPostOnlyAndAuthorizedUsers() => MyController <PhotoAlbumsController> .Calling(c => c.Edit(With.Default <EditPhotoAlbumViewModel>())) .ShouldHave() .ActionAttributes(attributes => attributes .RestrictingForHttpMethod(HttpMethod.Post) .RestrictingForAuthorizedRequests());
public void CreatePostShouldHaveRestrictionsForHttpPostOnlyAndAuthorizedUsers() => MyController <ArticlesController> .Calling(c => c.Create(With.Empty <ArticleFormModel>())) .ShouldHave() .ActionAttributes(attrs => attrs .RestrictingForHttpMethod(HttpMethod.Post) .RestrictingForAuthorizedRequests());
public void GetLoginShouldHaveCorrectAttributes() => MyController <IdentityController> .Calling(c => c.Login(new LoginUserCommand(IdentityFakes.TestEmail, IdentityFakes.ValidPassword))) .ShouldHave() .ActionAttributes(attr => attr .RestrictingForHttpMethod(HttpMethod.Post));
public void DeleteListShouldHaveRestrictionsForHttpPostOnlyAndAuthorizedUsers() => MyController <ListsController> .Calling(c => c.DeleteList(With.Any <int>())) .ShouldHave() .ActionAttributes(attr => attr .RestrictingForHttpMethod(System.Net.Http.HttpMethod.Post) .RestrictingForAuthorizedRequests());
public void CreatePostShouldHaveRestrictionsForHttpPostOnlyAndAuthorizedUsers() => MyController <ListsController> .Calling(c => c.Create(With.Default <ListCreateInputModel>())) .ShouldHave() .ActionAttributes(attr => attr .RestrictingForHttpMethod(System.Net.Http.HttpMethod.Post) .RestrictingForAuthorizedRequests());
public void IndexShouldHaveAuthorizedAttribute() // Arrange => MyController <ListController> .Calling(c => c.Index()) // Assert .ShouldHave() .ActionAttributes(attr => attr.RestrictingForAuthorizedRequests());
public void ControllerAssertionShouldWorkCorrectlyWithVersioning() { MyController <VersioningController> .Calling(c => c.Index()) .ShouldReturn() .Ok(); }
public void CreatePostShouldSaveArticleSetTempDataMessageAndRedirectWhenValidModel(string title, string content) => MyController <ArticlesController> .Calling(c => c.Create(new ArticleFormModel { Title = title, Content = content })) .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 SearchShouldHaveCorrectAttributes() => MyController <ArticlesController> .Calling(c => c.Search(With.Default <SearchArticlesQuery>())) .ShouldHave() .ActionAttributes(attr => attr .RestrictingForHttpMethod(HttpMethod.Get));
public void DetailsShouldBeAllowedForAnonymousUsersAndGetRequestsOnly() => MyController <ArticlesController> .Calling(c => c.Details(With.Default <GetArticleDetails>())) .ShouldHave() .ActionAttributes(attr => attr .AllowingAnonymousRequests() .RestrictingForHttpMethod(HttpMethod.Get));
public void UpdateAddNewListItemShouldHaveRestrictionsForHttpPostOnlyAndAuthorizedUsers() => MyController <ListsController> .Calling(c => c.UpdateAddNewListItem(With.Default <ListUpdateViewModel>())) .ShouldHave() .ActionAttributes(attr => attr .RestrictingForHttpMethod(System.Net.Http.HttpMethod.Post) .RestrictingForAuthorizedRequests());
public void AddIngredientShouldWorkCorrectly() { var addIngredient = new AddIngredientViewModel() { Name = "test", AllergensId = new List <int>() { 1, 2 }, }; MyController <ManageController> .Calling(c => c.AddIngredient(addIngredient)) .ShouldHave() .ValidModelState() .AndAlso() .ShouldReturn() .RedirectToAction("Index"); addIngredient.Name = null; MyController <ManageController> .Calling(c => c.AddIngredient(addIngredient)) .ShouldReturn() .View(); }
public void AddDishShouldWorkCorrectly() { var addDishModel = new AddDishViewModel() { Name = "test", Price = 49.02m, Weight = 250, PrepareTime = 10, AdditionalInfo = "This is additional info", DishTypeId = 3, IngredientsId = new List <int>() { 1, 2 }, Image = this.GetImageMock(), }; MyController <ManageController> .Calling(c => c.AddDish(addDishModel)) .ShouldHave() .ValidModelState() .AndAlso() .ShouldReturn() .RedirectToAction("Index"); addDishModel.Weight = -5; MyController <ManageController> .Calling(c => c.AddDish(addDishModel)) .ShouldReturn() .View(); }
public void EditPostShouldReturnNotFoundWhenInvalidId() => MyController <ArticlesController> .Calling(c => c.Edit( With.Any <int>(), With.Any <ArticleFormModel>())) .ShouldReturn() .NotFound();
public void EditGetShouldHaveRestrictionsForHttpGetOnlyAndAuthorizedUsers() => MyController <ArticlesController> .Calling(c => c.Edit(With.Empty <int>())) .ShouldHave() .ActionAttributes(attrs => attrs .RestrictingForHttpMethod(HttpMethod.Get) .RestrictingForAuthorizedRequests());
public void IndexShouldReturnViewWithCorrectModel() => MyController <HomeController> .Calling(c => c.Index()) .ShouldReturn() .View(view => view .WithName(nameof(HomeController.Index)) .WithModel("2020 Test Data"));
public void Register_ShouldHaveCorrectAttributes() => MyController <IdentityController> .Calling(c => c .Register(RegisterCommandFakes.Data.GetCommand())) .ShouldHave() .ActionAttributes(attr => attr .RestrictingForHttpMethod(HttpMethod.Post) .SpecifyingRoute(nameof(IdentityController.Register)));
public void ListingAllShouldHaveCorrectAttributes() => MyController <ListingController> .Calling(c => c.All(With.Default <AllListingQuery>())) .ShouldHave() .ActionAttributes(attr => attr .RestrictingForHttpMethod(HttpMethod.Get) .SpecifyingRoute("All"));
public void CreateGETPredictionMustBeOnlyForAuthorizedUsers() => MyController <PredictionsController> .Calling(x => x.Create()) .ShouldHave() .ActionAttributes(attrs => attrs .RestrictingForHttpMethod(HttpMethod.Get) .RestrictingForAuthorizedRequests());
public void DeleteShouldBeRestrictedForPOSTRequest() // Arrange => MyController <VolumeController> // Act .Calling(c => c.Delete(2)) // Assert .ShouldHave() .ActionAttributes(a => a.RestrictingForHttpMethod(HttpMethod.Post));
public void ListingDetailsShouldHaveCorrectAttributes() => MyController <ListingController> .Calling(c => c.Details(With.Default <DetailsListingQuery>())) .ShouldHave() .ActionAttributes(attr => attr .RestrictingForHttpMethod(HttpMethod.Get) .SpecifyingRoute(ApiController.Id));
public void LoginShouldHaveCorrectAttributes() => MyController <IdentityController> .Calling(c => c .Login(new LoginUserCommand(With.No <string>(), With.No <string>()))) .ShouldHave() .ActionAttributes(attr => attr .RestrictingForHttpMethod(HttpMethod.Post) .SpecifyingRoute(nameof(IdentityController.Login)));
public void DeleteShouldReturnNotFoundWithNullValueIfVolumeDoesNotExist() // Arrange => MyController <VolumeController> // Act .Calling(c => c.Delete(2)) // Assert .ShouldReturn() .NotFound();
public void CreatePostShouldReturnViewWithSameModelWhenInvalidModelState() => MyController <ArticlesController> .Calling(c => c.Create(With.Default <ArticleFormModel>())) .ShouldHave() .InvalidModelState() .AndAlso() .ShouldReturn() .View(With.Default <ArticleFormModel>());
public void CreatePOSTMustByOnlyForAuthorizedUser() => MyController <PredictionsController> .Calling(x => x.Create(With.Default <CreatePredictionInputViewModel>())) .ShouldHave() .ActionAttributes(attrs => attrs .RestrictingForHttpMethod(HttpMethod.Post) .RestrictingForAuthorizedRequests());
public void RegisterShouldHaveCorrectAttributes(string email, string password, string name, string phoneNumber) => MyController <IdentityController> .Calling(c => c .Register(new RegisterUserCommand(email, password, name, phoneNumber))) .ShouldHave() .ActionAttributes(attr => attr .RestrictingForHttpMethod(HttpMethod.Post) .SpecifyingRoute(nameof(IdentityController.Register)));
public void MockMemoryCacheShouldBeDifferentForEveryCallSynchronouslyWithCachedControllerBuilder() { MyApplication .StartsFrom<DefaultStartup>() .WithServices(services => services.AddMemoryCache()); var controller = new MyController<MvcController>(); // second call should not have cache entries controller .WithMemoryCache(cache => cache.WithEntry("test", "value")) .Calling(c => c.MemoryCacheAction()) .ShouldReturn() .Ok(); controller .Calling(c => c.MemoryCacheAction()) .ShouldReturn() .BadRequest(); MyApplication.StartsFrom<DefaultStartup>(); }