Esempio n. 1
0
        public void Should_OK_GetCatById_When_Exist_Element()
        {
            var options = new DbContextOptionsBuilder <CatMashDBContext>()
                          .UseInMemoryDatabase(databaseName: "CatMashDB4")
                          .Options;

            // Run the test against one instance of the context
            using (var context = new CatMashDBContext(options))
            {
                context.TCat.Add(new TCat {
                    CatId = 78, CatUrl = "img1"
                });
                context.TCat.Add(new TCat {
                    CatUrl = "img2"
                });
                context.TCat.Add(new TCat {
                    CatUrl = "img3"
                });
                var updateCount = context.SaveChanges();

                Assert.Equal(3, updateCount);

                var catId             = 78;
                var catMashRepository = new CatMashRepository(context);

                var result = catMashRepository.GetCatById(catId);

                Assert.NotNull(result);
                Assert.Equal(78, result.CatId);
            }
        }
Esempio n. 2
0
        public void Should_OK_AddMatche_When_Valid_Params()
        {
            var options = new DbContextOptionsBuilder <CatMashDBContext>()
                          .UseInMemoryDatabase(databaseName: "CatMashDB9")
                          .Options;

            // Run the test against one instance of the context
            using (var context = new CatMashDBContext(options))
            {
                context.TCat.Add(new TCat {
                    CatId = 55, CatUrl = "img1"
                });
                context.TCat.Add(new TCat {
                    CatId = 56, CatUrl = "img2"
                });
                context.TCat.Add(new TCat {
                    CatId = 57, CatUrl = "img3"
                });
                var updateCountTCat = context.SaveChanges();

                Assert.Equal(3, updateCountTCat);

                var matche = new TMatche()
                {
                    LeftCatId = 55, RightCatId = 56, MatchResult = "X"
                };

                var catMashRepository = new CatMashRepository(context);
                var result            = catMashRepository.AddMatche(matche);

                Assert.True(result);
            }
        }
Esempio n. 3
0
        public void Should_Exception_AddMatche_When_MatchResult_Invalid()
        {
            var options = new DbContextOptionsBuilder <CatMashDBContext>()
                          .UseInMemoryDatabase(databaseName: "CatMashDB8")
                          .Options;

            // Run the test against one instance of the context
            using (var context = new CatMashDBContext(options))
            {
                context.TCat.Add(new TCat {
                    CatId = 55, CatUrl = "img1"
                });
                context.TCat.Add(new TCat {
                    CatId = 56, CatUrl = "img2"
                });
                context.TCat.Add(new TCat {
                    CatId = 57, CatUrl = "img3"
                });
                var updateCountTCat = context.SaveChanges();

                Assert.Equal(3, updateCountTCat);

                var matche = new TMatche()
                {
                    LeftCatId = 55, RightCatId = 56, MatchResult = "UnknownResult"
                };

                var catMashRepository = new CatMashRepository(context);

                Assert.Throws <UnknownMatcheResultException>(() => catMashRepository.AddMatche(matche));
            }
        }
Esempio n. 4
0
        public void Should_OK_GetAllCats_When_Full_DataBase()
        {
            var options = new DbContextOptionsBuilder <CatMashDBContext>()
                          .UseInMemoryDatabase(databaseName: "CatMashDB1")
                          .Options;

            // Run the test against one instance of the context
            using (var context = new CatMashDBContext(options))
            {
                context.TCat.Add(new TCat {
                    CatUrl = "img1"
                });
                context.TCat.Add(new TCat {
                    CatUrl = "img2"
                });
                context.TCat.Add(new TCat {
                    CatUrl = "img3"
                });
                var updateCount = context.SaveChanges();

                Assert.Equal(3, updateCount);

                var catMashRepository = new CatMashRepository(context);
                var result            = catMashRepository.GetAllCats();

                Assert.NotNull(result);
                Assert.NotEmpty(result);
                Assert.Equal(3, result.Count());
            }
        }
Esempio n. 5
0
        public void Should_NullReferenceException_GetCatById_When_Emty_DataBase()
        {
            var options = new DbContextOptionsBuilder <CatMashDBContext>()
                          .UseInMemoryDatabase(databaseName: "CatMashDB3")
                          .Options;

            // Run the test against one instance of the context
            using (var context = new CatMashDBContext(options))
            {
                var catId             = 1;
                var catMashRepository = new CatMashRepository(context);

                Assert.Throws <ElementNotFoundException>(() => catMashRepository.GetCatById(catId));
            }
        }
Esempio n. 6
0
        public void Should_OK_GetAllCats_When_Emty_DataBase()
        {
            var options = new DbContextOptionsBuilder <CatMashDBContext>()
                          .UseInMemoryDatabase(databaseName: "CatMashDB2")
                          .Options;

            // Run the test against one instance of the context
            using (var context = new CatMashDBContext(options))
            {
                var catMashRepository = new CatMashRepository(context);
                var result            = catMashRepository.GetAllCats();

                Assert.NotNull(result);
                Assert.Empty(result);
            }
        }