Exemplo n.º 1
0
        public void TestGetPoints_WithSingleRecord_ReturnOk()
        {
            //Arrange
            DbContextOptionsBuilder <SquareContext> optionsBuilder = new();

            optionsBuilder.UseInMemoryDatabase(MethodBase.GetCurrentMethod().Name);

            using (SquareContext ctx = new(optionsBuilder.Options))
            {
                ctx.Add(new Point {
                    CoordinateX = 10, CoordinateY = 20
                });
                ctx.SaveChanges();
            }

            IActionResult result;

            using (SquareContext ctx = new(optionsBuilder.Options))
            {
                var pointService = new PointService(ctx);

                var controller = new SquareController(pointService);

                //Act
                result = controller.GetPoints();
            }

            var okResult    = result as OkObjectResult;
            var points      = (List <Point>)okResult.Value;
            var singlePoint = points.Single();

            //Assert
            Assert.IsNotNull(okResult);
            Assert.AreEqual(10, singlePoint.CoordinateX);
            Assert.AreEqual(20, singlePoint.CoordinateY);
        }
Exemplo n.º 2
0
        public void TestGetPoints_WithNoRecords_ReturnNoContent()
        {
            //Arrange
            DbContextOptionsBuilder <SquareContext> optionsBuilder = new();

            optionsBuilder.UseInMemoryDatabase(MethodBase.GetCurrentMethod().Name);

            IActionResult result;

            using (SquareContext ctx = new(optionsBuilder.Options))
            {
                var pointService = new PointService(ctx);

                var controller = new SquareController(pointService);

                //Act
                result = controller.GetPoints();
            }

            var noContentResult = result as NoContentResult;

            //Assert
            Assert.IsNotNull(noContentResult);
        }