Exemplo n.º 1
0
        public async Task Post()
        {
            var response = await _client.PostAsync("/sample/Products", Helpers.JSON(new
            {
                Name           = "Sample X",
                UnitPrice      = 9.99m,
                SalesPatternId = 1,
                SalesProduct   = new
                {
                    TaxRoundMode = "Ceil",
                    TaxRate      = 0.20m,
                }
            }));

            Assert.Equal(HttpStatusCode.Created, response.StatusCode);

            var result = JObject.Parse(await response.Content.ReadAsStringAsync());

            Assert.Equal("Sample X", (string)result.SelectToken("$.Name"));

            var id = (long)result.SelectToken("$.Id");

            response = await _client.GetAsync($"/sample/SalesProducts({id}L)");

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);

            result = JObject.Parse(await response.Content.ReadAsStringAsync());

            Assert.Equal("Ceil", (string)result.SelectToken("$.TaxRoundMode"));
            Assert.Equal(0.20m, (decimal)result.SelectToken("$.TaxRate"));
        }
Exemplo n.º 2
0
        public async Task Batch()
        {
            Skip.IfNot(RuntimeInformation.IsOSPlatform(OSPlatform.Windows));

            var batch     = new MultipartContent("mixed", "batch" + Guid.NewGuid());
            var changeset = new MultipartContent("mixed", "changeset" + Guid.NewGuid());

            {
                var message = new HttpRequestMessage(HttpMethod.Post, "http://localhost/sample/SalesPatterns")
                {
                    Content = Helpers.JSON(new
                    {
                        TaxRoundMode = "Round",
                        TaxRate      = 0.08m
                    })
                };
                message.Headers.Add("Content-ID", "1");

                var content = new HttpMessageContent(message);
                content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/http");
                content.Headers.Add("Content-Transfer-Encoding", "binary");

                changeset.Add(content);
            }

            {
                var message = new HttpRequestMessage(HttpMethod.Post, "http://localhost/sample/$1/Products")
                {
                    Content = Helpers.JSON(new
                    {
                        Name      = "Sample Batch",
                        UnitPrice = 9.99m
                    })
                };
                message.Headers.Add("Content-ID", "2");

                var content = new HttpMessageContent(message);
                content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/http");
                content.Headers.Add("Content-Transfer-Encoding", "binary");

                changeset.Add(content);
            }

            batch.Add(changeset);
            var response = await _client.PostAsync("/sample/$batch", batch);

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.Equal("multipart/mixed", response.Content.Headers.ContentType.MediaType);

            var parts = await Helpers.ParseMultipartMixedAsync(response);

            Assert.Equal(2, parts.Length);

            Assert.Equal(HttpStatusCode.Created, parts[0].StatusCode);
            var salesPattern = await parts[0].Content.ReadAsAsync <dynamic>();

            Assert.True((int)salesPattern.Id > 0);
            Assert.Equal("Round", (string)salesPattern.TaxRoundMode);

            Assert.Equal(HttpStatusCode.Created, parts[1].StatusCode);
            var product = await parts[1].Content.ReadAsAsync <dynamic>();

            Assert.True((long)product.Id > 0);
            Assert.Equal("Sample Batch", (string)product.Name);
            Assert.Equal((int)salesPattern.Id, (int)product.SalesPatternId);
        }
Exemplo n.º 3
0
        public async Task PutOne()
        {
            var response = await _client.PutAsync("/sample/Products(1L)/SalesProduct", Helpers.JSON(new {
                ProductId    = 1L,
                TaxRoundMode = "Floor",
            }));

            Assert.Equal(HttpStatusCode.NoContent, response.StatusCode);

            response = await _client.GetAsync("/sample/Products(1L)/SalesProduct");

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);

            var result = JObject.Parse(await response.Content.ReadAsStringAsync());

            Assert.Equal("Floor", (string)result.SelectToken("$.TaxRoundMode"));
        }
Exemplo n.º 4
0
        public async Task PostOne()
        {
            var response = await _client.PostAsync("/sample/Products(2L)/SalesProduct", Helpers.JSON(new
            {
                TaxRoundMode = "None",
            }));

            Assert.Equal(HttpStatusCode.Created, response.StatusCode);

            response = await _client.GetAsync("/sample/Products(2L)/SalesProduct");

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);

            var result = JObject.Parse(await response.Content.ReadAsStringAsync());

            Assert.Equal("None", (string)result.SelectToken("$.TaxRoundMode"));
        }
Exemplo n.º 5
0
        public async Task PutLastMany2()
        {
            var response = await _client.PutAsync("/sample/Products(1L)/CampaignRelations(1)/Campaign/Actions('Sample')", Helpers.JSON(new
            {
                CampaignId   = 1,
                CampaignType = "Sample",
                OptionValue  = "Option 2"
            }));;

            Assert.Equal(HttpStatusCode.NoContent, response.StatusCode);

            response = await _client.GetAsync("/sample/Products(1L)/CampaignRelations(1)/Campaign/Actions('Sample')");

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);

            var result = JObject.Parse(await response.Content.ReadAsStringAsync());

            Assert.Equal("Option 2", (string)result.SelectToken("$.OptionValue"));
        }
