Exemple #1
0
        public async Task SaveHealthItemTest()
        {
            var objA = new HealthItemInsertDto
            {
                Name = Guid.NewGuid().ToString()
            };

            using var srv = new TestServer(TestHostBuilder <Startup, IntegrationTestStartup>());
            var client = srv.CreateClient();

            GenerateAuthHeader(client, GenerateTestToken());

            var resp = await client.PostAsJsonAsync($"api/v1/{nameof(HealthItem)}s.json", objA);

            _ = resp.EnsureSuccessStatusCode();
            var result = await DeserializeResponseAsync <HealthItem>(resp);

            Assert.AreEqual(objA.Name, result.Name);
            Assert.IsTrue(result.IsEnabled);
            Assert.IsNotNull(result.CreatedBy);

            var ctx  = srv.GetDbContext <HealthItemsContext>();
            var item = await ctx.HealthItems.FirstOrDefaultAsync(t => t.Name == result.Name);

            Assert.IsNotNull(item);
            Assert.AreEqual(result.CreatedOnUtc.ToString(), item.CreatedOnUtc.ToString());
        }
Exemple #2
0
        public async Task <ActionResult> Post([FromBody] HealthItemInsertDto value)
        {
            var obj = value.ToHealthItem();

            _ = _ctx.HealthItems.Add(obj);
            if (0 < await _ctx.SaveChangesAsync())
            {
                await _createdPublisher.PublishAsync(obj);
            }
            return(Ok(obj));
        }