Exemple #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);
            }
        }
Exemple #2
0
        public async void TestReadOneinDB()
        {
            DbContextOptions <NetGramDBContext> options = new DbContextOptionsBuilder <NetGramDBContext>().UseInMemoryDatabase("ReadPost").Options;


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

                INetGramServices netGramService = new INetGramServices(context);

                await netGramService.Save(testPost10);

                Post returnedPost1 = await netGramService.FindPosts(testPost10.ID);

                var testPost10Answer = context.PostsTable.FirstOrDefault(a => a.ID == testPost10.ID);

                Assert.Equal(returnedPost1, testPost10Answer);
            }
        }