private static ControllerContext GetControllerContext() { var controller = new TestingController(); var mockHttpContext = MockRepository.GenerateStub <HttpContextBase>(); var controllerContext = new ControllerContext(mockHttpContext, new RouteData(), controller); controller.ControllerContext = controllerContext; return(controllerContext); }
public void IsNotCompleteTaskSorted_TwoNeedsActionInList_Returns2AndPass() { //Arrange objects, creating and setting them up as necessary. TestingController controller = new TestingController(); string[] tasks = { "needsAction", "completed", "needsAction", "completed" }; //Act on an object. string[] result = controller.CountingTasks(tasks); //Assert that something is as expected. Assert.AreEqual(2, result.Length); }
public void ShouldIgnoreActionParametersThatAreNull() { var attribute = new SubControllerActionToViewDataAttribute(); var controller = new TestingController(); ActionExecutingContext context = GetFilterContext(controller); context.ActionParameters["c1"] = null; context.ActionParameters["c2"] = new SubController(); attribute.OnActionExecuting(context); Assert.That(controller.ViewData.Count, Is.EqualTo(1)); Assert.That(controller.ViewData.Get<Action>("c2"), Is.Not.Null); }
public void ShouldIgnoreActionParametersThatAreNull() { var attribute = new SubControllerActionToViewDataAttribute(); var controller = new TestingController(); ActionExecutingContext context = GetFilterContext(controller); context.ActionParameters["c1"] = null; context.ActionParameters["c2"] = new SubController(); attribute.OnActionExecuting(context); Assert.That(controller.ViewData.Count, Is.EqualTo(1)); Assert.That(controller.ViewData.Get <Action>("c2"), Is.Not.Null); }
public void ShouldPushTheActionOfEachSubcontrollerIntoViewdata() { var c1 = new SubController(); var c2 = new SubController(); var attribute = new SubControllerActionToViewDataAttribute(); var controller = new TestingController(); ActionExecutingContext context = GetFilterContext(controller); context.ActionParameters["c1"] = c1; context.ActionParameters["c2"] = c2; attribute.OnActionExecuting(context); Assert.That(controller.ViewData.Get<Action>("c1"), Is.Not.Null); Assert.That(controller.ViewData.Get<Action>("c2"), Is.Not.Null); }
public void TestDeleteValueFromHttpContext() { // arrange this.InitialTestHttpContext(); using (var httpContextLifetimeManger = new HttpContextLifetimeManager<TestingController>()) { var testingController = new TestingController(); // act httpContextLifetimeManger.SetValue(testingController); httpContextLifetimeManger.RemoveValue(); object controllerFromHttpContext = httpContextLifetimeManger.GetValue(); // assert Assert.Null(controllerFromHttpContext); } }
public void SelfCareQuiz_Result1_ReturnsResult1AndPass() { TestingController controller = new TestingController(); //variables to plug in //number of 1's is clearly greater than all the others int num1 = 7; int num2 = 1; int num3 = 2; int num4 = 3; string expectedResult = "result1"; string actualResult = controller.QuizAlgorithmTest(num1, num2, num3, num4); Assert.AreEqual(actualResult, expectedResult); }
public void ShouldPushTheActionOfEachSubcontrollerIntoViewdata() { var c1 = new SubController(); var c2 = new SubController(); var attribute = new SubControllerActionToViewDataAttribute(); var controller = new TestingController(); ActionExecutingContext context = GetFilterContext(controller); context.ActionParameters["c1"] = c1; context.ActionParameters["c2"] = c2; attribute.OnActionExecuting(context); Assert.That(controller.ViewData.Get <Action>("c1"), Is.Not.Null); Assert.That(controller.ViewData.Get <Action>("c2"), Is.Not.Null); }
public void TestDeleteValueFromHttpContext() { // arrange this.InitialTestHttpContext(); using (var httpContextLifetimeManger = new HttpContextLifetimeManager <TestingController>()) { var testingController = new TestingController(); // act httpContextLifetimeManger.SetValue(testingController); httpContextLifetimeManger.RemoveValue(); object controllerFromHttpContext = httpContextLifetimeManger.GetValue(); // assert Assert.Null(controllerFromHttpContext); } }
public void TestSetValueAndSetValueFromHttpContext() { // arrange this.InitialTestHttpContext(); using (var httpContextLifetimeManger = new HttpContextLifetimeManager<TestingController>()) { var testingController = new TestingController(); // act httpContextLifetimeManger.SetValue(testingController); object controllerFromHttpContext = httpContextLifetimeManger.GetValue(); // assert Assert.NotNull(controllerFromHttpContext); Assert.IsType<TestingController>(controllerFromHttpContext); Assert.Same(testingController, controllerFromHttpContext); } }
public void SelfCareQuiz_TieBreaker_ReturnsResult1AndPass() { TestingController controller = new TestingController(); //variables to plug in //number of 1's & 2's is clearly greater than all the others //tie breaker for 1 and 2s being equal is result 1 int num1 = 5; int num2 = 5; int num3 = 2; int num4 = 1; string expectedResult = "result1"; string actualResult = controller.QuizAlgorithmTest(num1, num2, num3, num4); Assert.AreEqual(actualResult, expectedResult); }
public void TestSetValueAndSetValueFromHttpContext() { // arrange this.InitialTestHttpContext(); using (var httpContextLifetimeManger = new HttpContextLifetimeManager <TestingController>()) { var testingController = new TestingController(); // act httpContextLifetimeManger.SetValue(testingController); object controllerFromHttpContext = httpContextLifetimeManger.GetValue(); // assert Assert.NotNull(controllerFromHttpContext); Assert.IsType <TestingController>(controllerFromHttpContext); Assert.Same(testingController, controllerFromHttpContext); } }
public void Setup() { controller = new TestingController().SetupControllerContext(); attr = new ModelStateToTempDataAttribute(); context = new ActionExecutedContext(controller.ControllerContext, MockRepository.GenerateStub <ActionDescriptor>(), false, null); }
private static ControllerContext GetControllerContext() { var controller = new TestingController(); var mockHttpContext = MockRepository.GenerateStub<HttpContextBase>(); var controllerContext = new ControllerContext(mockHttpContext, new RouteData(), controller); controller.ControllerContext = controllerContext; return controllerContext; }
public void Setup() { controller = new TestingController().SetupControllerContext(); attr = new ModelStateToTempDataAttribute(); context = new ActionExecutedContext(controller.ControllerContext, MockRepository.GenerateStub<ActionDescriptor>(),false, null); }