forked from aspnet/AspNetWebStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMvcFormTest.cs
More file actions
99 lines (79 loc) · 2.59 KB
/
Copy pathMvcFormTest.cs
File metadata and controls
99 lines (79 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections;
using System.IO;
using Microsoft.TestCommon;
using Moq;
namespace System.Web.Mvc.Html.Test
{
public class MvcFormTest
{
[Fact]
public void ConstructorWithNullViewContextThrows()
{
Assert.ThrowsArgumentNull(
delegate { new MvcForm((ViewContext)null); },
"viewContext");
}
[Fact]
public void DisposeRendersCloseFormTag()
{
// Arrange
StringWriter writer = new StringWriter();
ViewContext viewContext = GetViewContext(writer);
MvcForm form = new MvcForm(viewContext);
// Act
form.Dispose();
// Assert
Assert.Equal("</form>", writer.ToString());
}
[Fact]
public void EndFormRendersCloseFormTag()
{
// Arrange
StringWriter writer = new StringWriter();
ViewContext viewContext = GetViewContext(writer);
MvcForm form = new MvcForm(viewContext);
// Act
form.EndForm();
// Assert
Assert.Equal("</form>", writer.ToString());
}
[Fact]
public void DisposeTwiceRendersCloseFormTagOnce()
{
// Arrange
StringWriter writer = new StringWriter();
ViewContext viewContext = GetViewContext(writer);
MvcForm form = new MvcForm(viewContext);
// Act
form.Dispose();
form.Dispose();
// Assert
Assert.Equal("</form>", writer.ToString());
}
[Fact]
public void EndFormTwiceRendersCloseFormTagOnce()
{
// Arrange
StringWriter writer = new StringWriter();
ViewContext viewContext = GetViewContext(writer);
MvcForm form = new MvcForm(viewContext);
// Act
form.EndForm();
form.EndForm();
// Assert
Assert.Equal("</form>", writer.ToString());
}
private static ViewContext GetViewContext(TextWriter writer)
{
Mock<HttpContextBase> mockHttpContext = new Mock<HttpContextBase>();
mockHttpContext.Setup(o => o.Items).Returns(new Hashtable());
return new ViewContext()
{
HttpContext = mockHttpContext.Object,
Writer = writer
};
}
}
}