DinnersController CreateDinnersController()
        {
            var testData   = FakeDinnerData.CreateTestDinners();
            var repository = new FakeDinnerRepository(testData);

            var nerdIdentity = FakeIdentity.CreateIdentity("SomeUser");

            return(new DinnersController(repository, nerdIdentity));
        }
Beispiel #2
0
        RSVPController CreateRSVPControllerAs(string userName)
        {
            var mock         = new Mock <ControllerContext>();
            var nerdIdentity = FakeIdentity.CreateIdentity("SomeUser");

            mock.SetupGet(p => p.HttpContext.User.Identity).Returns(nerdIdentity);

            var controller = CreateRSVPController();

            controller.ControllerContext = mock.Object;

            return(controller);
        }
        SearchController CreateSearchControllerAs(string userName)
        {
            var mock         = new Mock <ControllerContext>();
            var nerdIdentity = FakeIdentity.CreateIdentity(userName);

            mock.SetupGet(p => p.HttpContext.User.Identity).Returns(nerdIdentity);

            var controller = new SearchController(new DinnerRepository(new NerdDinners()));

            controller.ControllerContext = mock.Object;

            return(controller);
        }
        /// <summary>
        ///     Builds a controller of the required type using any data previously supplied (or defaults).
        /// </summary>
        /// <returns>An initialized controller of type <typeparamref name="TController" />.</returns>
        /// <exception cref="SpecificationException">Thrown if the controller cannot be built.</exception>
        public TController Build()
        {
            var dataLoader = new ObjectDataLoader(data);

            UnitOfWork = uowBuilder.WithData(dataLoader).Build();
            var mapperConfiguration = new MapperConfiguration(cfg => { cfg.AddProfile <ViewModelMappingProfile>(); });

            mapperConfiguration.AssertConfigurationIsValid();
            Mapper = mapperConfiguration.CreateMapper();
            var notifier = new FakeNotificationService();

            RulesService = new GameRulesService(UnitOfWork, Mapper, notifier);
            HttpContextBase httpContext;

            if (postedFile == null)
            {
                httpContext = new FakeHttpContext(requestPath, requestMethod.ToString("G"));
            }
            else
            {
                var filesCollection = new FakeHttpFileCollection(postedFile);
                httpContext = new FakeHttpContext(requestPath, filesCollection);
            }
            var fakeIdentity  = new FakeIdentity(requestUsername);
            var fakePrincipal = new FakePrincipal(fakeIdentity, requestUserRoles);

            httpContext.User = fakePrincipal;
            var context = new ControllerContext {
                HttpContext = httpContext
            };

            /*
             * Use Ninject to create the controller, as we don't know in advance what
             * type of controller or how many constructor parameters it has.
             */
            var kernel     = BuildNinjectKernel(fakeIdentity, requestUserId, RulesService);
            var controller = kernel.Get <TController>();

            if (controller == null)
            {
                throw new SpecificationException(
                          $"ControllerContextBuilder: Unable to create controller instance of type {nameof(TController)}");
            }

            controller.ControllerContext = context;
            controller.TempData          = tempdata;
            return(controller);
        }
Beispiel #5
0
        private void ChangeContactInfo()
        {
            var consultantProfilePage = new ProfilePage(_rootUrl, _browser, _delay);

            consultantProfilePage.EditContactInfoLink.Click();

            var fakeIdentity        = FakeIdentity.Generate();
            var editContactInfoPage = new EditContactInfoPage(_rootUrl, _browser, _delay);

            editContactInfoPage.FillForm(
                fakeIdentity.FirstName,
                fakeIdentity.LastName,
                fakeIdentity.EmailAddress,
                fakeIdentity.Phone);
            editContactInfoPage.SubmitForm();
        }
