Exemplo n.º 1
0
        public async Task GetById(Pizza p)
        {
            Pizzas.Setup(ps => ps.Get(It.IsAny <Guid>())).ReturnsAsync(p);

            var pizza = await Client.GetJsonAsync <Pizza>($"api/v1/pizza/{p.Id}");

            Assert.Equal(p, pizza);
            Pizzas.Verify(ps => ps.Get(p.Id), Times.Once);
        }
Exemplo n.º 2
0
        public async Task GetMany(List <Pizza> pzs)
        {
            Pizzas.Setup(ps => ps.GetAll()).ReturnsAsync(pzs);

            var response = (await Client.GetJsonAsync <IEnumerable <Pizza> >("api/v1/pizza")).ToList();

            Assert.Equal(pzs.Count, response.Count);
            Assert.All(response, p => Assert.Contains(p, pzs));
        }
Exemplo n.º 3
0
        public async Task ConflicForDuplicateAdd(Pizza p)
        {
            Pizzas.Setup(ps => ps.Add(It.IsAny <Pizza>())).ThrowsAsync(new PostgresException {
                SqlState = "23505"
            });
            var response = await Client.PostJsonAsync("api/v1/pizza", p);

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

            var error = JsonConvert.DeserializeObject <ApiExceptionMessage>(await response.Content.ReadAsStringAsync());

            Assert.Equal($"The pizza identified by {p.Id} already exists", error.Message);

            Pizzas.Verify(ps => ps.Add(p), Times.Once);
        }