Exemplo n.º 6
0
        public async Task PatchLastOne()
        {
            var response = await _client.PatchAsync("/sample/Products(1L)/CampaignRelations(ProductId=1L,CampaignId=1)/Campaign", Helpers.JSON(new
            {
                Name = "Patched"
            }));;

            Assert.Equal(HttpStatusCode.NoContent, response.StatusCode);

            response = await _client.GetAsync("/sample/Products(1L)/CampaignRelations(ProductId=1L,CampaignId=1)/Campaign");

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);

            var result = JObject.Parse(await response.Content.ReadAsStringAsync());

            Assert.Equal("Patched", (string)result.SelectToken("$.Name"));
        }
Exemplo n.º 7
0
        public async Task PutLastOne()
        {
            var response = await _client.PutAsync("/sample/Products(1L)/CampaignRelations(ProductId=1L,CampaignId=1)/Campaign", Helpers.JSON(new
            {
                Id        = 1,
                Name      = "Put",
                StartDate = DateTimeOffset.MinValue,
                EndDate   = DateTimeOffset.MaxValue,
            }));;

            Assert.Equal(HttpStatusCode.NoContent, response.StatusCode);

            response = await _client.GetAsync("/sample/Products(1L)/CampaignRelations(ProductId=1L,CampaignId=1)/Campaign");

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);

            var result = JObject.Parse(await response.Content.ReadAsStringAsync());

            Assert.Equal("Put", (string)result.SelectToken("$.Name"));
        }
Exemplo n.º 8
0
        public async Task PostLastOne()
        {
            var response = await _client.PostAsync("/sample/SalesPatterns(1)/Products(3L)/SalesProduct", Helpers.JSON(new
            {
                TaxRoundMode = "Floor",
                TaxRate      = 0.1m
            }));;

            Assert.Equal(HttpStatusCode.Created, response.StatusCode);

            var result = JObject.Parse(await response.Content.ReadAsStringAsync());

            Assert.Equal("Floor", (string)result.SelectToken("$.TaxRoundMode"));
            Assert.Equal(0.1m, (decimal)result.SelectToken("$.TaxRate"));
        }
Exemplo n.º 9
0
        public async Task PostOneMany()
        {
            var response = await _client.PostAsync("/sample/SalesProducts(1L)/Product/CategoryRelations", Helpers.JSON(new {
                CategoryId = 2
            }));;

            Assert.Equal(HttpStatusCode.Created, response.StatusCode);

            var result = JObject.Parse(await response.Content.ReadAsStringAsync());

            Assert.Equal(1, (long)result.SelectToken("$.ProductId"));
            Assert.Equal(2, (int)result.SelectToken("$.CategoryId"));
        }
Exemplo n.º 10
0
        public async Task PatchMany()
        {
            var response = await _client.PatchAsync("/sample/SalesPatterns(1)/Products(1L)", Helpers.JSON(new
            {
                Name = "Patched",
            }));

            Assert.Equal(HttpStatusCode.NoContent, response.StatusCode);

            response = await _client.GetAsync("/sample/SalesPatterns(1)/Products(1L)");

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);

            var result = JObject.Parse(await response.Content.ReadAsStringAsync());

            Assert.Equal("Patched", (string)result.SelectToken("$.Name"));
        }
Exemplo n.º 11
0
        public async Task PutMany()
        {
            var response = await _client.PutAsync("/sample/SalesPatterns(1)/Products(1L)", Helpers.JSON(new
            {
                Id             = 1,
                Name           = "Sample X",
                UnitPrice      = 4.00m,
                SalesPatternId = 1
            }));

            Assert.Equal(HttpStatusCode.NoContent, response.StatusCode);

            response = await _client.GetAsync("/sample/SalesPatterns(1)/Products(1L)");

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);

            var result = JObject.Parse(await response.Content.ReadAsStringAsync());

            Assert.Equal("Sample X", (string)result.SelectToken("$.Name"));
        }
Exemplo n.º 12
0
        public async Task PostMany()
        {
            var response = await _client.PostAsync("/sample/SalesPatterns(1)/Products", Helpers.JSON(new {
                Name      = "Sample X",
                UnitPrice = 4.00m,
            }));

            Assert.Equal(HttpStatusCode.Created, response.StatusCode);

            var result = JObject.Parse(await response.Content.ReadAsStringAsync());

            Assert.Equal(1, (int)result.SelectToken("$.SalesPatternId"));
        }
Exemplo n.º 13
0
        public async Task Post()
        {
            var response = await _client.PostAsync("/sample/Products(1L)/Categories/$ref", Helpers.JSON(new Dictionary <string, object> {
                ["@odata.id"] = "http://localhost/sample/Categories(2)"
            }));

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);

            response = await _client.GetAsync("/sample/Products(1L)/Categories(2)");

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
        }