public void Put_CalledWithRequest_ReturnsRequestReponse()
        {
            // Given
            var response = new RequestResponse {
                Item = new Request {
                    Subject = "blah blah"
                }
            };
            var request = new RequestRequest {
                Item = new Request {
                    Subject = "blah blah", Id = 123
                }
            };

            _client.Setup(b => b.Put <RequestResponse>(
                              It.IsAny <Uri>(),
                              request,
                              "application/json",
                              It.IsAny <string>(),
                              It.IsAny <string>()))
            .Returns(response);

            var resource = new RequestResource(_client.Object);

            // When
            var result = resource.Put(request);

            // Then
            Assert.That(result, Is.EqualTo(response));
        }
        public void PutAsync_RequestHasNoId_ThrowsException()
        {
            // Given
            var response = new RequestResponse {
                Item = new Request {
                    Subject = "blah blah"
                }
            };
            var request = new RequestRequest {
                Item = new Request {
                    Subject = "blah blah"
                }
            };

            _client.Setup(b => b.PutAsync <RequestResponse>(
                              It.IsAny <Uri>(),
                              request,
                              "application/json",
                              It.IsAny <string>(),
                              It.IsAny <string>()))
            .Returns(TaskHelper.CreateTaskFromResult(response));

            var requestResource = new RequestResource(_client.Object);

            // When, Then
            Assert.Throws <ArgumentException>(async() => await requestResource.PutAsync(request));
        }
        public void Put_RequestHasNoId_ThrowsException()
        {
            // Given
            var response = new RequestResponse {
                Item = new Request {
                    Subject = "blah blah"
                }
            };
            var request = new RequestRequest {
                Item = new Request {
                    Subject = "blah blah"
                }
            };

            _client.Setup(b => b.Put <RequestResponse>(
                              It.IsAny <Uri>(),
                              request,
                              "application/json",
                              It.IsAny <string>(),
                              It.IsAny <string>()))
            .Returns(response);

            var requestResource = new RequestResource(_client.Object);

            // When, Then
            Assert.Throws <ArgumentException>(() => requestResource.Put(request));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 访问权限判断
        /// </summary>
        /// <returns></returns>
        private bool HasAccess()
        {
            Ajax.Model.Poup pResult = SystemConst.MenuList.Find(delegate(Ajax.Model.Poup p)
            {
                return(p.Value == RequestResource.ToString("D"));
            });
            bool flag = false;

            if (pResult != null)
            {
                foreach (KeyValuePair <string, int> vote in MyTicket.CurrentTicket.VoteDic)
                {
                    if (vote.Key == pResult.Path)
                    {
                        List <int> hasVotes    = GetVoteArray(vote.Value);       //拥有的权限
                        int        requireVote = (int)VoteArray;                 //要求的权限
                        foreach (int v in hasVotes)
                        {
                            if (v == requireVote)
                            {
                                flag = true;
                                break;
                            }
                        }
                        break;
                    }
                }
            }
            return(flag);
        }
        public async void PostAsync_CalledWithRequest_ReturnsRequestReponse()
        {
            // Given
            var response = new RequestResponse {
                Item = new Request {
                    Subject = "blah blah"
                }
            };
            var request = new RequestRequest {
                Item = new Request {
                    Subject = "blah blah"
                }
            };

            _client.Setup(b => b.PostAsync <RequestResponse>(
                              It.IsAny <Uri>(),
                              request,
                              "application/json",
                              It.IsAny <string>(),
                              It.IsAny <string>()))
            .Returns(TaskHelper.CreateTaskFromResult(response));

            var requestResource = new RequestResource(_client.Object);

            // When
            var result = await requestResource.PostAsync(request);

            // Then
            Assert.That(result, Is.EqualTo(response));
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Set the request headers.
 /// </summary>
 /// <param name="headers">The header collection.</param>
 /// <param name="request">The request header.</param>
 public void ReadRequestHeaders(List <NameValue> headers, string request)
 {
     // If headers exist.
     if (headers != null)
     {
         // Get the request method, query and version
         RequestResource resource = Nequeo.Net.Http2.Utility.GetRequestResource(request);
         ReadRequestHeaders(headers, resource);
     }
 }
        public void Get_Called_CallsBuildUriWithFieldId()
        {
            // Given
            _client.Setup(b => b.BuildUri(It.IsAny<string>(), It.Is<string>(s => s.Contains("321")))).Returns(new Uri("http://search"));
            var resource = new RequestResource(_client.Object);

            // When
            resource.Get(321);

            // Then
            _client.Verify(c => c.BuildUri(It.Is<string>(s => s.Contains("321")), ""));
        }
        public async void GetAsync_Called_CallsBuildUriWithFieldId()
        {
            // Given
            _client.Setup(b => b.BuildUri(It.IsAny <string>(), It.Is <string>(s => s.Contains("321")))).Returns(new Uri("http://search"));
            var resource = new RequestResource(_client.Object);

            // When
            await resource.GetAsync(321);

            // Then
            _client.Verify(c => c.BuildUri(It.Is <string>(s => s.Contains("321")), ""));
        }
        public void Put_Called_BuildsUri()
        {
            // Given
            var request = new RequestRequest { Item = new Request { Subject = "blah blah", Id = 123 } };
            var resource = new RequestResource(_client.Object);

            // When
            resource.Put(request);

            // Then
            _client.Setup(b => b.BuildUri(It.IsAny<string>(), ""));
        }
        public void Get_CalledWithStatuses_CallsBuildUriWithStatuses()
        {
            // Given
            _client.Setup(b => b.BuildUri(It.IsAny<string>(), It.Is<string>(s => s.Contains("321")))).Returns(new Uri("http://search"));
            var resource = new RequestResource(_client.Object);
            var statuses = new List<TicketStatus> {TicketStatus.Hold, TicketStatus.Open};

            // When
            resource.Get(statuses);

            // Then
            _client.Verify(c => c.BuildUri(It.Is<string>(s => s.Contains("requests")), It.Is<string>(s => s.Contains("status=hold,open"))));
        }
        public void Get_Called_ReturnsRequestResponse()
        {
            // Given
            var response = new RequestResponse { Item = new Request { Id = 1 } };
            _client.Setup(b => b.Get<RequestResponse>(It.IsAny<Uri>())).Returns(response);
            var resource = new RequestResource(_client.Object);

            // When
            var result = resource.Get(321);

            // Then
            Assert.That(result, Is.EqualTo(response));
        }
Ejemplo n.º 12
0
        public IHttpActionResult PostRequest(RequestResource request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var requestService = new RequestService();

            if (!requestService.CreateRequest(request))
            {
                return(InternalServerError());
            }

            return(Ok());
        }
        public void Get_CalledWithStatuses_CallsBuildUriWithStatuses()
        {
            // Given
            _client.Setup(b => b.BuildUri(It.IsAny <string>(), It.Is <string>(s => s.Contains("321")))).Returns(new Uri("http://search"));
            var resource = new RequestResource(_client.Object);
            var statuses = new List <TicketStatus> {
                TicketStatus.Hold, TicketStatus.Open
            };

            // When
            resource.Get(statuses);

            // Then
            _client.Verify(c => c.BuildUri(It.Is <string>(s => s.Contains("requests")), It.Is <string>(s => s.Contains("status=hold,open"))));
        }
        public void UploadRequestToResource(ValidationRequest requestModel, BlobModel blobModel)
        {
            //insert to file location storage
            //get id of the file location storage
            int fileID = InsertBlobToFileLocationStorage(blobModel, "Requirements");

            //upload resource
            RequestResource resource = new RequestResource()
            {
                RequestID = requestModel.RequestID,
                FileID    = fileID
            };

            dbObject.RequestResources.Add(resource);
            dbObject.SaveChanges();
        }
        public async void PostAsync_Called_BuildsUri()
        {
            // Given
            var request = new RequestRequest {
                Item = new Request {
                    Subject = "blah blah"
                }
            };
            var requestResource = new RequestResource(_client.Object);

            // When
            await requestResource.PostAsync(request);

            // Then
            _client.Setup(b => b.BuildUri(It.IsAny <string>(), ""));
        }
        public void Put_Called_BuildsUri()
        {
            // Given
            var request = new RequestRequest {
                Item = new Request {
                    Subject = "blah blah", Id = 123
                }
            };
            var resource = new RequestResource(_client.Object);

            // When
            resource.Put(request);

            // Then
            _client.Setup(b => b.BuildUri(It.IsAny <string>(), ""));
        }
        public async void PutAsync_Called_BuildsUri()
        {
            // Given
            var client  = new Mock <IRestClient>();
            var request = new RequestRequest {
                Item = new Request {
                    Subject = "blah blah", Id = 123
                }
            };
            var resource = new RequestResource(client.Object);

            // When
            await resource.PutAsync(request);

            // Then
            client.Verify(b => b.BuildUri(It.IsAny <string>(), ""));
        }
Ejemplo n.º 18
0
 public ZendeskClient(Uri baseUri, ZendeskDefaultConfiguration configuration, ISerializer serializer = null, IHttpChannel httpChannel = null, ILogAdapter logger = null)
     :base(baseUri, configuration, serializer, httpChannel, logger)
 {
     Tickets = new TicketResource(this);
     TicketComments = new TicketCommentResource(this);
     RequestComments = new RequestCommentResource(this);
     Organizations = new OrganizationResource(this);
     Search = new SearchResource(this);
     Groups = new GroupsResource(this);
     AssignableGroups = new AssignableGroupResource(this);
     Users = new UserResource(this);
     UserIdentities = new UserIdentityResource(this);
     Upload = new UploadResource(this);
     OrganizationMemberships = new OrganizationMembershipResource(this);
     Request = new RequestResource(this);
     SatisfactionRating = new SatisfactionRatingResource(this);
 }
Ejemplo n.º 19
0
 public ZendeskClient(Uri baseUri, ZendeskDefaultConfiguration configuration, ISerializer serializer = null, IHttpChannel httpChannel = null, ILogAdapter logger = null)
     : base(baseUri, configuration, serializer, httpChannel, logger)
 {
     Tickets                 = new TicketResource(this);
     TicketComments          = new TicketCommentResource(this);
     RequestComments         = new RequestCommentResource(this);
     Organizations           = new OrganizationResource(this);
     Search                  = new SearchResource(this);
     Groups                  = new GroupsResource(this);
     AssignableGroups        = new AssignableGroupResource(this);
     Users                   = new UserResource(this);
     UserIdentities          = new UserIdentityResource(this);
     Upload                  = new UploadResource(this);
     OrganizationMemberships = new OrganizationMembershipResource(this);
     Request                 = new RequestResource(this);
     SatisfactionRating      = new SatisfactionRatingResource(this);
 }
        public async void DeleteAsync_Called_CallsDeleteOnClient()
        {
            // Given
            var response = new RequestResponse {
                Item = new Request {
                    Id = 1
                }
            };

            _client.Setup(b => b.GetAsync <RequestResponse>(It.IsAny <Uri>())).Returns(TaskHelper.CreateTaskFromResult(response));
            var requestResource = new RequestResource(_client.Object);

            // When
            await requestResource.DeleteAsync(321);

            // Then
            _client.Verify(c => c.DeleteAsync(It.IsAny <Uri>()));
        }
        public async void GetAsync_Called_ReturnsRequestResponse()
        {
            // Given
            var response = new RequestResponse {
                Item = new Request {
                    Id = 1
                }
            };

            _client.Setup(b => b.GetAsync <RequestResponse>(It.IsAny <Uri>())).Returns(TaskHelper.CreateTaskFromResult(response));
            var resource = new RequestResource(_client.Object);

            // When
            var result = await resource.GetAsync(321);

            // Then
            Assert.That(result, Is.EqualTo(response));
        }
        public void Delete_Called_CallsDeleteOnClient()
        {
            // Given
            var response = new RequestResponse {
                Item = new Request {
                    Id = 1
                }
            };

            _client.Setup(b => b.Get <RequestResponse>(It.IsAny <Uri>())).Returns(response);
            var requestResource = new RequestResource(_client.Object);

            // When
            requestResource.Delete(321);

            // Then
            _client.Verify(c => c.Delete(It.IsAny <Uri>()));
        }
        public void Get_Called_ReturnsRequestResponse()
        {
            // Given
            var response = new RequestResponse {
                Item = new Request {
                    Id = 1
                }
            };

            _client.Setup(b => b.Get <RequestResponse>(It.IsAny <Uri>())).Returns(response);
            var resource = new RequestResource(_client.Object);

            // When
            var result = resource.Get(321);

            // Then
            Assert.That(result, Is.EqualTo(response));
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Get a new resources with the supplied request.
        /// </summary>
        /// <param name="request">The request header.</param>
        /// <returns>The request resource.</returns>
        public static RequestResource GetRequestResource(string request)
        {
            RequestResource resource = new RequestResource();

            resource.ProtocolVersion = "HTTP/2";

            // Split the request
            string[] requestItems = request.Split(new string[] { ":" }, StringSplitOptions.RemoveEmptyEntries);

            // For each resources.
            foreach (string item in requestItems)
            {
                // Get the name value pair.
                string[] resourceNameValue = item.Split(new string[] { "=" }, StringSplitOptions.None);

                // Get the method.
                if (resourceNameValue[0].Trim().ToLower().Equals("method"))
                {
                    resource.Method = resourceNameValue[1].Trim();
                }

                // Get the scheme.
                if (resourceNameValue[0].Trim().ToLower().Equals("scheme"))
                {
                    resource.Scheme = resourceNameValue[1].Trim();
                }

                // Get the path.
                if (resourceNameValue[0].Trim().ToLower().Equals("path"))
                {
                    resource.Path = resourceNameValue[1].Trim();
                }

                // Get the authority.
                if (resourceNameValue[0].Trim().ToLower().Equals("authority"))
                {
                    resource.Authority = resourceNameValue[1].Trim();
                }
            }

            // Return the resource.
            return(resource);
        }
Ejemplo n.º 25
0
        public void ReturnStatusCodeResultWithMissingData()
        {
            var guid = Guid.Parse("321caff1-f442-4dbb-8c5b-3ed528cde3fd");
            var persistenceStoreMock = new Mock <IReadOnlyPersistenceStore>();

            persistenceStoreMock.Setup(ps => ps.GetByRequestId(guid)).Returns <GlimpseRequest>(null);
            var contextMock = new Mock <IResourceContext>();

            contextMock.Setup(c => c.Parameters).Returns(new Dictionary <string, string> {
                { ResourceParameter.RequestId.Name, guid.ToString() }
            });
            contextMock.Setup(c => c.PersistenceStore).Returns(persistenceStoreMock.Object);

            var resource = new RequestResource();

            var result = resource.Execute(contextMock.Object);

            Assert.NotNull(result as StatusCodeResourceResult);
        }
Ejemplo n.º 26
0
        public void ReturnStatusCodeResultWithImproperRequestId()
        {
            var guid                 = Guid.Parse("321caff1-f442-4dbb-8c5b-3ed528cde3fd");
            var metadataMock         = new Mock <IRequestMetadata>();
            var persistenceStoreMock = new Mock <IReadOnlyPersistenceStore>();

            persistenceStoreMock.Setup(ps => ps.GetByRequestId(guid)).Returns(new GlimpseRequest(guid, metadataMock.Object, new Dictionary <string, TabResult>(), TimeSpan.FromMilliseconds(0)));
            var contextMock = new Mock <IResourceContext>();

            contextMock.Setup(c => c.Parameters).Returns(new Dictionary <string, string> {
                { ResourceParameter.RequestId.Name, "Not a real guid" }
            });
            contextMock.Setup(c => c.PersistenceStore).Returns(persistenceStoreMock.Object);

            var resource = new RequestResource();

            var result = resource.Execute(contextMock.Object);

            Assert.NotNull(result as StatusCodeResourceResult);
        }
Ejemplo n.º 27
0
        public bool CreateRequest(RequestResource request)
        {
            var entity =
                new Request()
            {
                Date    = request.Date,
                Offer   = request.Offer,
                VenueId = request.VenueId
            };

            using (var context = new OneOffEntities())
            {
                Venue venue = context
                              .Venues
                              .SingleOrDefault(v => v.VenueId == entity.VenueId);

                venue.Requests.Add(entity);
                context.Requests.Add(entity);
                return(context.SaveChanges() == 1);
            }
        }
Ejemplo n.º 28
0
        /*
         * Deletes the selected uploaded requiremensts from the database and azure blob storage.
         * */
        public ActionResult DeleteRequestBlob(string fileName, int?fileID)
        {
            try
            {
                if (User.IsInRole("Student"))
                {
                    if (fileName == null || fileID == null)
                    {
                        return(RedirectToAction("RequestStatus"));
                    }
                    else
                    {
                        if (studentActions.DeleteRequestBlob(fileName))
                        {
                            RequestResource requestResource = studentActions.GetRequestResourceByFileID((int)fileID);
                            studentActions.DeleteFromRequestResource(requestResource);

                            FileLocationStorage fileLocationStorage = studentActions.GetFileLocationStorageByFileID((int)fileID);
                            studentActions.DeleteFromFileLocationStorage(fileLocationStorage);

                            return(RedirectToAction("EditRequest", new { requestID = requestResource.RequestID }));
                        }
                        TempData["errorMessage"] = "There was an error in the server. Please try again.";
                        return(RedirectToAction("RequestStatus"));
                    }
                }
                else
                {
                    TempData["errorMessage"] = "Sorry you do not have access.";
                    return(RedirectToAction("Announcement", "WebsiteContent"));
                }
            }
            catch (Exception e)
            {
                TempData["errorMessage"] = "There was an error in deletings. Please try again, thank you!";
                return(RedirectToAction("RequestStatus"));
            }
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Get a new resources with the supplied request.
        /// </summary>
        /// <param name="headers">The header list to search in.</param>
        /// <returns>The request resource.</returns>
        public static RequestResource GetRequestResource(List <NameValue> headers)
        {
            RequestResource resource = new RequestResource();

            resource.ProtocolVersion = "HTTP/2";

            // For each header.
            foreach (NameValue item in headers)
            {
                // Get the method.
                if ((item.Name.Trim().ToLower().Equals("method")) || (item.Name.Trim().ToLower().Equals(":method")))
                {
                    resource.Method = item.Value.Trim();
                }

                // Get the scheme.
                if ((item.Name.Trim().ToLower().Equals("scheme")) || (item.Name.Trim().ToLower().Equals(":scheme")))
                {
                    resource.Scheme = item.Value.Trim();
                }

                // Get the path.
                if ((item.Name.Trim().ToLower().Equals("path")) || (item.Name.Trim().ToLower().Equals(":path")))
                {
                    resource.Path = item.Value.Trim();
                }

                // Get the authority.
                if ((item.Name.Trim().ToLower().Equals("authority")) || (item.Name.Trim().ToLower().Equals(":authority")))
                {
                    resource.Authority = item.Value.Trim();
                }
            }

            // Return the resource.
            return(resource);
        }
        public async void GetAsync_Called_ReturnsRequestResponse()
        {
            // Given
            var client   = new Mock <IRestClient>();
            var response = new RequestResponse {
                Item = new Request {
                    Id = 1
                }
            };

            client.Setup(b => b.GetAsync <RequestResponse>(
                             It.IsAny <Uri>(),
                             It.IsAny <string>(),
                             It.IsAny <string>()))
            .Returns(TaskHelper.CreateTaskFromResult(response));

            var resource = new RequestResource(client.Object);

            // When
            var result = await resource.GetAsync(321);

            // Then
            Assert.Equal(result, response);
        }
Ejemplo n.º 31
0
        public void ThrowExceptionWithNullParameters()
        {
            var resource = new RequestResource();

            Assert.Throws <ArgumentNullException>(() => resource.Execute(null));
        }
Ejemplo n.º 32
0
        public void ReturnThreeParameterKeys()
        {
            var resource = new RequestResource();

            Assert.Equal(3, resource.Parameters.Count());
        }
Ejemplo n.º 33
0
        public void ProvideProperName()
        {
            var resource = new RequestResource();

            Assert.Equal("glimpse_request", resource.Name);
        }
        public void Put_CalledWithRequest_ReturnsRequestReponse()
        {
            // Given
            var response = new RequestResponse { Item = new Request { Subject = "blah blah" } };
            var request = new RequestRequest { Item = new Request { Subject = "blah blah", Id = 123 } };
            _client.Setup(b => b.Put<RequestResponse>(It.IsAny<Uri>(), request, "application/json")).Returns(response);
            var resource = new RequestResource(_client.Object);

            // When
            var result = resource.Put(request);

            // Then
            Assert.That(result, Is.EqualTo(response));
        }
        public void Put_RequestHasNoId_ThrowsException()
        {
            // Given
            var response = new RequestResponse { Item = new Request { Subject = "blah blah" } };
            var request = new RequestRequest { Item = new Request { Subject = "blah blah" } };
            _client.Setup(b => b.Put<RequestResponse>(It.IsAny<Uri>(), request, "application/json")).Returns(response);
            var requestResource = new RequestResource(_client.Object);

            // When, Then
            Assert.Throws<ArgumentException>(() => requestResource.Put(request));
        }
Ejemplo n.º 36
0
        /// <summary>
        /// Set the request headers.
        /// </summary>
        /// <param name="headers">The header collection.</param>
        /// <param name="request">The request header.</param>
        public void ReadRequestHeaders(List <NameValue> headers, RequestResource request)
        {
            // If headers exist.
            if (headers != null)
            {
                // Create the new header collection.
                Headers = new NameValueCollection();

                // For each header found.
                foreach (NameValue item in headers)
                {
                    // Assign the header collection.
                    Headers.Add(item.Name, item.Value);
                }

                // If top level header information exists.
                if (request != null)
                {
                    // Assign the headers.
                    Method          = (String.IsNullOrEmpty(request.Method) ? Method : request.Method);
                    ProtocolVersion = (String.IsNullOrEmpty(request.ProtocolVersion) ? ProtocolVersion : request.ProtocolVersion);
                    Path            = (String.IsNullOrEmpty(request.Path) ? Path : request.Path);
                    Scheme          = (String.IsNullOrEmpty(request.Scheme) ? Scheme : request.Scheme);
                    Authority       = (String.IsNullOrEmpty(request.Authority) ? Authority : request.Authority);
                }

                try
                {
                    // Get the Host
                    if (!String.IsNullOrEmpty(Headers["host"]))
                    {
                        // Get the query details.
                        Uri uri = new Uri(Scheme + "://" + Headers["host"] + "/" + Path.TrimStart('/'));
                        Url = uri;
                    }
                }
                catch { }

                // Get the Host
                if (!String.IsNullOrEmpty(Headers["host"]))
                {
                    // Get the content length.
                    Host = Headers["host"].Trim();
                }

                // Get the content length
                if (!String.IsNullOrEmpty(Headers["content-length"]))
                {
                    // Get the content length.
                    ContentLength = Int64.Parse(Headers["content-length"].Trim());
                }

                // Get the list of languages
                if (!String.IsNullOrEmpty(Headers["accept-language"]))
                {
                    // Get the languages.
                    AcceptLanguages = Headers["accept-language"].Split(new string[] { "," }, StringSplitOptions.None).Trim();
                }

                // Get the list of encoding
                if (!String.IsNullOrEmpty(Headers["accept-encoding"]))
                {
                    // Get the encoding.
                    AcceptEncoding = Headers["accept-encoding"].Split(new string[] { "," }, StringSplitOptions.None).Trim();
                }

                // Get the content type
                if (!String.IsNullOrEmpty(Headers["content-type"]))
                {
                    // Get the content type.
                    ContentType = Headers["content-type"].Trim();
                }

                // Get the connection
                if (!String.IsNullOrEmpty(Headers["connection"]))
                {
                    // Get keep-alive indicator.
                    if (Headers["connection"].Trim().ToLower().Contains("keep-alive"))
                    {
                        KeepAlive = true;
                    }
                    else
                    {
                        KeepAlive = false;
                    }

                    // Get the upgrade indicator if it exists.
                    string connUpgrade = Headers["connection"];
                    UpgradeRequest = (connUpgrade.Trim().ToLower().Contains("upgrade") ? true : false);
                }

                // Get the accept
                if (!String.IsNullOrEmpty(Headers["accept"]))
                {
                    // Get the accept.
                    AcceptTypes = Headers["accept"].Split(new string[] { "," }, StringSplitOptions.None).Trim();
                }

                // Get the upgrade
                if (!String.IsNullOrEmpty(Headers["upgrade"]))
                {
                    // Get the upgrade.
                    Upgrade = Headers["upgrade"].Trim();
                }

                // Get the authorization
                if (!String.IsNullOrEmpty(Headers["authorization"]))
                {
                    // Get the authorization.
                    string   authorization  = Headers["authorization"].Trim();
                    string[] authCredential = authorization.Split(new string[] { " " }, StringSplitOptions.None).Trim();

                    // If authorization data exists.
                    if (authCredential.Length > 0)
                    {
                        // Assign the credential.
                        AuthorizationType = authCredential[0].Trim();

                        // If authorization credential data exists.
                        if (authCredential.Length > 1)
                        {
                            byte[]   credentialBytes  = Convert.FromBase64String(authCredential[1].Trim());
                            string   credentialString = Encoding.Default.GetString(credentialBytes);
                            string[] credentialData   = credentialString.Split(new string[] { ":" }, StringSplitOptions.None).Trim();

                            // If credentails exists.
                            if (credentialData.Length > 1)
                            {
                                // Create the credentials
                                NetworkCredential credentials = new NetworkCredential(credentialData[0].Trim(), credentialData[1].Trim());
                                Credentials = credentials;
                            }
                        }
                    }
                }

                // Get the user agent
                if (!String.IsNullOrEmpty(Headers["user-agent"]))
                {
                    // Get the user agent.
                    UserAgent = Headers["user-agent"].Trim();
                }

                // Get the cookie
                if (!String.IsNullOrEmpty(Headers["cookie"]))
                {
                    // Create a new collection.
                    CookieCollection CookieCollection = new CookieCollection();

                    // Get all cookies.
                    string[] cookies = Headers["cookie"].Split(new string[] { ";" }, StringSplitOptions.None).Trim();
                    for (int i = 0; i < cookies.Length; i++)
                    {
                        // Make sure a cookie exists.
                        if (!String.IsNullOrEmpty(cookies[i].Trim()))
                        {
                            // Split the name and value header pair.
                            string[] nameValue = cookies[i].Split(new string[] { "=" }, StringSplitOptions.None).Trim();

                            // Create a new cookie and add to the collection.
                            Cookie cookie = new Cookie(nameValue[0].Trim(), nameValue[1].Trim());
                            CookieCollection.Add(cookie);
                        }
                    }

                    // Assign the collection.
                    Cookies = CookieCollection;
                }

                // Make sure a URI exists.
                if (Url != null)
                {
                    // Make sure a query exists before processing.
                    if (!String.IsNullOrEmpty(Url.Query))
                    {
                        string[] queryCol = Url.Query.TrimStart(new char[] { '?' }).Split(new string[] { "&" }, StringSplitOptions.None);

                        // Create a header name value collection.
                        NameValueCollection queries = new NameValueCollection();

                        // For each query
                        for (int i = 0; i < queryCol.Length; i++)
                        {
                            // Split the name and value header pair.
                            string[] nameValue = queryCol[i].Split(new string[] { "=" }, StringSplitOptions.None);
                            queries.Add(nameValue[0].Trim(), nameValue[1].Trim());
                        }

                        // Assign the queries.
                        Query = queries;
                    }
                }

                // Get the referer
                if (!String.IsNullOrEmpty(Headers["referer"]))
                {
                    try
                    {
                        // Get the referer.
                        UrlReferrer = new Uri(Headers["referer"].Trim());
                    }
                    catch { }
                }
            }
        }
 internal void DeleteFromRequestResource(RequestResource requestResource)
 {
     dbObject.RequestResources.Remove(requestResource);
     dbObject.SaveChanges();
 }
        public void Delete_Called_CallsDeleteOnClient()
        {
            // Given
            var response = new RequestResponse { Item = new Request { Id = 1 } };
            _client.Setup(b => b.Get<RequestResponse>(It.IsAny<Uri>())).Returns(response);
            var requestResource = new RequestResource(_client.Object);

            // When
            requestResource.Delete(321);

            // Then
            _client.Verify(c => c.Delete(It.IsAny<Uri>()));
        }