Get() private method

private Get ( ) : List
return List
Esempio n. 1
0
        public async void Get_Blog_Page_Test()
        {
            MessageModel <PageModel <BlogArticle> > blogs = await blogController.Get(1, 1, "技术博文", "");

            Assert.NotNull(blogs);
            Assert.NotNull(blogs.response);
            Assert.True(blogs.response.dataCount >= 0);
        }
        public void GetById()
        {
            BlogController controller = new BlogController();

            var blogs = controller.Get();

            Assert.IsTrue(blogs.Count() > 0);

            var b1  = blogs.First();
            var id1 = b1._Id;
            var b2  = controller.Get(id1.ToString());

            Assert.IsTrue(b2._Id == b1._Id);
        }
        public void T1_CadastrarBlogComUmUsuario()
        {
            var            ownerName   = "Teste1 VariasPostagens";
            var            login       = $"emanuel1_{DateTime.Now.ToString("hhMMss")}";
            var            password    = "******";
            var            description = "Blog teste para validação do projeto";
            BlogController blogCtr     = new BlogController();

            BlogModel blog = new BlogModel
            {
                OwnerName   = ownerName,
                Login       = login,
                Password    = password,
                Description = description,
            };

            var idBlog = blogCtr.Post(blog);

            // V A L I D A Ç Ã O ///////////////////////

            var leituraBlog = blogCtr.Get(idBlog);

            Assert.IsNotNull(leituraBlog);
            Assert.AreEqual(ownerName, leituraBlog.OwnerName);
            Assert.AreEqual(login, leituraBlog.Login);
            Assert.AreEqual(password, leituraBlog.Password);
            Assert.AreEqual(description, leituraBlog.Description);
        }
        public async Task <int> GetShouldReturn204WhenNoDataExists()
        {
            using (var fixture = new BlogContextFixture())
            {
                // Arrange
                var controller = new BlogController(fixture.Context)
                {
                    ActionContext = new ActionContext {
                        HttpContext = new DefaultHttpContext
                        {
                            RequestServices = CreateServices()
                        }
                    }
                };

                // Act
                var result = await controller.Get();

                await result.ExecuteResultAsync(controller.ActionContext);

                var response = result as NoContentResult;
                if (response != null)
                {
                    await response.ExecuteResultAsync(controller.ActionContext);
                }

                // Assert
                Assert.IsType <NoContentResult>(result);
                Assert.Equal(StatusCodes.Status204NoContent, controller.Response.StatusCode);
            }

            return(0);
        }
        public async Task <object> GetByIdShouldReturnNoContentWhenNoBlogs()
        {
            using (var fixture = new BlogContextFixture())
            {
                // Arrange
                var controller = new BlogController(fixture.Context)
                {
                    ActionContext = new ActionContext {
                        HttpContext = new DefaultHttpContext
                        {
                            RequestServices = CreateServices()
                        }
                    }
                };

                // Act
                var result = await controller.Get(1);

                await result.ExecuteResultAsync(controller.ActionContext);

                var response = result as HttpNotFoundResult;
                if (response != null)
                {
                    await response.ExecuteResultAsync(controller.ActionContext);
                }

                // Assert
                Assert.IsType <HttpNotFoundResult>(result);
                Assert.Equal(StatusCodes.Status404NotFound, controller.Response.StatusCode);
            }

            return(Task.FromResult <object>(null));
        }
        public void Put()
        {
            BlogController controller = new BlogController();

            var b1 = CreateNewBlog();

            //crio um cara para existir um e pegar o id
            controller.Post(b1);
            var id1 = b1._Id;

            var b2    = CreateNewBlog();
            var owner = "zzzzzzzz" + DateTime.Now.ToLongTimeString();

            b2.OwnerName   = owner;
            b2.Description = "zzzzzzzz" + DateTime.Now.ToLongTimeString();

            var count = controller.Put(id1.ToString(), b2);

            Assert.AreEqual(count, 1);

            var b3 = controller.Get(id1.ToString());

            Assert.AreEqual(b1._Id, b2._Id);
            Assert.AreNotEqual(b1.OwnerName, b3.OwnerName);
        }
Esempio n. 7
0
        public void TestNullReturn()
        {
            BlogPostContext    ctx     = newContext();
            BlogPostCtxWrapper wrapper = new BlogPostCtxWrapper(ctx);
            BlogController     bpc     = new BlogController(wrapper);
            var obj = bpc.Get(2);

            Assert.Null(obj.Value);
        }
