コード例 #1
0
 public void PostAddShouldBeMapped()
 => MyRouting
 .Configuration()
 .ShouldMap(request => request
            .WithPath($"{basePath}/Add")
            .WithMethod(HttpMethod.Post))
 .To <WeaponsController>(c => c.Add(With.Any <AddWeaponFormModel>()));
コード例 #2
0
 public void AddArmorReplyShouldBeMapped()
 => MyRouting
 .Configuration()
 .ShouldMap(request => request
            .WithPath($"{basePath}/AddArmorReply")
            .WithMethod(HttpMethod.Post))
 .To <CommentsController>(c => c.AddArmorReply(With.Any <AddReplyFormModel>()));
コード例 #3
0
 public void GetEditShouldBeMapped()
 => MyRouting
 .Configuration()
 .ShouldMap(request => request
            .WithPath($"{basePath}/Edit")
            .WithMethod(HttpMethod.Post))
 .To <WeaponsController>(c => c.Edit(With.Any <string>()));
コード例 #4
0
 public void GetCompleteShouldBeRoutedCorrectly()
 {
     MyMvc
     .Routing()
     .ShouldMap("/Checkout/Complete/1")
     .To <CheckoutController>(c => c.Complete(With.Any <MusicStoreContext>(), 1));
 }
コード例 #5
0
 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>()));
コード例 #6
0
 public void DetailsShouldBeRoutedCorrectly()
 {
     MyMvc
     .Routes()
     .ShouldMap("/Store/Details/1")
     .To <StoreController>(c => c.Details(With.Any <IMemoryCache>(), 1));;
 }
コード例 #7
0
 public void RestoreAlbumShouldHaveRestrictionsForHttpPostOnlyAndAuthorizedUsers()
 => MyController <DashboardController>
 .Calling(c => c.RestoreAlbum(With.Any <int>()))
 .ShouldHave()
 .ActionAttributes(attr => attr
                   .RestrictingForHttpMethod(System.Net.Http.HttpMethod.Post)
                   .RestrictingForAuthorizedRequests());
コード例 #8
0
 public void CreateShouldHaveRestrictionsForHttpPostOnlyAndAuthorizedUsers()
 => MyController <WallPostsController>
 .Calling(c => c.Create(With.Any <string>()))
 .ShouldHave()
 .ActionAttributes(attr => attr
                   .RestrictingForHttpMethod(System.Net.Http.HttpMethod.Post)
                   .RestrictingForAuthorizedRequests());
コード例 #9
0
        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));
        }
コード例 #10
0
 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>()));
 }
コード例 #12
0
 public void PostCreateShouldBeRoutedCorrectly()
 => MyRouting
 .Configuration()
 .ShouldMap(request => request
            .WithLocation("/Vacancies/Create")
            .WithMethod(HttpMethod.Post))
 .To <VacanciesController>(c => c.Create(With.Any <Vacancy>()));
コード例 #13
0
 public void DeleteListShouldHaveRestrictionsForHttpPostOnlyAndAuthorizedUsers()
 => MyController <ListsController>
 .Calling(c => c.DeleteList(With.Any <int>()))
 .ShouldHave()
 .ActionAttributes(attr => attr
                   .RestrictingForHttpMethod(System.Net.Http.HttpMethod.Post)
                   .RestrictingForAuthorizedRequests());
コード例 #14
0
        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>();
        }
コード例 #15
0
 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>())));
コード例 #16
0
 public void PostBecomeShouldBeMapped()
 => MyRouting
 .Configuration()
 .ShouldMap(request => request
            .WithPath("/Dealers/Become")
            .WithMethod(HttpMethod.Post))
 .To <DealersController>(c => c.Become(With.Any <BecomeDealerFormModel>()));
コード例 #17
0
 public void EditPostShouldReturnNotFoundWhenInvalidId()
 => MyController <ArticlesController>
 .Calling(c => c.Edit(
              With.Any <int>(),
              With.Any <ArticleFormModel>()))
 .ShouldReturn()
 .NotFound();
