Exemple #1
0
        public void PropertyWithDataTypeTextAttributeShouldMakeTheTagATextArea()
        {
            var model = new TestViewModel();
            var tag   = MvcMockHelpers.GetHtmlHelper(model).Input(x => x.Text);

            tag.TagName().ShouldBe("textarea");
        }
Exemple #2
0
        public void Test2()
        {
            var model = new LoopViewModel()
            {
                Address = "My Address"
            };

            for (int j = 0; j < 1000; j++)
            {
                model.LoopItems.Add(new LoopViewModel.LoopItem()
                {
                    Name = "MyName:" + j
                });
            }

            var helper = MvcMockHelpers.GetHtmlHelper(model);
            var sw     = Stopwatch.StartNew();

            foreach (var loop in helper.Loop(x => x.LoopItems))
            {
                loop.Input(x => x.Name);
                loop.Display(x => x.Name);

                foreach (var loopItem in loop.Loop(x => x.NestedLoopItems))
                {
                    loopItem.Input(x => x.Age);
                }
            }
            sw.Stop();
            Console.WriteLine(sw.ElapsedMilliseconds);
        }
        public void ProfileWithNesteds()
        {
            HtmlConventionFactory.Add(new DefaultHtmlConventions());
            HtmlConventionFactory.Add(new DataAnnotationHtmlConventions());

            var model = new ProfileViewModel()
            {
                Name = "Test"
            };
            var helper = MvcMockHelpers.GetHtmlHelper(model);

            using (helper.Profile(new ProfileTest1()))
            {
                var tag = helper.Input(x => x.Name);
                tag.ToHtmlString().ShouldBe("<profile>Test</profile>");

                using (helper.Profile(new ProfileTest2()))
                {
                    var tag3 = helper.Input(x => x.Name);
                    tag3.ToHtmlString().ShouldBe("<profilenested>Test</profilenested>");
                }

                var tag2 = helper.Input(x => x.Name);
                tag2.ToHtmlString().ShouldBe("<profile>Test</profile>");
            }

            var tag1 = helper.Input(x => x.Name);

            tag1.ToHtmlString().ShouldBe("<input type=\"text\" value=\"Test\" id=\"Name\" name=\"Name\" />");
        }
        private static TestableAuthController GetTestableAuthController(
            IOpenIdRelyingParty relyingParty,
            IFormsAuthentication formsAuth,
            CreateUser createUser,
            GetUserByClaimId getUser,
            string providerUrl = @"http:\\testprovider.com")
        {
            HttpContextBase contextMock    = MvcMockHelpers.FakeHttpContext(providerUrl);
            var             authController = new TestableAuthController(relyingParty, formsAuth, createUser, getUser);

            authController.ControllerContext = new ControllerContext(contextMock, new RouteData(), authController);
            authController.InvokeInitialize(authController.ControllerContext.RequestContext);

            // default routes
            var routes = new RouteCollection();

            routes.MapRoute(
                "Default",                    // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Home", action = "Index", id = "" } // Parameter defaults
                );
            authController.Url = new UrlHelper(authController.ControllerContext.RequestContext,
                                               routes);

            return(authController);
        }
