Beispiel #1
0
        public async void Operations(OperationType type, Double[] values, Double result)
        {
            OperationModel data = new OperationModel
            {
                Type  = type,
                Value = values,
            };

            using (HttpClient client = Client)
            {
                using (HttpResponseMessage response = await client.PostAsync($"{Version}/operations",
                                                                             data.ToStringContent()))
                {
                    response.EnsureSuccessStatusCode();

                    String content = await response.Content.ReadAsStringAsync();

                    Assert.False(String.IsNullOrEmpty(content));

                    OperationModel operation = JsonConvert.DeserializeObject <OperationModel>(content);

                    Assert.NotNull(operation);

                    Assert.NotNull(Context.Operations);
                    Assert.NotEmpty(Context.Operations);
                    Assert.Single(Context.Operations, (e) => { return(e.Id == operation.Id); });

                    Assert.Equal(data.Type, operation.Type);
                    Assert.Equal(data.Value, operation.Value);

                    Assert.Equal(result, operation.Result);
                }
            }
        }
Beispiel #2
0
        public async void Operations_Fails(OperationType type, Double[] values)
        {
            OperationModel data = new OperationModel
            {
                Type  = type,
                Value = values,
            };

            using (HttpClient client = Client)
            {
                using (HttpResponseMessage response = await client.PostAsync($"{Version}/operations",
                                                                             data.ToStringContent()))
                {
                    Assert.Throws <HttpRequestException>(() => response.EnsureSuccessStatusCode());

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