コード例 #18
0
 public void AddToCartShouldBeRoutedCorrectly()
 {
     MyMvc
     .Routing()
     .ShouldMap("/ShoppingCart/AddToCart/1")
     .To <ShoppingCartController>(c => c.AddToCart(1, With.Any <CancellationToken>()));
 }
コード例 #19
0
 public void UserHasCommitsShouldReturnUnauthorizedStatusCodeWithNoRequestHeader()
 {
     controller
     .Calling(c => c.UserHasCommits(With.Any <string>()))
     .ShouldReturn()
     .HttpResponseMessage()
     .WithStatusCode(HttpStatusCode.Unauthorized);
 }
コード例 #20
0
 private WithMatcher GetAnyWatcher <T>()
 {
     using (var context = new MatchingContext())
     {
         With.Any <T>();
         return(context.LastMatcher);
     }
 }
コード例 #21
0
 public void ToShouldResolveCorrectlyWithIgnoredParameter()
 {
     MyWebApi
     .Routes()
     .ShouldMap("api/Route/WithParameter/5")
     .WithHttpMethod(HttpMethod.Post)
     .To <RouteController>(c => c.WithParameter(With.Any <int>()));
 }
コード例 #22
0
 public void PostCreateShouldBeRoutedCorrectly()
 => MyRouting
 .Configuration()
 .ShouldMap(request => request
            .WithLocation("/Games/Create")
            .WithMethod(HttpMethod.Post)
            .WithUser())
 .To <GamesController>(c => c.Create(With.Any <CreateGameInputModel>()));
コード例 #23
0
 public void WithAnyShouldWorkCorrectlyWhereTheValueOfActionParametersAreNotImportant()
 {
     MyWebApi
     .Controller <AttributesController>()
     .Calling(c => c.WithAttributesAndParameters(With.Any <int>()))
     .ShouldHave()
     .ActionAttributes(attrs => attrs.AllowingAnonymousRequests());
 }
コード例 #24
0
 public void RemoveFromCartShouldBeRoutedCorrectly()
 {
     MyMvc
     .Routing()
     .ShouldMap(request => request
                .WithMethod(HttpMethod.Post)
                .WithLocation("/ShoppingCart/RemoveFromCart/1"))
     .To <ShoppingCartController>(c => c.RemoveFromCart(1, With.Any <CancellationToken>()));
 }
コード例 #25
0
 public void GetIndexShouldBeRoutedCorrectly()
 {
     MyMvc
     .Routing()
     .ShouldMap("/Home/Index")
     .To <HomeController>(c => c.Index(
                              With.Any <MusicStoreContext>(),
                              With.Any <IMemoryCache>()));
 }
コード例 #26
0
 public void PostCreateShouldBeRoutedCorrectly()
 => MyRouting
 .Configuration()
 .ShouldMap(request => request
            .WithLocation("/Articles/Create")
            .WithMethod(HttpMethod.Post)
            .WithUser()
            .WithAntiForgeryToken())
 .To <ArticlesController>(c => c.Create(With.Any <ArticleFormModel>()));
コード例 #27
0
 public void GetCompleteShouldBeRoutedCorrectly()
 {
     MyMvc
     .Routing()
     .ShouldMap(request => request
                .WithLocation("/Checkout/Complete/1")
                .WithAuthenticatedUser())
     .To <CheckoutController>(c => c.Complete(With.Any <MusicStoreContext>(), 1));
 }
コード例 #28
0
 public void MapToUpdateTodo()
 {
     MyMvc
     .Routing()
     .ShouldMap(request => request
                .WithMethod(HttpMethod.Put)
                .WithLocation("/api/todos"))
     .To <UpdateTodoController>(x => x.Update(With.Any <TodoUpdatingRequest>()));
 }
コード例 #29
0
 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>());
 }
コード例 #30
0
 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>()));