Esempio n. 8
0
        public void TestSimpleReturn()
        {
            BlogPostContext    ctx     = newContext();
            BlogPostCtxWrapper wrapper = new BlogPostCtxWrapper(ctx);
            BlogController     bpc     = new BlogController(wrapper);
            var obj = bpc.Get(1);

            Assert.Equal("Help", obj.Value.Title);
            Assert.Equal(1, obj.Value.Version);
        }
Esempio n. 9
0
        public async Task GetLatestPosts_Ok()
        {
            //Act
            var jsonResponse = await _blogController.Get();

            var blogPosts = jsonResponse.CastJsonResult <IEnumerable <BlogPostViewModel> >();

            //Assert
            Assert.True(jsonResponse is JsonResult);
            Assert.NotNull(blogPosts);
        }
Esempio n. 10
0
        public void Inmemory_Controller_Integration()
        {
            var options = new DbContextOptionsBuilder()
                          .UseInMemoryDatabase(databaseName: "controllerDb")
                          .Options;

            using (var context = new BlogContext(options))
            {
                var blogRepository = new BlogRepository(context);
                var controller     = new BlogController(blogRepository);
                var objectResult   = controller.Get().Result as OkObjectResult;
                var blogEntries    = objectResult.Value as IEnumerable <DataAccess.Blog>;
                Assert.AreEqual(0, blogEntries.Count());
                context.Blogs.Add(new DataAccess.Blog());
                context.SaveChanges();
                objectResult = controller.Get().Result as OkObjectResult;
                blogEntries  = objectResult.Value as IEnumerable <DataAccess.Blog>;
                Assert.AreEqual(1, blogEntries.Count());
            }
        }
Esempio n. 11
0
        public void ReturnAllBlogObjects_Mock_Repository()
        {
            var blogRepository = new Mock <IBlogRepository>();

            blogRepository
            .Setup(x => x.GetAllBlogEntries())
            .Returns(new List <Blog.DataAccess.Blog> {
                new Blog.DataAccess.Blog()
            });
            var blogController = new BlogController(blogRepository.Object);
            var blogResult     = blogController.Get().Result as OkObjectResult;
        }
Esempio n. 12
0
        /// <summary>
        /// Busca ou cria um blog.
        /// </summary>
        /// <returns></returns>
        private BlogModel GetOneBlog()
        {
            BlogController ctr  = new BlogController();
            var            blog = ctr.Get().FirstOrDefault();

            if (blog == null)
            {
                blog = Tests.Controllers.BlogControllerTest.CreateNewBlog();
                ctr.Post(blog);
            }
            return(blog);
        }
Esempio n. 13
0
             public void GetDoesSomething()
             {
                 // Arrange
 				BlogContext db = new BlogContext(); // This should be mocked somehow
 				const int id = 5;
                 var controller = new BlogController(db);
  
                 // Act
                 var result = controller.Get(id);
  
                 // Assert something
             }
        public void GetTest_ReturnsListofPosts()
        {
            //arrange
            var mockPosts = new List <Post> {
                new Post {
                    Title = "Tdd One"
                },
                new Post {
                    Title = "Tdd and Bdd"
                }
            };

            _mockPostsList.Object.AddRange(mockPosts);

            //act
            var result = _blogController.Get();

            //assert
            var model = Assert.IsAssignableFrom <ActionResult <List <Post> > >(result);

            Assert.Equal(2, model.Value.Count);
        }
Esempio n. 15
0
        public void GetTest_ReturnsListOfPosts()
        {
            //arrange: Cenário
            var mockPosts = new List <Post>
            {
                new Post {
                    Title = "Tdd One"
                },
                new Post {
                    Title = "Tdd and Bdd"
                }
            };

            _mockPostList.Object.AddRange(mockPosts);

            //act: Ação
            var result = _blogController.Get();

            //assert: Validação
            //Verifico se o objeto dado é do tipo pssado ou de um tipo deriv ado a este.
            var model = Assert.IsAssignableFrom <ActionResult <List <Post> > >(result);

            Assert.Equal(2, model.Value.Count);
        }
Esempio n. 16
0
        public void AddEntity()
        {
            BlogArticle blogArticle = new BlogArticle()
            {
                bCreateTime = DateTime.Now,
                bUpdateTime = DateTime.Now,
                btitle      = "xuint",
            };
            //blogController.Post(blogArticle).Wait();

            var data = blogController.Get(1);

            Assert.Null(data);//为空包错了,证明不为空,
            //Assert.NotNull(data); 你可以这么判断不为空
        }
