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,36 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System;
using System.ComponentModel;
namespace Microsoft.Web.Mvc.Controls.Test
{
public class DesignModeSite : ISite
{
IComponent ISite.Component
{
get { throw new NotImplementedException(); }
}
IContainer ISite.Container
{
get { throw new NotImplementedException(); }
}
bool ISite.DesignMode
{
get { return true; }
}
string ISite.Name
{
get { throw new NotImplementedException(); }
set { throw new NotImplementedException(); }
}
object IServiceProvider.GetService(Type serviceType)
{
throw new NotImplementedException();
}
}
}

View File

@@ -0,0 +1,130 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System.Web.Mvc;
using Xunit;
namespace Microsoft.Web.Mvc.Controls.Test
{
public class DropDownListTest
{
[Fact]
public void NameProperty()
{
// TODO: This
}
[Fact]
public void RenderWithNoNameNotInDesignModeThrows()
{
// TODO: This
}
[Fact]
public void RenderWithNoNameInDesignModeRendersWithSampleData()
{
// Setup
DropDownList c = new DropDownList();
// Execute
string html = MvcTestHelper.GetControlRendering(c, true);
// Verify
Assert.Equal(@"<select>
<option>
Sample Item
</option>
</select>", html);
}
[Fact]
public void RenderWithNoAttributes()
{
// Setup
DropDownList c = new DropDownList();
c.Name = "nameKey";
ViewDataContainer vdc = new ViewDataContainer();
vdc.Controls.Add(c);
vdc.ViewData = new ViewDataDictionary();
vdc.ViewData["nameKey"] = new SelectList(new[] { "aaa", "bbb", "ccc" }, "bbb");
// Execute
string html = MvcTestHelper.GetControlRendering(c, false);
// Verify
Assert.Equal(@"<select name=""nameKey"">
<option>
aaa
</option><option selected=""selected"">
bbb
</option><option>
ccc
</option>
</select>", html);
}
[Fact]
public void RenderWithTextsAndValues()
{
// Setup
DropDownList c = new DropDownList();
c.Name = "nameKey";
ViewDataContainer vdc = new ViewDataContainer();
vdc.Controls.Add(c);
vdc.ViewData = new ViewDataDictionary();
vdc.ViewData["nameKey"] = new SelectList(
new[]
{
new { Text = "aaa", Value = "111" },
new { Text = "bbb", Value = "222" },
new { Text = "ccc", Value = "333" }
},
"Value",
"Text",
"222");
// Execute
string html = MvcTestHelper.GetControlRendering(c, false);
// Verify
Assert.Equal(@"<select name=""nameKey"">
<option value=""111"">
aaa
</option><option value=""222"" selected=""selected"">
bbb
</option><option value=""333"">
ccc
</option>
</select>", html);
}
[Fact]
public void RenderWithNameAndIdRendersNameAndIdAttribute()
{
// Setup
DropDownList c = new DropDownList();
c.Name = "nameKey";
c.ID = "someID";
ViewDataContainer vdc = new ViewDataContainer();
vdc.Controls.Add(c);
vdc.ViewData = new ViewDataDictionary();
vdc.ViewData["nameKey"] = new SelectList(new[] { "aaa", "bbb", "ccc" }, "bbb");
// Execute
string html = MvcTestHelper.GetControlRendering(c, false);
// Verify
Assert.Equal(@"<select id=""someID"" name=""nameKey"">
<option>
aaa
</option><option selected=""selected"">
bbb
</option><option>
ccc
</option>
</select>", html);
}
}
}

View File

@@ -0,0 +1,82 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Web.Mvc;
using System.Web.UI;
using Xunit;
namespace Microsoft.Web.Mvc.Controls.Test
{
public class MvcControlTest
{
[Fact]
public void AttributesProperty()
{
// Setup
DummyMvcControl c = new DummyMvcControl();
// Execute
IDictionary<string, string> attrs = c.Attributes;
// Verify
Assert.NotNull(attrs);
Assert.Empty(attrs);
}
[Fact]
public void GetSetAttributes()
{
// Setup
DummyMvcControl c = new DummyMvcControl();
IAttributeAccessor attrAccessor = c;
IDictionary<string, string> attrs = c.Attributes;
// Execute and Verify
string value;
value = attrAccessor.GetAttribute("xyz");
Assert.Null(value);
attrAccessor.SetAttribute("a1", "v1");
value = attrAccessor.GetAttribute("a1");
Assert.Equal("v1", value);
Assert.Single(attrs);
value = c.Attributes["a1"];
Assert.Equal("v1", value);
}
[Fact]
public void EnableViewStateProperty()
{
DummyMvcControl c = new DummyMvcControl();
Assert.True(c.EnableViewState);
Assert.True((c).EnableViewState);
c.EnableViewState = false;
Assert.False(c.EnableViewState);
Assert.False((c).EnableViewState);
c.EnableViewState = true;
Assert.True(c.EnableViewState);
Assert.True((c).EnableViewState);
}
[Fact]
public void ViewContextWithNoPageIsNull()
{
// Setup
DummyMvcControl c = new DummyMvcControl();
Control c1 = new Control();
c1.Controls.Add(c);
// Execute
ViewContext vc = c.ViewContext;
// Verify
Assert.Null(vc);
}
private sealed class DummyMvcControl : MvcControl
{
}
}
}

View File

@@ -0,0 +1,21 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System.IO;
using System.Web.UI;
namespace Microsoft.Web.Mvc.Controls.Test
{
public static class MvcTestHelper
{
public static string GetControlRendering(Control c, bool designMode)
{
if (designMode)
{
c.Site = new DesignModeSite();
}
HtmlTextWriter writer = new HtmlTextWriter(new StringWriter());
c.RenderControl(writer);
return writer.InnerWriter.ToString();
}
}
}

View File

@@ -0,0 +1,12 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System.Web.Mvc;
using System.Web.UI;
namespace Microsoft.Web.Mvc.Controls.Test
{
public class ViewDataContainer : Control, IViewDataContainer
{
public ViewDataDictionary ViewData { get; set; }
}
}