コード例 #1
0
		public void should_not_set_any_result_if_https_not_required()
		{
			//arrange
			var configuration = Substitute.For<IConfigurationHelper>();
			configuration.IsHttpsRequired.Returns(false);
			var target = new DVSRequireHttpsAttribute(configuration);

			var request = Substitute.For<HttpRequestBase>();
			request.IsSecureConnection.Returns(false);
			var httpContext = Substitute.For<HttpContextBase>();
			httpContext.Request.Returns(request);
			var authorizationContext = new AuthorizationContext();
			authorizationContext.HttpContext = httpContext;
			//act
			target.OnAuthorization(authorizationContext);
			//assert
			Assert.IsNull(authorizationContext.Result);
		}
コード例 #2
0
		private void redirect_result_test_cases(string applicationPath)
		{
			//arrange
			const string host = "myhost";
			var configuration = Substitute.For<IConfigurationHelper>();
			configuration.IsHttpsRequired.Returns(true);
			var target = new DVSRequireHttpsAttribute(configuration);

			var url = new Uri("http://" + host);
			var request = Substitute.For<HttpRequestBase>();
			request.IsSecureConnection.Returns(false);
			request.ApplicationPath.Returns(applicationPath);
			request.HttpMethod.Returns("GET");
			request.Url.Returns(url);
			var httpContext = Substitute.For<HttpContextBase>();
			httpContext.Request.Returns(request);
			var authorizationContext = new AuthorizationContext();
			authorizationContext.HttpContext = httpContext;
			//act
			target.OnAuthorization(authorizationContext);
			//assert
			var actualResult = (RedirectResult)authorizationContext.Result;
			Assert.AreEqual("https://" + host + applicationPath, actualResult.Url);
		}
コード例 #3
0
		public void should_not_redirect_if_https()
		{
			//arrange
			const string host = "myhost";
			var configuration = Substitute.For<IConfigurationHelper>();
			configuration.IsHttpsRequired.Returns(true);
			var target = new DVSRequireHttpsAttribute(configuration);

			var url = new Uri("http://" + host);
			var request = Substitute.For<HttpRequestBase>();
			request.IsSecureConnection.Returns(true);
			request.RawUrl.Returns("someUrl");
			request.HttpMethod.Returns("GET");
			request.Url.Returns(url);
			var httpContext = Substitute.For<HttpContextBase>();
			httpContext.Request.Returns(request);
			var authorizationContext = new AuthorizationContext();
			authorizationContext.HttpContext = httpContext;
			//act
			target.OnAuthorization(authorizationContext);
			//assert
			Assert.IsNull(authorizationContext.Result);
		}