public void PostAddShouldBeMapped() => MyRouting .Configuration() .ShouldMap(request => request .WithPath($"{basePath}/Add") .WithMethod(HttpMethod.Post)) .To <WeaponsController>(c => c.Add(With.Any <AddWeaponFormModel>()));
public void AddArmorReplyShouldBeMapped() => MyRouting .Configuration() .ShouldMap(request => request .WithPath($"{basePath}/AddArmorReply") .WithMethod(HttpMethod.Post)) .To <CommentsController>(c => c.AddArmorReply(With.Any <AddReplyFormModel>()));
public void GetEditShouldBeMapped() => MyRouting .Configuration() .ShouldMap(request => request .WithPath($"{basePath}/Edit") .WithMethod(HttpMethod.Post)) .To <WeaponsController>(c => c.Edit(With.Any <string>()));
public void GetCompleteShouldBeRoutedCorrectly() { MyMvc .Routing() .ShouldMap("/Checkout/Complete/1") .To <CheckoutController>(c => c.Complete(With.Any <MusicStoreContext>(), 1)); }
public void PostEditShouldBeMapped() => MyRouting .Configuration() .ShouldMap(request => request .WithPath($"{basePath}/Edit") .WithMethod(HttpMethod.Post)) .To <ArmorsController>(c => c.Edit(With.Any <string>(), With.Any <AddArmorFormModel>()));
public void DetailsShouldBeRoutedCorrectly() { MyMvc .Routes() .ShouldMap("/Store/Details/1") .To <StoreController>(c => c.Details(With.Any <IMemoryCache>(), 1));; }
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 CreateShouldHaveRestrictionsForHttpPostOnlyAndAuthorizedUsers() => MyController <WallPostsController> .Calling(c => c.Create(With.Any <string>())) .ShouldHave() .ActionAttributes(attr => attr .RestrictingForHttpMethod(System.Net.Http.HttpMethod.Post) .RestrictingForAuthorizedRequests());
private void ConfigureRuhRoh(IServiceCollection services) { services.AffectScoped <ITodoItemService, TodoItemService>() .WhenCalling(x => x.GetAllTodoItems()) .SlowItDownBy(TimeSpan.FromSeconds(10)) .AtRandom(); services.AffectScoped <ITodoItemService, TodoItemService>() .WhenCalling(x => x.AddNewTodoItem(With.Any <string>())) .Throw <Exception>() .AtRandom(); Func <Task <TodoItem>, Task <TodoItem> > taskWithChaosFunc = async task => { var item = await task; item.Completed = !item.Completed; item.Description = string.Concat("CHAOS - ", item.Description, " - CHAOS"); return(item); }; services.AffectScoped <ITodoItemService, TodoItemService>() .WhenCalling(x => x.GetTodoItem(With.Any <Guid>())) .ReturnsAsync <TodoItem>(x => taskWithChaosFunc(x)) .EveryNCalls(2); services.AffectScoped <ITodoItemService, TodoItemService>() .WhenCalling(x => x.GetTodoItem(With.Any <Guid>())) .Throw <Exception>() .EveryNCalls(3) .And // During 5 minutes after running, every third call should fail .PlannedAt(new DateTimeOffset(DateTime.Now.AddMinutes(-40)), TimeSpan.FromMinutes(45)); }
public void DeleteShouldReturnBadRequestWhenAddressIdIsNotExisting() => MyController <AddressesController> .Instance(instance => instance .WithUser()) .Calling(c => c.Delete(With.Any <int>())) .ShouldReturn() .BadRequest();
public void ToShouldResolveCorrectlyWithIgnoredParameter() { MyMvc .Routes() .ShouldMap("/Home/Contact/1") .To <HomeController>(c => c.Contact(With.Any <int>())); }
public void PostCreateShouldBeRoutedCorrectly() => MyRouting .Configuration() .ShouldMap(request => request .WithLocation("/Vacancies/Create") .WithMethod(HttpMethod.Post)) .To <VacanciesController>(c => c.Create(With.Any <Vacancy>()));
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 ConfigureServices(IServiceCollection services) { services .AddDbContext <ApplicationDbContext>(options => options .UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); services .AddIdentity <ApplicationUser, IdentityRole>() .AddEntityFrameworkStores <ApplicationDbContext>() .AddDefaultTokenProviders(); services .AddMvc() .AddTypedRouting(routes => routes .Get("CustomController/{action}", route => route.ToController <ExpressionsController>()) .Get("CustomContact", route => route.ToAction <HomeController>(a => a.Contact())) .Get("WithParameter/{id}", route => route.ToAction <HomeController>(a => a.Index(With.Any <int>()))) .Get("Async", route => route.ToAction <AccountController>(a => a.LogOff())) .Get("Named", route => route .ToAction <AccountController>(a => a.Register(With.Any <string>())) .WithName("CustomName")) .Add("Constraint", route => route .ToAction <AccountController>(c => c.Login(With.Any <string>())) .WithActionConstraints(new HttpMethodActionConstraint(new[] { "PUT" }))) .Add("MultipleMethods", route => route .ToAction <HomeController>(a => a.About()) .ForHttpMethods("GET", "POST"))); services.AddTransient <IEmailSender, AuthMessageSender>(); services.AddTransient <ISmsSender, AuthMessageSender>(); }
public void PostBecomeShouldBeForAuthorizedUsersAndReturnRedirectWithValidModel( string dealerName, string phoneNumber) => MyController <DealersController> .Instance(controller => controller .WithUser()) .Calling(c => c.Become(new BecomeDealerFormModel { Name = dealerName, PhoneNumber = phoneNumber })) .ShouldHave() .ActionAttributes(attributes => attributes .RestrictingForHttpMethod(HttpMethod.Post) .RestrictingForAuthorizedRequests()) .ValidModelState() .Data(data => data .WithSet <Dealer>(dealers => dealers .Any(d => d.Name == dealerName && d.PhoneNumber == phoneNumber && d.UserId == TestUser.Identifier))) .TempData(tempData => tempData .ContainingEntryWithKey(GlobalMessageKey)) .AndAlso() .ShouldReturn() .Redirect(redirect => redirect .To <CarsController>(c => c.All(With.Any <AllCarsQueryModel>())));
public void PostBecomeShouldBeMapped() => MyRouting .Configuration() .ShouldMap(request => request .WithPath("/Dealers/Become") .WithMethod(HttpMethod.Post)) .To <DealersController>(c => c.Become(With.Any <BecomeDealerFormModel>()));
public void EditPostShouldReturnNotFoundWhenInvalidId() => MyController <ArticlesController> .Calling(c => c.Edit( With.Any <int>(), With.Any <ArticleFormModel>())) .ShouldReturn() .NotFound();
public void AddToCartShouldBeRoutedCorrectly() { MyMvc .Routing() .ShouldMap("/ShoppingCart/AddToCart/1") .To <ShoppingCartController>(c => c.AddToCart(1, With.Any <CancellationToken>())); }
public void UserHasCommitsShouldReturnUnauthorizedStatusCodeWithNoRequestHeader() { controller .Calling(c => c.UserHasCommits(With.Any <string>())) .ShouldReturn() .HttpResponseMessage() .WithStatusCode(HttpStatusCode.Unauthorized); }
private WithMatcher GetAnyWatcher <T>() { using (var context = new MatchingContext()) { With.Any <T>(); return(context.LastMatcher); } }
public void ToShouldResolveCorrectlyWithIgnoredParameter() { MyWebApi .Routes() .ShouldMap("api/Route/WithParameter/5") .WithHttpMethod(HttpMethod.Post) .To <RouteController>(c => c.WithParameter(With.Any <int>())); }
public void PostCreateShouldBeRoutedCorrectly() => MyRouting .Configuration() .ShouldMap(request => request .WithLocation("/Games/Create") .WithMethod(HttpMethod.Post) .WithUser()) .To <GamesController>(c => c.Create(With.Any <CreateGameInputModel>()));
public void WithAnyShouldWorkCorrectlyWhereTheValueOfActionParametersAreNotImportant() { MyWebApi .Controller <AttributesController>() .Calling(c => c.WithAttributesAndParameters(With.Any <int>())) .ShouldHave() .ActionAttributes(attrs => attrs.AllowingAnonymousRequests()); }
public void RemoveFromCartShouldBeRoutedCorrectly() { MyMvc .Routing() .ShouldMap(request => request .WithMethod(HttpMethod.Post) .WithLocation("/ShoppingCart/RemoveFromCart/1")) .To <ShoppingCartController>(c => c.RemoveFromCart(1, With.Any <CancellationToken>())); }
public void GetIndexShouldBeRoutedCorrectly() { MyMvc .Routing() .ShouldMap("/Home/Index") .To <HomeController>(c => c.Index( With.Any <MusicStoreContext>(), With.Any <IMemoryCache>())); }
public void PostCreateShouldBeRoutedCorrectly() => MyRouting .Configuration() .ShouldMap(request => request .WithLocation("/Articles/Create") .WithMethod(HttpMethod.Post) .WithUser() .WithAntiForgeryToken()) .To <ArticlesController>(c => c.Create(With.Any <ArticleFormModel>()));
public void GetCompleteShouldBeRoutedCorrectly() { MyMvc .Routing() .ShouldMap(request => request .WithLocation("/Checkout/Complete/1") .WithAuthenticatedUser()) .To <CheckoutController>(c => c.Complete(With.Any <MusicStoreContext>(), 1)); }
public void MapToUpdateTodo() { MyMvc .Routing() .ShouldMap(request => request .WithMethod(HttpMethod.Put) .WithLocation("/api/todos")) .To <UpdateTodoController>(x => x.Update(With.Any <TodoUpdatingRequest>())); }
public void CommentsControllerShouldHaveAuthorizedHttpGetRouteAndValidateTakeAttribute() { controller .Calling(c => c.ByUser(With.Any <string>(), With.Any <int>(), With.Any <int>())) .ShouldHave() .ActionAttributes(attrs => attrs .RestrictingForRequestsWithMethod(HttpMethod.Get) .ChangingRouteTo("api/Comments/ByUser/{id}") .ContainingAttributeOfType <ValidateTakeAttribute>()); }
public void PostAddShouldBeRoutedCorrectly() => MyMvc .Routing() .ShouldMap(request => request .WithMethod(HttpMethod.Post) .WithLocation("/CreditCompanies/Add") .WithUser(user => user.InRole(GlobalConstants.AdministratorRoleName)) .WithAntiForgeryToken()) .To <CreditCompaniesController>(c => c.Add(With.Any <CreditCompanyCreateInputModel>()));