Beispiel #6
0
        public static ClaimsPrincipal CreateFakePrincipal()
        {
            var identity = new FakeIdentity("ehsan", "Basic", true);

            var incomingPrincipal = new ClaimsPrincipal(identity);

            incomingPrincipal.Identities.First().AddClaims(new List <Claim>
            {
                new Claim(ClaimTypes.Role, "Admin"),
                new Claim(ClaimTypes.Role, "Employee"),
                new Claim("http://identityserver.thinktecture.com/claims/profileclaims/employeeno", "30000"),
                new Claim("http://identityserver.thinktecture.com/claims/profileclaims/firstname", "احسان"),
                new Claim("http://identityserver.thinktecture.com/claims/profileclaims/lastname", "محمدی"),
                new Claim("http://identityserver.thinktecture.com/claims/profileclaims/jobpositionnames", "مدیر فنی"),
            });
            return(incomingPrincipal);
        }
Beispiel #7
0
        private void SignUpForANewAccount()
        {
            var fakeIdentity = FakeIdentity.Generate();

            var registrationPage = new RegistrationPage(_rootUrl, _browser, _delay);

            registrationPage.Navigate();

            registrationPage.FillForm(
                fakeIdentity.EmailAddress,
                fakeIdentity.Password,
                AccountTypes.CONSULTANT,
                fakeIdentity.FirstName,
                fakeIdentity.LastName,
                fakeIdentity.Phone);

            registrationPage.SubmitForm();
        }
        public void CreateAction_With_New_Dinner_Should_Return_View_And_Repo_Should_Contain_New_Dinner()
        {
            // Arrange
            var mock = new Mock <ControllerContext>();

            var nerdIdentity = FakeIdentity.CreateIdentity("SomeUser");
            var testData     = FakeDinnerData.CreateTestDinners();
            var repository   = new FakeDinnerRepository(testData);
            var controller   = new DinnersController(repository, nerdIdentity);

            controller.ControllerContext = mock.Object;
            mock.SetupGet(p => p.HttpContext.User.Identity).Returns(nerdIdentity);

            var dinner = FakeDinnerData.CreateDinner();

            // Act
            ActionResult result = (ActionResult)controller.Create(dinner);

            // Assert
            Assert.AreEqual(102, repository.All.Count());
            Assert.IsInstanceOf <RedirectToRouteResult>(result);
        }
        public void IndexAction_With_Dinner_Just_Started_Should_Show_Dinner()
        {
            // Arrange
            var testData = FakeDinnerData.CreateTestDinners();
            var dinner   = FakeDinnerData.CreateDinner();

            dinner.EventDate = DateTime.Now.AddHours(1);
            dinner.Title     = "Dinner which just started";
            testData.Item1.Add(dinner);
            var repository   = new FakeDinnerRepository(testData);
            var nerdIdentity = FakeIdentity.CreateIdentity("SomeUser");

            var controller = new DinnersController(repository, nerdIdentity);

            // Act
            // Get first page
            ViewResult         result = (ViewResult)controller.Index(null, null);
            PagedList <Dinner> list   = result.ViewData.Model as PagedList <Dinner>;

            // Assert
            Assert.AreEqual("Dinner which just started", list.First().Title);
        }
        public void IndexAction_With_Search_Term_Should_Filter()
        {
            // Arrange
            string searchterm = "Dinner we will be searching for (spaghetti)";

            var testData = FakeDinnerData.CreateTestDinners();
            var dinner   = FakeDinnerData.CreateDinner();

            dinner.Title = searchterm;
            testData.Item1.Add(dinner);
            var repository   = new FakeDinnerRepository(testData);
            var nerdIdentity = FakeIdentity.CreateIdentity("SomeUser");

            var controller = new DinnersController(repository, nerdIdentity);

            // Act
            // Get first page
            ViewResult         result = (ViewResult)controller.Index("etti", null);
            PagedList <Dinner> list   = result.ViewData.Model as PagedList <Dinner>;

            // Assert
            Assert.AreEqual(searchterm, list.First().Title);
        }
Beispiel #11
0
 public FakePrincipal()
 {
     Identity = new FakeIdentity();
 }
Beispiel #12
0
 public FakePrincipal(FakeIdentity ident)
 {
     _ident = ident;
 }