public void Create_Should_Call_CommandBus_When_Api_Called() { //Arrange var command = CommandFactory.BuildACommandOfType().CreateQuestion; //Act _controller.Create(command); //Assert _commandBus.Verify(x => x.Dispatch(command)); }
public void Create_ModelIsValid_ReturnsCreatedAtAction() { //Arrange _questionService.Setup(s => s.CreateEntityAsync(_question)); //Act var actionResult = _questionController.Create(_question); //Assert actionResult.Result.Should().BeOfType <CreatedAtActionResult>(); }
public void QuestionsController_Create_Get_Should_Return_View() { //Arrange var mockedService = new Mock <IQuestionService>(); MapperHelper helper = new MapperHelper(); QuestionController controller = new QuestionController(mockedService.Object, helper); //Act var result = controller.Create(); //Assert Assert.IsInstanceOf <ViewResult>(result); }
public void PostCreateQuestion() { var res = controller.Create(questions[1]); Assert.IsInstanceOfType(res, typeof(RedirectToRouteResult)); var redirectRes = res as RedirectToRouteResult; Assert.AreEqual("Test", redirectRes.RouteValues["controller"]); Assert.AreEqual("Details", redirectRes.RouteValues["action"]); Assert.AreEqual(questions[1].TestID, redirectRes.RouteValues["id"]); mockRepository.Verify(r => r.Insert(questions[1])); mockRepository.Verify(r => r.Save()); }
public void QuestionController_Create_Should_Call_Service_Create() { //Arrange QuestionViewModel model = new QuestionViewModel() { Id = 0, Title = "test" }; ApplicationUser user = new ApplicationUser() { UserName = "******" }; var mockedProvider = new Mock <IEfSociumDataProvider>(); mockedProvider.Setup(p => p.FindUserByUsername(It.IsAny <string>())).Returns(user); var mockedService = new Mock <IQuestionService>(); mockedService.Setup(s => s.GetProvider).Returns(mockedProvider.Object); mockedService.Setup(s => s.Create(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())); var helper = new MapperHelper(); var mockPrincipal = new Mock <IPrincipal>(); mockPrincipal.SetupGet(p => p.Identity.Name).Returns("Pesho"); mockPrincipal.Setup(p => p.IsInRole("User")).Returns(true); // create mock controller context var mockContext = new Mock <ControllerContext>(); mockContext.SetupGet(p => p.HttpContext.User).Returns(mockPrincipal.Object); mockContext.SetupGet(p => p.HttpContext.Request.IsAuthenticated).Returns(true); QuestionController controller = new QuestionController(mockedService.Object, helper) { ControllerContext = mockContext.Object }; //Act controller.Create("test", model); //Assert mockedService.Verify(s => s.Create(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()), Times.Once); }