public override void Observe()
        {
            base.RefreshDb();

            Container.Install(new BusInstaller(), new RepositoryInstaller(), new CommandInstaller());

            var state = StateMother.Draft;
            SaveAndFlush(state, StateMother.Published);



            var id = GetFromDb(state).Id;
            _browser = new Browser(with =>
            {
                with.Module(new StateModule(Container.Resolve<IPublishStorableCommands>(), Container.Resolve<IRepository<State>>()));
            });

            Session.FlushMode = FlushMode.Never;

            //Transaction(x =>
            //{
            _response = _browser.Post("/State/Edit", with =>
            {
                with.HttpRequest();
                with.Body("{ 'id': '" + id + "', 'name': 'Draft', 'alias': 'Test Draft'}");
                with.Header("content-type", "application/json");
                //with.Header("Authorization", "ApiKey 4E7106BA-16B6-44F2-AF4C-D1C411440F8E");
            });
            //});

            Session.Flush();
            // Session.Close();
        }
 public GetRootTests()
 {
     _response = _browser.Get("/", with =>
     {
         with.HttpRequest();
     });
 }
 public void HomeModule()
 {
     browser = new Browser (with => with.Module (new HomeModule ()));
     result = browser.Get ("/", with => {
         with.HttpRequest ();
     });
 }
        public void SetUp()
        {
            _server = new Browser(new ServerBootstrapper());

            sampleConfig = TestHelper.GetSampleConfig();
            environmentConfig = TestHelper.GetEnvironmentOverrideConfig();

            setConfigResponse = _server.Post("application/new", context =>
            {
                context.HttpRequest();
                context.JsonBody(sampleConfig as object);
            });

            setEnvironmentConfigResponse = _server.Post("application/new", context =>
            {
                context.HttpRequest();
                context.JsonBody(environmentConfig as object);
                context.Query(TestHelper.Environment, "test");
            });

            getCreatedEnvironmentConfigResponse = _server.Get("application/new", context =>
            {
                context.Query(TestHelper.Environment, "test");
            });

            getEnvironmentConfigResult = getCreatedEnvironmentConfigResponse.Body.AsJson();
        }
Exemple #5
0
 public void FixtureSetup()
 {
     var formsAuthenticationConfiguration = new FormsAuthenticationConfiguration()
         {
             RedirectUrl = "~/login",
             UserMapper = new FakeUserMapper(new UserService())
         };
     var configuration = A.Fake<IRazorConfiguration>();
     var bootstrapper = new ConfigurableBootstrapper(config =>
         {
             config.Module<UsersModule>();
             config.Module<LoginModule>();
             config.ViewEngine(new RazorViewEngine(configuration));
         });
     var bootstrapper2 = new ConfigurableBootstrapper(config =>
         {
             config.Module<UsersModule>();
             config.Module<LoginModule>();
             config.ViewEngine(new RazorViewEngine(configuration));
             config.RequestStartup((x, pipelines, z) => FormsAuthentication.Enable(pipelines, formsAuthenticationConfiguration));
         });
     _notLoggedInBrowser = new Browser(bootstrapper);
     _loggedInBrowserResponse = new Browser(bootstrapper2).Post("/login", x =>
         {
             x.HttpRequest();
             x.FormValue("Username", "Chris1");
             x.FormValue("Password", "123");
         });
 }
        public void SetUp()
        {
            var bootstrapper = new AppBootstrapper();
            var browser = new Browser(bootstrapper);
            bootstrapper.Initialise();

            _result = browser.Get("/", with => with.HttpRequest());
        }
 public When_an_error_message_is_present()
 {
     _Browser = Testing.CreateBrowser<PagesModule>(with =>
     {
         with.Session(SessionKeys.FLASH_ERROR, "There was an error!");
     });
     _Response = _Browser.Get("/");
 }
