Ejemplo n.º 1
0
        public void Accepts_Null()
        {
            var viewPage = new AutoTypeViewPageTestingSubclass <TestViewData>();

            viewPage.SetViewData(null);
            Assert.IsNull(viewPage.ViewData.Model);
        }
Ejemplo n.º 2
0
        public void Accepts_Correct_Type_Without_Conversion()
        {
            var viewPage = new AutoTypeViewPageTestingSubclass <TestViewData>();
            var data     = new TestViewData();

            viewPage.SetViewData(new ViewDataDictionary(data));
            Assert.AreSame(data, viewPage.ViewData.Model, "ViewData was not set without conversion");
        }
Ejemplo n.º 3
0
        public void Accepts_IDictionary()
        {
            var viewPage = new AutoTypeViewPageTestingSubclass <TestViewData>();

            var data     = new ViewDataDictionary();
            var uriValue = new Uri("http://www.google.com/");

            data["StringValue"]      = "hello";
            data["BoolValue"]        = true;
            data["UriValue"]         = uriValue;
            data["NonExistentValue"] = new object();

            viewPage.SetViewData(data);
            Assert.AreEqual("hello", viewPage.ViewData.Model.StringValue);
            Assert.AreEqual(true, viewPage.ViewData.Model.BoolValue);
            Assert.AreSame(uriValue, viewPage.ViewData.Model.UriValue);
        }
Ejemplo n.º 4
0
        public void Accepts_Anonymous_Type()
        {
            var viewPage = new AutoTypeViewPageTestingSubclass <TestViewData>();

            var uriValue = new Uri("http://www.google.com/");

            viewPage.SetViewData(new ViewDataDictionary(new
            {
                StringValue         = "nice",
                BoolValue           = true,
                UriValue            = uriValue,
                SomeOtherValue      = new object(),
                SomeRandomNullValue = (object)null
            }));

            Assert.AreEqual("nice", viewPage.ViewData.Model.StringValue);
            Assert.AreEqual(true, viewPage.ViewData.Model.BoolValue);
            Assert.AreSame(uriValue, viewPage.ViewData.Model.UriValue);
        }