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,31 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System.Web.Razor.Utils;
using Xunit;
using Assert = Microsoft.TestCommon.AssertEx;
namespace System.Web.Razor.Test.Utils
{
public class DisposableActionTest
{
[Fact]
public void ConstructorRequiresNonNullAction()
{
Assert.ThrowsArgumentNull(() => new DisposableAction(null), "action");
}
[Fact]
public void ActionIsExecutedOnDispose()
{
// Arrange
bool called = false;
DisposableAction action = new DisposableAction(() => { called = true; });
// Act
action.Dispose();
// Assert
Assert.True(called, "The action was not run when the DisposableAction was disposed");
}
}
}

View File

@ -0,0 +1,19 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System.Collections.Generic;
namespace System.Web.Razor.Test.Utils
{
public static class EnumerableUtils
{
public static void RunPairwise<T, V>(IEnumerable<T> left, IEnumerable<V> right, Action<T, V> action)
{
IEnumerator<T> leftEnum = left.GetEnumerator();
IEnumerator<V> rightEnum = right.GetEnumerator();
while (leftEnum.MoveNext() && rightEnum.MoveNext())
{
action(leftEnum.Current, rightEnum.Current);
}
}
}
}

View File

@ -0,0 +1,33 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System.Linq.Expressions;
using Xunit;
namespace System.Web.Razor.Test.Utils
{
public static class MiscAssert
{
public static void AssertBothNullOrPropertyEqual<T>(T expected, T actual, Expression<Func<T, object>> propertyExpr, string objectName)
{
// Unpack convert expressions
Expression expr = propertyExpr.Body;
while (expr.NodeType == ExpressionType.Convert)
{
expr = ((UnaryExpression)expr).Operand;
}
string propertyName = ((MemberExpression)expr).Member.Name;
Func<T, object> property = propertyExpr.Compile();
if (expected == null)
{
Assert.Null(actual);
}
else
{
Assert.NotNull(actual);
Assert.Equal(property(expected), property(actual));
}
}
}
}

View File

@ -0,0 +1,35 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System.Diagnostics;
using System.Text.RegularExpressions;
using System.Threading;
using Xunit;
namespace System.Web.Razor.Test.Utils
{
class MiscUtils
{
public const int TimeoutInSeconds = 1;
public static string StripRuntimeVersion(string s)
{
return Regex.Replace(s, @"Runtime Version:[\d.]*", "Runtime Version:N.N.NNNNN.N");
}
public static void DoWithTimeoutIfNotDebugging(Func<int, bool> withTimeout)
{
#if DEBUG
if (Debugger.IsAttached)
{
withTimeout(Timeout.Infinite);
}
else
{
#endif
Assert.True(withTimeout((int)TimeSpan.FromSeconds(TimeoutInSeconds).TotalMilliseconds), "Timeout expired!");
#if DEBUG
}
#endif
}
}
}

View File

@ -0,0 +1,58 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.Web.Razor.Parser.SyntaxTree;
using System.Web.Razor.Text;
using Xunit;
namespace System.Web.Razor.Test.Utils
{
public static class EventAssert
{
public static void NoMoreSpans(IEnumerator<Span> enumerator)
{
IList<Span> tokens = new List<Span>();
while (enumerator.MoveNext())
{
tokens.Add(enumerator.Current);
}
Assert.False(tokens.Count > 0, String.Format(CultureInfo.InvariantCulture, @"There are more tokens available from the source: {0}", FormatList(tokens)));
}
private static string FormatList<T>(IList<T> items)
{
StringBuilder tokenString = new StringBuilder();
foreach (T item in items)
{
tokenString.AppendLine(item.ToString());
}
return tokenString.ToString();
}
public static void NextSpanIs(IEnumerator<Span> enumerator, SpanKind type, string content, SourceLocation location)
{
Assert.True(enumerator.MoveNext(), "There is no next token!");
IsSpan(enumerator.Current, type, content, location);
}
public static void NextSpanIs(IEnumerator<Span> enumerator, SpanKind type, string content, int actualIndex, int lineIndex, int charIndex)
{
NextSpanIs(enumerator, type, content, new SourceLocation(actualIndex, lineIndex, charIndex));
}
public static void IsSpan(Span tok, SpanKind type, string content, int actualIndex, int lineIndex, int charIndex)
{
IsSpan(tok, type, content, new SourceLocation(actualIndex, lineIndex, charIndex));
}
public static void IsSpan(Span tok, SpanKind type, string content, SourceLocation location)
{
Assert.Equal(content, tok.Content);
Assert.Equal(type, tok.Kind);
Assert.Equal(location, tok.Start);
}
}
}