Exemple #5
0
        public void Can_Run_Two_Tests_And_Convert_One()
        {
            using (var req = MvcMockHelpers.SimulateRequest("http://localhost/Test.aspx"))
            {
                ABTester.Start();

                Assert.IsNotNull(ABTester.Current);

                var testname = "Can_Run_Two_Tests_And_Convert_One";

                var option1 = "one";
                var option2 = "two";

                var output = ABTester.Test(testname, option1, option2);

                Assert.IsTrue(output == option1 || output == option2);

                //Call Start again to similate next request with new ABTester instance
                ABTester.Start();

                var output2 = ABTester.Test(testname, option1, option2);

                Assert.IsTrue(output2 == option1 || output2 == option2);

                ABTester.Convert(testname);

                var results = ABTester.GetResults(testname);

                Assert.IsNotNull(results);
                Assert.AreEqual(2, results.Count);
                Assert.IsFalse(results[0].Converted);
                Assert.IsTrue(results[1].Converted);
            }
        }
            public static void SetMockController(this Controller controller, string url)
            {
                var httpContext = MvcMockHelpers.MockHttpContext(url);
                var routeData   = RouteTable.Routes.GetRouteData(httpContext);

                controller.SetMockControllerContext(httpContext, routeData, RouteTable.Routes);
            }
        public void RenderTagConditionally2()
        {
            var selectListItems = new List <SelectListItem>()
            {
                new SelectListItem()
                {
                    Text = "testtext", Value = "testvalue"
                }
            };
            var model = new TestViewModel()
            {
                CombinationType = new CombinationType()
                {
                    Items    = selectListItems,
                    IsSingle = true,
                    Name     = "Text",
                    Value    = "Value"
                },
                Dropdown = selectListItems
            };
            var helper = MvcMockHelpers.GetHtmlHelper(model);
            var tag    = helper.Input(x => x.CombinationType);

            Assert.AreEqual("<div>Text<input type=\"hidden\" id=\"CombinationType\" name=\"CombinationType\" value=\"Value\" /></div>", tag.ToHtmlString());
        }
        public void InputOfListSelectItemListPropertyShouldGenerateSelectTagWithClientSelectedOptionStillSelectedIfError()
        {
            var model = new TestViewModel()
            {
                Dropdown = new List <SelectListItem>()
                {
                    new SelectListItem()
                    {
                        Text = "Text1", Value = "Value1"
                    },
                    new SelectListItem()
                    {
                        Text = "Text2", Value = "Value2", Selected = true
                    }
                }
            };

            var helper = MvcMockHelpers.GetHtmlHelper(model);

            helper.ViewContext.SetError("Dropdown", "Value1");

            var tag = helper.Input(x => x.Dropdown);

            tag.Children[0].HasAttr("selected").ShouldBe(true);
            tag.Children[1].HasAttr("selected").ShouldBe(false);
        }
Exemple #9
0
        public void Can_Convert_Test_With_Results()
        {
            using (var req = MvcMockHelpers.SimulateRequest("http://localhost/Test.aspx"))
            {
                ABTester.Start();

                Assert.IsNotNull(ABTester.Current);

                var testname = "Can_Convert_Test_With_Results";

                var option1 = "one";
                var option2 = "two";

                var output = ABTester.Test(testname, option1, option2);

                Assert.IsTrue(output == option1 || output == option2);

                ABTester.Convert(testname);

                var results = ABTester.GetResults(testname);

                Assert.IsNotNull(results);
                Assert.AreEqual(1, results.Count);
                Assert.IsTrue(results[0].Converted);
            }
        }
        public void Command_Executing()
        {
            var sessionMock          = new Mock <ISession>();
            var nHbernateContextMock = new Mock <NHibernateContext>(sessionMock.Object, UserName);

            var controller = new FakeBaseController(nHbernateContextMock.Object);

            controller.SetFakeControllerContext(MvcMockHelpers.FakeUnauthenticatedHttpContext("~/Home/", UserName));

            var commandMock = new Mock <ICommand>();

            controller.ExecuteExecuteCommand(commandMock.Object);

            nHbernateContextMock.Verify(c => c.ExecuteCommand(It.IsAny <ICommand>()));

            const string result            = "result";
            var          commandResultMock = new Mock <ICommand <string> >();

            commandResultMock.Setup(c => c.Result).Returns(result);
            nHbernateContextMock.Setup(c => c.ExecuteCommand(It.IsAny <ICommand <string> >())).Returns(result);

            var actualResult = controller.ExecuteExecuteCommand(commandResultMock.Object);

            nHbernateContextMock.Verify(c => c.ExecuteCommand(It.IsAny <ICommand <string> >()));
            Assert.AreEqual(result, actualResult);
        }
Exemple #11
0
 public void Setup()
 {
     _datasource = new List <string> {
         "test1", "test2"
     };
     _context = MvcMockHelpers.DynamicHttpContextBase();
 }
Exemple #12
0
        public void ComplexUrlGeneration()
        {
            RouteTable.Routes.Clear();
            ActionFactory.Actions[typeof(NestedQueryModel)] = new ActionInfo();
            RouteTable.Routes.Add(typeof(NestedQueryModel).FullName, new Route("fakeUrl", null));
            ModelBinders.Binders.Remove(typeof(DateTime?));
            ModelBinders.Binders.Add(typeof(DateTime?), new DateTimeBinder());

            ActionFactory.TypeFormatters[typeof(DateTime?)] = (o, context) => ((DateTime?)o).Value.ToString("dd/MM/yyyy HH:mm:ss");

            var urlHelper = MvcMockHelpers.GetUrlHelper("~/fakeUrl");

            var httpContext = Mock.Get(urlHelper.RequestContext.HttpContext.Request);

            httpContext.Setup(x => x.QueryString).Returns(new NameValueCollection()
            {
                { "Age", "1" },
                { "NestedList[0].Name", "MyName" },
                { "NestedObj.Name", "MyName2" },
                { "Today", "17/10/2010 12:00:00" }
            });

            var url = urlHelper.For <NestedQueryModel>(x => x.Age = 2, x => x.NestedObj.Name = "Wow");

            Assert.AreEqual("/fakeUrl?Age=2&Today=17%2F10%2F2010%2012%3A00%3A00&NestedList%5B0%5D.Name=MyName&NestedObj.Name=Wow", url);
        }
