Exemplo n.º 1
0
        public async void CanFindPostTest()
        {
            //testing post manger service
            DbContextOptions <PostDbContext> options =
                new DbContextOptionsBuilder <PostDbContext>().UseInMemoryDatabase("CreatePost").Options;

            using (PostDbContext context = new PostDbContext(options))
            {
                //arrange
                Post post = new Post();
                post.ID      = 1;
                post.Title   = "Fun";
                post.Caption = "in the sun";
                post.URL     = "www.funinthesun.com";
                //act
                PostManager postservice = new PostManager(context);

                await postservice.SaveAsync(post);

                Post check    = context.Posts.FirstOrDefault(p => p.ID == p.ID);
                Post validate = await postservice.FindPost(1);

                //assert
                Assert.Equal(check, validate);
            }
        }
Exemplo n.º 2
0
        public async void CanReadSinglePost()
        {
            DbContextOptions <PostDbContext> options = new DbContextOptionsBuilder <PostDbContext>().UseInMemoryDatabase("ReadPost").Options;

            using (PostDbContext context = new PostDbContext(options))
            {
                PostManager postService = new PostManager(context);
                Post        post        = new Post();
                post.Author   = "John";
                post.ImageURL = "test.img";
                post.Caption  = "Read me!";
                await postService.SaveAsync(post);

                Post result = await postService.FindPost(post.ID);

                Assert.Equal(post, result);
            }
        }
Exemplo n.º 3
0
        public async void TestPostCanFind()
        {
            ///Test that you can find a post
            DbContextOptions <GramDbContext> options = new DbContextOptionsBuilder <GramDbContext>().UseInMemoryDatabase("FindPost").Options;

            using (GramDbContext context = new GramDbContext(options))
            {
                Post        post    = new Post();
                PostManager manager = new PostManager(context);
                post.ID      = 3;
                post.Details = "Cray";
                await manager.SaveAsync(post);

                Post testPost = await manager.FindPost(post.ID);

                Assert.Equal(3, testPost.ID);
            }
        }
Exemplo n.º 4
0
        public async void TestPostCanDelete()
        {
            ///Test that you can delete a post
            DbContextOptions <GramDbContext> options = new DbContextOptionsBuilder <GramDbContext>().UseInMemoryDatabase("DeletePost").Options;

            using (GramDbContext context = new GramDbContext(options))
            {
                Post        post    = new Post();
                PostManager manager = new PostManager(context);
                post.ID      = 4;
                post.Details = "Cray";
                post.Author  = "JTT";
                await manager.SaveAsync(post);

                await manager.DeleteAsync(post.ID);

                Assert.Null(await manager.FindPost(post.ID));
            }
        }
Exemplo n.º 5
0
        public async void TestPostCanEdit()
        {
            ///Test that you can edit a post
            DbContextOptions <GramDbContext> options = new DbContextOptionsBuilder <GramDbContext>().UseInMemoryDatabase("EditPost").Options;

            using (GramDbContext context = new GramDbContext(options))
            {
                Post        post    = new Post();
                PostManager manager = new PostManager(context);
                post.ID      = 4;
                post.Details = "Cray";
                post.Author  = "JTT";
                await manager.SaveAsync(post);

                post.Details = "Changed cray";
                string expected = "Changed cray";
                Post   testPost = await manager.FindPost(post.ID);

                Assert.Equal(expected, testPost.Details);
            }
        }