Esempio n. 17
0
        public void GetTest_ReturnsListsOfPosts()
        {
            var mockPosts = new List <Post> {
                new Post {
                    Title = "TDD One"
                },
                new Post {
                    Title = "TDD and BDD"
                }
            };

            _mockPostsList.Object.AddRange(mockPosts);

            var result = _blogController.Get();

            var model = Assert.IsAssignableFrom <ActionResult <List <Post> > >(result);
        }
        public void Get()
        {
            // Arrange
            BlogController controller = new BlogController();

            var blogs = controller.Get();

            Assert.IsNotNull(blogs);
            if (blogs.Count() == 0)
            {
                Assert.Inconclusive("O banco de dados está vazio. Execute o teste novamente.");
            }

            var b1 = blogs.First();

            Assert.IsTrue(b1.OwnerName.Length > 0);
        }
Esempio n. 19
0
        public void ReturnAllBlogObjects_Mock_Repository()
        {
            var blogRepository = new Mock <IBlogRepository>();

            blogRepository
            .Setup(b => b.GetAllBlogEntries())
            .Returns(new List <DataAccess.Blog> {
                new DataAccess.Blog()
            });
            var blogController = new BlogController(blogRepository.Object);
            var blogResult     = blogController.Get().Result as OkObjectResult;

            Assert.IsNotNull(blogResult);
            var returnedBlogEntries = blogResult.Value as IEnumerable <DataAccess.Blog>;

            Assert.IsNotNull(returnedBlogEntries);
            Assert.AreEqual(1, returnedBlogEntries.Count());
        }
        public void ReturnAllBlogObjects_Mock_Repository()
        {
            var blogRepository = new Mock <IBlogRepository>();

            blogRepository
            .Setup(b => b.GetAllBlogEntries())
            .Returns(new List <DataAccess.Blog> {
                new DataAccess.Blog()
            });
            var blogController = new BlogController(blogRepository.Object);
            var blogResult     = blogController.Get().Result as OkObjectResult;

            blogResult.Should().NotBeNull();
            var returnedBlogEntries = blogResult.Value as IEnumerable <DataAccess.Blog>;

            returnedBlogEntries.Should().NotBeNull();
            returnedBlogEntries.Should().HaveCount(1);
        }
        public void Delete()
        {
            BlogController controller = new BlogController();

            var blog = CreateNewBlog();

            //blog.Id = "999";

            controller.Post(blog);
            Assert.IsNotNull(blog._Id);
            var id1 = blog._Id;

            controller.Remove(id1.ToString());

            var b2 = controller.Get(id1.ToString());

            Assert.IsNull(b2);
        }
        public async Task <int> GetShouldReturnResultsWhenDataExists()
        {
            string expected = "Jim's Blog";

            using (var fixture = new BlogContextFixture())
            {
                // Arrange
                fixture.Context.Blogs.Add(new Blog {
                    Name = expected
                });
                await fixture.Context.SaveChangesAsync();

                var controller = new BlogController(fixture.Context)
                {
                    ActionContext = new ActionContext {
                        HttpContext = new DefaultHttpContext
                        {
                            RequestServices = CreateServices()
                        }
                    }
                };

                // Act
                var result = await controller.Get();

                await result.ExecuteResultAsync(controller.ActionContext);

                var response = result as ObjectResult;
                if (response != null)
                {
                    await response.ExecuteResultAsync(controller.ActionContext);
                }

                // Assert
                Assert.NotNull(response);
                Assert.Equal(StatusCodes.Status200OK, controller.Response.StatusCode);
                Assert.Equal(expected, ((List <Blog>)response.Value).First().Name);
            }

            return(0);
        }
Esempio n. 23
0
        public void ShouldBeReturnListOfPosts()
        {
            var mockPost = new List <Post>
            {
                new Post {
                    Title = "Tdd One"
                },
                new Post {
                    Title = "Tdd Two"
                }
            };

            _mockPostsList.Object.AddRange(mockPost);

            //act
            var result = _blogController.Get();

            //assert
            var model = Assert.IsAssignableFrom <ActionResult <List <Post> > >(result);

            Assert.Equal(2, model.Value.Count);
        }
Esempio n. 24
0
        public async void GetBlogsTest()
        {
            object blogs = await blogController.Get(1);

            Assert.NotNull(blogs);
        }
 public void SetUp() => Blogs = BlogController.Get();
Esempio n. 26
0
        public static void RefreshBlogCache(object data)
        {
            BlogController controller = new BlogController();

            CurrentBlogPosts = controller.Get();
        }