/// <summary>
 /// Initializes a new instance of the <see cref="ModelErrorTestBuilder"/> class.
 /// </summary>
 /// <param name="testContext"><see cref="ControllerTestContext"/> containing data about the currently executed assertion chain.</param>
 /// <param name="modelState">Optional <see cref="ModelStateDictionary"/> to use the test builder with. Default is controller's <see cref="ModelStateDictionary"/>.</param>
 public ModelErrorTestBuilder(
     ControllerTestContext testContext,
     ModelStateDictionary modelState = null)
     : base(testContext)
 {
     this.ModelState = modelState ?? testContext.ModelState;
 }
        public static void Validate(
            ControllerTestContext controllerTestContext,
            LinkGenerationTestContext linkGenerationTestContext,
            LambdaExpression expectedRouteValuesAsLambdaExpression,
            Action<string, string, string> failedValidationAction)
        {
            var actionContext = controllerTestContext.ComponentContext;
            if (!actionContext.RouteData.Routers.Any())
            {
                actionContext.RouteData.Routers.Add(TestApplication.Router);
            }

            var urlHelper = linkGenerationTestContext.UrlHelper ?? TestServiceProvider
                .GetRequiredService<IUrlHelperFactory>()
                .GetUrlHelper(actionContext);

            ICollection<string> ignoredRouteKeys;
            var expectedUri = urlHelper.ExpressionLink(
                expectedRouteValuesAsLambdaExpression,
                out ignoredRouteKeys);

            var actualUri = urlHelper.GenerateLink(
                linkGenerationTestContext,
                controllerTestContext,
                ignoredRouteKeys);

            if (!string.Equals(expectedUri, actualUri, StringComparison.OrdinalIgnoreCase))
            {
                failedValidationAction(
                    "to have resolved location to",
                    $"{expectedUri.GetErrorMessageName()}",
                    $"in fact received {actualUri.GetErrorMessageName()}");
            }
        }
        public static string GenerateLink(
            this IUrlHelper urlHelper,
            LinkGenerationTestContext linkGenerationTestContext,
            ControllerTestContext controllerTestContext)
        {
            string uri = null;

            if (!string.IsNullOrWhiteSpace(linkGenerationTestContext.Location))
            {
                uri = linkGenerationTestContext.Location;
            }
            else if (!string.IsNullOrWhiteSpace(linkGenerationTestContext.RouteName))
            {
                uri = urlHelper.RouteUrl(
                    linkGenerationTestContext.RouteName,
                    linkGenerationTestContext.RouteValues);
            }
            else
            {
                linkGenerationTestContext.Action = linkGenerationTestContext.Action
                                                   ?? controllerTestContext.RouteData.Values["action"] as string
                                                   ?? controllerTestContext.ActionName;

                linkGenerationTestContext.Controller = linkGenerationTestContext.Controller
                                                       ?? controllerTestContext.RouteData.Values["controller"] as string
                                                       ?? controllerTestContext.ControllerContext.ActionDescriptor.ControllerName;

                uri = urlHelper.Action(
                    linkGenerationTestContext.Action,
                    linkGenerationTestContext.Controller,
                    linkGenerationTestContext.RouteValues);
            }

            return(uri);
        }
