public void MovieStore_MovieIsNull() { var list = new List <Movie> { new Movie() { MovieId = 1, Title = "Superman" }, new Movie() { MovieId = 2, Title = "Batman" } }.AsQueryable(); Mock <MovieStoreDBContext> mockContext = new Mock <MovieStoreDBContext>(); Mock <DbSet <Movie> > mockSet = new Mock <DbSet <Movie> >(); mockSet.As <IQueryable <Movie> >().Setup(m => m.GetEnumerator()).Returns(list.GetEnumerator()); Movie movie = null; mockSet.Setup(m => m.Find(It.IsAny <object>())).Returns(movie); mockContext.Setup(db => db.Movies).Returns(mockSet.Object); MoviesController controller = new MoviesController(mockContext.Object); HttpStatusCodeResult result = controller.Details(0) as HttpStatusCodeResult; Assert.AreEqual(HttpStatusCode.NotFound, (HttpStatusCode)result.StatusCode); }
//Todo: fix redirect if null public ActionResult Index(int?genusId) { ActionResult result = null; if (!genusId.HasValue) { return(RedirectToAction("Index")); } Genus genus = m_repo.GetGenus(genusId.Value); if (genus == null) { result = new HttpStatusCodeResult(HttpStatusCode.BadRequest); } else { SessionManager.Genus = genus; string url = SessionManager.RedirectUrl; if (!url.IsNullOrWhiteSpace()) { result = Redirect(url); SessionManager.RedirectUrl = string.Empty; } else { result = RedirectToAction("Index", "Default", new { Area = "Accessions" }); } } return(result); }
public void MovieStore_IndexRedirect_BadRequest() { MoviesController controller = new MoviesController(); HttpStatusCodeResult result = controller.IndexRedirect(0) as HttpStatusCodeResult; Assert.AreEqual(HttpStatusCode.BadRequest, (HttpStatusCode)result.StatusCode); }
public void MovieStore_Details_IdIsNull() { //Goal: query from out own list instead of DB var list = new List <Movie> { new Movie() { MovieID = 1, Title = "Superman 1" }, new Movie() { MovieID = 2, Title = "Superman 2" } }.AsQueryable(); Mock <MovieStoreDBContext> mockContext = new Mock <MovieStoreDBContext>(); Mock <DbSet <Movie> > mockSet = new Mock <DbSet <Movie> >(); mockSet.As <IQueryable <Movie> >().Setup(expression: m => m.GetEnumerator()).Returns(list.GetEnumerator()); mockSet.As <IQueryable <Movie> >().Setup(expression: m => m.Provider).Returns(list.Provider); mockSet.As <IQueryable <Movie> >().Setup(expression: m => m.ElementType).Returns(list.ElementType); mockSet.Setup(expression: m => m.Find(It.IsAny <Object>())).Returns(list.First()); mockContext.Setup(expression: db => db.Movies).Returns(mockSet.Object); // Arrange MoviesController controller = new MoviesController(mockContext.Object); // Act HttpStatusCodeResult result = controller.Details(id: null) as HttpStatusCodeResult; // Assert Assert.AreEqual(expected: HttpStatusCode.BadRequest, actual: (HttpStatusCode)result.StatusCode); }
public void MovieStore_Movie_IsNull() { //Step 1 var list = new List <Movie> { new Movie { MovieID = 1, Title = "Spiderman 1" }, new Movie { MovieID = 1, Title = "Spiderman 2" } }.AsQueryable(); //Step 2 Mock <MovieStoreDBContext> mockContext = new Mock <MovieStoreDBContext>(); Mock <DbSet <Movie> > mockSet = new Mock <DbSet <Movie> >(); //Step 3 mockSet.As <IQueryable <Movie> >().Setup(m => m.GetEnumerator()).Returns(list.GetEnumerator()); mockSet.As <IQueryable <Movie> >().Setup(m => m.Provider).Returns(list.Provider); mockSet.As <IQueryable <Movie> >().Setup(m => m.ElementType).Returns(list.ElementType); Movie movie = null; mockSet.Setup(m => m.Find(It.IsAny <Object>())).Returns(movie); //Step 4 mockContext.Setup(db => db.Movies).Returns(mockSet.Object); //Arrange MoviesController controller = new MoviesController(mockContext.Object); //Act HttpStatusCodeResult result = controller.Details(0) as HttpStatusCodeResult; //Assert Assert.AreEqual(HttpStatusCode.NotFound, (HttpStatusCode)result.StatusCode); }
public static void IsErrorResult(ActionResult result, int statusCode) { HttpStatusCodeResult statusCodeResult = (HttpStatusCodeResult)result; Assert.AreEqual(statusCode, statusCodeResult.StatusCode); Assert.AreEqual("Error", ((ViewResult)statusCodeResult.NextResult).ViewName); }
public void ItReturnsABadRequestHttpStatusCodeIfThereIsNoPlayerId() { int?nullPlayerId = null; HttpStatusCodeResult result = autoMocker.ClassUnderTest.Edit(nullPlayerId) as HttpStatusCodeResult; Assert.AreEqual((int)HttpStatusCode.BadRequest, result.StatusCode); }
public ActionResult RemoveTask(int id) { ActionResult operationResult; if (ModelState.IsValid) { try { using (TasksListContext context = new TasksListContext()) { context.RemoveTask(id); operationResult = new HttpStatusCodeResult(HttpStatusCode.OK); } } catch (Exception) { operationResult = new HttpStatusCodeResult(HttpStatusCode.InternalServerError); } } else { operationResult = new HttpStatusCodeResult(HttpStatusCode.BadRequest); } return(operationResult); }
public ActionResult UpdateTask(int id, string updatedDescription) { ActionResult operationResult; if (ModelState.IsValid && !string.IsNullOrWhiteSpace(updatedDescription)) { try { using (TasksListContext context = new TasksListContext()) { context.UpdateTask(id, updatedDescription); operationResult = new HttpStatusCodeResult(HttpStatusCode.OK); } } catch (Exception) { operationResult = new HttpStatusCodeResult(HttpStatusCode.InternalServerError); } } else { operationResult = new HttpStatusCodeResult(HttpStatusCode.BadRequest); } return(operationResult); }
public ActionResult AddTask(string description) { Task newTask; ActionResult operationResult; if (ModelState.IsValid && !string.IsNullOrWhiteSpace(description)) { try { using (TasksListContext context = new TasksListContext()) { newTask = new Task(description); context.AddNewTask(newTask); operationResult = new HttpStatusCodeResult(HttpStatusCode.OK); } } catch (Exception) { operationResult = new HttpStatusCodeResult(HttpStatusCode.InternalServerError); } } else { operationResult = new HttpStatusCodeResult(HttpStatusCode.BadRequest); } return(operationResult); }
public void ControllerTest() { //准备-创建控制器 ExampleController target = new ExampleController(); ////动作-调用动作方法 //ViewResult result = target.Index(); ////断言-检查结果 //Assert.AreEqual("Hello",result.ViewBag.Message); ////动作-调用动作方法 //RedirectResult result = target.Redirect(); ////断言-检查结果 //Assert.IsTrue(result.Permanent); //Assert.AreEqual("/Example/Index", result.Url); //RedirectToRouteResult result=target.Redirect(); //Assert.IsFalse(result.Permanent); //Assert.AreEqual("Example",result.RouteValues["controller"]); //Assert.AreEqual("Index", result.RouteValues["action"]); //Assert.AreEqual("MyID", result.RouteValues["ID"]); //Dictionary<string,string> dictionary=new Dictionary<string, string>(); //dictionary.Add("name","zhangsan"); //Assert.AreEqual("zhangsan", dictionary["name"]); //动作-调用动作方法 HttpStatusCodeResult result = target.StatusCode(); //断言-检查结果 Assert.AreEqual(401, result.StatusCode); }
protected bool HasErrorsRenderingPage(out ActionResult errorAction, RedirectionHandler redirection = null) { bool hasError = false; errorAction = null; var model = new LoginViewModel(); try { if (IsUserLogged()) { if (HasRole()) { model = (LoginViewModel)Session["user"]; } else { hasError = true; errorAction = new HttpStatusCodeResult(HttpStatusCode.Forbidden); } } else { hasError = true; errorAction = GetRedirection(RedirectionHandler.LOGIN, redirection); } } catch { } return(hasError); }
/// <summary> /// Return orders general data listener /// </summary> /// <param name="offset"></param> /// <param name="recCount">Records count on page</param> /// <returns></returns> public ActionResult Index(int offset = 0, int recCount = 12) { if (recCount <= 0) { recCount = 12; } if (offset <= 0) { offset = 0; } ViewBag.offset = offset + 12; ViewBag.currRecords = recCount; this.orders = new OrdersGeneralDataViewModel(); this.orders.Orders = this.repos.GetOrdersGeneralData(offset, recCount); if (this.orders.Orders == null) { HttpStatusCodeResult resp = new HttpStatusCodeResult(System.Net.HttpStatusCode.NotFound, this.repos.UnresolvedExceptions.Last().Message); return(resp); } return(View(this.orders)); }
public void ControllerTest() { //arrange MyExampleController target = new MyExampleController(); //action //ViewResult result = target.Index(); //assert //Assert.AreEqual("Homepage", result.ViewName); //if ViewResult("Homepage") //Assert.AreEqual("", result.ViewName); //if ViewResult() //Assert.AreEqual("~/Views/Derived/MyView.cshtml", result.ViewName); //if ViewResult("~/Views/Derived/MyView") //Assert.AreEqual("", result.ViewName); //Assert.IsInstanceOfType(result.ViewData.Model, typeof(System.DateTime)); //Assert.AreEqual("Hello",result.ViewBag.Hi); //RedirectResult result = target.Redirect(); //Assert.IsTrue(result.Permanent); //Assert.AreEqual("Index", result.Url); //RedirectToRouteResult result = target.Redirect(); //Assert.IsFalse(result.Permanent); //Assert.AreEqual("MyExample", result.RouteValues["conroller"]); //Assert.AreEqual("Index", result.RouteValues["action"]); //Assert.AreEqual("MyId", result.RouteValues["id"]); HttpStatusCodeResult result_2 = target.StatusCode(); Assert.AreEqual(401, result_2.StatusCode); }
// GET: ClientsOfCarWashViews/Details/5 public async Task <ActionResult> Info(int?idClientInfo, int?idClient, bool?statusPage = true) { if (idClient == null && idClientInfo == null) { var logo = new HttpStatusCodeResult(HttpStatusCode.BadRequest); return(RedirectToAction("Client")); } if (statusPage != null) { ViewBag.Page = statusPage; } var ClientWhare = Mapper.Map <IEnumerable <ClientsOfCarWashView> >(await _services.GetAll(idClientInfo)); var singlClien = ClientWhare.FirstOrDefault(x => x.IdInfoClient == idClientInfo); ClientsOfCarWashView clientsOfCarWashView = Mapper.Map <ClientsOfCarWashView>(await _services.GetId(singlClien.id)); ViewBag.ClientInfo = ClientWhare.Where(x => x.arxiv == true); if (clientsOfCarWashView == null) { return(HttpNotFound()); } return(View(clientsOfCarWashView)); }
public void Should_Have_304_Http_Status_Code_If_Response_Has_Modified_Since_Header_Matching_Page_Modified_Date() { // The file date and the browser date always match for a 304 status, the browser will never send back a more recent date, // i.e. "Has the file changed since this date I've stored for the last time it was changed?" // and *not* "has the file changed since the time right now?". // Arrange BrowserCacheAttribute attribute = new BrowserCacheAttribute(); attribute.SettingsService = GetSettingsService(); WikiController controller = CreateWikiController(attribute); ResultExecutedContext filterContext = CreateContext(controller); // (page modified date is set in CreateWikiController) filterContext.HttpContext.Request.Headers.Add("If-Modified-Since", DateTime.Today.ToString("r")); // Act attribute.OnResultExecuted(filterContext); // Assert HttpStatusCodeResult result = filterContext.Result as HttpStatusCodeResult; Assert.That(filterContext.HttpContext.Response.StatusCode, Is.EqualTo(304)); Assert.That(result.StatusCode, Is.EqualTo(304)); Assert.That(result.StatusDescription, Is.EqualTo("Not Modified")); }
public ActionResult Install([Bind(Prefix = "package-id")] string id, [Bind(Prefix = "package-version")] string version) { ActionResult ret; var pkg = App.Instance.AddIns.Repository.Get(id, version); if (pkg == null) { string message = string.Format("Package (Id: '{0}', Version: '{1}') not found.", id, version); ret = new HttpStatusCodeResult(HttpStatusCode.NotFound, message); } else { // TODO handle errors PackageResult result = App.Instance.AddIns.Install(pkg); if (result == PackageResult.PendingRestart) { string message = string.Format("Package {0} failed to install, another attempt will be made upon site restart.", pkg.Id); App.Instance.Notifications.Add(Severity.Warning, Lifetime.Application, Scope.Administration, "Pending restart", message, NotificationActions.Restart); } ret = this.Redirect(this.Url.Action("Installed")); } return(ret); }
public async Task PostFromAnUnAuthenticatedUserThatHasSentTokens5Times_ReturnsHttpStatusCode403WithCustomMessage() { TestableAccountController controller = TestableAccountController.Create(); controller.MockContextService.Setup(x => x.CurrentUserIsAuthenticated).Returns(false); const string email = "*****@*****.**"; const int accountId = 1; var existingAuthenticationToken = new AuthenticationToken { AccountId = accountId, Token = "SOME_TOKEN", NumberOfTimesSent = 5 }; var account = new Account { Email = email, Id = accountId, }; controller.AccountRepository.Accounts.Add(account); controller.AuthenticationTokenRepository.AuthenticationTokens.Add(existingAuthenticationToken); HttpStatusCodeResult result = await controller.Login(new LoginViewModel { Email = "*****@*****.**" }) as HttpStatusCodeResult; Assert.IsNotNull(result); Assert.AreEqual(403, result.StatusCode); Assert.AreEqual("Forbidden", result.StatusDescription); }
public ActionResult SignOn(string username = "", string password = "", string returnUrl = "") { //查库先省略 var user = studentService.GetUser(username, password); user.TimeSpan = DateTime.Now.ToString(); if (user == null) { var reuslt = new HttpStatusCodeResult(401, "用户名密码错误"); return(Json(reuslt)); } else { string token = Newtonsoft.Json.JsonConvert.SerializeObject(user); var ss = RSAWorker.RsaEncrypt(token); FormsAuthentication.SetAuthCookie(ss, false); if (string.IsNullOrEmpty(returnUrl)) { returnUrl = "/Home/Index"; } var reuslt = new HttpStatusCodeResult(200, returnUrl); return(Json(reuslt)); } }
public void Movie_Delete_IdIsNull() { // Goal: Query from our own list instead of the database. var list = new List <Movie> { new Movie() { MovieId = 1, Title = "Superman 1" }, new Movie() { MovieId = 2, Title = "Superman 2" } }.AsQueryable(); Mock <MovieStoreDbContext> mockContext = new Mock <MovieStoreDbContext>(); Mock <DbSet <Movie> > mockSet = new Mock <DbSet <Movie> >(); mockSet.As <IQueryable <Movie> >().Setup(m => m.GetEnumerator()).Returns(list.GetEnumerator()); mockSet.As <IQueryable <Movie> >().Setup(m => m.Provider).Returns(list.Provider); mockSet.As <IQueryable <Movie> >().Setup(m => m.ElementType).Returns(list.ElementType); mockSet.Setup(m => m.Find(It.IsAny <Object>())).Returns(list.First()); mockContext.Setup(db => db.Movies).Returns(mockSet.Object); // Arrange MoviesController controller = new MoviesController(mockContext.Object); // Act HttpStatusCodeResult result = controller.Delete(null) as HttpStatusCodeResult; // Assert Assert.AreEqual(HttpStatusCode.BadRequest, (HttpStatusCode)result.StatusCode); }
public virtual void OnException(ExceptionContext filterContext) { if (filterContext == null) { throw new ArgumentNullException("filterContext"); } if (filterContext.IsChildAction || (filterContext.ExceptionHandled || !filterContext.HttpContext.IsCustomErrorEnabled)) { return; } var innerException = filterContext.Exception; if ((new HttpException(null, innerException).GetHttpCode() != 500) || !ExceptionType.IsInstanceOfType(innerException)) { return; } var result = new HttpStatusCodeResult(StatusCode); filterContext.Result = result; filterContext.ExceptionHandled = true; filterContext.HttpContext.Response.Clear(); filterContext.HttpContext.Response.StatusCode = (int)StatusCode; filterContext.HttpContext.Response.TrySkipIisCustomErrors = true; }
public static void AssertHttpStatusCode(ActionResult result, HttpStatusCode statusCode) { Assert.IsInstanceOfType(result, typeof(HttpStatusCodeResult), "An HTTP status code was not returned."); HttpStatusCodeResult statusCodeResult = (HttpStatusCodeResult)result; Assert.AreEqual((int)statusCode, statusCodeResult.StatusCode, "The wrong HTTP status code was returned."); }
public void MovieStore_Edit_IdIsNull() { var list = new List <Movie> { new Movie { MovieId = 1, Title = "Superman 1" }, new Movie { MovieId = 2, Title = "Superman 2" }, }.AsQueryable(); //2 Mock <MovieStoreDBContext> mockContext = new Mock <MovieStoreDBContext>(); Mock <DbSet <Movie> > mockSet = new Mock <DbSet <Movie> >(); //3 mockSet.As <IQueryable <Movie> >().Setup(m => m.GetEnumerator()).Returns(list.GetEnumerator()); mockSet.As <IQueryable <Movie> >().Setup(m => m.Provider).Returns(list.Provider); mockSet.As <IQueryable <Movie> >().Setup(m => m.ElementType).Returns(list.ElementType); mockSet.Setup(m => m.Find(It.IsAny <Object>())).Returns(list.First()); //4 mockContext.Setup(db => db.Movies).Returns(mockSet.Object); //Arrage MoviesController controller = new MoviesController(mockContext.Object); //Act HttpStatusCodeResult result = controller.Edit(id: null) as HttpStatusCodeResult; //Assert Assert.AreEqual(HttpStatusCode.BadRequest, (HttpStatusCode)result.StatusCode); }
public void ItReturnsABadRequestHttpStatusCodeIfNoIdIsPassed() { int?nullGameId = null; HttpStatusCodeResult statusCodeResult = gameDefinitionControllerPartialMock.Edit(nullGameId, currentUser) as HttpStatusCodeResult; Assert.AreEqual((int)HttpStatusCode.BadRequest, statusCodeResult.StatusCode); }
public async Task <ActionResult> Done(string signature, string selectedSignMethod, string state) { Guid requestId = Guid.Empty; if (!Guid.TryParse(state, out requestId)) { ActionResult result = new HttpStatusCodeResult(HttpStatusCode.BadRequest); return(await Task.FromResult(result)); } var expectedText = this.PopRequestState(requestId); if (string.IsNullOrWhiteSpace(expectedText)) { ActionResult result = new HttpStatusCodeResult(HttpStatusCode.InternalServerError); return(await Task.FromResult(result)); } var displayModel = await signatureRequester.ValidateSignature(signature, selectedSignMethod); if (displayModel.SignText != expectedText) { ActionResult result = new HttpStatusCodeResult(HttpStatusCode.Forbidden); return(await Task.FromResult(result)); } return(this.View("SignatureResult", displayModel)); }
public HttpStatusCodeResult DeleteAgent(int id) { HttpStatusCodeResult output = new HttpStatusCodeResult(System.Net.HttpStatusCode.Conflict); try { if (id > 0) { SNMPController controller = new SNMPController(Properties.Settings.Default.ProdDatabaseConnectionString); controller.DeleteAgent(id); output = new HttpStatusCodeResult(System.Net.HttpStatusCode.OK); } else { output = new HttpStatusCodeResult(System.Net.HttpStatusCode.BadRequest); } } catch (Exception exc) { BusinessLayer.ExceptionHandling.ExceptionCore.HandleException(BusinessLayer.ExceptionHandling.ExceptionCategory.Normal, exc); output = new HttpStatusCodeResult(System.Net.HttpStatusCode.InternalServerError); } return(output); }
public HttpStatusCodeResult UpdateAgentInMonitor(int inputAgentNr, string inputAgentName, string inputIpAddress, string inputPortNr, string typeName, bool cpuCheck, bool discCheck) { HttpStatusCodeResult output = new HttpStatusCodeResult(System.Net.HttpStatusCode.OK); try { SNMPController controller = new SNMPController(Properties.Settings.Default.ProdDatabaseConnectionString); int portNr; if (int.TryParse(inputPortNr, out portNr)) { List <SNMPMonitor.BusinessLayer.Type> types = controller.GetTypes(); SNMPMonitor.BusinessLayer.Type type = null; foreach (SNMPMonitor.BusinessLayer.Type temp in types) { if (temp.Name == typeName) { type = temp; } } Agent updatedAgent = new Agent(inputAgentNr, inputAgentName, inputIpAddress, type, portNr, 1, "", "", ""); controller.UpdateAgentInDatabase(updatedAgent, cpuCheck, discCheck); output = new HttpStatusCodeResult(System.Net.HttpStatusCode.OK); } } catch (Exception exc) { BusinessLayer.ExceptionHandling.ExceptionCore.HandleException(BusinessLayer.ExceptionHandling.ExceptionCategory.Normal, exc); } return(output); }
// GET: api/Kundens public IHttpActionResult Get() { List <Customer> list = new List <Customer>(); var model = unitOfWork.Query <Kundenstamm>(); foreach (var obj in model) { list.Add(new Customer { Selektion = obj.Selektion, KDNr = obj.KDNr, Suchname = obj.Suchname, Anrede = obj.Anrede, Titel = obj.Titel, Name1 = obj.Name1, Name2 = obj.Name2, Name3 = obj.Name3, Strasse = obj.Strasse, Nation = obj.Nation, PLZ = obj.PLZ, Ort = obj.Ort, eMail = obj.eMail, Kundenart = obj.Kundenart.Oid, kdauftrgesperrt = obj.kdauftrgesperrt }); } var result = new HttpStatusCodeResult(201); return(Ok(list.ToArray())); }
public void MovieStore_Details_No_Id() { //Arrange Mock <MovieStoreDbContext> mockContext = new Mock <MovieStoreDbContext>(); Mock <DbSet <Movie> > mockSet = new Mock <DbSet <Movie> >(); var list = new List <Movie> { new Movie { MovieId = 1, Title = "Jaws" }, new Movie { MovieId = 2, Title = "Despicable Me" } }.AsQueryable(); mockSet.As <IQueryable>().Setup(m => m.Provider).Returns(list.Provider); mockSet.As <IQueryable>().Setup(m => m.GetEnumerator()).Returns(list.GetEnumerator()); mockSet.As <IQueryable>().Setup(m => m.Expression).Returns(list.Expression); mockSet.As <IQueryable>().Setup(m => m.ElementType).Returns(list.ElementType); mockSet.Setup(m => m.Find(It.IsAny <Object>())).Returns(list.First()); mockContext.Setup(db => db.Movies).Returns(mockSet.Object); //Controller needs a mock object for Dependency Injection MoviesController controller = new MoviesController(mockContext.Object); //mocDb using Moq //Act //Id is null HttpStatusCodeResult result = controller.Details(null) as HttpStatusCodeResult; //Assert Assert.AreEqual(HttpStatusCode.BadRequest, (HttpStatusCode)result.StatusCode); }
public void OnActionExecuting(ActionExecutingContext filterContext) { if (!filterContext.Controller.ViewData.ModelState.IsValid) { if (filterContext.HttpContext.Request.HttpMethod == "GET") { var result = new HttpStatusCodeResult(HttpStatusCode.BadRequest); filterContext.Result = result; } else { var result = new ContentResult(); string content = JsonConvert.SerializeObject(filterContext.Controller.ViewData.ModelState, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); result.Content = content; result.ContentType = "application/json"; filterContext.HttpContext.Response.StatusCode = 400; filterContext.Result = result; } } }
public void Cannot_EditWithouId_BadRequest() { HttpStatusCodeResult expected = new HttpStatusCodeResult(HttpStatusCode.BadRequest); int? x = null; var result = solutionController.Edit(x) as HttpStatusCodeResult; Assert.AreEqual(expected.StatusCode, result.StatusCode); }
public void Cannot_EditNonExistsSolution_NotFound() { MockDbRepository.Mock.Setup(x => x.GetSetupSolution(It.IsAny<int>())).Returns((SetupSolution)null); HttpStatusCodeResult expected = new HttpStatusCodeResult(HttpStatusCode.NotFound); var result = solutionController.Edit(It.IsAny<int>()) as HttpStatusCodeResult; Assert.AreEqual(expected.StatusCode, result.StatusCode); }
public void HttpStatusCodeAndStatusDescription() { // Arrange int unusedStatusCode = 306; // Act HttpStatusCodeResult result = new HttpStatusCodeResult(HttpStatusCode.Unused, "foobar"); // Assert Assert.Equal(unusedStatusCode, result.StatusCode); Assert.Equal("foobar", result.StatusDescription); }
public void ExecuteResult() { // Arrange Mock<ControllerContext> mockControllerContext = new Mock<ControllerContext>(); mockControllerContext.SetupSet(c => c.HttpContext.Response.StatusCode = 666).Verifiable(); HttpStatusCodeResult result = new HttpStatusCodeResult(666); // Act result.ExecuteResult(mockControllerContext.Object); // Assert mockControllerContext.Verify(); }
public void ExecuteResultWithHttpStatusCode() { // Arrange int unusedStatusCode = 306; Mock<ControllerContext> mockControllerContext = new Mock<ControllerContext>(); mockControllerContext.SetupSet(c => c.HttpContext.Response.StatusCode = unusedStatusCode).Verifiable(); HttpStatusCodeResult result = new HttpStatusCodeResult(HttpStatusCode.Unused); // Act result.ExecuteResult(mockControllerContext.Object); // Assert mockControllerContext.Verify(); }
public void Cannot_Delete_WithoutId() { HttpStatusCodeResult expected = new HttpStatusCodeResult(HttpStatusCode.BadRequest); var result = solutionController.Delete(null) as HttpStatusCodeResult; Assert.AreEqual(expected.StatusCode, result.StatusCode); }