Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,141 @@
2009-10-02 Marek Habersack <mhabersack@novell.com>
* DynamicValidatorTest.cs: added.
2009-09-18 Marek Habersack <mhabersack@novell.com>
* DynamicControlTest.cs: FieldTemplate_1 - fixed fake edit
postback for Mono.
2009-09-15 Marek Habersack <mhabersack@novell.com>
* FieldTemplateFactoryTest.cs: implemented tests for
BuildVirtualPath, GetFieldTemplateVirtualPath and PreprocessMode.
2009-09-10 Marek Habersack <mhabersack@novell.com>
* DynamicControlTest.cs: added seveal tests for DataField and UIHint
2009-07-14 Marek Habersack <mhabersack@novell.com>
* FieldTemplateFactoryTest.cs: added
* DynamicControlTest.cs: added TearDown method to clean up after
non-default field template tests.
Added tests for GetAttribute, HtmlEncode, FormattingOptions, Mode,
NullDisplayText, SetAttribute, ValidationGroup.
2009-07-08 Marek Habersack <mhabersack@novell.com>
* DynamicControlTest.cs: added tests for ApplyFormatInEditMode,
Column, ConvertEmptyStringToNull, CssClass, DataField,
DataFormatString, FieldTemplate, Table, UIHint
2009-07-03 Marek Habersack <mhabersack@novell.com>
* DynamicControlTest.cs: added
2009-06-27 Marek Habersack <mhabersack@novell.com>
* DynamicDataExtensionsTest.cs: added test for ConvertEditedValue
* MetaModelTest.cs: added test for DynamicDataFolderVirtualPath
* DynamicDataRouteHandlerTest.cs: implemented tests for
CreateHandler (one of them isn't working atm),
GetCustomVirtualPagePath, GetScaffoldVirtualPagePath,
GetRequestMetaTable, SetRequestMetaTable
2009-06-26 Marek Habersack <mhabersack@novell.com>
* DynamicDataRouteTest.cs: MyDataContext3 is safely registered in
the fixture setup method.
Enabled the GetTableFromRouteData3 and GetRouteData tests - the
work fine now.
Added test for the RouteHandler property.
* DynamicDataRouteHandlerTest.cs: added tests for the constructor
and the Model property.
2009-06-25 Marek Habersack <mhabersack@novell.com>
* MetaTableTest.cs: new GetVirtualPath tests.
* DynamicDataRouteTest.cs: added tests for route.Defaults
modifications on class init.
* DynamicDataRouteHandlerTest.cs: added
2009-06-18 Marek Habersack <mhabersack@novell.com>
* MetaColumnTest.cs: added test for SortExpression
2009-06-17 Marek Habersack <mhabersack@novell.com>
* MetaColumnTest.cs: added another data context.
Added tests for EntityTypeProperty, HtmlEncode, IsBinaryData,
IsCustomProperty, IsFloatingPoint, IsForeignKeyComponent,
IsGenerated, IsInteger, IsLongString, IsPrimaryKey, IsReadOnly,
IsString, MaxLength, Model, Name, NullDisplayText, Provider,
RequiredErrorMessage, Scaffold, Table, TypeCode, UIHint.
2009-06-15 Marek Habersack <mhabersack@novell.com>
* MetaColumnTest.cs: added
2009-06-12 Marek Habersack <mhabersack@novell.com>
* MetaTableTest.cs: tests use single data model provider now.
Implemented tests for IsReadOnly, ListActionPath, Model, Name,
Provider, Scaffold, SortColumn, SortDescending, ToString.
Fixed ForeignKeyColumnNames test.
2009-06-10 Marek Habersack <mhabersack@novell.com>
* MetaTableTest.cs: added more table contexts.
Added tests for: Attributes, Columns, DataContextPropertyName,
DataContextType, DisplayName, EntityType, ForeignKeyColumnNames
(doesn't work on .NET), GetPrimaryKeyString, GetQuery,
HasPrimaryKey,
2009-06-09 Marek Habersack <mhabersack@novell.com>
* MetaTableTest.cs: added two more tables for various kinds of
tests (in fixture setup).
More tests for GetActionPath.
Tests for GetPrimaryKeyValues, DisplayColumn, Attributes,
GetDisplayString, GetColumn, TryGetColumn
2009-06-08 Marek Habersack <mhabersack@novell.com>
* MetaTableTest.cs: added.
2009-06-01 Marek Habersack <mhabersack@novell.com>
* MetaModelTest.cs: disabled GetActionPath test - nothing to test
there.
2009-04-23 Marek Habersack <mhabersack@novell.com>
* ContextConfigurationTest.cs: added
2008-11-10 Raja R Harinath <harinath@hurrynot.org>
* MetaModelTest.cs: Remove 'using System.ComponentModel' to avoid
ambiguities with the CategoryAttribute.
2008-10-21 Atsushi Enomoto <atsushi@ximian.com>
* DynamicDataRouteTest.cs, MetaModelTest.cs : added NotWorking mark.
2008-10-17 Atsushi Enomoto <atsushi@ximian.com>
* DynamicDataRouteTest.cs, TestStubTypes.cs: new tests.
* MetaModelTest.cs : fixed test namespace and type aliases.
Now that this test does not always run first, remove run-order-
dependent assertions. Added some more assertions.
2008-10-16 Atsushi Enomoto <atsushi@ximian.com>
* MetaModelTest.cs : initial checkin.

View File

@@ -0,0 +1,54 @@
//
// DynamicDataRouteTest.cs
//
// Author:
// Marek Habersack <mhabersack@novell.com>
//
// Copyright (C) 2009 Novell Inc. http://novell.com
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Web;
using System.Web.DynamicData;
using NUnit.Framework;
namespace MonoTests.System.Web.DynamicData
{
[TestFixture]
public class ContextConfigurationTests
{
[Test]
public void DefaultValues()
{
var ctx = new ContextConfiguration();
var func = ctx.MetadataProviderFactory;
Assert.IsTrue(func != null, "#A1");
Assert.AreEqual(typeof (Func <Type, TypeDescriptionProvider>), func.GetType (), "#A2");
Assert.AreEqual(false, ctx.ScaffoldAllTables, "#A3");
Assert.AreEqual(typeof(AssociatedMetadataTypeTypeDescriptionProvider), func(typeof(string)).GetType (), "#A4");
}
}
}

View File

@@ -0,0 +1,187 @@
//
// DynamicDataRouteTest.cs
//
// Author:
// Marek Habersack <mhabersack@novell.com>
//
// Copyright (C) 2009 Novell Inc. http://novell.com
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;
using System.Web.DynamicData;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using NUnit.Framework;
using MonoTests.Common;
namespace MonoTests.System.Web.DynamicData
{
class FakeWorkerRequest : HttpWorkerRequest
{
public override string GetUriPath()
{
return "/";
}
public override string GetQueryString()
{
return "GetQueryString";
}
public override string GetRawUrl()
{
return "GetRawUrl";
}
public override string GetHttpVerbName()
{
return "GetVerbName";
}
public override string GetHttpVersion()
{
return "GetHttpVersion";
}
public override string GetRemoteAddress()
{
return "__GetRemoteAddress";
}
public override int GetRemotePort()
{
return 1010;
}
public override string GetLocalAddress()
{
return "GetLocalAddress";
}
public override int GetLocalPort()
{
return 2020;
}
public override void SendStatus(int s, string x)
{
}
public override void SendKnownResponseHeader(int x, string j)
{
}
public override void SendUnknownResponseHeader(string a, string b)
{
}
public override void SendResponseFromMemory(byte[] arr, int x)
{
}
public override void SendResponseFromFile(string a, long b, long c)
{
}
public override void SendResponseFromFile(IntPtr a, long b, long c)
{
}
public override void FlushResponse(bool x)
{
}
public override void EndOfRequest()
{
}
}
[TestFixture]
public class DynamicDataExtensionsTest
{
[Test]
public void ConvertEditedValue ()
{
FieldFormattingOptions fld = null;
AssertExtensions.Throws<NullReferenceException> (() => {
fld.ConvertEditedValue (null);
}, "#A1");
fld = new FieldFormattingOptions ();
fld.SetProperty ("ConvertEmptyStringToNull", false);
Assert.AreEqual (null, fld.ConvertEditedValue (null), "#A2");
Assert.AreEqual (String.Empty, fld.ConvertEditedValue (String.Empty), "#A2-1");
Assert.AreEqual ("stuff", fld.ConvertEditedValue ("stuff"), "#A2-2");
fld.SetProperty ("ConvertEmptyStringToNull", true);
Assert.AreEqual (null, fld.ConvertEditedValue (null), "#A3");
Assert.AreEqual (null, fld.ConvertEditedValue (String.Empty), "#A3-1");
Assert.AreEqual ("stuff", fld.ConvertEditedValue ("stuff"), "#A3-2");
fld.SetProperty ("ConvertEmptyStringToNull", false);
fld.SetProperty ("NullDisplayText", "NULL");
Assert.AreEqual (null, fld.ConvertEditedValue (null), "#A4");
Assert.AreEqual (String.Empty, fld.ConvertEditedValue (String.Empty), "#A4-1");
Assert.AreEqual (null, fld.ConvertEditedValue ("NULL"), "#A4-2");
Assert.AreEqual ("stuff", fld.ConvertEditedValue ("stuff"), "#A4-3");
fld.SetProperty ("ConvertEmptyStringToNull", false);
fld.SetProperty ("NullDisplayText", String.Empty);
Assert.AreEqual (String.Empty, fld.ConvertEditedValue (String.Empty), "#A5");
}
[Test]
public void DynamicDataExtensions_GetTable_Test ()
{
IDynamicDataSource dds = null;
dds.GetTable ();
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void DynamicDataExtensions_GetTable_Test2()
{
HttpContext.Current = new HttpContext(new FakeWorkerRequest());
var dds = new LinqDataSource();
dds.TableName = "test";
dds.GetTable();
}
[Test]
[ExpectedException(typeof(InvalidOperationException))]
public void DynamicDataExtensions_GetTable_Test3()
{
HttpContext.Current = new HttpContext(new FakeWorkerRequest());
var dds = new LinqDataSource();
dds.GetTable();
}
}
}

View File

@@ -0,0 +1,361 @@
//
// DynamicDataRouteHandlerTest.cs
//
// Authors:
// Marek Habersack <mhabersack@novell.com>
//
// Copyright (C) 2009 Novell Inc. http://novell.com
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel.DataAnnotations;
using System.Data.SqlClient;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Security.Permissions;
using System.Security.Principal;
using System.Web;
using System.Web.UI;
using System.Web.DynamicData;
using System.Web.DynamicData.ModelProviders;
using System.Web.Routing;
using NUnit.Framework;
using NUnit.Mocks;
using MonoTests.stand_alone.WebHarness;
using MonoTests.SystemWeb.Framework;
using MonoTests.Common;
using MonoTests.ModelProviders;
using MetaModel = System.Web.DynamicData.MetaModel;
using MetaTable = System.Web.DynamicData.MetaTable;
namespace MonoTests.System.Web.DynamicData
{
[TestFixture]
public class DynamicDataRouteHandlerTest
{
DynamicDataContainerModelProvider <TestDataContext> dynamicModelProvider;
[TestFixtureSetUp]
public void SetUp ()
{
dynamicModelProvider = new DynamicDataContainerModelProvider <TestDataContext> ();
Utils.RegisterContext (dynamicModelProvider, new ContextConfiguration () { ScaffoldAllTables = true });
}
[Test]
public void Constructor ()
{
var ddrh = new DynamicDataRouteHandler ();
Assert.AreEqual (null, ddrh.Model, "#A1");
}
[Test]
public void CreateHandlerParams ()
{
MetaModel m = Utils.CommonInitialize ();
var route = RouteTable.Routes[0] as DynamicDataRoute;
MetaTable t = m.Tables[TestDataContext.TableFooEmpty];
var handler = route.RouteHandler = new DynamicDataRouteHandler ();
// No null check is made, of course - throws from some internal method
AssertExtensions.Throws<NullReferenceException> (() => {
handler.CreateHandler (null, t, PageAction.Details);
}, "#A1");
// No null check again - this time throws from GetCustomPageVirtualPath
AssertExtensions.Throws<NullReferenceException> (() => {
handler.CreateHandler (route, null, PageAction.Details);
}, "#A2");
// And once again, no null check and thrown from GetCustomPageVirtualPath as well
AssertExtensions.Throws<NullReferenceException> (() => {
handler.CreateHandler (route, t, null);
}, "#A3");
}
[Test]
[Ignore ("Throws NREX on .NET - no idea why and how to make it work. Probably needs full request emulation (using Mainsoft test suite)")]
// Probably need to simulate a full reqest using similar environment as System.Web tests
public void CreateHandler ()
{
MetaModel m = Utils.CommonInitialize ();
var route = RouteTable.Routes[0] as DynamicDataRoute;
MetaTable t = m.Tables[TestDataContext.TableFooEmpty];
Assert.IsNotNull (t, "#A1");
var handler = route.RouteHandler = new DynamicDataRouteHandler ();
var wrapper = new MyHttpContextWrapper ();
var request = wrapper.Request as MyHttpRequestWrapper;
request.SetProperty ("AppRelativeCurrentExecutionFilePath", "~/FooEmptyTable/List.aspx");
request.SetProperty ("PathInfo", String.Empty);
// This must be non-null because DynamicData doesn't care to check whether the returned
// value is null or not...
request.SetProperty ("QueryString", new NameValueCollection ());
// This will assign the route handler's Model property
RouteData rd = route.GetRouteData (wrapper);
Assert.IsNotNull (handler.Model, "#A2");
// Throws a NREX from some internal method - no slightest idea why, as none of the parameters
// passed are null
IHttpHandler h = handler.CreateHandler (route, t, PageAction.Details);
Assert.IsNotNull (h, "#A3");
Assert.AreEqual (typeof (Page), h.GetType (), "#A3-1");
var page = h as Page;
Assert.AreEqual (String.Empty, page.AppRelativeVirtualPath, "#A3-2");
}
[Test]
public void GetCustomPageVirtualPath ()
{
MetaModel m = Utils.CommonInitialize ();
var route = RouteTable.Routes[0] as DynamicDataRoute;
MetaTable t = m.Tables[TestDataContext.TableFooEmpty];
Assert.IsNotNull (t, "#A1");
// We neeed the handler to have its Model property set
route.RouteHandler = new MyDynamicDataRouteHandler ();
var handler = route.RouteHandler as MyDynamicDataRouteHandler;
Assert.IsNotNull (handler, "#A2");
// Lack of null check (for table)
AssertExtensions.Throws<NullReferenceException> (() => {
handler.DoGetCustomPageVirtualPath (null, null);
}, "#A2-1");
// Another missing null check (this time for Model)... Are null checks
// out of fashion?
AssertExtensions.Throws<NullReferenceException> (() => {
handler.DoGetCustomPageVirtualPath (t, String.Empty);
}, "#A2-2");
var wrapper = new MyHttpContextWrapper ();
var request = wrapper.Request as MyHttpRequestWrapper;
request.SetProperty ("AppRelativeCurrentExecutionFilePath", "~/FooEmptyTable/List.aspx");
request.SetProperty ("PathInfo", String.Empty);
// This must be non-null because DynamicData doesn't care to check whether the returned
// value is null or not...
request.SetProperty ("QueryString", new NameValueCollection ());
// This will assign the route handler's Model property
RouteData rd = route.GetRouteData (wrapper);
Assert.IsNotNull (handler.Model, "#A3");
Assert.AreEqual (handler.Model.DynamicDataFolderVirtualPath + "CustomPages/" + t.Name + "/MyCustomPage.aspx",
handler.DoGetCustomPageVirtualPath (t, "MyCustomPage"), "#A4");
handler.Model.DynamicDataFolderVirtualPath = "~/MyFolder";
Assert.AreEqual (handler.Model.DynamicDataFolderVirtualPath + "CustomPages/" + t.Name + "/MyCustomPage.aspx",
handler.DoGetCustomPageVirtualPath (t, "MyCustomPage"), "#A5");
// doh!
Assert.AreEqual (handler.Model.DynamicDataFolderVirtualPath + "CustomPages/" + t.Name + "/.aspx",
handler.DoGetCustomPageVirtualPath (t, null), "#A6");
Assert.AreEqual (handler.Model.DynamicDataFolderVirtualPath + "CustomPages/" + t.Name + "/.aspx",
handler.DoGetCustomPageVirtualPath (t, String.Empty), "#A7");
}
[Test]
public void GetRequestContext ()
{
AssertExtensions.Throws<ArgumentNullException> (() => {
DynamicDataRouteHandler.GetRequestContext (null);
}, "#A1");
var req = new FakeHttpWorkerRequest ();
var ctx = new HttpContext (req);
RequestContext rc = DynamicDataRouteHandler.GetRequestContext (ctx);
Assert.IsNotNull (rc, "#B1");
Assert.IsNotNull (rc.HttpContext, "#B1-1");
Assert.IsNotNull (rc.RouteData, "#B1-2");
Assert.IsNull (rc.RouteData.Route, "#C1");
Assert.IsNull (rc.RouteData.RouteHandler, "#C1-1");
Assert.IsNotNull (rc.RouteData.Values, "#C1-2");
Assert.AreEqual (0, rc.RouteData.Values.Count, "#C1-3");
}
[Test]
public void GetRequestMetaTable ()
{
MetaModel m = Utils.CommonInitialize ();
var route = RouteTable.Routes[0] as DynamicDataRoute;
MetaTable t = m.Tables[TestDataContext.TableFooDisplayName];
Assert.IsNotNull (t, "#A1");
// Surprise! A null check is present!
AssertExtensions.Throws<ArgumentNullException> (() => {
DynamicDataRouteHandler.GetRequestMetaTable (null);
}, "#A2");
MetaTable t2 = DynamicDataRouteHandler.GetRequestMetaTable (HttpContext.Current);
Assert.IsNull (t2, "#A3");
DynamicDataRouteHandler.SetRequestMetaTable (HttpContext.Current, t);
t2 = DynamicDataRouteHandler.GetRequestMetaTable (HttpContext.Current);
Assert.IsNotNull (t2, "#A4");
Assert.AreEqual (t, t2, "#A4-1");
}
[Test]
public void GetScaffoldPageVirtualPath ()
{
MetaModel m = Utils.CommonInitialize ();
var route = RouteTable.Routes[0] as DynamicDataRoute;
MetaTable t = m.Tables[TestDataContext.TableFooDisplayName];
Assert.IsNotNull (t, "#A1");
// We neeed the handler to have its Model property set
route.RouteHandler = new MyDynamicDataRouteHandler ();
var handler = route.RouteHandler as MyDynamicDataRouteHandler;
Assert.IsNotNull (handler, "#A2");
// Lack of null check (for table)
AssertExtensions.Throws<NullReferenceException> (() => {
handler.DoGetScaffoldPageVirtualPath (null, null);
}, "#A2-1");
// Another missing null check (this time for Model)... Are null checks
// out of fashion?
AssertExtensions.Throws<NullReferenceException> (() => {
handler.DoGetScaffoldPageVirtualPath (t, String.Empty);
}, "#A2-2");
var wrapper = new MyHttpContextWrapper ();
var request = wrapper.Request as MyHttpRequestWrapper;
request.SetProperty ("AppRelativeCurrentExecutionFilePath", "~/FooDisplayNameTable/List.aspx");
request.SetProperty ("PathInfo", String.Empty);
// This must be non-null because DynamicData doesn't care to check whether the returned
// value is null or not...
request.SetProperty ("QueryString", new NameValueCollection ());
// This will assign the route handler's Model property
RouteData rd = route.GetRouteData (wrapper);
Assert.IsNotNull (handler.Model, "#A3");
Assert.AreEqual (handler.Model.DynamicDataFolderVirtualPath + "PageTemplates/" + "MyCustomPage.aspx",
handler.DoGetScaffoldPageVirtualPath (t, "MyCustomPage"), "#A4");
handler.Model.DynamicDataFolderVirtualPath = "~/MyFolder";
Assert.AreEqual (handler.Model.DynamicDataFolderVirtualPath + "PageTemplates/" + "MyCustomPage.aspx",
handler.DoGetScaffoldPageVirtualPath (t, "MyCustomPage"), "#A5");
// doh!
Assert.AreEqual (handler.Model.DynamicDataFolderVirtualPath + "PageTemplates/" + ".aspx",
handler.DoGetScaffoldPageVirtualPath (t, null), "#A6");
Assert.AreEqual (handler.Model.DynamicDataFolderVirtualPath + "PageTemplates/" + ".aspx",
handler.DoGetScaffoldPageVirtualPath (t, String.Empty), "#A7");
}
[Test]
public void Model ()
{
MetaModel m = Utils.CommonInitialize ();
var route = RouteTable.Routes[0] as DynamicDataRoute;
Assert.IsNotNull (route, "#A1");
Assert.IsNotNull (route.Model, "#A1-1");
var handler = route.RouteHandler;
Assert.IsNotNull (handler, "#A2");
Assert.IsTrue (handler.GetType () == typeof (MyDynamicDataRouteHandler), "#A2-1");
Assert.IsNull (handler.Model, "#A2-2");
var req = new FakeHttpWorkerRequest ();
var ctx = new HttpContext (req);
RequestContext rc = DynamicDataRouteHandler.GetRequestContext (ctx);
Assert.IsNotNull (rc, "#B1");
Assert.IsNull (handler.Model, "#B1-2");
var wrapper = new MyHttpContextWrapper ();
var request = wrapper.Request as MyHttpRequestWrapper;
// It appears .NET checks whether the indicated table exists - if not, GetRouteData will return
// null (even though the Route class will find a match)
request.SetProperty ("AppRelativeCurrentExecutionFilePath", "~/NoSuchTable/List.aspx");
request.SetProperty ("PathInfo", String.Empty);
// This must be non-null because DynamicData doesn't care to check whether the returned
// value is null or not...
request.SetProperty ("QueryString", new NameValueCollection ());
// No table FooTable in the context - returns null
RouteData rd = route.GetRouteData (wrapper);
Assert.IsNull (rd, "#C1");
// Apparently Model is set in the above call even though it returns null
Assert.IsNotNull (handler.Model, "#C1-1");
Assert.AreEqual (route.Model, handler.Model, "#C1-2");
request.SetProperty ("AppRelativeCurrentExecutionFilePath", "~/BarTable/List.aspx");
rd = route.GetRouteData (wrapper);
Assert.IsNotNull (rd, "#D1");
Assert.IsNotNull (handler.Model, "#D1-1");
Assert.AreEqual (route.Model, handler.Model, "#D1-2");
}
[Test]
public void SetRequestMetaTable ()
{
MetaModel m = Utils.CommonInitialize ();
var route = RouteTable.Routes[0] as DynamicDataRoute;
MetaTable t = m.Tables[TestDataContext.TableFooDisplayName];
Assert.IsNotNull (t, "#A1");
// And following the tradition... [drum roll] - NO NULL CHECK!
AssertExtensions.Throws<NullReferenceException> (() => {
DynamicDataRouteHandler.SetRequestMetaTable (null, t);
}, "#A2");
DynamicDataRouteHandler.SetRequestMetaTable (HttpContext.Current, t);
MetaTable t2 = DynamicDataRouteHandler.GetRequestMetaTable (HttpContext.Current);
Assert.IsNotNull (t2, "#A3");
Assert.AreEqual (t, t2, "#A3-1");
DynamicDataRouteHandler.SetRequestMetaTable (HttpContext.Current, null);
t2 = DynamicDataRouteHandler.GetRequestMetaTable (HttpContext.Current);
Assert.IsNull (t2, "#A4");
}
}
}

View File

@@ -0,0 +1,478 @@
//
// DynamicValidatorTest.cs
//
// Authors:
// Marek Habersack <mhabersack@novell.com>
//
// Copyright (C) 2009 Novell Inc. http://novell.com
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel.DataAnnotations;
using System.Data.SqlClient;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Globalization;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Security.Permissions;
using System.Security.Principal;
using System.Web;
using System.Web.UI;
using System.Web.DynamicData;
using System.Web.DynamicData.ModelProviders;
using System.Web.Routing;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.IO;
using NUnit.Framework;
using NUnit.Mocks;
using MonoTests.stand_alone.WebHarness;
using MonoTests.SystemWeb.Framework;
using MonoTests.Common;
using MonoTests.DataSource;
using MonoTests.DataObjects;
using MonoTests.ModelProviders;
using MetaModel = System.Web.DynamicData.MetaModel;
using MetaTable = System.Web.DynamicData.MetaTable;
namespace MonoTests.System.Web.DynamicData
{
[TestFixture]
public class DynamicValidatorTest
{
DynamicDataContainerModelProvider<TestDataContext> dynamicModelProvider;
[TestFixtureSetUp]
public void SetUp ()
{
Type type = GetType ();
WebTest.CopyResource (type, "MonoTests.WebPages.ListView_DynamicControl_04.aspx", "ListView_DynamicControl_04.aspx");
WebTest.CopyResource (type, "MonoTests.WebPages.ListView_DynamicControl_04.aspx.cs", "ListView_DynamicControl_04.aspx.cs");
WebTest.CopyResource (type, "MonoTests.WebPages.DynamicValidator_01.aspx", "DynamicValidator_01.aspx");
WebTest.CopyResource (type, "MonoTests.WebPages.DynamicValidator_01.aspx.cs", "DynamicValidator_01.aspx.cs");
WebTest.CopyResource (type, "MonoTests.WebPages.DynamicValidator_02.aspx", "DynamicValidator_02.aspx");
WebTest.CopyResource (type, "MonoTests.WebPages.DynamicValidator_02.aspx.cs", "DynamicValidator_02.aspx.cs");
dynamicModelProvider = new DynamicDataContainerModelProvider<TestDataContext> ();
Utils.RegisterContext (dynamicModelProvider, new ContextConfiguration () { ScaffoldAllTables = true });
}
[Test]
public void Defaults ()
{
var dv = new PokerDynamicValidator ();
Assert.IsNull (dv.Column, "#A1");
Assert.IsNotNull (dv.ColumnName, "#A2");
Assert.AreEqual (String.Empty, dv.ColumnName, "#A2-1");
Assert.IsNull (dv.GetValidationException (), "#A3");
}
[Test]
public void Column ()
{
MetaModel m = Utils.CommonInitialize ();
MetaTable t = m.Tables[TestDataContext.TableBazColumnAttributes];
MetaColumn mc = t.GetColumn ("ColumnNoAttributes");
var dv = new PokerDynamicValidator ();
Assert.IsNull (dv.Column, "#A1");
dv.Column = mc;
Assert.IsNotNull (dv.Column, "#B1");
Assert.AreEqual (mc, dv.Column, "#B1-1");
dv.Column = null;
Assert.IsNull (dv.Column, "#C1");
}
[Test]
[Category ("NotWorking")]
public void Column_1 ()
{
var test = new WebTest ("ListView_DynamicControl_04.aspx");
var p = test.Run ();
// Fake post-back
var delegates = new PageDelegates ();
delegates.PreRenderComplete = Column_1_OnPreRenderComplete;
test.Invoker = new PageInvoker (delegates);
var fr = new FormRequest (test.Response, "form1");
#if TARGET_DOTNET
fr.Controls.Add ("ListView4$ctrl0$editMe");
fr.Controls["ListView4$ctrl0$editMe"].Value = "Edit";
#else
fr.Controls.Add ("ListView4$ctl01$editMe");
fr.Controls["ListView4$ctl01$editMe"].Value = "Edit";
#endif
test.Request = fr;
p = test.Run ();
Assert.IsNotNull (test.Response, "#X1");
Assert.AreNotEqual (HttpStatusCode.NotFound, test.Response.StatusCode, "#X1-1{0}Returned HTML:{0}{1}", Environment.NewLine, p);
Assert.AreNotEqual (HttpStatusCode.InternalServerError, test.Response.StatusCode, "#X1-2{0}Returned HTML:{0}{1}", Environment.NewLine, p);
Assert.IsFalse (String.IsNullOrEmpty (p), "#X1-3");
}
static void Column_1_OnPreRenderComplete (Page p)
{
var lc = p.FindControl ("ListView4") as ListView;
Assert.IsNotNull (lc, "#A1");
var dc = lc.FindChild<DynamicControl> ("String_Column");
Assert.IsNotNull (dc, "#B1");
var field = dc.FieldTemplate as FieldTemplateUserControl;
Assert.IsNotNull (field, "#C1");
Assert.AreEqual ("~/DynamicData/FieldTemplates/Text_Edit.ascx", field.AppRelativeVirtualPath, "#C1-1");
var dv = field.FindChild<DynamicValidator> ("DynamicValidator1");
Assert.IsNotNull (dv, "#D1");
Assert.AreEqual (dc.Column, dv.Column, "#D1-1");
}
[Test]
public void ColumnName ()
{
MetaModel m = Utils.CommonInitialize ();
MetaTable t = m.Tables[TestDataContext.TableBazColumnAttributes];
MetaColumn mc = t.GetColumn ("ColumnNoAttributes");
var dv = new PokerDynamicValidator ();
Assert.AreEqual (String.Empty, dv.ColumnName, "#A1");
dv.Column = mc;
Assert.AreEqual (mc.Name, dv.ColumnName, "#B1");
}
[Test]
[Category ("NotWorking")]
public void ColumnName_1 ()
{
var test = new WebTest ("ListView_DynamicControl_04.aspx");
var p = test.Run ();
// Fake post-back
var delegates = new PageDelegates ();
delegates.PreRenderComplete = ColumnName_1_OnPreRenderComplete;
test.Invoker = new PageInvoker (delegates);
var fr = new FormRequest (test.Response, "form1");
#if TARGET_DOTNET
fr.Controls.Add ("ListView4$ctrl0$editMe");
fr.Controls["ListView4$ctrl0$editMe"].Value = "Edit";
#else
fr.Controls.Add ("ListView4$ctl01$editMe");
fr.Controls["ListView4$ctl01$editMe"].Value = "Edit";
#endif
test.Request = fr;
p = test.Run ();
Assert.IsNotNull (test.Response, "#X1");
Assert.AreNotEqual (HttpStatusCode.NotFound, test.Response.StatusCode, "#X1-1{0}Returned HTML:{0}{1}", Environment.NewLine, p);
Assert.AreNotEqual (HttpStatusCode.InternalServerError, test.Response.StatusCode, "#X1-2{0}Returned HTML:{0}{1}", Environment.NewLine, p);
Assert.IsFalse (String.IsNullOrEmpty (p), "#X1-3");
}
static void ColumnName_1_OnPreRenderComplete (Page p)
{
var lc = p.FindControl ("ListView4") as ListView;
Assert.IsNotNull (lc, "#A1");
var dc = lc.FindChild<DynamicControl> ("String_Column");
Assert.IsNotNull (dc, "#B1");
var field = dc.FieldTemplate as FieldTemplateUserControl;
Assert.IsNotNull (field, "#C1");
Assert.AreEqual ("~/DynamicData/FieldTemplates/Text_Edit.ascx", field.AppRelativeVirtualPath, "#C1-1");
var dv = field.FindChild<PokerDynamicValidator> ("DynamicValidator1");
Assert.IsNotNull (dv, "#D1");
Assert.AreEqual (dc.Column.Name, dv.ColumnName, "#D1-1");
}
[Test]
public void ControlPropertiesValid ()
{
var dv = new PokerDynamicValidator ();
// Nice...:
//
// MonoTests.System.Web.DynamicData.DynamicValidatorTest.ControlPropertiesValid:
// System.NullReferenceException : Object reference not set to an instance of an object.
// at System.Web.DynamicData.DynamicDataExtensions.FindDataSourceControl(Control current)
// at System.Web.DynamicData.DynamicValidator.get_DynamicDataSource()
// at System.Web.DynamicData.DynamicValidator.ControlPropertiesValid()
// at MonoTests.Common.PokerDynamicValidator.CallControlPropertiesValid() in C:\Users\grendel\Documents\Visual Studio 2008\Projects\DynamicDataNunit\DynamicDataNunitTests\Common\PokerDynamicValidator.cs:line 20
// at MonoTests.System.Web.DynamicData.DynamicValidatorTest.ControlPropertiesValid() in C:\Users\grendel\Documents\Visual Studio 2008\Projects\DynamicDataNunit\DynamicDataNunitTests\System.Web.DynamicData\DynamicValidatorTest.cs:line 220
// Assert.IsFalse (dv.CallControlPropertiesValid (), "#A1");
}
[Test]
public void ControlPropertiesValid_01 ()
{
var test = new WebTest ("DynamicValidator_01.aspx");
var p = test.Run ();
test.Invoker = PageInvoker.CreateOnLoad (ControlPropertiesValid_01_OnLoad);
Assert.AreNotEqual (HttpStatusCode.NotFound, test.Response.StatusCode, "#X1-1{0}Returned HTML:{0}{1}", Environment.NewLine, p);
Assert.AreNotEqual (HttpStatusCode.InternalServerError, test.Response.StatusCode, "#X1-2{0}Returned HTML:{0}{1}", Environment.NewLine, p);
Assert.IsFalse (String.IsNullOrEmpty (p), "#X1-3");
}
static void ControlPropertiesValid_01_OnLoad (Page p)
{
var dv = p.FindChild<PokerDynamicValidator> ("dynamicValidator1");
Assert.IsNotNull (dv, "#A1");
Assert.IsFalse (dv.CallControlPropertiesValid (), "#A2");
Assert.IsNull (dv.Column, "#A2-1");
Assert.IsNull (dv.ColumnName, "#A2-2");
MetaModel m = Utils.CommonInitialize ();
MetaTable t = m.Tables[TestDataContext.TableBar];
MetaColumn mc = t.GetColumn ("Column1");
dv.Column = mc;
Assert.IsFalse (dv.CallControlPropertiesValid (), "#A3");
Assert.IsNotNull (dv.Column, "#A3-1");
Assert.IsNull (dv.ColumnName, "#A3-2");
}
[Test]
[Category ("NotWorking")]
public void ControlPropertiesValid_2 ()
{
var test = new WebTest ("ListView_DynamicControl_04.aspx");
var p = test.Run ();
// Fake post-back
var delegates = new PageDelegates ();
delegates.PreRenderComplete = ControlPropertiesValid_2_OnPreRenderComplete;
test.Invoker = new PageInvoker (delegates);
var fr = new FormRequest (test.Response, "form1");
#if TARGET_DOTNET
fr.Controls.Add ("ListView4$ctrl0$editMe");
fr.Controls["ListView4$ctrl0$editMe"].Value = "Edit";
#else
fr.Controls.Add ("ListView4$ctl01$editMe");
fr.Controls["ListView4$ctl01$editMe"].Value = "Edit";
#endif
test.Request = fr;
p = test.Run ();
Assert.IsNotNull (test.Response, "#X1");
Assert.AreNotEqual (HttpStatusCode.NotFound, test.Response.StatusCode, "#X1-1{0}Returned HTML:{0}{1}", Environment.NewLine, p);
Assert.AreNotEqual (HttpStatusCode.InternalServerError, test.Response.StatusCode, "#X1-2{0}Returned HTML:{0}{1}", Environment.NewLine, p);
Assert.IsFalse (String.IsNullOrEmpty (p), "#X1-3");
}
static void ControlPropertiesValid_2_OnPreRenderComplete (Page p)
{
var lc = p.FindControl ("ListView4") as ListView;
Assert.IsNotNull (lc, "#A1");
var dc = lc.FindChild<DynamicControl> ("String_Column");
Assert.IsNotNull (dc, "#B1");
var field = dc.FieldTemplate as FieldTemplateUserControl;
Assert.IsNotNull (field, "#C1");
Assert.AreEqual ("~/DynamicData/FieldTemplates/Text_Edit.ascx", field.AppRelativeVirtualPath, "#C1-1");
var dv = field.FindChild<PokerDynamicValidator> ("DynamicValidator1");
Assert.IsNotNull (dv, "#D1");
Assert.IsTrue (dv.CallControlPropertiesValid (), "#D1-2");
Assert.IsNotNull (dv.Column, "#D1-3");
Assert.IsNotNull (dv.ColumnName, "#D1-4");
}
[Test]
public void EvaluateIsValid ()
{
var dv = new PokerDynamicValidator ();
Assert.IsTrue (dv.CallEvaluateIsValid (), "#A1");
Assert.IsNotNull (dv.ControlToValidate, "#A1-1");
Assert.AreEqual (String.Empty, dv.ControlToValidate, "#A1-2");
Assert.AreEqual (String.Empty, dv.ErrorMessage, "#A1-3");
dv.SetValidationException (new Exception ("test message"));
Assert.IsFalse (dv.CallEvaluateIsValid (), "#A2");
Assert.AreEqual (dv.GetValidationException ().Message, dv.ErrorMessage, "#A2-1");
dv.SetValidationException (new Exception ("<script>message</script>"));
Assert.IsFalse (dv.CallEvaluateIsValid (), "#A3");
Assert.AreEqual (HttpUtility.HtmlEncode (dv.GetValidationException ().Message), dv.ErrorMessage, "#A3-1");
}
[Test]
[Category ("NotWorking")]
public void EvaluateIsValid_1 ()
{
var test = new WebTest ("DynamicValidator_02.aspx");
var p = test.Run ();
// Fake post-back
var delegates = new PageDelegates ();
delegates.PreRenderComplete = EvaluateIsValid_1_OnPreRenderComplete;
test.Invoker = new PageInvoker (delegates);
var fr = new FormRequest (test.Response, "form1");
#if TARGET_DOTNET
fr.Controls.Add ("ListView1$ctrl0$editMe");
fr.Controls["ListView1$ctrl0$editMe"].Value = "Edit";
#else
fr.Controls.Add ("ListView1$ctl01$editMe");
fr.Controls["ListView1$ctl01$editMe"].Value = "Edit";
#endif
test.Request = fr;
p = test.Run ();
Assert.IsNotNull (test.Response, "#X1");
Assert.AreNotEqual (HttpStatusCode.NotFound, test.Response.StatusCode, "#X1-1{0}Returned HTML:{0}{1}", Environment.NewLine, p);
Assert.AreNotEqual (HttpStatusCode.InternalServerError, test.Response.StatusCode, "#X1-2{0}Returned HTML:{0}{1}", Environment.NewLine, p);
Assert.IsFalse (String.IsNullOrEmpty (p), "#X1-3");
}
static void EvaluateIsValid_1_OnPreRenderComplete (Page p)
{
var lc = p.FindControl ("ListView1") as ListView;
Assert.IsNotNull (lc, "#A1");
var dc = lc.FindChild<PokerDynamicControl> ("Column1");
Assert.IsNotNull (dc, "#B1");
var field = dc.FieldTemplate as FieldTemplateUserControl;
Assert.IsNotNull (field, "#C1");
Assert.AreEqual ("~/DynamicData/FieldTemplates/Integer_Edit.ascx", field.AppRelativeVirtualPath, "#C1-1");
var dv = field.FindChild<PokerDynamicValidator> ("DynamicValidator1");
Assert.IsNotNull (dv, "#D1");
var tb = field.FindChild<TextBox> ("TextBox1");
Assert.IsNotNull (tb, "#D1-2");
Assert.AreEqual ("0", tb.Text, "#D1-3");
Assert.IsTrue (dv.CallEvaluateIsValid (), "#E1");
}
[Test]
public void ValidationException ()
{
var dv = new PokerDynamicValidator ();
Assert.IsNull (dv.GetValidationException (), "#A1");
Exception ex = new Exception ();
dv.SetValidationException (ex);
Assert.AreEqual (ex, dv.GetValidationException (), "#B1");
ex = new ArgumentNullException ();
dv.SetValidationException (ex);
Assert.AreEqual (ex, dv.GetValidationException (), "#C1");
dv.SetValidationException (null);
Assert.IsNull (dv.GetValidationException (), "#D1");
}
[Test]
public void ValidationException_1 ()
{
var test = new WebTest ("ListView_DynamicControl_04.aspx");
var p = test.Run ();
// Fake post-back
var delegates = new PageDelegates ();
delegates.PreRenderComplete = ValidationException_1_OnPreRenderComplete;
test.Invoker = new PageInvoker (delegates);
var fr = new FormRequest (test.Response, "form1");
#if TARGET_DOTNET
fr.Controls.Add ("ListView4$ctrl0$editMe");
fr.Controls["ListView4$ctrl0$editMe"].Value = "Edit";
#else
fr.Controls.Add ("ListView4$ctl01$editMe");
fr.Controls["ListView4$ctl01$editMe"].Value = "Edit";
#endif
test.Request = fr;
p = test.Run ();
Assert.IsNotNull (test.Response, "#X1");
Assert.AreNotEqual (HttpStatusCode.NotFound, test.Response.StatusCode, "#X1-1{0}Returned HTML:{0}{1}", Environment.NewLine, p);
Assert.AreNotEqual (HttpStatusCode.InternalServerError, test.Response.StatusCode, "#X1-2{0}Returned HTML:{0}{1}", Environment.NewLine, p);
Assert.IsFalse (String.IsNullOrEmpty (p), "#X1-3");
}
static void ValidationException_1_OnPreRenderComplete (Page p)
{
var lc = p.FindControl ("ListView4") as ListView;
Assert.IsNotNull (lc, "#A1");
var dc = lc.FindChild<DynamicControl> ("String_Column");
Assert.IsNotNull (dc, "#B1");
var field = dc.FieldTemplate as FieldTemplateUserControl;
Assert.IsNotNull (field, "#C1");
Assert.AreEqual ("~/DynamicData/FieldTemplates/Text_Edit.ascx", field.AppRelativeVirtualPath, "#C1-1");
var dv = field.FindChild<PokerDynamicValidator> ("DynamicValidator1");
Assert.IsNotNull (dv, "#D1");
Assert.IsNull (dv.GetValidationException (), "#D1-1");
Exception ex = new Exception ();
dv.SetValidationException (ex);
Assert.AreEqual (ex, dv.GetValidationException (), "#E1");
ex = new ArgumentNullException ();
dv.SetValidationException (ex);
Assert.AreEqual (ex, dv.GetValidationException (), "#F1");
dv.SetValidationException (null);
Assert.IsNull (dv.GetValidationException (), "#G1");
}
[Test]
[Category ("NotWorking")]
public void ValidateException ()
{
var dv = new PokerDynamicValidator ();
dv.CallValidateException (null);
Assert.IsNull (dv.GetValidationException (), "#A1");
Exception ex = new Exception ();
dv.CallValidateException (ex);
Assert.IsNull (dv.GetValidationException (), "#B1");
ex = new ValidationException ("test message");
dv.CallValidateException (ex);
Assert.IsNotNull (dv.GetValidationException (), "#C1");
Assert.AreEqual (ex, dv.GetValidationException (), "#C1-1");
Assert.AreEqual ("test message", dv.GetValidationException ().Message, "#C1-2");
}
}
}

View File

@@ -0,0 +1,240 @@
//
// FieldTemplateUserControlTest.cs
//
// Authors:
// Marek Habersack <mhabersack@novell.com>
//
// Copyright (C) 2009 Novell Inc. http://novell.com
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel.DataAnnotations;
using System.Data.SqlClient;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Globalization;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Security.Permissions;
using System.Security.Principal;
using System.Web;
using System.Web.UI;
using System.Web.DynamicData;
using System.Web.DynamicData.ModelProviders;
using System.Web.Routing;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.IO;
using NUnit.Framework;
using NUnit.Mocks;
using MonoTests.stand_alone.WebHarness;
using MonoTests.SystemWeb.Framework;
using MonoTests.Common;
using MonoTests.DataSource;
using MonoTests.DataObjects;
using MonoTests.ModelProviders;
using MetaModel = System.Web.DynamicData.MetaModel;
using MetaTable = System.Web.DynamicData.MetaTable;
namespace MonoTests.System.Web.DynamicData
{
[TestFixture]
public class FieldTemplateUserControlTest
{
DynamicDataContainerModelProvider<TestDataContext> dynamicModelProvider;
[TestFixtureSetUp]
public void SetUp ()
{
Type type = GetType ();
WebTest.CopyResource (type, "MonoTests.WebPages.ListView_DynamicControl_01.aspx", "ListView_DynamicControl_01.aspx");
WebTest.CopyResource (type, "MonoTests.WebPages.ListView_DynamicControl_01.aspx.cs", "ListView_DynamicControl_01.aspx.cs");
WebTest.CopyResource (type, "MonoTests.WebPages.ListView_DynamicControl_10.aspx", "ListView_DynamicControl_10.aspx");
WebTest.CopyResource (type, "MonoTests.WebPages.ListView_DynamicControl_10.aspx.cs", "ListView_DynamicControl_10.aspx.cs");
dynamicModelProvider = new DynamicDataContainerModelProvider<TestDataContext> ();
Utils.RegisterContext (dynamicModelProvider, new ContextConfiguration () { ScaffoldAllTables = true });
}
[TestFixtureTearDown]
public void TearDown ()
{
WebTest.Unload ();
}
[Test]
public void Defaults ()
{
var field = new PokerFieldTemplateUserControl ();
// And for another time - not a single null check in the code...
//
// All the asserts commented out below throw a NREX
//
//Assert.IsNull (field.ChildrenColumn, "#A1");
//Assert.IsNull (field.GetChildrenPath (), "#A2");
//Assert.IsNull (field.Column, "#A3");
Assert.IsNull (field.DataControl, "#A4");
//Assert.IsNull (field.FieldValue, "#A5");
//Assert.IsNull (field.FieldValueEditString, "#A6");
//Assert.IsNull (field.FieldValueString, "#A7");
//Assert.IsNull (field.ForeignKeyColumn, "#A8");
//Assert.IsNull (field.GetForeignKeyPath (), "#A9");
Assert.IsNull (field.Host, "#A10");
//Assert.IsNull (field.MetadataAttributes, "#A11");
//Assert.IsNull (field.Mode, "#A12");
//Assert.IsNull (field.Row, "#A13");
//Assert.IsNull (field.Table, "#A14");
}
[Test]
public void Defaults_WithHost ()
{
var test = new WebTest ("ListView_DynamicControl_01.aspx");
test.Invoker = PageInvoker.CreateOnLoad (Defaults_WithHost_OnLoad);
var p = test.Run ();
Assert.IsNotNull (test.Response, "#X1");
Assert.AreNotEqual (HttpStatusCode.NotFound, test.Response.StatusCode, "#X1-1{0}Returned HTML:{0}{1}", Environment.NewLine, p);
Assert.AreNotEqual (HttpStatusCode.InternalServerError, test.Response.StatusCode, "#X1-2{0}Returned HTML:{0}{1}", Environment.NewLine, p);
Assert.IsFalse (String.IsNullOrEmpty (p), "#X1-3");
}
static void Defaults_WithHost_OnLoad (Page p)
{
// Not many "defaults" here
var lc = p.FindControl ("ListView1") as ListView;
Assert.IsNotNull (lc, "#A1");
var dc = lc.FindChild<DynamicControl> ("FirstName");
Assert.IsNotNull (dc, "#B1-1");
Assert.AreEqual ("FirstName", dc.ID, "#B1-2");
var field = new PokerFieldTemplateUserControl ();
// Without it Row NREXes... However, with Page set, we still get an exception
// this time from Page.GetDataItem () as we're not bound to data. So, there is
// no way to test the "defaults" as if we used a field control retrieved from
// DataControl it would already be initialized
field.Page = p;
((IFieldTemplate) field).SetHost (dc);
AssertExtensions.Throws<Exception> (() => {
var f = field.ChildrenColumn;
}, "#C1");
// The FirstName column is not a children one
AssertExtensions.Throws<Exception> (() => {
field.GetChildrenPath ();
}, "#C2");
Assert.IsNotNull (field.Column, "#C3");
Assert.AreEqual (dc.Column, field.Column, "#C3-1");
Assert.IsNull (field.DataControl, "#C4");
// The tests below fail with exception:
//
// MonoTests.System.Web.DynamicData.FieldTemplateUserControlTest.Defaults_WithHost:
// System.InvalidOperationException : System.InvalidOperationException: Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.
// at System.Web.UI.Page.GetDataItem()
// at System.Web.DynamicData.FieldTemplateUserControl.get_Row()
// at System.Web.DynamicData.FieldTemplateUserControl.GetColumnValue(MetaColumn column)
// at System.Web.DynamicData.FieldTemplateUserControl.get_FieldValue()
// at System.Web.DynamicData.FieldTemplateUserControl.get_FieldValueEditString()
// at MonoTests.System.Web.DynamicData.FieldTemplateUserControlTest.Defaults_WithHost_OnLoad(Page p)
// at MonoTests.SystemWeb.Framework.PageInvoker.Invoke(PageDelegate callback)
// at MonoTests.SystemWeb.Framework.PageInvoker.OnLoad(Object sender, EventArgs a)
// at System.EventHandler.Invoke(Object sender, EventArgs e)
// at System.Web.UI.Control.OnLoad(EventArgs e)
// at System.Web.UI.Control.LoadRecursive()
// at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
// ----> System.InvalidOperationException : Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.
//Assert.IsNull (field.FieldValue, "#C5");
//Assert.IsNull (field.FieldValueEditString, "#C6");
//Assert.IsNull (field.FieldValueString, "#C7");
// The FirstName column is not a foreign key one
AssertExtensions.Throws<Exception> (() => {
var f = field.ForeignKeyColumn;
}, "#C8");
AssertExtensions.Throws<Exception> (() => {
var f = field.GetForeignKeyPath ();
}, "#C9");
Assert.IsNotNull (field.Host, "#C10");
Assert.AreEqual (dc, field.Host, "#C10-1");
Assert.IsNotNull (field.MetadataAttributes, "#C11");
Assert.AreEqual (dc.Column.Attributes, field.MetadataAttributes, "#C11-1");
Assert.AreEqual (DataBoundControlMode.ReadOnly, field.Mode, "#C12");
Assert.AreEqual (field.Host.Mode, field.Mode, "#C12-1");
// Failure with the same exception as above
//Assert.IsNull (field.Row, "#C13");
Assert.IsNotNull (field.Table, "#C14");
Assert.AreEqual (dc.Table, field.Table, "#C14-1");
}
[Test]
public void ChildrenPath ()
{
var test = new WebTest ("ListView_DynamicControl_10.aspx");
test.Invoker = PageInvoker.CreateOnInit (ChildrenPath_OnInit);
var p = test.Run ();
Assert.IsNotNull (test.Response, "#X1");
Assert.AreNotEqual (HttpStatusCode.NotFound, test.Response.StatusCode, "#X1-1{0}Returned HTML:{0}{1}", Environment.NewLine, p);
Assert.AreNotEqual (HttpStatusCode.InternalServerError, test.Response.StatusCode, "#X1-2{0}Returned HTML:{0}{1}", Environment.NewLine, p);
Assert.IsFalse (String.IsNullOrEmpty (p), "#X1-3");
}
static void ChildrenPath_OnInit (Page p)
{
var lc = p.FindControl ("ListView1") as ListView;
Assert.IsNotNull (lc, "#A1");
var page = p as TestsBasePage<TestDataContext3>;
Assert.IsNotNull (p, "#A1-1");
page.ItemDataBinding += new EventHandler(ChildrenPath_ListControl_OnItemDataBinding);
}
static void ChildrenPath_ListControl_OnItemDataBinding (object sender, EventArgs e)
{
var dc = sender as DynamicControl;
Assert.IsNotNull (dc, "#B1");
Assert.AreEqual ("PrimaryKeyColumn2", dc.ID, "#B1-1");
Assert.AreEqual (typeof (MetaChildrenColumn), dc.Column.GetType (), "#B1-2");
var field = dc.FieldTemplate as PokerFieldTemplateUserControl;
Assert.IsNotNull (field, "#C1");
Assert.AreEqual ("/NunitWeb/AssociatedBarTable/List.aspx", field.GetChildrenPath (), "#C1-1");
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,335 @@
//
// MetaModelTest.cs
//
// Authors:
// Atsushi Enomoto <atsushi@ximian.com>
// Marek Habersack <mhabersack@novell.com>
//
// Copyright (C) 2008-2009 Novell Inc. http://novell.com
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel.DataAnnotations;
using System.Data.SqlClient;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Globalization;
using System.Reflection;
using System.Security.Permissions;
using System.Security.Principal;
using System.Web;
using System.Web.UI;
using System.Web.DynamicData;
using System.Web.DynamicData.ModelProviders;
using System.Web.Routing;
using NUnit.Framework;
using NUnit.Mocks;
using MonoTests.stand_alone.WebHarness;
using MonoTests.SystemWeb.Framework;
using MonoTests.Common;
using MetaModel = System.Web.DynamicData.MetaModel;
using MetaTable = System.Web.DynamicData.MetaTable;
namespace MonoTests.System.Web.DynamicData
{
[TestFixture]
public class MetaModelTest
{
static MetaModel defaultModel;
static MetaModelTest ()
{
defaultModel = new MetaModel ();
}
[Test]
public void DefaultValues ()
{
var model = new MetaModel ();
Assert.IsNotNull (MetaModel.Default, "#A1");
// We can't be sure which model will be the default one when running under Nunit
//Assert.IsTrue (MetaModel.Default == defaultModel, "#A2");
Assert.IsNotNull (model.Tables, "#A3");
Assert.IsNotNull (model.VisibleTables, "#A4");
Assert.IsNotNull (model.FieldTemplateFactory, "#A5");
Assert.AreEqual ("~/DynamicData/", model.DynamicDataFolderVirtualPath, "#A6");
Assert.AreEqual (0, model.VisibleTables.Count, "#B1");
Assert.AreEqual (0, model.Tables.Count, "#B2");
Assert.AreEqual (typeof (FieldTemplateFactory), model.FieldTemplateFactory.GetType (), "#B3");
}
[Test]
public void DynamicDataFolderVirtualPath ()
{
var model = new MetaModel ();
Assert.AreEqual ("~/DynamicData/", model.DynamicDataFolderVirtualPath, "#A1");
model.DynamicDataFolderVirtualPath = null;
Assert.AreEqual ("~/DynamicData/", model.DynamicDataFolderVirtualPath, "#A2");
model.DynamicDataFolderVirtualPath = String.Empty;
Assert.AreEqual (String.Empty, model.DynamicDataFolderVirtualPath, "#A3");
model.DynamicDataFolderVirtualPath = "~/FolderNoTrailingSlash";
Assert.AreEqual ("~/FolderNoTrailingSlash/", model.DynamicDataFolderVirtualPath, "#A4");
model.DynamicDataFolderVirtualPath = "AnotherFolder";
Assert.AreEqual ("AnotherFolder/", model.DynamicDataFolderVirtualPath, "#A5");
model.DynamicDataFolderVirtualPath = "/YetAnotherFolder";
Assert.AreEqual ("/YetAnotherFolder/", model.DynamicDataFolderVirtualPath, "#A6");
model.DynamicDataFolderVirtualPath = null;
Assert.AreEqual ("~/DynamicData/", model.DynamicDataFolderVirtualPath, "#A7");
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void GetTableNull ()
{
new MetaModel ().GetTable ((Type) null);
}
[Test]
public void RegisterContext ()
{
var m = new MetaModel ();
try {
m.RegisterContext (typeof (Foo));
Assert.Fail ("#1");
} catch (TargetInvocationException ex) {
Assert.AreEqual ("ERROR", ex.InnerException.Message, "#2");
} finally {
MetaModel.ResetRegistrationException ();
}
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void RegisterContext2 ()
{
try {
var m = new MetaModel ();
m.RegisterContext (typeof (Bar)); // not supported
} finally {
MetaModel.ResetRegistrationException ();
}
}
[Test]
[ExpectedException (typeof (MissingMethodException))]
public void RegisterContext3 ()
{
var m = new MetaModel ();
try {
// no public constructor
m.RegisterContext (typeof (DataContext));
} finally {
MetaModel.ResetRegistrationException ();
}
}
[Test]
public void RegisterContext4 ()
{
MetaModel m = Utils.GetModel<MyDataContext1> ();
Assert.AreEqual (0, m.Tables.Count, "#1-1");
Assert.AreEqual (0, m.VisibleTables.Count, "#1-2");
Assert.IsNotNull (MetaModel.GetModel (typeof (MyDataContext1)), "#2");
}
[Test]
public void RegisterContext5 ()
{
// In the process of several experiments (as the docs lack any good explanation),
// I determined that this test needs the following for succesful completion:
//
// - a worker request
// - a HttpContext
// - a fake route handler derived from DynamicDataRouteHandler, so that its CreateHandler
// returns a handler without attempting to actually find a View for the requested action
// - a route which can match table actions (taken from the skeleton DynamicData project
// generated by VisualStudio)
// - _empty_ query string returned from the fake worker request, or .NET will populate the
// HttpRequest.QueryString collection with one null item, and .NET's DynamicData will happily
// assume any entry in that collection is not null (it seems null checks aren't very popular
// in DynamicData code)
var req = new FakeHttpWorkerRequest ();
var ctx = new HttpContext (req);
HttpContext.Current = ctx;
MetaModel m = Utils.GetModel<MyDataContext2> ();
RouteTable.Routes.Add (
new DynamicDataRoute ("{table}/{action}.aspx") {
Constraints = new RouteValueDictionary (new { action = "List|Details|Edit|Insert" }),
Model = m,
RouteHandler = new MyDynamicDataRouteHandler ()
});
MetaTable t = m.Tables[0];
Assert.AreEqual (1, m.Tables.Count, "#1-1");
Assert.AreEqual (1, m.VisibleTables.Count, "#1-2");
Assert.AreEqual (typeof (Foo), t.EntityType, "#1-3");
// Those names are only the last part before '.' (i.e. without schema name).
Assert.AreEqual ("FooTable", t.Name, "#2-1");
Assert.AreEqual ("FooTable", t.DisplayName, "#2-2");
Assert.AreEqual ("FooTable", t.DataContextPropertyName, "#2-3");
Assert.AreEqual ("/FooTable/List.aspx", t.ListActionPath, "#2-4");
Assert.AreEqual ("FooTable", t.Provider.Name, "#3-1");
}
[Test]
public void ResetRegistrationException ()
{
MetaModel.ResetRegistrationException ();
var m = new MetaModel ();
try {
m.RegisterContext (typeof (Foo));
Assert.Fail ("#1");
} catch (TargetInvocationException) {
}
try {
m.RegisterContext (typeof (MyDataContext1));
Assert.Fail ("#2");
} catch (InvalidOperationException) {
} finally {
MetaModel.ResetRegistrationException ();
}
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void GetTableObject ()
{
// entity type 'System.Object' not found.
new MetaModel ().GetTable (typeof (object));
}
[Test]
public void GetModel ()
{
Utils.GetModel<UseOnlyInGetModelTestDataContext> ();
AssertExtensions.Throws<ArgumentNullException> (() => MetaModel.GetModel (null), "#A1");
AssertExtensions.Throws<InvalidOperationException> (() => MetaModel.GetModel (typeof (object)), "#A2");
Assert.IsNotNull (MetaModel.GetModel (typeof (UseOnlyInGetModelTestDataContext)));
}
[Test]
public void TryGetTable ()
{
MetaModel m = Utils.GetModel<MyDataContext2> ();
MetaTable t;
AssertExtensions.Throws<ArgumentNullException> (() => m.TryGetTable (null, out t), "#A1");
Assert.IsTrue (m.TryGetTable ("FooTable", out t), "#B1");
Assert.IsNotNull (t, "#B2");
Assert.AreEqual (typeof (Foo), t.EntityType, "#B3");
Assert.IsFalse (m.TryGetTable (String.Empty, out t), "#C1");
Assert.IsNull (t, "#C2");
Assert.IsFalse (m.TryGetTable ("NoSuchTable", out t), "#C3");
Assert.IsNull (t, "#C4");
}
[Test]
public void GetTable ()
{
MetaModel m = Utils.GetModel<MyDataContext2> ();
MetaTable t;
string str = null;
Type type = null;
AssertExtensions.Throws<ArgumentNullException> (() => t = m.GetTable (str), "#A1");
AssertExtensions.Throws<ArgumentNullException> (() => t = m.GetTable (type), "#A2");
AssertExtensions.Throws<ArgumentNullException> (() => t = m.GetTable (null, null), "#A3");
AssertExtensions.Throws<ArgumentNullException> (() => t = m.GetTable (null, typeof (Foo)), "#A4");
AssertExtensions.Throws<ArgumentNullException> (() => t = m.GetTable ("FooTable", null), "#A5");
AssertExtensions.Throws<ArgumentException> (() => t = m.GetTable (String.Empty), "#B1");
AssertExtensions.Throws<ArgumentException> (() => t = m.GetTable ("NoSuchName"), "#B2");
AssertExtensions.Throws<ArgumentException> (() => t = m.GetTable (typeof (object)), "#B3");
AssertExtensions.Throws<ArgumentException> (() => t = m.GetTable ("FooTable", typeof (object)), "#B4");
AssertExtensions.Throws<ArgumentException> (() => t = m.GetTable ("NoSuchTable", typeof (object)), "#B5");
Assert.IsNotNull (t = m.GetTable ("FooTable"), "#C1");
Assert.AreEqual (typeof (Foo), t.EntityType, "#C2");
Assert.IsNotNull (t = m.GetTable (typeof (Foo)), "#C3");
Assert.AreEqual (typeof (Foo), t.EntityType, "#C4");
Assert.IsNotNull (t = m.GetTable ("FooTable", typeof (MyDataContext2)), "#C5");
Assert.AreEqual (typeof (Foo), t.EntityType, "#C6");
}
[Test]
public void GetActionPath ()
{
var foo = new Foo (true);
MetaModel m = Utils.GetModel<MyDataContext2> ();
// None of those are thrown from GetTable - it seems this method performs NO checks at all, sigh...
//
//AssertExtensions.Throws<ArgumentNullException> (() => m.GetActionPath (null, PageAction.List, foo), "#A1");
//AssertExtensions.Throws<ArgumentException> (() => m.GetActionPath (String.Empty, PageAction.List, foo), "#A2");
//AssertExtensions.Throws<ArgumentNullException> (() => m.GetActionPath ("FooTable", null, foo), "#A3");
//AssertExtensions.Throws<ArgumentNullException> (() => m.GetActionPath ("FooTable", PageAction.List, null), "#A4");
//AssertExtensions.Throws<ArgumentException> (() => m.GetActionPath ("NoSuchTable", PageAction.List, foo), "#A5");
}
[Test]
public void GetActionPath2 ()
{
var foo = new Foo (true);
var req = new FakeHttpWorkerRequest ();
var ctx = new HttpContext (req);
HttpContext.Current = ctx;
MetaModel m = Utils.GetModel<MyDataContext2> ();
RouteTable.Routes.Add (
new DynamicDataRoute ("{table}/{action}.aspx") {
Constraints = new RouteValueDictionary (new { action = "List|Details|Edit|Insert" }),
Model = m,
RouteHandler = new MyDynamicDataRouteHandler ()
});
// .NET stacktrace:
//
// at System.Web.DynamicData.MetaModel.TryGetTable(String uniqueTableName, MetaTable& table)
// at System.Web.DynamicData.MetaModel.GetTable(String uniqueTableName)
AssertExtensions.Throws<ArgumentNullException> (() => m.GetActionPath (null, PageAction.List, foo), "#A1");
Assert.AreEqual (String.Empty, m.GetActionPath ("FooTable", null, foo), "#A2");
Assert.AreEqual ("/FooTable/List.aspx", m.GetActionPath ("FooTable", PageAction.List, null), "#A3");
AssertExtensions.Throws<ArgumentException> (() => m.GetActionPath ("NoSuchTable", PageAction.List, foo), "#A4");
Assert.AreEqual ("/FooTable/List.aspx", m.GetActionPath ("FooTable", "List", foo), "#B1");
}
}
}

File diff suppressed because it is too large Load Diff