Esempio n. 1
0
 public OperationResult Post(Cat c)
 {
     return new OperationResult.Created
       {
     ResponseResource = c,
     RedirectLocation = typeof(Cat).CreateUri(new { name = c.Name })
       };
 }
        public void CanPostJsonUsingShorthand()
        {
            // Arrange
              Cat cat = new Cat { Name = "Prince" };
              Request request = Session.Bind(CatsTemplate);

              // Act
              Cat createdCat = request.AsJson().AcceptJson().Post<Cat>(cat).Created();

              // Assert
              Assert.IsNotNull(createdCat);
              Assert.AreEqual("Prince", createdCat.Name);
        }
        public void CanPostJson()
        {
            // Arrange
              Cat cat = new Cat { Name = "Prince", DateOfBirth = DateTime.Now.ToUniversalTime() };
              cat.DateOfBirth = cat.DateOfBirth.AddTicks(-(cat.DateOfBirth.Ticks % TimeSpan.TicksPerSecond));

              Request request = Session.Bind(CatsTemplate);

              // Act
              Cat createdCat = request.Accept("application/json").ContentType("application/json").Post<Cat>(cat).Created();

              // Assert
              Assert.IsNotNull(createdCat);
              Assert.AreEqual("Prince", createdCat.Name);
              Assert.AreEqual(cat.DateOfBirth, createdCat.DateOfBirth);
        }
        public void WhenPostingWithoutSpecifyingContentTypeItSelectsRandomCodec()
        {
            // Arrange
              Cat c1 = new Cat { Name = "Monster Baby" };
              Request catReq = Session.Bind(CatTemplate, new { name = "Fiona" });

              // Act + Assert
              using (var c2 = catReq.Post<Cat>(c1))
            Assert.AreEqual("Fiona", c2.Body.Name);
        }
        public void CanPostCatAsText()
        {
            // Arrange
              Cat c = new Cat { Name = "Monster Baby" };
              Request catReq = Session.Bind(CatTemplate, new { name = "Fiona" });

              // Act + Assert
              catReq.ContentType("text/plain").Post<Cat>(c).Dispose();
        }