Esempio n. 1
0
 private Uri CreateGetBasketUri(BasketResource basketResource)
 {
     return _uriResolver.CreateUriFor(
         _communicationContext.ApplicationBaseUri,
         basketResource.GetType(),
         null,
         new NameValueCollection { { "id", basketResource.Id.ToString() } }
         );
 }
 private static XDocument Serialise(BasketResource basketResource)
 {
     var xmlSerialiser = new XmlSerializer(typeof(BasketResource));
     using (var sw = new StringWriter())
     {
         xmlSerialiser.Serialize(sw, basketResource);
         var serialisedBasket = sw.ToString();
         return XDocument.Parse(serialisedBasket);
     }
 }
Esempio n. 3
0
 public OperationResult Create()
 {
     var basketResource = new BasketResource { Id = 1 };
     var getBasketUri = CreateGetBasketUri(basketResource);
     var selfLink = CreateSelfLink(getBasketUri);
     basketResource.SelfLink = selfLink;
     return new OperationResult.Created
             {
                 RedirectLocation = getBasketUri,
                 ResponseResource = basketResource
             };
 }
        public void Basket_element_has_a_self_link_element()
        {
            var selfLink = new LinkResource { Relation = "self", Uri = "doody"};
            var basket = new BasketResource { SelfLink = selfLink };

            var basketXml = Serialise(basket);

            var selfLinkElement = basketXml.Root.Elements("link").Where(l => l.Attribute("rel").Value == "self").Single();
            Assert.That(selfLinkElement, Is.Not.Null);

            var selfLinkUriAttribute = selfLinkElement.Attribute("uri").Value;
            Assert.That(selfLinkUriAttribute, Is.EqualTo(selfLink.Uri));
        }