public void SerializeToNameValueWithDefaults()
        {
            string expected = "Id=0&UID=00000000-0000-0000-0000-000000000000&Email=&NoOfSiblings=0&DOB=1%2F1%2F0001%2012%3A00%3A00%20AM&IsActive=False&Salary=0";

            RestObjectRequestBody<Person> target = new RestObjectRequestBody<Person>(new Person());

            string actual = target.ToString(ContentType.ApplicationX_WWW_Form_UrlEncoded);

            Assert.Equal(expected, actual);
        }
        public void SerializeToNameValueWithValues()
        {
            string expected = "Id=1&UID=e4d2c5c2-2e7a-4117-90c2-28214879d3b7&Email=abc%40abc.com&NoOfSiblings=2&DOB=1%2F1%2F2010%2012%3A00%3A00%20AM&IsActive=True&Salary=100";

            RestObjectRequestBody<Person> target = new RestObjectRequestBody<Person>(new Person { Id = 1, UID = new Guid("E4D2C5C2-2E7A-4117-90C2-28214879D3B7"), Email = "*****@*****.**", NoOfSiblings = 2, DOB = new DateTime(2010, 1, 1), IsActive = true, Salary = 100 });

            string actual = target.ToString(ContentType.ApplicationX_WWW_Form_UrlEncoded);

            Assert.Equal(expected, actual);
        }
        public void SerializeToJSONWithDefaults()
        {
            string expected = "{\"Id\":0,\"UID\":\"00000000-0000-0000-0000-000000000000\",\"Email\":null,\"NoOfSiblings\":0,\"DOB\":\"0001-01-01T00:00:00Z\",\"IsActive\":false,\"Salary\":0}";

            RestObjectRequestBody<Person> target = new RestObjectRequestBody<Person>(new Person());

            string actual = target.ToString(ContentType.ApplicationJson);

            Assert.Equal(expected, actual);
        }
        public void SerializeToJSONWithValues()
        {
            string expected = "{\"Id\":1,\"UID\":\"e4d2c5c2-2e7a-4117-90c2-28214879d3b7\",\"Email\":\"[email protected]\",\"NoOfSiblings\":2,\"DOB\":\"2010-01-01T00:00:00Z\",\"IsActive\":true,\"Salary\":100}";

            RestObjectRequestBody<Person> target = new RestObjectRequestBody<Person>(new Person { Id = 1, UID = new Guid("E4D2C5C2-2E7A-4117-90C2-28214879D3B7"), Email = "*****@*****.**", NoOfSiblings = 2, DOB = new DateTime(2010, 1, 1, 0, 0, 0, DateTimeKind.Utc), IsActive = true, Salary = 100 });

            string actual = target.ToString(ContentType.ApplicationJson);

            Assert.Equal(expected, actual);
        }
Ejemplo n.º 5
0
        public void SerializeToNameValueWithDefaults()
        {
            string expected = "Id=0&UID=00000000-0000-0000-0000-000000000000&Email=&NoOfSiblings=0&DOB=1%2F1%2F0001%2012%3A00%3A00%20AM&IsActive=False&Salary=0";

            RestObjectRequestBody <Person> target = new RestObjectRequestBody <Person>(new Person());

            string actual = target.ToString(ContentType.ApplicationX_WWW_Form_UrlEncoded);

            Assert.Equal(expected, actual);
        }
Ejemplo n.º 6
0
        public void SerializeToJSONWithDefaults()
        {
            string expected = "{\"Id\":0,\"UID\":\"00000000-0000-0000-0000-000000000000\",\"Email\":null,\"NoOfSiblings\":0,\"DOB\":\"0001-01-01T00:00:00Z\",\"IsActive\":false,\"Salary\":0}";

            RestObjectRequestBody <Person> target = new RestObjectRequestBody <Person>(new Person());

            string actual = target.ToString(ContentType.ApplicationJson);

            Assert.Equal(expected, actual);
        }
Ejemplo n.º 7
0
        public void SerializeToNameValueWithValues()
        {
            string expected = "Id=1&UID=e4d2c5c2-2e7a-4117-90c2-28214879d3b7&Email=abc%40abc.com&NoOfSiblings=2&DOB=1%2F1%2F2010%2012%3A00%3A00%20AM&IsActive=True&Salary=100";

            RestObjectRequestBody <Person> target = new RestObjectRequestBody <Person>(new Person {
                Id = 1, UID = new Guid("E4D2C5C2-2E7A-4117-90C2-28214879D3B7"), Email = "*****@*****.**", NoOfSiblings = 2, DOB = new DateTime(2010, 1, 1), IsActive = true, Salary = 100
            });

            string actual = target.ToString(ContentType.ApplicationX_WWW_Form_UrlEncoded);

            Assert.Equal(expected, actual);
        }
Ejemplo n.º 8
0
        public void SerializeToJSONWithValues()
        {
            string expected = "{\"Id\":1,\"UID\":\"e4d2c5c2-2e7a-4117-90c2-28214879d3b7\",\"Email\":\"[email protected]\",\"NoOfSiblings\":2,\"DOB\":\"2010-01-01T00:00:00Z\",\"IsActive\":true,\"Salary\":100}";

            RestObjectRequestBody <Person> target = new RestObjectRequestBody <Person>(new Person {
                Id = 1, UID = new Guid("E4D2C5C2-2E7A-4117-90C2-28214879D3B7"), Email = "*****@*****.**", NoOfSiblings = 2, DOB = new DateTime(2010, 1, 1, 0, 0, 0, DateTimeKind.Utc), IsActive = true, Salary = 100
            });

            string actual = target.ToString(ContentType.ApplicationJson);

            Assert.Equal(expected, actual);
        }
