示例#1
0
        public void WhenCreatedHasNoBodyItFollowsLocation()
        {
            // Arrange
              Dossier dossier = new Dossier
              {
            Title = "Do not return body" // magic string!
              };

              Request request = Session.Request(DossiersUrl);

              // Act
              using (Response<Dossier> response = request.Post<Dossier>(dossier))
              {
            // Assert that server does as expected
            Uri createdDossierLocation = response.CreatedLocation;
            Dossier createdDossier = response.Body;

            Assert.IsNotNull(createdDossierLocation);
            Assert.Null(createdDossier);

            // Assert that client does as expected
            createdDossier = response.Created();
            Assert.IsNotNull(createdDossier);
              }
        }
示例#2
0
        public void CanGetCreatedLocationAndBody_Async()
        {
            // Arrange
              Dossier dossier = new Dossier
              {
            Title = "A new dossier"
              };

              Request request = Session.Request(DossiersUrl);

              // Act
              TestAsync(wh =>
            {
              request.Async().Post<Dossier>(dossier, response =>
            {
              // Assert
              Uri createdDossierLocation = response.CreatedLocation;
              Dossier createdDossier = response.Body;

              Assert.IsNotNull(createdDossierLocation);
              Assert.IsNotNull(createdDossier);
              Assert.AreEqual("A new dossier", createdDossier.Title);
              Assert.AreEqual(999, createdDossier.Id);
              wh.Set();
            });
            });
        }
 public OperationResult Put(Dossier dossier)
 {
     return new OperationResult.Created
       {
     ResponseResource = dossier,
     RedirectLocation = dossier.CreateUri()
       };
 }
        public OperationResult Post(Dossier dossier)
        {
            Dossier d = new Dossier
              {
            Id = 999,
            Title = dossier.Title
              };

              if (dossier.Title == "Do not return body")
            d = null;

              return new OperationResult.Created
              {
            ResponseResource = d,
            RedirectLocation = typeof(Dossier).CreateUri(new { id = 999 })
              };
        }
示例#5
0
        public void CanGetCreatedLocationAndBody()
        {
            // Arrange
              Dossier dossier = new Dossier
              {
            Title = "A new dossier"
              };

              Request request = Session.Request(DossiersUrl);

              // Act
              using (Response<Dossier> response = request.Post<Dossier>(dossier))
              {
            // Assert
            Uri createdDossierLocation = response.CreatedLocation;
            Dossier createdDossier = response.Body;

            Assert.IsNotNull(createdDossierLocation);
            Assert.IsNotNull(createdDossier);
            Assert.AreEqual("A new dossier", createdDossier.Title);
            Assert.AreEqual(999, createdDossier.Id);
              }
        }
示例#6
0
 public OperationResult Put(string method, Dossier dossier)
 {
     if (method != "PUT")
     throw new InvalidOperationException(string.Format("Unexpected method (should have been {0}, was PUT'.", method));
       return Put(dossier);
 }