public async Task MustUpdateExpense(string url)
        {
            var client = _factory.CreateClient();

            var expense = await ExpenseGenerator.CreateAsync(client);

            var command = new
            {
                Category    = "update test",
                Description = "update test",
                Id          = expense.Id,
                Value       = 10000
            };

            var requestContent = new StringContent(JsonSerializer.Serialize(command), Encoding.UTF8, "text/json");

            var response = await client.PutAsync(url, requestContent, CancellationToken.None);

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

            var result = JsonSerializer.Deserialize <RemoveExpenseCommandResult>(content);

            Assert.True(result.Valid);
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
        }
Ejemplo n.º 2
0
        public async Task MustGetExpensies(string url)
        {
            var client = _factory.CreateClient();

            var expense = await ExpenseGenerator.CreateAsync(client);

            var response = await client.GetAsync(url, CancellationToken.None);

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

            var result = JsonSerializer.Deserialize <ExpensiesQueryResult>(content);

            Assert.Contains(result.Expensies, x => x.Id == expense.Id);
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
        }
        public async Task MustRemoveExpense()
        {
            var client = _factory.CreateClient();

            var expense = await ExpenseGenerator.CreateAsync(client);

            var url = $"/api/v1/expense?id={expense.Id}";

            var response = await client.DeleteAsync(url, CancellationToken.None);

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

            var result = JsonSerializer.Deserialize <RemoveExpenseCommandResult>(content);

            Assert.True(result.Valid);
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
        }
Ejemplo n.º 4
0
        public async Task MustGetExpenseById()
        {
            var client = _factory.CreateClient();

            var expense = await ExpenseGenerator.CreateAsync(client);

            var url = $"/api/v1/expense/{expense.Id}";

            var response = await client.GetAsync(url, CancellationToken.None);

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

            var result = JsonSerializer.Deserialize <ExpenseByIdQueryResult>(content);

            Assert.Equal(expense.Id, result.Expense.Id);
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
        }