Exemple #1
0
        public void TestGetSquaresCount_WhenNoSquares_Return0()
        {
            //Arrange
            DbContextOptionsBuilder <SquareContext> optionsBuilder = new();

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

            using (SquareContext ctx = new(optionsBuilder.Options))
            {
                var s1_point1 = new Point {
                    CoordinateX = 0, CoordinateY = 3
                };
                var s1_point2 = new Point {
                    CoordinateX = 1, CoordinateY = 2
                };
                var s1_point3 = new Point {
                    CoordinateX = 3, CoordinateY = 0
                };
                var s1_point4 = new Point {
                    CoordinateX = 0, CoordinateY = 0
                };

                var s2_point1 = new Point {
                    CoordinateX = -1, CoordinateY = 1
                };
                var s2_point2 = new Point {
                    CoordinateX = 1, CoordinateY = 1
                };
                var s2_point3 = new Point {
                    CoordinateX = 1, CoordinateY = -2
                };
                var s2_point4 = new Point {
                    CoordinateX = -1, CoordinateY = -1
                };


                ctx.AddRange(new Point[] { s1_point1, s1_point2, s1_point3, s1_point4 });
                ctx.AddRange(new Point[] { s2_point1, s2_point2, s2_point3, s2_point4 });
                ctx.SaveChanges();
            }

            ActionResult <int> result;

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

                var controller = new SquareController(pointService);

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

            var count = result.Value;

            //Assert
            Assert.AreEqual(0, count);
        }