Exemple #8
0
 public App(BrowserResponse response, FakeCommandSender commandSender = null)
 {
     if (commandSender != null)
     {
         Dispatched = new List<object>(commandSender.SentCommands).AsReadOnly();
     }
     Response = response;
 }
 public When_a_success_message_is_present()
 {
     _Browser = Testing.CreateBrowser<PagesModule>(with =>
     {
         with.Session(SessionKeys.FLASH_SUCCESS, "All done!");
     });
     _Response = _Browser.Get("/");
 }
 public When_deploying_an_app_that_doesnt_exist()
 {
     _Browser = Testing.CreateBrowser<SecuredPagesModule>(with =>
     {
         with.LoggedInUser();
     });
     _Response = _Browser.Post("/Deploy/foofoo");
 }
 public When_user_signs_out()
 {
     _Browser = Testing.CreateBrowser<OAuthModule>(with =>
     {
         with.LoggedInUser();
     });
     _Response = _Browser.Get("/SignOut");
 }
 public When_user_is_logged_on()
 {
     _Browser = Testing.CreateBrowser<PagesModule>(with =>
     {
         with.LoggedInUser();
     });
     _Response = _Browser.Get("/");
 }
 public When_no_payload_is_sent()
 {
     _Browser = Testing.CreateBrowser<HookModule>();
     _Response = _Browser.Post("/Sites/foofoo/NotifyByEmail", with =>
     {
         with.Query("email", "*****@*****.**");
     });
 }
 public When_displaying_the_deploy_page()
 {
     _Browser = Testing.CreateBrowser<SecuredPagesModule>(with =>
     {
         with.LoggedInUser();
     });
     _Response = _Browser.Get("/Deploy/jabbr");
 }
 public when_posting_a_new_idea()
 {
     mockUsersRepo.Setup(d => d.GetUserFromIdentifier(user.Id)).Returns(user);
     response = browser.Post("/api/ideas", with => {
         with.JsonBody(new { title = "Test" });
         with.LoggedInUser(user);
     });
 }
 public void SetUpGet()
 {
     response = browser.Get(url, (with) => {
     with.HttpRequest();
     with.Query("longitude", longitude);
     with.Query("latitude", latitude);
     with.Query("accuracy", "0.631");
       });
 }
 public void WhenIWantTempCredetialsSupplyingAnIPAddressAndMySecretAccountKey()
 {
     var accountKey = FeatureContext.Current["AccountKey2"];
     response = Browser.Post(string.Format("/{0}/Authorisation", accountKey), with =>
     {
         with.HttpRequest();
         with.FormValue("IPAddress", "192.168.129.186");
     });
 }
Exemple #18
0
        public WhenRequestingTheIndexPage()
        {
            var browser = new Browser(with =>
            {
                with.Module<HomeModule>();
            });

            _response = browser.Get("/");
        }
 public when_updating_an_idea()
 {
     mockIdeasRepo.Setup(d => d.Get(1)).Returns(testIdea);
     mockUsersRepo.Setup(d => d.GetUserFromIdentifier(user.Id)).Returns(user);
     response = browser.Put("/api/ideas/1", with => {
         with.JsonBody(new { title = "New Title" });
         with.LoggedInUser(user);
     });
 }
 public When_no_email_is_passed()
 {
     _Api = new Mock<IApiService>(MockBehavior.Strict);
     _Browser = Testing.CreateBrowser<SecuredPagesModule>(with =>
     {
         with.LoggedInUser();
         with.Api(_Api);
     });
     _Response = _Browser.Put("/Sites/testsite/Notifications/Email");
 }
        public void WhenSendingMyValidationKeyThatIsInvalid()
        {
            var validationKey = "I've made something up";

            _response = Browser.Post(string.Format("/Account/Validate"), with =>
            {
                with.HttpRequest();
                with.FormValue("ValidationKey", (string)validationKey);
            });
        }
 public When_requesting_the_sign_in_page()
 {
     _OAuth = new Mock<IOAuth>(MockBehavior.Strict);
     _OAuth.Setup(d => d.GetAuthUrl()).Returns("http://www.test.com");
     _Browser = Testing.CreateBrowser<OAuthModule>(with =>
     {
         with.OAuth(_OAuth);
     });
     _Response = _Browser.Get("/SignIn");
 }
        public void WhenSendingMyValidationKey()
        {
            var validationKey = FeatureContext.Current["AccountKey2"];

            _response = Browser.Post(string.Format("/Account/Validate"), with =>
                                                                             {
                                                                                 with.HttpRequest();
                                                                                 with.FormValue("ValidationKey", (string)validationKey);
                                                                             });
        }
 public void WhenCreatingAnAccountWithMyEmailAndPassword()
 {
     _response = Browser.Post("/Account/Create", with =>
     {
         with.HttpRequest();
         with.FormValue("EmailAddress", "*****@*****.**");
         with.FormValue("Password", "Pa55word");
         with.FormValue("RateOutOf", "100");
     });
 }
        public void GivenEuAcessoAPaginaDeItens()
        {
            var bootstrapper = new ToDoListBootstrapper();
            var browser = new Browser(bootstrapper);

            result = browser.Get("/", with =>
            {
                with.HttpRequest();
            });
        }
 public When_no_code_is_sent()
 {
     _OAuth = new Mock<IOAuth>(MockBehavior.Strict);
     _Browser = Testing.CreateBrowser<OAuthModule>(with =>
     {
         with.OAuth(_OAuth);
     });
     _Response = _Browser.Get("/callback", with =>
     {
     });
 }
 public When_no_application_name_is_specified()
 {
     _Browser = Testing.CreateBrowser<SecuredPagesModule>(with =>
     {
         with.LoggedInUser();
     });
     _Response = _Browser.Post("/Deploy/jabbr", with =>
     {
         with.FormValue("region_id", "amazon-web-services::us-east-1");
     });
 }
 public When_no_region_id_is_specified()
 {
     _Browser = Testing.CreateBrowser<SecuredPagesModule>(with =>
     {
         with.LoggedInUser();
     });
     _Response = _Browser.Post("/Deploy/jabbr", with =>
     {
         with.FormValue("application_name", "foo");
     });
 }
 public When_no_session_is_present()
 {
     var boot = new ConfigurableBootstrapper(with =>
     {
         with.DisableAutoRegistration();
         with.Module<SessionTestModule>();
     });
     KeyValueStoreSessions.Enable(boot, A.Fake<IKeyValueStore>());
     var browser = new Browser(boot);
     _Response = browser.Get("/TestVariable");
 }
        public When_displaying_the_sites_page()
        {
            var api = new Mock<IApiService>(MockBehavior.Strict);
            api.Setup(d => d.GetApplications()).Returns(new[] { new Application { Slug = "test", Name = "My Test Site" } });

            _Browser = Testing.CreateBrowser<SecuredPagesModule>(with =>
            {
                with.LoggedInUser();
                with.Api(api);
            });
            _Response = _Browser.Get("/Sites");
        }
        /// <summary>
        /// Asserts that a redirect to a certain location took place.
        /// </summary>
        /// <param name="response">The <see cref="BrowserResponse"/> that the assert should be made on.</param>
        /// <param name="location">The location that should have been redirected to.</param>
        /// <param name="stringComparer">The string comparer that should be used by the assertion. The default value is <see cref="StringComparison.InvariantCulture"/>.</param>
        public static void ShouldHaveRedirectedTo(this BrowserResponse response, string location, StringComparison stringComparer = StringComparison.InvariantCulture)
        {
            if (response.StatusCode != HttpStatusCode.SeeOther)
            {
                throw new AssertException("Status code should be SeeOther");
            }

            if (!response.Headers["Location"].Equals(location, stringComparer))
            {
                throw new AssertException(String.Format("Location should have been: {0}, but was {1}", location, response.Headers["Location"]));
            }
        }
