Inheritance: BaseODataController
コード例 #1
0
        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());
        }
コード例 #2
0
 public void TestUnauthenticated()
 {
     var controller = new FooController();
     controller.SetupFakeControllerContext();
     Assert.IsTrue(new ActionInvokerExpecter<HttpUnauthorizedResult>().InvokeAction(
         controller.ControllerContext, "Details"));
 }
コード例 #3
0
        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);
        }
コード例 #4
0
    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);
    }
コード例 #5
0
    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);
    }
コード例 #6
0
    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]);
    }
コード例 #7
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);
    }
コード例 #8
0
        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>));
        }
コード例 #9
0
        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));
        }
コード例 #10
0
        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());
        }
コード例 #11
0
    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);
    }
コード例 #12
0
    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);
    }
コード例 #13
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);
        }
コード例 #14
0
        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"));
            });
        }
コード例 #15
0
    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
        };
    }
コード例 #16
0
    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.");
        }
    }
コード例 #17
0
    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.");
        }
    }
コード例 #18
0
        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);
            }
        }
コード例 #19
0
    public void PersistingNullFooMustThrow()
    {
        var systemUnderTest = new FooController(new Mock <IFooSaverService>().Object);

        Assert.Throws <ArgumentNullException>(() => systemUnderTest.PersistTheFoo(null));
    }
コード例 #20
0
        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());
        }
コード例 #21
0
 public void Setup()
 {
     _fooController = new FooController();
 }
コード例 #22
0
 public FooController_Fixture()
 {
     modelRepo  = MockRepository.GenerateStrictMock <IRepository <Foo> >();
     controller = new FooController(modelRepo);
 }
コード例 #23
0
 public FooController_Fixture()
 {
     modelRepo = MockRepository.GenerateStrictMock<IRepository<Foo>>();
       controller = new FooController(modelRepo);
 }
コード例 #24
0
 public void ShouldThrowIfRedirectWrongTarget()
 {
     var controller = new FooController();
     controller.RedirectToAction((BarController c) => Console.WriteLine(c.Value));
 }
コード例 #25
0
 public void Setup()
 {
     _sut = new FooController();
     _sut.Configuration = new System.Web.Http.HttpConfiguration();
     _sut.Request       = new System.Net.Http.HttpRequestMessage();
 }