Beispiel #1
0
        public async void TestUpdateinDB()
        {
            DbContextOptions <NetGramDBContext> options = new DbContextOptionsBuilder <NetGramDBContext>().UseInMemoryDatabase("UpdatePost").Options;


            using (NetGramDBContext context = new NetGramDBContext(options))
            {
                Post testPost12 = new Post();
                testPost12.ID          = 1;
                testPost12.Title       = "aTitle";
                testPost12.Description = "aDescription";
                testPost12.ImageURL    = ".URL";

                INetGramServices netGramService = new INetGramServices(context);

                await netGramService.Save(testPost12);

                testPost12.Title = "NEWTitle";
                await netGramService.Save(testPost12);

                var returnedPost3 = await netGramService.FindPosts(1);

                var testPost12Answer = context.PostsTable.FirstOrDefault(a => a.ID == testPost12.ID);

                Assert.Equal("NEWTitle", testPost12Answer.Title);
            }
        }
Beispiel #2
0
        public async void TestCreateinDB()
        {
            DbContextOptions <NetGramDBContext> options = new DbContextOptionsBuilder <NetGramDBContext>().UseInMemoryDatabase("CreatePost").Options;


            using (NetGramDBContext context = new NetGramDBContext(options))
            {
                Post testPost9 = new Post();
                testPost9.ID          = 1;
                testPost9.Title       = "aTitle";
                testPost9.Description = "aDescription";
                testPost9.ImageURL    = ".URL";

                INetGramServices netGramService = new INetGramServices(context);

                await netGramService.Save(testPost9);

                var testPost9Answer = context.PostsTable.FirstOrDefault(a => a.ID == testPost9.ID);

                Assert.Equal(testPost9, testPost9Answer);
            }
        }
Beispiel #3
0
        public async void TestReadAllinDB()
        {
            DbContextOptions <NetGramDBContext> options = new DbContextOptionsBuilder <NetGramDBContext>().UseInMemoryDatabase("Read2Post").Options;


            using (NetGramDBContext context = new NetGramDBContext(options))
            {
                Post testPost11 = new Post();
                testPost11.ID          = 1;
                testPost11.Title       = "aTitle";
                testPost11.Description = "aDescription";
                testPost11.ImageURL    = ".URL";

                INetGramServices netGramService = new INetGramServices(context);

                await netGramService.Save(testPost11);

                var returnedPost2 = await netGramService.GetAllPosts();

                var testPost11Answer = context.PostsTable.FirstOrDefault(a => a.ID == testPost11.ID);

                Assert.Equal(returnedPost2[0], testPost11Answer);
            }
        }
Beispiel #4
0
 public INetGramServices(NetGramDBContext context)
 {
     _context = context;
 }