Exemple #32
0
        /// <summary>
        /// Performs a request of the HTTP <paramref name="method"/>, on the given <paramref name="url"/>, using the
        /// provided <paramref name="browserContext"/> configuration.
        /// </summary>
        /// <param name="method">HTTP method to send the request as.</param>
        /// <param name="url">The URl of the request.</param>
        /// <param name="browserContext">An closure for providing browser context for the request.</param>
        /// <returns>An <see cref="BrowserResponse"/> instance of the executed request.</returns>
        public BrowserResponse HandleRequest(string method, Url url, Action <BrowserContext> browserContext)
        {
            var browserContextValues =
                BuildBrowserContextValues(browserContext ?? (with => { }));

            var request =
                CreateRequest(method, url, browserContextValues);

            var response = new BrowserResponse(this.engine.HandleRequest(request), this, (BrowserContext)browserContextValues);

            this.CaptureCookies(response);

            return(response);
        }
Exemple #33
0
        /// <summary>
        /// Performs a request of the HTTP <paramref name="method"/>, on the given <paramref name="url"/>, using the
        /// provided <paramref name="browserContext"/> configuration.
        /// </summary>
        /// <param name="method">HTTP method to send the request as.</param>
        /// <param name="url">The URl of the request.</param>
        /// <param name="browserContext">An closure for providing browser context for the request.</param>
        /// <returns>An <see cref="BrowserResponse"/> instance of the executed request.</returns>
        public async Task <BrowserResponse> HandleRequest(string method, Url url, Action <BrowserContext> browserContext)
        {
            var browserContextValues =
                BuildBrowserContextValues(browserContext ?? (with => { }));

            var request =
                CreateRequest(method, url, browserContextValues);

            var context = await this.engine.HandleRequest(request).ConfigureAwait(false);

            var response = new BrowserResponse(context, this, (BrowserContext)browserContextValues);

            this.CaptureCookies(response);

            return(response);
        }
Exemple #34
0
        private void CaptureCookies(BrowserResponse response)
        {
            if (response.Cookies == null || !response.Cookies.Any())
            {
                return;
            }

            foreach (var cookie in response.Cookies)
            {
                if (string.IsNullOrEmpty(cookie.Value))
                {
                    this.cookies.Remove(cookie.Name);
                }
                else
                {
                    this.cookies[cookie.Name] = cookie.Value;
                }
            }
        }
        /// <summary>
        /// Asserts that a redirect to a certain location took place.
        /// </summary>
        /// <param name="response">The <see cref="BrowserResponse"/> that the assert should be made on.</param>
        /// <param name="location">The location that should have been redirected to.</param>
        /// <param name="stringComparer">The string comparer that should be used by the assertion. The default value is <see cref="StringComparison.Ordinal"/>.</param>
        public static void ShouldHaveRedirectedTo(this BrowserResponse response, string location, StringComparison stringComparer = StringComparison.Ordinal)
        {
            var validRedirectStatuses = new[]
            {
                HttpStatusCode.MovedPermanently,
                HttpStatusCode.SeeOther,
                HttpStatusCode.TemporaryRedirect
            };

            if (!validRedirectStatuses.Any(x => x == response.StatusCode))
            {
                throw new AssertException(
                          string.Format("Status code should be one of 'MovedPermanently, SeeOther, TemporaryRedirect', but was {0}.", response.StatusCode));
            }

            if (!response.Headers["Location"].Equals(location, stringComparer))
            {
                throw new AssertException(string.Format("Location should have been: {0}, but was {1}", location, response.Headers["Location"]));
            }
        }