public void HtmlHelperForEnablesLocalHelperMethods() { //arrange var controller = new FooController { ControllerContext = new ControllerContext() }; var viewContext = new ViewContext { ViewData = new ViewDataDictionary { TemplateInfo = new TemplateInfo { HtmlFieldPrefix = "topprefix" } }, Controller = controller, View = new Mock <IView>().Object, TempData = new TempDataDictionary(), Writer = TextWriter.Null }; var viewDataContainer = new Mock <IViewDataContainer>(); viewDataContainer.SetupGet(o => o.ViewData).Returns(() => new ViewDataDictionary()); var html = new HtmlHelper(viewContext, viewDataContainer.Object); var localHelper = html.HtmlHelperFor(new { SomeString = "foo" }, "prefix"); //act var result = localHelper.LabelFor(p => p.SomeString, "bar", null); //assert Assert.AreEqual(@"<label for=""prefix_SomeString"">bar</label>", result.ToString()); }
public void TestUnauthenticated() { var controller = new FooController(); controller.SetupFakeControllerContext(); Assert.IsTrue(new ActionInvokerExpecter<HttpUnauthorizedResult>().InvokeAction( controller.ControllerContext, "Details")); }
public void DoSomething_AnyString_ReturnsTrue() { var mockFoo = new Mock <IFoo>(); mockFoo.Setup(foo => foo.DoSomething(It.IsAny <string>())).Returns(true); FooController fc = new FooController(mockFoo.Object); Assert.That(fc.DoSomething("ping"), Is.True); }
public void EnsureNewFoosAreSaved() { var mockFooSaver = new Mock <IFooSaverService>(); var systemUnderTest = new FooController(mockFooSaver.Object); systemUnderTest.PersistTheFoo(new Foo { Name = "New Foo", ExpiryDate = new DateTime(2038, 1, 1) }); mockFooSaver.Verify(m => m.Save(It.IsAny <Foo>()), Times.Once); }
public void Verify_Index_Is_Decorated_With_My_Attribute() { var controller = new FooController(); var type = controller.GetType(); var methodInfo = type.GetMethod("Index"); var attributes = methodInfo.GetCustomAttributes(typeof(MyAttribute), true); Assert.IsTrue(attributes.Any(), "MyAttribute found on Index"); Assert.IsTrue(((MyAttribute)attr[0]).baz); }
public void DynamicObjectResultValue_DynamicCollection_Index_at_0_Should_Not_be_Null() { //Arrange var controller = new FooController(); //Act var result = controller.GetAnonymousCollection() as JsonResult; dynamic jsonCollection = result.Value.AsDynamicObject(); //Assert Assert.IsNotNull(jsonCollection[0]); }
public void DynamicObjectResultValue_DynamicCollection_Count_Should_Be_20() { //Arrange var controller = new FooController(); //Act var result = controller.GetAnonymousCollection() as JsonResult; //Assert dynamic jsonCollection = result.Value.AsDynamicObject(); Assert.AreEqual(20, jsonCollection.Count); }
public void is_index_returns_model_type_of_iqueryable_foo() { //Arrange //Create the controller instance FooController fooController = new FooController(fooRepo); //Act var indexModel = fooController.Index().Model; //Assert Assert.IsInstanceOfType(indexModel, typeof(IQueryable <Foo>)); }
public void is_details_returns_type_of_HttpNotFoundResult() { //Arrange //Create the controller instance FooController fooController = new FooController(fooRepo); //Act var detailsResult = fooController.Details(5); //Assert Assert.IsInstanceOfType(detailsResult, typeof(HttpNotFoundResult)); }
public void is_index_returns_iqueryable_foo_count_of_4() { //Arrange //Create the controller instance FooController fooController = new FooController(fooRepo); //Act var indexModel = (IQueryable <object>)fooController.Index().Model; //Assert Assert.AreEqual <int>(4, indexModel.Count()); }
public void DynamicObjectResultValue_Member_Should_Exist() { //Arrange var controller = new FooController(); //Act var result = controller.GetAnonymousObject() as JsonResult; //Assert dynamic obj = result.Value.AsDynamicObject(); Assert.IsNotNull(obj); Assert.AreEqual(1, obj.id); Assert.AreEqual("Foo", obj.name); Assert.AreEqual(3, obj.name.Length); Assert.AreEqual("Bar", obj.type); }
public void DynamicObjectResultValue_DynamicCollection_Should_Convert_To_IEnumerable() { //Arrange var controller = new FooController(); //Act var result = controller.GetAnonymousCollection() as JsonResult; dynamic jsonCollection = result.Value.AsDynamicObject(); int count = 0; foreach (var value in jsonCollection) { count++; } //Assert Assert.IsTrue(count > 0); }
public void GetControllerInstance_GivenRequestContextAndControllerType_ShouldResolveControllerType() { //---------------Set up test pack------------------- var kernel = Substitute.For<IKernel>(); var windsorControllerFactory = new WindsorControllerFactory_EXPOSES_GetControllerInstance(kernel); var requestContext = new RequestContext(); var controllerType = typeof (int); var expected = new FooController(); kernel.Resolve(controllerType).Returns(expected); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- var result = windsorControllerFactory.BaseGetControllerInstance(requestContext, controllerType); //---------------Test Result ----------------------- Assert.AreEqual(expected, result); }
public void TryParse_AnyString_ReturnsTrueAndOutsAck() { var mockFoo = new Mock <IFoo>(); var outString = "ack"; mockFoo.Setup(foo => foo.TryParse("ping", out outString)).Returns(true); FooController fc = new FooController(mockFoo.Object); var resultString = ""; Assert.Multiple(() => { Assert.That(fc.TryParse("ping", out resultString), Is.True); Assert.That(resultString, Is.EqualTo("ack")); }); }
public void SetUp() { var config = new HttpConfiguration(); config.Routes.MapHttpRoute( name: "Default", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional }); var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost"); request.Properties[HttpPropertyKeys.HttpConfigurationKey] = config; request.Properties[HttpPropertyKeys.HttpRouteDataKey] = new HttpRouteData(new HttpRoute()); controller = new FooController { Request = request }; }
public void DynamicObjectResultValue_DynamicCollection() { //Arrange var controller = new FooController(); //Act var result = controller.GetAnonymousCollection() as JsonResult; //Assert dynamic jsonCollection = result.Value; foreach (object value in jsonCollection) { dynamic json = value.AsDynamicObject(); Assert.IsNotNull(json.id, "JSON record does not contain \"id\" required property."); Assert.IsNotNull(json.name, "JSON record does not contain \"name\" required property."); Assert.IsNotNull(json.type, "JSON record does not contain \"type\" required property."); } }
public void DynamicObjectResultValue_DynamicCollection_Should_Be_Indexable() { //Arrange var controller = new FooController(); //Act var result = controller.GetAnonymousCollection() as JsonResult; dynamic jsonCollection = result.Value.AsDynamicObject(); //Assert for (var i = 0; i < jsonCollection.Count; i++) { var json = jsonCollection[i]; Assert.IsNotNull(json); Assert.IsNotNull(json.id, "JSON record does not contain \"id\" required property."); Assert.IsNotNull(json.name, "JSON record does not contain \"name\" required property."); Assert.IsNotNull(json.type, "JSON record does not contain \"type\" required property."); } }
public void TestUnauthorized() { var controller = new FooController(); controller.SetupFakeControllerContext(new AuthenticatedUser { Name = "*****@*****.**", Permissions = new List<string> { "Sem permissão" } }); try { Assert.IsTrue(new ActionInvokerExpecter<ViewResult>().InvokeAction(controller.ControllerContext, "Details")); Assert.Fail("Ele não deveria ter permissão para passar por aqui! Se tem permissão está errado!"); } catch (HttpException exception) { Assert.AreEqual(403, exception.GetHttpCode()); Assert.AreEqual("Unauthorized Request", exception.Message); } }
public void PersistingNullFooMustThrow() { var systemUnderTest = new FooController(new Mock <IFooSaverService>().Object); Assert.Throws <ArgumentNullException>(() => systemUnderTest.PersistTheFoo(null)); }
public void HtmlHelperForEnablesLocalHelperMethods() { //arrange var controller = new FooController { ControllerContext = new ControllerContext() }; var viewContext = new ViewContext { ViewData = new ViewDataDictionary { TemplateInfo = new TemplateInfo { HtmlFieldPrefix = "topprefix" } }, Controller = controller, View = new Mock<IView>().Object, TempData = new TempDataDictionary(), Writer = TextWriter.Null }; var viewDataContainer = new Mock<IViewDataContainer>(); viewDataContainer.SetupGet(o => o.ViewData).Returns(() => new ViewDataDictionary()); var html = new HtmlHelper(viewContext, viewDataContainer.Object); var localHelper = html.HtmlHelperFor(new {SomeString = "foo"}, "prefix"); //act var result = localHelper.LabelFor(p => p.SomeString, "bar", null); //assert Assert.AreEqual(@"<label for=""prefix_SomeString"">bar</label>", result.ToString()); }
public void Setup() { _fooController = new FooController(); }
public FooController_Fixture() { modelRepo = MockRepository.GenerateStrictMock <IRepository <Foo> >(); controller = new FooController(modelRepo); }
public FooController_Fixture() { modelRepo = MockRepository.GenerateStrictMock<IRepository<Foo>>(); controller = new FooController(modelRepo); }
public void ShouldThrowIfRedirectWrongTarget() { var controller = new FooController(); controller.RedirectToAction((BarController c) => Console.WriteLine(c.Value)); }
public void Setup() { _sut = new FooController(); _sut.Configuration = new System.Web.Http.HttpConfiguration(); _sut.Request = new System.Net.Http.HttpRequestMessage(); }