Esempio n. 1
0
        protected void ValidateCompany(ICompany companyElement)
        {
            if (!companyElement.IsCompanyValid(CurrentUser.CompanyId))
            {
                var result = new HttpStatusCodeResult(HttpStatusCode.Forbidden);

                result.ExecuteResult(this.ControllerContext);
                HttpContext.Response.End();
                //TODO redirect to forbidden page
            }
        }
        public void ExecuteResult() {
            // Arrange
            Mock<ControllerContext> mockControllerContext = new Mock<ControllerContext>();
            mockControllerContext.SetupSet(c => c.HttpContext.Response.StatusCode = 666).Verifiable();

            HttpStatusCodeResult result = new HttpStatusCodeResult(666);

            // Act
            result.ExecuteResult(mockControllerContext.Object);

            // Assert
            mockControllerContext.Verify();
        }
Esempio n. 3
0
        public void ExecuteResultWithDescription()
        {
            // Arrange
            Mock <ControllerContext> mockControllerContext = new Mock <ControllerContext>();

            mockControllerContext.SetupSet(c => c.HttpContext.Response.StatusCode        = 666).Verifiable();
            mockControllerContext.SetupSet(c => c.HttpContext.Response.StatusDescription = "Foo Bar").Verifiable();
            HttpStatusCodeResult result = new HttpStatusCodeResult(666, "Foo Bar");

            // Act
            result.ExecuteResult(mockControllerContext.Object);

            // Assert
            mockControllerContext.Verify();
        }
Esempio n. 4
0
        public void ExecuteResultWithHttpStatusCode()
        {
            // Arrange
            int unusedStatusCode = 306;
            Mock <ControllerContext> mockControllerContext = new Mock <ControllerContext>();

            mockControllerContext.SetupSet(c => c.HttpContext.Response.StatusCode = unusedStatusCode).Verifiable();

            HttpStatusCodeResult result = new HttpStatusCodeResult(HttpStatusCode.Unused);

            // Act
            result.ExecuteResult(mockControllerContext.Object);

            // Assert
            mockControllerContext.Verify();
        }
Esempio n. 5
0
        public override void ExecuteResult(ControllerContext context)
        {
            bool notModified = IsNotModified(context.HttpContext.Request);

            if (notModified)
            {
                var statusCode = new HttpStatusCodeResult(304, "Not Modified");
                statusCode.ExecuteResult(context);
            }
            else
            {
                context.HttpContext.Response.Cache.SetLastModified(lastModified);
                // HttpCachePolicyは、CacheabilityがPrivate(デフォルト値)に設定されていると、
                // SetETag()でETagヘッダを追加しません。(既知の不具合)
                context.HttpContext.Response.AddHeader("ETag", guid.ToString());
                base.ExecuteResult(context);
            }
        }
        public void ExecuteResultWithHttpStatusCode()
        {
            // Arrange
            int unusedStatusCode = 306;
            Mock<ControllerContext> mockControllerContext = new Mock<ControllerContext>();
            mockControllerContext.SetupSet(c => c.HttpContext.Response.StatusCode = unusedStatusCode).Verifiable();

            HttpStatusCodeResult result = new HttpStatusCodeResult(HttpStatusCode.Unused);

            // Act
            result.ExecuteResult(mockControllerContext.Object);

            // Assert
            mockControllerContext.Verify();
        }