Exemple #13
0
        public void Search_Without_Location()
        {
            var sessionMock          = new Mock <ISession>();
            var nHbernateContextMock = new Mock <NHibernateContext>(sessionMock.Object, UserName);
            var services             = GetSampleServices();

            nHbernateContextMock.Setup(c => c.ExecuteQuery(It.IsAny <IQuery <IEnumerable <Service> > >()))
            .Returns(services);

            var categories = GetSampleCategories();

            nHbernateContextMock.Setup(c => c.ExecuteQuery(It.IsAny <Func <ISession, IList <Category> > >()))
            .Returns(categories);

            var fileSystemMock        = new Mock <IFileSystem>();
            var geoCodingServicemMock = new Mock <IGeoCodingService>();

            var userLocation = PointFactory.Create(6.9319444, 79.8877778);
            var controller   = new ServicesController(nHbernateContextMock.Object, fileSystemMock.Object, geoCodingServicemMock.Object);

            controller.SetFakeControllerContext(MvcMockHelpers.FakeAuthenticatedHttpContext("~/Services/Search", UserName));
            controller.SetUserInfoWitLocation(userLocation);

            var model = new SearchModel {
                Terms = "Foo"
            };

            controller.Search(model);

            Assert.AreEqual(model, controller.ViewData.Model);
            Assert.AreEqual(userLocation, controller.ViewData[ViewDataKeys.UserLocation]);
        }
Exemple #14
0
        public void SetUp()
        {
            var context = MvcMockHelpers.DynamicHttpContextBase();

            context.Request.QueryString["ids[0]"]  = "1";
            context.Request.QueryString["dupe[0]"] = "1";

            context.Request.Form["ids[1]"]  = "2";
            context.Request.Form["dupe[0]"] = "2";

            context.Request.Cookies.Add(new HttpCookie("ids[2]", "3"));
            context.Request.Cookies.Add(new HttpCookie("dupe[0]", "3"));

            context.Request.ServerVariables["ids[3]"]  = "4";
            context.Request.ServerVariables["dupe[0]"] = "4";

            var controller = MockRepository.GenerateStub <ControllerBase>();

            controller.TempData            = new TempDataDictionary();
            controller.TempData["ids[4]"]  = 5;
            controller.TempData["dupe[0]"] = 5;

            var routeData = new RouteData();

            routeData.Values.Add("ids[5]", 6);
            routeData.Values.Add("dupe[0]", 6);

            var requestContext = new RequestContext(context, routeData);

            _controllerContext = new ControllerContext(requestContext, controller);
        }
        public void PasswordForRegisterValidatesOnLogin()
        {
            var formsAuthMoq   = new Mock <IFormsAuthentication>();
            var requestContext = new RequestContext(_httpContextMock.Object, new RouteData());
            var outputCacheMoq = new Mock <OutputCache>();

            App.OutputCache = outputCacheMoq.Object;

            var loginCredentials = new LoginCredentials
            {
                Email    = "*****@*****.**",
                Password = "******"
            };

            var controller = new AccountAccessController(DocumentStore)
            {
                FormsAuthentication = formsAuthMoq.Object,
                Url = new UrlHelper(requestContext, _routes)
            };

            controller.ControllerContext = new ControllerContext(requestContext, controller);

            MvcMockHelpers.Invoke(() => controller.Register(loginCredentials));
            MvcMockHelpers.Invoke(() => controller.Login(loginCredentials, string.Empty));

            Assert.That(controller.ErrorMessage, Is.Null, controller.ErrorMessage);
        }
        public void PropertyOfTypeDoubleShouldHaveNumberClass()
        {
            var model  = new TestViewModel();
            var helper = MvcMockHelpers.GetHtmlHelper(model);
            var tag    = helper.Input(x => x.Double);

            tag.HasClass("number").ShouldBe(true);
        }
        public void PropertyOfTypeIntShouldHaveDigitsClass()
        {
            var model  = new TestViewModel();
            var helper = MvcMockHelpers.GetHtmlHelper(model);
            var tag    = helper.Input(x => x.Int);

            tag.HasClass("digits").ShouldBe(true);
        }
