Beispiel #1
0
        public void IfRangeHeader_Should_Be_Ignored_If_ItNotEquals_Etag()
        {
            Request.Headers[HttpHeaders.IfRange] = "ifRange fake header";
            var mock = new MockResumeFileResult(_file.FullName, Request);

            mock.WriteFileTest(Response);

            Assert.AreNotEqual(ResumeFileResult.Util.Etag(_file), Request.Headers[HttpHeaders.IfRange]);
            Assert.AreEqual(200, Response.StatusCode);
        }
Beispiel #2
0
        public void Etag_Should_Be_Added_To_Response_If_It_Equals_With_IfRange_In_Request()
        {
            var etag = ResumeFileResult.Util.Etag(_file);

            Request.Headers[HttpHeaders.IfRange] = etag;
            var mock = new MockResumeFileResult(_file.FullName, Request);

            mock.WriteFileTest(Response);
            Assert.AreEqual(Response.Headers[HttpHeaders.Etag], etag);
            Assert.AreEqual(200, Response.StatusCode);
        }
Beispiel #3
0
        public void HeadersTest_Should_Send_File_If_All_Headers_Are_Null()
        {
            var result = new MockResumeFileResult(_file.FullName, Request);

            result.WriteFileTest(Response);
            Assert.AreEqual((int)HttpStatusCode.OK, Response.StatusCode);
            Assert.IsNotNull(Response.Headers[HttpHeaders.Etag]);
            Assert.IsNotNull(Response.Headers[HttpHeaders.Expires]);
            Assert.IsNotNull(Response.Headers[HttpHeaders.LastModified]);
            Assert.IsNotNull(Response.Headers[HttpHeaders.ContentRange]);
            Assert.IsNotNull(Response.Headers[HttpHeaders.ContentLength]);
            Assert.AreEqual(_file.Length, Response.OutputStream.Length);
        }
Beispiel #4
0
        public void HeadersTest_Should_Not_Send_File_Is_RangeNotSatisfiable()
        {
            Request.Headers[HttpHeaders.Range] = "invalid";
            var result = new MockResumeFileResult(_file.FullName, Request);

            Assert.IsTrue(result.IsRangeNotSatisfiable());
            result.WriteFileTest(Response);
            Assert.AreEqual((int)HttpStatusCode.RequestedRangeNotSatisfiable, Response.StatusCode);
            Assert.IsNotNull(Response.Headers[HttpHeaders.Etag]);
            Assert.IsNotNull(Response.Headers[HttpHeaders.Expires]);
            Assert.IsNotNull(Response.Headers[HttpHeaders.LastModified]);
            Assert.AreEqual("bytes */" + _file.Length, Response.Headers[HttpHeaders.ContentRange]);
            Assert.AreEqual(0, Response.OutputStream.Length);
        }
Beispiel #5
0
        public void HeadersTest_Should_Not_Send_File_If_File_Has_Not_Been_Changed()
        {
            Request.Headers[HttpHeaders.IfNoneMatch] = ResumeFileResult.Util.Etag(_file);
            var result = new MockResumeFileResult(_file.FullName, Request);

            Assert.IsTrue(result.IsNotModified());
            result.WriteFileTest(Response);
            Assert.AreEqual((int)HttpStatusCode.NotModified, Response.StatusCode);
            Assert.IsNotNull(Response.Headers[HttpHeaders.Etag]);
            Assert.IsNotNull(Response.Headers[HttpHeaders.Expires]);
            Assert.IsNotNull(Response.Headers[HttpHeaders.LastModified]);
            Assert.IsNull(Response.Headers[HttpHeaders.ContentRange]);
            Assert.AreEqual(0, Response.OutputStream.Length);
        }
Beispiel #6
0
        public void HeadersTest_Should_Not_Send_File_IfPreconditionFailed()
        {
            Request.Headers[HttpHeaders.IfMatch] = "invalid";
            var result = new MockResumeFileResult(_file.FullName, Request);

            Assert.IsTrue(result.IsPreconditionFailed());

            result.WriteFileTest(Response);
            Assert.AreEqual((int)HttpStatusCode.PreconditionFailed, Response.StatusCode);
            Assert.IsNotNull(Response.Headers[HttpHeaders.Etag]);
            Assert.IsNotNull(Response.Headers[HttpHeaders.Expires]);
            Assert.IsNotNull(Response.Headers[HttpHeaders.LastModified]);
            Assert.IsNull(Response.Headers[HttpHeaders.ContentRange]);
            Assert.AreEqual(0, Response.OutputStream.Length);
        }