public void Get_WhenCalled_ReturnsOkResult() { // Act var okResult = _controller.GetAll(); // Assert Assert.IsType <OkObjectResult>(okResult.Result); }
public void GetAllTest() { var fileMock = new Mock <IFormFile>(); //Setup mock file using a memory stream var content = "Hello World from a Fake File"; var fileName = "test.mp4"; var ms = new MemoryStream(); var writer = new StreamWriter(ms); writer.Write(content); writer.Flush(); ms.Position = 0; fileMock.Setup(_ => _.OpenReadStream()).Returns(ms); fileMock.Setup(_ => _.FileName).Returns(fileName); fileMock.Setup(_ => _.Length).Returns(ms.Length); var postMockOject = new Mock <IPost>(); postMockOject.Setup(r => r.GetAll(It.IsAny <PaginationModel>())).Returns(ValueFunction); var mailSeviceObject = new Mock <IMailService>(); var loggerObject = new Mock <ILogger <PostController> >(); var userObject = new Mock <IUser>(); var photoUploadObject = new Mock <IPhoto>(); var youTubeObject = new Mock <IYoutube>(); var videoObject = new Mock <IVideo>(); var mapper = new Mock <IMapper>(); var photoAccessorObject = new Mock <IPhotoAccessor>(); var redisObject = new Mock <IRedis>(); var postController = new PostController(postMockOject.Object, mailSeviceObject.Object, loggerObject.Object, userObject.Object, photoUploadObject.Object, youTubeObject.Object, mapper.Object, photoAccessorObject.Object, videoObject.Object, redisObject.Object); var result = postController.GetAll(It.IsAny <PaginationModel>()); Assert.IsType <ObjectResult>(result); }
public void Post_GetAll_ReturnsAllPosts() { var result = _postController.GetAll(); List <Post> posts = result.ToList(); Assert.Equal(_dummyContext.Posts.Count(), posts.Count()); }
public string TestAdd() { var pc = new PostController(); var uniqueName = "Post on " + DateTime.Now.ToString(); pc.Add(new api.Models.Post() { Name = uniqueName, Title = "Test Item", Contents = "Test Contents" }); int changes = pc.SaveChanges(); Assert.AreEqual(1, changes); var all = pc.GetAll().Where(p => p.Name == uniqueName).ToList(); var count = all.Count(); Assert.AreEqual(1, count); return uniqueName; }
public async Task GetAll_ShouldReturnAllPosts() { var mock = new Mock <IPostRepository>(); var dbPostList = DbInitializer.GenerateListOfPost(); mock.Setup(repo => repo.GetAll()).Returns(Task.FromResult(dbPostList as IEnumerable <Post>)); var controller = new PostController(mock.Object); var actionResult = await controller.GetAll(); Assert.IsNotNull(actionResult); OkObjectResult result = actionResult as OkObjectResult; Assert.IsNotNull(result); var resultValue = result.Value as List <PostEnhanceDTO>; Assert.AreEqual(dbPostList.Count, resultValue.Count); }
public void GetAllPosts() { var result = controller.GetAll(); Assert.Equal(posts, result.Value); }