Exemple #1
0
        public void AnalogousController3()
        {
            DbContextOptions <ColorWheelDbContext> options3 = new DbContextOptionsBuilder <ColorWheelDbContext>()
                                                              .UseInMemoryDatabase(databaseName: "ColorWheelDbContext")
                                                              .Options;

            using (ColorWheelDbContext dbContext3 = new ColorWheelDbContext(options3))
            {
                Color color = new Color();
                color.ColorName = "Yellow";
                Analogous analogous = new Analogous();
                analogous.ColorOneID   = 9;
                analogous.ColorTwoID   = 10;
                analogous.ColorThreeID = 8;
                dbContext3.Add(color);
                dbContext3.Add(analogous);
                dbContext3.SaveChanges();

                var expected       = "Yellow";
                var controller     = new AnalogousController(dbContext3);
                var actionResult   = controller.Get(expected);
                var okObjectResult = actionResult as OkObjectResult;
                Assert.IsType <OkObjectResult>(actionResult);
            }
        }
        public void CanReturn404StatusCode()
        {
            DbContextOptions <ColorWheelDbContext> moreFakeOptions = new DbContextOptionsBuilder <ColorWheelDbContext>()
                                                                     .UseInMemoryDatabase(databaseName: "ColorWheelDbContext")
                                                                     .Options;

            using (ColorWheelDbContext fakeDB = new ColorWheelDbContext(moreFakeOptions))
            {
                Color moreYellow = new Color {
                    ID = 1, ColorName = "Yellow", HexCode = "#FEFE33"
                };
                Color moreYellowOrange = new Color {
                    ID = 12, ColorName = "Yellow-Orange", HexCode = "#FCCC1A"
                };
                Color moreYellowGreen = new Color {
                    ID = 2, ColorName = "Yellow-Green", HexCode = "#B2D732"
                };

                Analogous moreAnalogous = new Analogous();
                moreAnalogous.ColorOneID   = 1;
                moreAnalogous.ColorTwoID   = 2;
                moreAnalogous.ColorThreeID = 12;

                fakeDB.Add(moreYellow);
                fakeDB.Add(moreYellowOrange);
                fakeDB.Add(moreYellowGreen);
                fakeDB.Add(moreAnalogous);
                fakeDB.SaveChanges();

                var moreColor1 = "Red";
                var moreColor2 = "Yellow-Orange";
                var moreColor3 = "Yellow-Green";

                var moreController   = new AnalogousController(fakeDB);
                var moreActionResult = moreController.Get(moreColor1, moreColor2, moreColor3);
                var notFoundResult   = moreActionResult as NotFoundResult;

                Assert.IsType <NotFoundResult>(moreActionResult);
            }
        }
        public void CanReturn200StatusCode()
        {
            DbContextOptions <ColorWheelDbContext> fakeOptions = new DbContextOptionsBuilder <ColorWheelDbContext>()
                                                                 .UseInMemoryDatabase(databaseName: "ColorWheelDbContext")
                                                                 .Options;

            using (ColorWheelDbContext fakeDB = new ColorWheelDbContext(fakeOptions))
            {
                Color yellow = new Color {
                    ID = 1, ColorName = "Yellow", HexCode = "#FEFE33"
                };
                Color yellowOrange = new Color {
                    ID = 12, ColorName = "Yellow-Orange", HexCode = "#FCCC1A"
                };
                Color yellowGreen = new Color {
                    ID = 2, ColorName = "Yellow-Green", HexCode = "#B2D732"
                };

                Analogous analogous = new Analogous();
                analogous.ColorOneID   = 1;
                analogous.ColorTwoID   = 2;
                analogous.ColorThreeID = 12;

                fakeDB.Add(yellow);
                fakeDB.Add(yellowOrange);
                fakeDB.Add(yellowGreen);
                fakeDB.Add(analogous);
                fakeDB.SaveChanges();

                var color1 = "Yellow";
                var color2 = "Yellow-Orange";
                var color3 = "Yellow-Green";

                var controller     = new AnalogousController(fakeDB);
                var actionResult   = controller.Get(color1, color2, color3);
                var okObjectResult = actionResult as OkObjectResult;

                Assert.IsType <OkObjectResult>(actionResult);
            }
        }