Ejemplo n.º 9
0
        public void Patch_overload1()
        {
            //Arrange
            RestInvoker target = new RestInvoker(_MyUri.OriginalString);
            StubModule.HaltProcessing = TimeSpan.FromSeconds(0);
            StubModule.PatchPerson = false;
            StubModule.TestHarness = new List<Person> { new Person { Id = 1, Email = "*****@*****.**" } };

            var uri = new RestUri(_MyUri, "/Person/{id}").SetParameter("id", "1");
            var contentType = ContentType.ApplicationX_WWW_Form_UrlEncoded;
            var body = new RestObjectRequestBody<Person>(new Person { Id = 1, Email = "*****@*****.**" });

            //Act
            using (RestResponse actual = target.Patch(uri, body, contentType))
            {
                //Assert
                Assert.True(StubModule.PatchPerson);
                Assert.NotNull(actual);
                Assert.True(actual.IsSuccessStatusCode);

                var person = StubModule.TestHarness.Where(x => x.Id == 1).FirstOrDefault();
                Assert.NotNull(person);
                Assert.Equal("*****@*****.**", person.Email);
            }
        }
Ejemplo n.º 10
0
        public void PatchAsync_overload5()
        {
            //Arrange
            RestInvoker target = new RestInvoker(_MyUri.OriginalString);
            StubModule.HaltProcessing = TimeSpan.FromSeconds(0);
            StubModule.PatchPerson = false;
            StubModule.TestHarness = new List<Person> { new Person { Id = 1, Email = "*****@*****.**" } };

            var body = new RestObjectRequestBody<Person>(new Person { Id = 1, Email = "*****@*****.**" });

            //Act
            target.PatchAsync("/Person/{id}", new { id = 1 }, body, ContentType.ApplicationX_WWW_Form_UrlEncoded).ContinueWith(task =>
            {
                using (RestResponse actual = task.Result)
                {
                    //Assert
                    Assert.True(StubModule.PatchPerson);
                    Assert.NotNull(actual);
                    Assert.True(actual.IsSuccessStatusCode);

                    var person = StubModule.TestHarness.Where(x => x.Id == 1).FirstOrDefault();
                    Assert.NotNull(person);
                    Assert.Equal("*****@*****.**", person.Email);
                }
            }).Wait();
        }
Ejemplo n.º 11
0
        public void Put_overload4()
        {
            //Arrange
            RestInvoker target = new RestInvoker(_MyUri.OriginalString);
            StubModule.HaltProcessing = TimeSpan.FromSeconds(0);
            StubModule.PutPerson = false;
            StubModule.TestHarness = new List<Person> { new Person { Id = 1, Email = "*****@*****.**" } };

            var body = new RestObjectRequestBody<Person>(new Person { Id = 1, Email = "*****@*****.**" });

            //Act
            using (RestResponse actual = target.Put("/Person/1", body))
            {
                //Assert
                Assert.True(StubModule.PutPerson);
                Assert.NotNull(actual);
                Assert.True(actual.IsSuccessStatusCode);

                var person = StubModule.TestHarness.Where(x => x.Id == 1).FirstOrDefault();
                Assert.NotNull(person);
                Assert.Equal("*****@*****.**", person.Email);
            }
        }
Ejemplo n.º 12
0
        public void PutAsync_overload2()
        {
            //Arrange
            RestInvoker target = new RestInvoker(_MyUri.OriginalString);
            StubModule.HaltProcessing = TimeSpan.FromSeconds(0);
            StubModule.PutPerson = false;
            StubModule.TestHarness = new List<Person> { new Person { Id = 1, Email = "*****@*****.**" } };

            var uri = new RestUri(_MyUri, "/Person/{id}").SetParameter("id", "1");
            var body = new RestObjectRequestBody<Person>(new Person { Id = 1, Email = "*****@*****.**" });

            //Act
            target.PutAsync(uri, body).ContinueWith(task =>
            {
                using (RestResponse actual = task.Result)
                {
                    //Assert
                    Assert.True(StubModule.PutPerson);
                    Assert.NotNull(actual);
                    Assert.True(actual.IsSuccessStatusCode);

                    var person = StubModule.TestHarness.Where(x => x.Id == 1).FirstOrDefault();
                    Assert.NotNull(person);
                    Assert.Equal("*****@*****.**", person.Email);
                }
            }).Wait();
        }
Ejemplo n.º 13
0
        public void Post_overload5()
        {
            //Arrange
            RestInvoker target = new RestInvoker(_MyUri.OriginalString);
            StubModule.HaltProcessing = TimeSpan.FromSeconds(0);
            StubModule.PostPerson = false;
            StubModule.TestHarness = new List<Person> { new Person { Id = 1, Email = "*****@*****.**" } };

            var body = new RestObjectRequestBody<Person>(new Person { Id = 2, Email = "*****@*****.**" });

            //Act
            using (RestResponse actual = target.Post("/Person", new { mode = "test" }, body, ContentType.ApplicationX_WWW_Form_UrlEncoded))
            {
                //Assert
                Assert.Equal("?mode=test", actual.ResponseUri.Query);
                Assert.True(StubModule.PostPerson);
                Assert.NotNull(actual);
                Assert.True(actual.IsSuccessStatusCode);
                var person = StubModule.TestHarness.Where(x => x.Id == 2).FirstOrDefault();
                Assert.NotNull(person);
                Assert.Equal("*****@*****.**", person.Email);
            }
        }