public void SurveyIsNull() { var response = controller.Create(null); Assert.AreEqual(response.StatusCode, HttpStatusCode.BadRequest); Assert.AreEqual(((System.Net.Http.ObjectContent)response.Content).Value, Service.Constants.Messages.SurveyDataPassedIsNullOrCouldNotBeParsed); }
public void ActionThrowsException() { TestCrmService service = new TestCrmService(context); service.Switch = DataSwitch.ActionThrowsError; controller = new SurveyController(surveyService, service); controller.Request = new System.Net.Http.HttpRequestMessage(); controller.Request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration()); var response = controller.Create(survey); Assert.AreEqual(response.StatusCode, HttpStatusCode.GatewayTimeout); }
public void ServiceLayerThrowsException() { TestCrmService service = new TestCrmService(context); service.Switch = DataSwitch.Created; controller = new SurveyController(surveyService, null); controller.Request = new System.Net.Http.HttpRequestMessage(); controller.Request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration()); survey = new List <Response>(); survey.Add(new Response() { Id = 123, CookieUID = "123", Mode = "WEB" }); var response = controller.Create(survey); Assert.AreEqual(response.StatusCode, HttpStatusCode.InternalServerError); }
public async Task GivenSurvey_WhenCreate_ThenCreatedSuccessful() { //?Given var surveyModel = new SurveyModel(); var survey = new Survey(); _mockMapper.Setup(x => x.Map <Survey>(surveyModel)) .Returns(survey) .Verifiable(); _mockManager.Setup(x => x.Create(survey)) .Verifiable(); //?When var result = await _surveyController.Create(surveyModel); //?Then Assert.IsType <OkResult>(result); _mockMapper.Verify(); _mockManager.Verify(); }
public void Create_RequestOK_ReturnsRedirectToNewSurvey() { var surveyMock = new Mock <ISurveyService>(); var dbMock = new Mock <IApplicationDBContext>(); var userDataMock = new Mock <DbSet <ApplicationUser> >().SetupData(new[] { new ApplicationUser() { UserName = "******" } }); dbMock.SetupGet(db => db.Users).Returns(userDataMock.Object); var securityMock = new Mock <ISecurity>(); securityMock.SetupGet(s => s.UserName).Returns("tyler"); var subject = new SurveyController(dbMock.Object, surveyMock.Object, securityMock.Object); var result = subject.Create("Question?").Result; Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult)); surveyMock.Verify(d => d.AddAsync(It.Is <Survey>(s => s.Owner.UserName == "tyler" && s.Description == "Question?"))); }