Пример #1
0
        public async void ValidPost()
        {
            // Arrange
            var options = new DbContextOptionsBuilder <AlpmysContext>()
                          .UseInMemoryDatabase("CreateNewEvent")
                          .Options;
            AlpmysContext     context    = new AlpmysContext(options);
            EventosController controller = new EventosController(context);
            Evento            e          = new Evento();

            e.Nome = "Evento!";

            // Act
            await controller.PostEvento(e);

            // Assert
            Assert.Equal(1, context.Evento.Count());
        }
Пример #2
0
        public async void InvalidPost()
        {
            // Arrange
            var options = new DbContextOptionsBuilder <AlpmysContext>()
                          .UseInMemoryDatabase("FailToCreate")
                          .Options;
            AlpmysContext     context    = new AlpmysContext(options);
            EventosController controller = new EventosController(context);

            controller.ModelState.AddModelError("error", "invalid model");
            Evento e = new Evento();

            e.Nome = null;

            // Act
            var result = await controller.PostEvento(null);

            // Assert
            Assert.IsType <BadRequestObjectResult>(result);
        }
Пример #3
0
        public async void GetSpecificEvent()
        {
            // Arrange
            var options = new DbContextOptionsBuilder <AlpmysContext>()
                          .UseInMemoryDatabase("UpdateEvent")
                          .Options;
            AlpmysContext     context    = new AlpmysContext(options);
            EventosController controller = new EventosController(context);
            Evento            e          = new Evento();

            e.Id   = 5;
            e.Nome = "Evento!";
            await controller.PostEvento(e);

            // Act
            var result = await controller.GetEvento(5);

            // Assert
            Assert.IsType <OkObjectResult>(result);
        }
Пример #4
0
        public async void FailDelete()
        {
            // Arrange
            var options = new DbContextOptionsBuilder <AlpmysContext>()
                          .UseInMemoryDatabase("FailDeleteEvent")
                          .Options;
            AlpmysContext     context    = new AlpmysContext(options);
            EventosController controller = new EventosController(context);
            Evento            e          = new Evento();

            e.Nome = "Evento!";

            // Act
            await controller.PostEvento(e);

            var result = await controller.DeleteEvento(10);

            // Assert
            Assert.IsType <NotFoundResult>(result);
        }