public async Task ForSession_ReturnsIdeasForSession(int testSessionId) { // Arrange var fixture = new Fixture(); var newIdea = fixture.Create <NewIdeaModel>(); var validatorMock = new Mock <IValidatorStrategy <NewIdeaModel> >(); validatorMock.Setup(x => x.IsValid(newIdea)).Returns(true); var mockRepo = new Mock <IBrainstormSessionRepository>(); mockRepo.Setup(repo => repo.GetByIdAsync(testSessionId)) .ReturnsAsync(GetTestSession()); var controller = new IdeasController(mockRepo.Object, validatorMock.Object); // Act var result = await controller.ForSession(testSessionId); // Assert var okResult = Assert.IsType <OkObjectResult>(result); var returnValue = Assert.IsType <List <IdeaDTO> >(okResult.Value); var idea = returnValue.FirstOrDefault(); Assert.Equal("One", idea.Name); }
public void ForSessionReturnsHttpNotFoundForInvalidSession() { var mockRepo = new Mock <IBrainstormSessionRepository>(); int testSessionId = 123; mockRepo.Setup(r => r.GetById(testSessionId)).Returns((BrainstormSession)null); var controller = new IdeasController(mockRepo.Object); var result = Assert.IsType <HttpNotFoundObjectResult>(controller.ForSession(testSessionId)); }
public void ForSessionReturnsIdeasForSession() { var mockRepo = new Mock <IBrainstormSessionRepository>(); int testSessionId = 123; mockRepo.Setup(r => r.GetById(testSessionId)).Returns(GetTestSession()); var controller = new IdeasController(mockRepo.Object); var result = Assert.IsType <HttpOkObjectResult>(controller.ForSession(testSessionId)); var returnValue = Assert.IsType <List <IdeaDTO> >(result.Value); var idea = returnValue.FirstOrDefault(); Assert.Equal("One", idea.name); }
public void ReturnsIdeasForSession() { var mockRepo = new Mock <IBrainStormSessionRepository>(); int testSessionId = 123; mockRepo.Setup(r => r.GetById(testSessionId)).Returns(GetTestSession()); var controller = new IdeasController(mockRepo.Object); var result = Assert.IsType <ObjectResult>(controller.ForSession(testSessionId)).Value as IEnumerable <dynamic>; dynamic idea = result.FirstOrDefault(); // this requires InternalsVisibleTo on the SUT project Assert.Equal("One", idea.name); }
public async Task ForSession_ResturnsHttpNotFound_ForInvalidSession() { int testSessionId = 123; var mockRepo = new Mock <IBrainstormSessionRepository>(); mockRepo.Setup(x => x.GetByIdAsync(testSessionId)) .ReturnsAsync((BrainstormSession)null); var controller = new IdeasController(mockRepo.Object); var result = await controller.ForSession(testSessionId); var notFoundObjectResult = Assert.IsType <NotFoundObjectResult>(result); Assert.Equal(testSessionId, notFoundObjectResult.Value); }
public async Task ForSession_ResturnsIdeasForSession() { int testSessionId = 1; var mockRepo = new Mock <IBrainstormSessionRepository>(); mockRepo.Setup(x => x.GetByIdAsync(testSessionId)) .ReturnsAsync((BrainstormSession)null); var controller = new IdeasController(mockRepo.Object); var result = await controller.ForSession(testSessionId); var okResult = Assert.IsType <OkObjectResult>(result); var returnValue = Assert.IsType <List <IdeaDTO> >(okResult.Value); var idea = returnValue.FirstOrDefault(); Assert.Equal("One", idea.Name); }
public async Task ForSession_ReturnsHttpNotFound_ForInvalidSession() { // Arrange int testSessionId = 123; var mockRepo = new Mock <IBrainstormSessionRepository>(); mockRepo.Setup(repo => repo.GetByIdAsync(testSessionId)) .ReturnsAsync((BrainstormSession)null); var controller = new IdeasController(mockRepo.Object); // Act var result = await controller.ForSession(testSessionId); // Assert Assert.That(result, Is.TypeOf <NotFoundObjectResult>()); var notFoundObjectResult = result as NotFoundObjectResult; Assert.AreEqual(testSessionId, notFoundObjectResult.Value); }
public async Task ForSession_ReturnsIdeasForSession() { // Arrange int testSessionId = 123; var mockRepo = new Mock <IBrainstormSessionRepository>(); mockRepo.Setup(repo => repo.GetByIdAsync(testSessionId)).Returns(Task.FromResult(GetTestSession())); var controller = new IdeasController(mockRepo.Object); // Act var result = await controller.ForSession(testSessionId); // Assert var okResult = Assert.IsType <OkObjectResult>(result); var returnValue = Assert.IsType <List <IdeaDTO> >(okResult.Value); var idea = returnValue.FirstOrDefault(); Assert.Equal("One", idea.Name); }
public async Task ForSession_ReturnsIdeasForSession() { // Arrange int testSessionId = 123; var mockRepo = new Mock <IBrainstormSessionRepository>(); mockRepo.Setup(repo => repo.GetByIdAsync(testSessionId)) .ReturnsAsync(_session); var controller = new IdeasController(mockRepo.Object); // Act var result = await controller.ForSession(testSessionId); // Assert Assert.That(result, Is.TypeOf <OkObjectResult>()); var okResult = result as OkObjectResult; Assert.That(okResult.Value, Is.TypeOf <List <IdeaDTO> >()); var returnValue = okResult.Value as List <IdeaDTO>; var idea = returnValue.FirstOrDefault(); Assert.AreEqual("One", idea.Name); }
public async Task ForSession_ReturnsHttpNotFound_ForInvalidSession() { // Arrange var testSessionId = 123; var fixture = new Fixture(); var newIdea = fixture.Create <NewIdeaModel>(); var validatorMock = new Mock <IValidatorStrategy <NewIdeaModel> >(); validatorMock.Setup(x => x.IsValid(newIdea)).Returns(true); var mockRepo = new Mock <IBrainstormSessionRepository>(); mockRepo.Setup(repo => repo.GetByIdAsync(testSessionId)) .ReturnsAsync((BrainstormSession)null); var controller = new IdeasController(mockRepo.Object, validatorMock.Object); // Act var result = await controller.ForSession(testSessionId); // Assert var notFoundObjectResult = Assert.IsType <NotFoundObjectResult>(result); Assert.Equal(testSessionId, notFoundObjectResult.Value); }