public void adding_not_found_property_should_be_returned_in_xml()
        {
            var response = new Response { Href = "/public/litmus" };
            response.NotFound.Status = "HTTP/1.1 404 Not Found";
            response.NotFound.AddProperty("getlastmodified", null);
            var multiStatus = new MultiStatusResult();
            multiStatus.Responses.Add(response);
            var result = multiStatus.ToString();

            Assert.That(result, Is.EqualTo(@"<d:multistatus xmlns:d=""DAV:"">
              <d:response>
            <d:href>/public/litmus</d:href>
            <d:propstat>
              <d:prop>
            <d:getlastmodified />
              </d:prop>
              <d:status>HTTP/1.1 404 Not Found</d:status>
            </d:propstat>
              </d:response>
            </d:multistatus>"));
        }
        public void adding_last_modified_property_should_be_returned_in_xml()
        {
            var response = new Response { Href = "/public/litmus" };
            response.Found.Status = "HTTP/1.1 200 OK";
            var dateTime = new DateTime(2012, 4, 23, 23, 09, 47);
            response.Found.AddLastModified(dateTime);
            var multiStatus = new MultiStatusResult();
            multiStatus.Responses.Add(response);
            var result = multiStatus.ToString();

            Assert.That(result, Is.EqualTo(@"<d:multistatus xmlns:d=""DAV:"">
              <d:response>
            <d:href>/public/litmus</d:href>
            <d:propstat>
              <d:prop>
            <d:getlastmodified>Mon, 23 Apr 2012 23:09:47 GMT</d:getlastmodified>
              </d:prop>
              <d:status>HTTP/1.1 200 OK</d:status>
            </d:propstat>
              </d:response>
            </d:multistatus>"));
            Assert.That(response.Found.LastModified, Is.EqualTo(dateTime));
        }
        public void adding_found_property_should_be_returned_in_xml()
        {
            var response = new Response { Href = "/public/litmus" };
            response.Found.Status = "HTTP/1.1 200 OK";
            XNamespace dateNs = "urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882";
            response.Found.AddProperty("getlastmodified", "Mon, 23 Apr 2012 23:09:47 GMT")
                          .SetAttributeValue(dateNs + "dt", "dateTime.rfc1123");
            var multiStatus = new MultiStatusResult();
            multiStatus.Responses.Add(response);
            var result = multiStatus.ToString();

            Assert.That(result, Is.EqualTo(@"<d:multistatus xmlns:d=""DAV:"">
              <d:response>
            <d:href>/public/litmus</d:href>
            <d:propstat>
              <d:prop>
            <d:getlastmodified p5:dt=""dateTime.rfc1123"" xmlns:p5=""urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882"">Mon, 23 Apr 2012 23:09:47 GMT</d:getlastmodified>
              </d:prop>
              <d:status>HTTP/1.1 200 OK</d:status>
            </d:propstat>
              </d:response>
            </d:multistatus>"));
        }
        public void mark_response_as_a_collection_should_be_returned_in_xml()
        {
            var response = new Response { Href = "/public/litmus" };
            response.Found.Status = "HTTP/1.1 200 Found";
            response.Found.AddResourceType(true);
            var multiStatus = new MultiStatusResult();
            multiStatus.Responses.Add(response);
            var result = multiStatus.ToString();

            Assert.That(result, Is.EqualTo(@"<d:multistatus xmlns:d=""DAV:"">
              <d:response>
            <d:href>/public/litmus</d:href>
            <d:propstat>
              <d:prop>
            <d:resourcetype>
              <d:collection />
            </d:resourcetype>
              </d:prop>
              <d:status>HTTP/1.1 200 Found</d:status>
            </d:propstat>
              </d:response>
            </d:multistatus>"));
            Assert.That(response.Found.IsCollection, Is.True);
        }
        public void set_content_length_property()
        {
            var response = new Response { Href = "/public/litmus" };
            response.Found.Status = "HTTP/1.1 200 Found";
            response.Found.AddContentLength(4096);
            var multiStatus = new MultiStatusResult();
            multiStatus.Responses.Add(response);
            var result = multiStatus.ToString();

            Assert.That(result, Is.EqualTo(@"<d:multistatus xmlns:d=""DAV:"">
              <d:response>
            <d:href>/public/litmus</d:href>
            <d:propstat>
              <d:prop>
            <d:getcontentlength>4096</d:getcontentlength>
              </d:prop>
              <d:status>HTTP/1.1 200 Found</d:status>
            </d:propstat>
              </d:response>
            </d:multistatus>"));
            Assert.That(response.Found.ContentLength, Is.EqualTo(4096));
        }
        public void namespaced_properties_should_be_returned_in_xml()
        {
            var response = new Response { Href = "/public/litmus" };
            response.Found.Status = "HTTP/1.1 200 Found";
            response.Found.AddProperty("http://example.com/neon/litmus/", "foo", null);
            var multiStatus = new MultiStatusResult();
            multiStatus.Responses.Add(response);
            var result = multiStatus.ToString();

            Assert.That(result, Is.EqualTo(@"<d:multistatus xmlns:d=""DAV:"">
              <d:response>
            <d:href>/public/litmus</d:href>
            <d:propstat>
              <d:prop>
            <foo xmlns=""http://example.com/neon/litmus/"" />
              </d:prop>
              <d:status>HTTP/1.1 200 Found</d:status>
            </d:propstat>
              </d:response>
            </d:multistatus>"));
        }
示例#7
0
        void Process(PropfindRequest request, string relativePath, int currentDepth, MultiStatusResult multiStatus)
        {
            var fullPath = GetFullPath(relativePath);

            var response = new Response { Href = relativePath };
            multiStatus.Responses.Add(response);
            var isACollection = IsACollection(fullPath);

            if (request.HasGetContentLength)
            {
                if (isACollection)
                    response.NotFound.AddProperty("getcontentlength", null);
                else
                    response.Found.AddContentLength(new FileInfo(fullPath).Length);
            }

            if (request.HasGetLastModified) {
                if (isACollection)
                    response.Found.AddLastModified(Directory.GetLastWriteTimeUtc(fullPath));
                else
                    response.Found.AddLastModified(File.GetLastWriteTimeUtc(fullPath));
            }

            if (request.HasResourceType)
                response.Found.AddResourceType(isACollection);

            if (response.Found.Properties.Any())
                response.Found.Status = "HTTP/1.1 200 OK";

            var supportedProperties = new[] { "getcontentlength", "getlastmodified", "resourcetype" };
            foreach (var prop in request.DavProperties.Where(p => !supportedProperties.Contains(p)))
                response.NotFound.AddProperty(prop, null);

            response.NotFound.Properties.AddRange(request.NonDavProperties);

            if (response.NotFound.Properties.Any())
                response.NotFound.Status = "HTTP/1.1 404 Not Found";

            if (currentDepth == 0)
                return;

            if (isACollection)
            {
                //process files
                var files = Directory.GetFiles(fullPath);
                foreach (var file in files)
                    Process(request, JoinRelativePath(relativePath, Path.GetFileName(file)), 0, multiStatus);

                //process directories
                var dirs = Directory.GetDirectories(fullPath);
                foreach (var dir in dirs)
                    Process(request, JoinRelativePath(relativePath, Path.GetFileName(dir)) + "/", currentDepth - 1, multiStatus);
            }
        }