예제 #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ModelErrorTestBuilder"/> class.
 /// </summary>
 /// <param name="testContext"><see cref="ControllerTestContext"/> containing data about the currently executed assertion chain.</param>
 /// <param name="modelState">Optional <see cref="ModelStateDictionary"/> to use the test builder with. Default is controller's <see cref="ModelStateDictionary"/>.</param>
 public ModelErrorTestBuilder(
     ControllerTestContext testContext,
     ModelStateDictionary modelState = null)
     : base(testContext)
 {
     this.ModelState = modelState ?? testContext.ModelState;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="MemoryCacheEntryTestBuilder"/> class.
        /// </summary>
        /// <param name="testContext"><see cref="ControllerTestContext"/> containing data about the currently executed assertion chain.</param>
        public MemoryCacheEntryTestBuilder(ControllerTestContext testContext)
        {
            CommonValidator.CheckForNullReference(testContext, nameof(testContext));

            this.testContext = testContext;
            this.validations = new List <Action <ICacheEntry, ICacheEntry> >();
        }
        public static string GenerateLink(
            this IUrlHelper urlHelper,
            LinkGenerationTestContext linkGenerationTestContext,
            ControllerTestContext controllerTestContext)
        {
            string uri = null;
            if (!string.IsNullOrWhiteSpace(linkGenerationTestContext.Location))
            {
                uri = linkGenerationTestContext.Location;
            }
            else if (!string.IsNullOrWhiteSpace(linkGenerationTestContext.RouteName))
            {
                uri = urlHelper.RouteUrl(
                    linkGenerationTestContext.RouteName,
                    linkGenerationTestContext.RouteValues);
            }
            else
            {
                linkGenerationTestContext.Action = linkGenerationTestContext.Action
                    ?? controllerTestContext.RouteData.Values["action"] as string
                    ?? controllerTestContext.ActionName;

                linkGenerationTestContext.Controller = linkGenerationTestContext.Controller
                    ?? controllerTestContext.RouteData.Values["controller"] as string
                    ?? controllerTestContext.ControllerContext.ActionDescriptor.ControllerName;

                uri = urlHelper.Action(
                    linkGenerationTestContext.Action,
                    linkGenerationTestContext.Controller,
                    linkGenerationTestContext.RouteValues);
            }

            return uri;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ViewTestBuilder{TViewResult}"/> class.
 /// </summary>
 /// <param name="testContext"><see cref="ControllerTestContext"/> containing data about the currently executed assertion chain.</param>
 /// <param name="viewType">View type name.</param>
 public ViewTestBuilder(
     ControllerTestContext testContext,
     string viewType)
     : base(testContext)
 {
     this.viewType = viewType;
 }
        public static void ValidateExpressionLink(
            ControllerTestContext controllerTestContext,
            LinkGenerationTestContext linkGenerationTestContext,
            LambdaExpression expectedRouteValuesAsLambdaExpression,
            Action <string, string, string> failedValidationAction)
        {
            var actionContext = controllerTestContext.ControllerContext;

            if (!actionContext.RouteData.Routers.Any())
            {
                actionContext.RouteData.Routers.Add(TestApplication.Router);
            }

            var urlHelper = linkGenerationTestContext.UrlHelper ?? TestServiceProvider
                            .GetRequiredService <IUrlHelperFactory>()
                            .GetUrlHelper(actionContext);

            var expectedUri = urlHelper.ExpressionLink(expectedRouteValuesAsLambdaExpression);
            var actualUri   = urlHelper.GenerateLink(linkGenerationTestContext, controllerTestContext);

            if (!string.Equals(expectedUri, actualUri, StringComparison.OrdinalIgnoreCase))
            {
                failedValidationAction(
                    "to have resolved location to",
                    $"{expectedUri.GetErrorMessageName()}",
                    $"in fact received {actualUri.GetErrorMessageName()}");
            }
        }
예제 #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BaseDataProviderTestBuilder"/> class.
 /// </summary>
 /// <param name="testContext"><see cref="ControllerTestContext"/> containing data about the currently executed assertion chain.</param>
 /// <param name="dataProviderName">Name of the data provider.</param>
 protected BaseDataProviderTestBuilder(ControllerTestContext testContext, string dataProviderName)
     : base(testContext)
 {
     CommonValidator.CheckForNotWhiteSpaceString(dataProviderName);
     this.DataProviderName = dataProviderName;
     this.DataProvider     = this.GetDataProvider();
     CommonValidator.CheckForNullReference(this.DataProvider);
 }
예제 #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ExceptionMessageTestBuilder"/> class.
 /// </summary>
 /// <param name="testContext"><see cref="ControllerTestContext"/> containing data about the currently executed assertion chain.</param>
 /// <param name="exceptionTestBuilder">Test builder of <see cref="IAndExceptionTestBuilder"/> type.</param>
 public ExceptionMessageTestBuilder(
     ControllerTestContext testContext,
     IAndExceptionTestBuilder exceptionTestBuilder)
     : base(testContext)
 {
     this.exceptionTestBuilder = exceptionTestBuilder;
     this.actualMessage        = testContext.CaughtException.Message;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ControllerBuilder{TController}"/> class.
 /// </summary>
 /// <param name="testContext"><see cref="ControllerTestContext"/> containing data about the currently executed assertion chain.</param>
 public ControllerBuilder(ControllerTestContext testContext)
     : base(testContext)
 {
     this.EnabledModelStateValidation = TestApplication
                                        .Configuration()
                                        .Controllers()
                                        .ModelStateValidation();
 }
예제 #12
0
        public static string GenerateLink(
            this IUrlHelper urlHelper,
            LinkGenerationTestContext linkGenerationTestContext,
            ControllerTestContext controllerTestContext,
            ICollection <string> ignoredRouteKeys = null)
        {
            // Add additional required route values.
            controllerTestContext
            .ComponentAttributes
            .Union(controllerTestContext.MethodAttributes)
            .OfType <RouteValueAttribute>()
            .Select(rva => rva.RouteKey)
            .Where(key => controllerTestContext.RouteData.Values.ContainsKey(key))
            .Select(key => new
            {
                Key   = key,
                Value = controllerTestContext.RouteData.Values[key]
            })
            .ForEach(kvp => linkGenerationTestContext.RouteValues.Add(kvp.Key, kvp.Value));

            if (ignoredRouteKeys != null)
            {
                linkGenerationTestContext.RouteValues = linkGenerationTestContext
                                                        .RouteValues
                                                        ?.Where(kvp => !ignoredRouteKeys.Contains(kvp.Key))
                                                        .ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
            }

            string uri;

            if (!string.IsNullOrWhiteSpace(linkGenerationTestContext.Location))
            {
                uri = linkGenerationTestContext.Location;
            }
            else if (!string.IsNullOrWhiteSpace(linkGenerationTestContext.RouteName))
            {
                uri = urlHelper.RouteUrl(
                    linkGenerationTestContext.RouteName,
                    linkGenerationTestContext.RouteValues);
            }
            else
            {
                linkGenerationTestContext.Action = linkGenerationTestContext.Action
                                                   ?? controllerTestContext.RouteData.Values["action"] as string
                                                   ?? controllerTestContext.MethodName;

                linkGenerationTestContext.Controller = linkGenerationTestContext.Controller
                                                       ?? controllerTestContext.RouteData.Values["controller"] as string
                                                       ?? controllerTestContext.ComponentContext.ActionDescriptor.ControllerName;

                uri = urlHelper.Action(
                    linkGenerationTestContext.Action,
                    linkGenerationTestContext.Controller,
                    linkGenerationTestContext.RouteValues);
            }

            return(uri);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="BadRequestErrorMessageTestBuilder"/> class.
 /// </summary>
 /// <param name="testContext"><see cref="ControllerTestContext"/> containing data about the currently executed assertion chain.</param>
 /// <param name="actualMessage">Actual text error message received from bad request result.</param>
 /// <param name="badRequestTestBuilder">Bad request test builder.</param>
 public BadRequestErrorMessageTestBuilder(
     ControllerTestContext testContext,
     string actualMessage,
     IAndBadRequestTestBuilder badRequestTestBuilder)
     : base(testContext)
 {
     this.actualMessage         = actualMessage;
     this.badRequestTestBuilder = badRequestTestBuilder;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="BadRequestErrorMessageTestBuilder"/> class.
 /// </summary>
 /// <param name="testContext"><see cref="ControllerTestContext"/> containing data about the currently executed assertion chain.</param>
 /// <param name="actualMessage">Actual text error message received from bad request result.</param>
 /// <param name="badRequestTestBuilder">Bad request test builder.</param>
 public BadRequestErrorMessageTestBuilder(
     ControllerTestContext testContext,
     string actualMessage,
     IAndBadRequestTestBuilder badRequestTestBuilder)
     : base(testContext)
 {
     this.actualMessage = actualMessage;
     this.badRequestTestBuilder = badRequestTestBuilder;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="ControllerBuilder{TController}"/> class.
        /// </summary>
        /// <param name="testContext"><see cref="ControllerTestContext"/> containing data about the currently executed assertion chain.</param>
        public ControllerBuilder(ControllerTestContext testContext)
            : base(testContext)
        {
            this.TestContext = testContext;

            this.enabledValidation  = TestApplication.TestConfiguration.ModelStateValidation;
            this.aggregatedServices = new Dictionary <Type, object>();

            this.ValidateControllerType();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="BaseTestBuilderWithErrorResult{TErrorResult}"/> class.
        /// </summary>
        /// <param name="testContext">
        /// <see cref="ControllerTestContext"/> containing data about the currently executed assertion chain.
        /// </param>
        /// <param name="actionResultName">Action result name.</param>
        protected BaseTestBuilderWithErrorResult(
            ControllerTestContext testContext,
            string actionResultName)
            : base(testContext)
        {
            this.TestContext = testContext;

            this.ErrorMessageFormat       = ErrorMessage.Replace($"{{{nameof(actionResultName)}}}", actionResultName);
            this.OfTypeErrorMessageFormat = OfTypeErrorMessage.Replace($"{{{nameof(actionResultName)}}}", actionResultName);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ModelErrorDetailsTestBuilder{TModel}"/> class.
 /// </summary>
 /// <param name="testContext"><see cref="ControllerTestContext"/> containing data about the currently executed assertion chain.</param>
 /// <param name="modelErrorTestBuilder">Test builder of <see cref="IAndModelErrorTestBuilder{TModel}"/> type.</param>
 /// <param name="errorKey">Key in <see cref="ModelStateDictionary"/> corresponding to this particular error.</param>
 /// <param name="aggregatedErrors">All errors found in <see cref="ModelStateDictionary"/> for given error key.</param>
 public ModelErrorDetailsTestBuilder(
     ControllerTestContext testContext,
     IAndModelErrorTestBuilder <TModel> modelErrorTestBuilder,
     string errorKey,
     IEnumerable <ModelError> aggregatedErrors)
     : base(testContext)
 {
     this.modelErrorTestBuilder = modelErrorTestBuilder;
     this.currentErrorKey       = errorKey;
     this.aggregatedErrors      = aggregatedErrors.Select(me => me.ErrorMessage);
 }
예제 #18
0
        public void SetUp()
        {
            ServiceLocatorInitializer.Init();
            controller = new TeamsController(
                CreateMockTeamRepository(),
                MockRepository.GenerateMock <IUserRepository>(),
                GamesControllerTests.CreateMockGameRepository());

            testContext = new ControllerTestContext(controller);
            user        = new User {
                Team = new Team()
            };
        }
예제 #19
0
        public void SetUp()
        {
            ServiceLocatorInitializer.Init();

            controller = new TasksController(
                CreateMockTaskRepository(),
                MockRepository.GenerateMock <IUserRepository>(),
                TipsControllerTests.CreateMockTipRepository(),
                CodesControllerTests.CreateMockCodeRepository());

            testContext = new ControllerTestContext(controller);
            user        = new User {
                Game = new Game()
            };
        }
        /// <summary>
        /// Validates whether Properties are the same as the provided ones from action result containing such property by using a builder.
        /// </summary>
        /// <param name="authenticationPropertiesBuilder">Authentication properties builder.</param>
        /// <param name="testContext"><see cref="ControllerTestContext"/> containing data about the currently executed assertion chain.</param>
        public static void ValidateAuthenticationProperties(
            Action <IAuthenticationPropertiesTestBuilder> authenticationPropertiesBuilder,
            ControllerTestContext testContext)
        {
            var actionResult = testContext.MethodResultAs <dynamic>();
            var actualAuthenticationProperties =
                (AuthenticationProperties)TryGetAuthenticationProperties(actionResult) ?? new AuthenticationProperties();

            var newAuthenticationPropertiesTestBuilder = new AuthenticationPropertiesTestBuilder(testContext);

            authenticationPropertiesBuilder(newAuthenticationPropertiesTestBuilder);
            var expectedAuthenticationProperties = newAuthenticationPropertiesTestBuilder.GetAuthenticationProperties();

            var validations = newAuthenticationPropertiesTestBuilder.GetAuthenticationPropertiesValidations();

            validations.ForEach(v => v(expectedAuthenticationProperties, actualAuthenticationProperties));
        }
        public void SetUp()
        {
            userService = MockRepository.GenerateStub<IUserService>();
            countryRepository = MockRepository.GenerateStub<IRepository<Country>>();
            basketRepository = MockRepository.GenerateStub<IRepository<Basket>>();

            basketService = new BasketService(countryRepository, userService);

            basketController = new BasketController(
                basketService,
                basketRepository);

            testContext = new ControllerTestContext(basketController);

			user = new User { Baskets = { new Basket { Id = 4, Country = new Country() } } };
			userService.Expect(x => x.CurrentUser).Return(user);
        }
예제 #22
0
        public void SetUp()
        {
            // you have to be an administrator to access the user controller
            Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("admin"), new[] {"Administrator"});

            userRepository = MockRepositoryBuilder.CreateUserRepository();
            
            var roleRepository = MockRepositoryBuilder.CreateRoleRepository();
        	userService = MockRepository.GenerateStub<IUserService>();
        	userService.Stub(x => x.HashPassword(Arg<string>.Is.Anything)).Do(new Func<string, string>(s => s + "HASHED"));

        	userController = new UserController(userRepository, roleRepository, userService);
            testContext = new ControllerTestContext(userController);


            // setup the querystring to return an empty name value collection by default
            testContext.TestContext.Request.Expect(r => r.QueryString).Return(new NameValueCollection());
        }
예제 #23
0
        public static string GenerateLink(
            this IUrlHelper urlHelper,
            LinkGenerationTestContext linkGenerationTestContext,
            ControllerTestContext controllerTestContext,
            ICollection <string> ignoredRouteKeys = null)
        {
            if (ignoredRouteKeys != null)
            {
                linkGenerationTestContext.RouteValues = linkGenerationTestContext
                                                        .RouteValues
                                                        ?.Where(kvp => !ignoredRouteKeys.Contains(kvp.Key))
                                                        .ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
            }

            string uri = null;

            if (!string.IsNullOrWhiteSpace(linkGenerationTestContext.Location))
            {
                uri = linkGenerationTestContext.Location;
            }
            else if (!string.IsNullOrWhiteSpace(linkGenerationTestContext.RouteName))
            {
                uri = urlHelper.RouteUrl(
                    linkGenerationTestContext.RouteName,
                    linkGenerationTestContext.RouteValues);
            }
            else
            {
                linkGenerationTestContext.Action = linkGenerationTestContext.Action
                                                   ?? controllerTestContext.RouteData.Values["action"] as string
                                                   ?? controllerTestContext.MethodName;

                linkGenerationTestContext.Controller = linkGenerationTestContext.Controller
                                                       ?? controllerTestContext.RouteData.Values["controller"] as string
                                                       ?? controllerTestContext.ComponentContext.ActionDescriptor.ControllerName;

                uri = urlHelper.Action(
                    linkGenerationTestContext.Action,
                    linkGenerationTestContext.Controller,
                    linkGenerationTestContext.RouteValues);
            }

            return(uri);
        }
        public static string GenerateLink(
            this IUrlHelper urlHelper,
            LinkGenerationTestContext linkGenerationTestContext,
            ControllerTestContext controllerTestContext,
            ICollection<string> ignoredRouteKeys = null)
        {
            if (ignoredRouteKeys != null)
            {
                linkGenerationTestContext.RouteValues = linkGenerationTestContext
                    .RouteValues
                    ?.Where(kvp => !ignoredRouteKeys.Contains(kvp.Key))
                    .ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
            }

            string uri = null;
            if (!string.IsNullOrWhiteSpace(linkGenerationTestContext.Location))
            {
                uri = linkGenerationTestContext.Location;
            }
            else if (!string.IsNullOrWhiteSpace(linkGenerationTestContext.RouteName))
            {
                uri = urlHelper.RouteUrl(
                    linkGenerationTestContext.RouteName,
                    linkGenerationTestContext.RouteValues);
            }
            else
            {
                linkGenerationTestContext.Action = linkGenerationTestContext.Action
                    ?? controllerTestContext.RouteData.Values["action"] as string
                    ?? controllerTestContext.MethodName;

                linkGenerationTestContext.Controller = linkGenerationTestContext.Controller
                    ?? controllerTestContext.RouteData.Values["controller"] as string
                    ?? controllerTestContext.ComponentContext.ActionDescriptor.ControllerName;

                uri = urlHelper.Action(
                    linkGenerationTestContext.Action,
                    linkGenerationTestContext.Controller,
                    linkGenerationTestContext.RouteValues);
            }

            return uri;
        }
예제 #25
0
        public void SetUp()
        {
            // you have to be an administrator to access the user controller
            Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("admin"), new[] { "Administrator" });

            userRepository = MockRepositoryBuilder.CreateUserRepository();

            var roleRepository = MockRepositoryBuilder.CreateRoleRepository();

            userService = MockRepository.GenerateStub <IUserService>();
            userService.Stub(x => x.HashPassword(Arg <string> .Is.Anything)).Do(new Func <string, string>(s => s + "HASHED"));

            userController = new UserController(userRepository, roleRepository, userService);
            testContext    = new ControllerTestContext(userController);


            // setup the querystring to return an empty name value collection by default
            testContext.TestContext.Request.Expect(r => r.QueryString).Return(new NameValueCollection());
        }
예제 #26
0
        public void SetUp()
        {
            // you have to be an administrator to access the order controller
            Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("admin"), new[] { "Administrator" });

            orderRepository    = MockRepository.GenerateStub <IRepository <Order> >();
            countryRepository  = MockRepository.GenerateStub <IRepository <Country> >();
            cardTypeRepository = MockRepository.GenerateStub <IRepository <CardType> >();


            encryptionService = MockRepository.GenerateStub <IEncryptionService>();
            userService       = MockRepository.GenerateStub <IUserService>();
            searchService     = MockRepository.GenerateStub <IOrderSearchService>();

            var mocks = new MockRepository();

            statusRepository = MockRepository.GenerateStub <IRepository <OrderStatus> >();
            orderController  = new OrderController(
                orderRepository,
                countryRepository,
                cardTypeRepository,
                encryptionService,
                userService,
                searchService,
                statusRepository
                );

            testContext = new ControllerTestContext(orderController);

            userService.Expect(us => us.CurrentUser).Return(new User {
                Id = 4, Role = Role.Administrator
            });

            testContext.TestContext.Context.User = new User {
                Id = 4
            };
            testContext.TestContext.Request.RequestType = "GET";
            testContext.TestContext.Request.Stub(r => r.QueryString).Return(new NameValueCollection());
            testContext.TestContext.Request.Stub(r => r.Form).Return(new NameValueCollection());
            statusRepository.Expect(x => x.GetAll()).Return(new List <OrderStatus>().AsQueryable());

            mocks.ReplayAll();
        }
        public void SetUp()
        {
            // you have to be an administrator to access the order controller
            Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("admin"), new[] { "Administrator" });

            orderRepository = MockRepository.GenerateStub<IRepository<Order>>();
            countryRepository = MockRepository.GenerateStub<IRepository<Country>>();
            cardTypeRepository = MockRepository.GenerateStub<IRepository<CardType>>();
			

            encryptionService = MockRepository.GenerateStub<IEncryptionService>();
            postageService = MockRepository.GenerateStub<IPostageService>();
            userService = MockRepository.GenerateStub<IUserService>();
			searchService = MockRepository.GenerateStub<IOrderSearchService>();

            var mocks = new MockRepository();
    		statusRepository = MockRepository.GenerateStub<IRepository<OrderStatus>>();
    		orderController = new OrderController(
                orderRepository,
                countryRepository,
                cardTypeRepository,
                encryptionService,
                postageService,
                userService,
				searchService,
				statusRepository
				);

            testContext = new ControllerTestContext(orderController);

            postageService.Expect(ps => ps.CalculatePostageFor(Arg<Order>.Is.Anything));

            userService.Expect(us => us.CurrentUser).Return(new User { UserId = 4, RoleId = Role.AdministratorId });

            testContext.TestContext.Context.User = new User { UserId = 4 };
            testContext.TestContext.Request.RequestType = "GET";
            testContext.TestContext.Request.Stub(r => r.QueryString).Return(new NameValueCollection());
            testContext.TestContext.Request.Stub(r => r.Form).Return(new NameValueCollection());
			statusRepository.Expect(x => x.GetAll()).Return(new List<OrderStatus>().AsQueryable());

            mocks.ReplayAll();
        }
        public void SetUp()
        {
            basketItemRepository = MockRepository.GenerateStub<IRepository<BasketItem>>();
            sizeRepository = MockRepository.GenerateStub<IRepository<Size>>();

            userService = MockRepository.GenerateStub<IUserService>();
            postageService = MockRepository.GenerateStub<IPostageService>();
            countryRepository = MockRepository.GenerateStub<IRepository<Country>>();

            basketController = new BasketController(basketItemRepository,
                sizeRepository,
                userService,
                postageService,
                countryRepository);

            testContext = new ControllerTestContext(basketController);

			user = new User { Baskets = { new Basket() { BasketId = 4 } } };
			userService.Expect(x => x.CurrentUser).Return(user);
        }
예제 #29
0
        public void SetUp()
        {
            userService       = MockRepository.GenerateStub <IUserService>();
            countryRepository = MockRepository.GenerateStub <IRepository <Country> >();
            basketRepository  = MockRepository.GenerateStub <IRepository <Basket> >();

            basketService = new BasketService(countryRepository, userService);

            basketController = new BasketController(
                basketService,
                basketRepository);

            testContext = new ControllerTestContext(basketController);

            user = new User {
                Baskets = { new Basket {
                                Id = 4, Country = new Country()
                            } }
            };
            userService.Expect(x => x.CurrentUser).Return(user);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="PhysicalFileTestBuilder"/> class.
 /// </summary>
 /// <param name="testContext"><see cref="ControllerTestContext"/> containing data about the currently executed assertion chain.</param>
 public PhysicalFileTestBuilder(ControllerTestContext testContext)
     : base(testContext)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ShouldThrowTestBuilder"/> class.
 /// </summary>
 /// <param name="testContext"><see cref="ControllerTestContext"/> containing data about the currently executed assertion chain.</param>
 public ShouldThrowTestBuilder(ControllerTestContext testContext)
     : base(testContext)
 {
     this.exceptionTestBuilder = new ExceptionTestBuilder(this.TestContext);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="VoidActionResultTestBuilder"/> class.
 /// </summary>
 /// <param name="testContext"><see cref="ControllerTestContext"/> containing data about the currently executed assertion chain.</param>
 public VoidActionResultTestBuilder(ControllerTestContext testContext)
     : base(testContext)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="BaseTestBuilderWithAction"/> class.
 /// </summary>
 /// <param name="testContext"><see cref="ControllerTestContext"/> containing data about the currently executed assertion chain.</param>
 protected BaseTestBuilderWithAction(ControllerTestContext testContext)
     : base(testContext)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ShouldPassForTestBuilderWithInvokedAction"/> class.
 /// </summary>
 /// <param name="testContext"><see cref="ControllerTestContext"/> containing data about the currently executed assertion chain.</param>
 public ShouldPassForTestBuilderWithInvokedAction(ControllerTestContext testContext)
     : base(testContext)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="AuthenticationPropertiesTestBuilder"/> class.
 /// </summary>
 /// <param name="testContext"><see cref="ControllerTestContext"/> containing data about the currently executed assertion chain.</param>
 public AuthenticationPropertiesTestBuilder(ControllerTestContext testContext)
     :base(testContext)
 {
     this.authenticationProperties = new AuthenticationProperties();
     this.validations = new List<Action<AuthenticationProperties, AuthenticationProperties>>();
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ShouldPassForTestBuilderWithController{TController}"/> class.
 /// </summary>
 /// <param name="testContext"><see cref="ControllerTestContext"/> containing data about the currently executed assertion chain.</param>
 public ShouldPassForTestBuilderWithController(ControllerTestContext testContext)
     : base(testContext)
 {
     this.TestContext = testContext;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="TempDataTestBuilder"/> class.
 /// </summary>
 /// <param name="testContext"><see cref="ControllerTestContext"/> containing data about the currently executed assertion chain.</param>
 public TempDataTestBuilder(ControllerTestContext testContext)
     : base(testContext, TempDataName)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ControllerTestBuilder"/> class.
 /// </summary>
 /// <param name="testContext"><see cref="ControllerTestContext"/> containing data about the currently executed assertion chain.</param>
 public ControllerTestBuilder(ControllerTestContext testContext)
     : base(testContext)
 {
 }
예제 #39
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BaseControllerBuilder{TController, TBuilder}"/> class.
 /// </summary>
 /// <param name="testContext"><see cref="ControllerTestContext"/> containing data about the currently executed assertion chain.</param>
 protected BaseControllerBuilder(ControllerTestContext testContext)
     : base(testContext)
     => this.EnabledModelStateValidation = ServerTestConfiguration
        /// <summary>
        /// Validates whether Properties are the same as the provided ones from action result containing such property by using a builder.
        /// </summary>
        /// <param name="authenticationPropertiesBuilder">Authentication properties builder.</param>
        /// <param name="testContext"><see cref="ControllerTestContext"/> containing data about the currently executed assertion chain.</param>
        public static void ValidateAuthenticationProperties(
            Action<IAuthenticationPropertiesTestBuilder> authenticationPropertiesBuilder,
            ControllerTestContext testContext)
        {
            var actionResult = testContext.ActionResultAs<dynamic>();
            var actualAuthenticationProperties = 
                (AuthenticationProperties)TryGetAuthenticationProperties(actionResult) ?? new AuthenticationProperties();

            var newAuthenticationPropertiesTestBuilder = new AuthenticationPropertiesTestBuilder(testContext);
            authenticationPropertiesBuilder(newAuthenticationPropertiesTestBuilder);
            var expectedAuthenticationProperties = newAuthenticationPropertiesTestBuilder.GetAuthenticationProperties();

            var validations = newAuthenticationPropertiesTestBuilder.GetAuthenticationPropertiesValidations();
            validations.ForEach(v => v(expectedAuthenticationProperties, actualAuthenticationProperties));
        }
예제 #41
0
 /// <summary>
 /// Initializes a new instance of the <see cref="StatusCodeTestBuilder{TStatusCodeResult}"/> class.
 /// </summary>
 /// <param name="testContext"><see cref="ControllerTestContext"/> containing data about the currently executed assertion chain.</param>
 public StatusCodeTestBuilder(ControllerTestContext testContext)
     : base(testContext)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="BaseTestBuilderWithAction"/> class.
 /// </summary>
 /// <param name="testContext"><see cref="ControllerTestContext"/> containing data about the currently executed assertion chain.</param>
 protected BaseTestBuilderWithAction(ControllerTestContext testContext)
     : base(testContext)
 {
 }
예제 #43
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ShouldPassForTestBuilderWithAction"/> class.
 /// </summary>
 /// <param name="testContext"><see cref="ControllerTestContext"/> containing data about the currently executed assertion chain.</param>
 public ShouldPassForTestBuilderWithAction(ControllerTestContext testContext)
     : base(testContext)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ContentTestBuilder"/> class.
 /// </summary>
 /// <param name="testContext"><see cref="ControllerTestContext"/> containing data about the currently executed assertion chain.</param>
 public ContentTestBuilder(ControllerTestContext testContext)
     : base(testContext)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="BaseTestBuilderWithResponseModel{TActionResult}"/> class.
 /// </summary>
 /// <param name="testContext"><see cref="ControllerTestContext"/> containing data about the currently executed assertion chain.</param>
 protected BaseTestBuilderWithResponseModel(ControllerTestContext testContext)
     : base(testContext)
 {
     this.ErrorMessageFormat       = ErrorMessage;
     this.OfTypeErrorMessageFormat = OfTypeErrorMessage;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="AndTestBuilderWithInvokedAction"/> class.
 /// </summary>
 /// <param name="testContext"><see cref="ControllerTestContext"/> containing data about the currently executed assertion chain.</param>
 public AndTestBuilderWithInvokedAction(ControllerTestContext testContext)
     : base(testContext)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="WhichControllerInstanceBuilder{TController}"/> class.
 /// </summary>
 /// <param name="testContext"><see cref="ControllerTestContext"/> containing data about the currently executed assertion chain.</param>
 public WhichControllerInstanceBuilder(ControllerTestContext testContext)
     : base(testContext)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="BaseTestBuilderWithController"/> class.
 /// </summary>
 /// <param name="testContext"><see cref="ControllerTestContext"/> containing data about the currently executed assertion chain.</param>
 protected BaseTestBuilderWithController(ControllerTestContext testContext)
     : base(testContext)
 {
     this.TestContext = testContext;
 }