Exemple #18
0
        public void PropertyWithDataTypePasswordAttributeShouldHaveTheTypePassword()
        {
            var model = new TestViewModel();
            var tag   = MvcMockHelpers.GetHtmlHelper(model).Input(x => x.Password);

            tag.TagName().ShouldBe("input");
            tag.Attr("type").ShouldBe("password");
        }
Exemple #19
0
 public void Setup()
 {
     _datasource = new List <object> {
         new object(), new object(), new object()
     };
     _context = MvcMockHelpers.DynamicHttpContextBase();
     RouteTable.Routes.MapRoute("default", "{controller}/{action}");
 }
        public void Should_have_single_singleton_instance_of_IRequestDescription()
        {
            // Arrange
            HttpContextRequestDescription.HttpContextProvider = () => MvcMockHelpers.FakeHttpContext();

            // Assert
            VerifyHasOneTransientOf <IRequestDescription, HttpContextRequestDescription>();
        }
        public void InputOfBoolPropertyWhosValueIsFalseShouldGiveAttrValueOfTrue()
        {
            var model  = new TestViewModel();
            var helper = MvcMockHelpers.GetHtmlHelper(model);
            var tag    = helper.Input(x => x.IsCorrect);

            tag.Attr("value").ShouldBe(true.ToString());
        }
Exemple #22
0
 public void Setup()
 {
     _datasource = new List <object> {
         new object(), new object(), new object()
     };
     _context = MvcMockHelpers.DynamicHttpContextBase();
     _context.Request.Stub(x => x.FilePath).Return("Test.mvc");
 }
        public void InputOfBoolPropertyShouldGenerateHiddenInputWithTheSameName()
        {
            var model  = new TestViewModel();
            var helper = MvcMockHelpers.GetHtmlHelper(model);
            var tag    = helper.Input(x => x.IsCorrect);

            tag.Next.TagName().ShouldBe(tag.TagName());
        }
        public void InputOfPropertyShouldBeCheckboxIfPropertyIsABool()
        {
            var model  = new TestViewModel();
            var helper = MvcMockHelpers.GetHtmlHelper(model);
            var tag    = helper.Input(x => x.IsCorrect);

            tag.Attr("type").ShouldBe("checkbox");
        }
Exemple #25
0
        public void PropertyWithHiddenInputAttributeShouldMakeTheTypeHidden()
        {
            var model = new TestViewModel();
            var tag   = MvcMockHelpers.GetHtmlHelper(model).Input(x => x.Hidden);

            tag.TagName().ShouldBe("input");
            tag.Attr("type").ShouldBe("hidden");
        }
Exemple #26
0
        public void CallingBuildShouldRunTheConventionsAsIfItWasAnotherType()
        {
            var model  = new ReusingViewModel();
            var helper = MvcMockHelpers.GetHtmlHelper(model);
            var tag    = helper.Input(x => x.AnimalId);

            tag.TagName().ShouldBe("select");
            Console.WriteLine(tag);
        }
        public Mock <ControllerContext> GetControllerContext()
        {
            var httpContext = MvcMockHelpers.FakeHttpContext("~/");
            Mock <ControllerContext> controllerContext = new Mock <ControllerContext>();

            controllerContext.Setup(ctx => ctx.HttpContext).Returns(httpContext);

            return(controllerContext);
        }
Exemple #28
0
        public void Can_Start_Tester()
        {
            using (var req = MvcMockHelpers.SimulateRequest("http://localhost/Test.aspx"))
            {
                ABTester.Start();

                Assert.IsNotNull(ABTester.Current);
            }
        }
        protected HttpContextBase GetHttpContext(PrincipalStub principal)
        {
            MvcMockContainer container = new MvcMockContainer();
            HttpContextBase  context   = MvcMockHelpers.FakeHttpContext(container);

            container.Context.SetupProperty(x => x.User, principal);

            return(context);
        }
Exemple #30
0
        public void Can_Get_Test_Results()
        {
            using (var req = MvcMockHelpers.SimulateRequest("http://localhost/Test.aspx"))
            {
                var results = ABTester.GetResults("Can_Get_Test_Results");

                Assert.IsNotNull(results);
            }
        }