Updating tests to use moq.netcore

This commit is contained in:
Pranav K 2015-11-12 16:59:39 -08:00
parent 31a68a0705
commit 2a301691db
11 changed files with 68 additions and 79 deletions

View File

@ -1,40 +1,38 @@
{
"version": "1.0.0",
"compilationOptions": {
"warningsAsErrors": true,
"keyFile": "../../tools/Key.snk"
"version": "1.0.0",
"compilationOptions": {
"warningsAsErrors": true,
"keyFile": "../../tools/Key.snk"
},
"dependencies": {
"Microsoft.AspNet.Razor.Runtime.Precompilation.Files": "1.0.0-*",
"Microsoft.AspNet.Razor.Runtime.Test": "1.0.0-*",
"Microsoft.AspNet.Razor.Test.Sources": {
"version": "4.0.0-*",
"type": "build"
},
"dependencies": {
"Microsoft.AspNet.Razor.Runtime.Precompilation.Files": "1.0.0-*",
"Microsoft.AspNet.Razor.Runtime.Test": "1.0.0-*",
"Microsoft.AspNet.Razor.Test.Sources": {
"version": "4.0.0-*",
"type": "build"
},
"Microsoft.Dnx.Compilation.CSharp.Common": "1.0.0-*",
"Microsoft.Extensions.HashCodeCombiner.Sources": {
"type": "build",
"version": "1.0.0-*"
}
},
"resource": [
"../Microsoft.AspNet.Razor.Runtime.Precompilation.Files/*.cs",
"../Microsoft.AspNet.Razor.Runtime.Test/Runtime/TagHelpers/TestTagHelpers/*.cs",
"BadFiles/*.cs"
],
"commands": {
"test": "xunit.runner.aspnet"
},
"frameworks": {
"dnx451": {
"frameworkAssemblies": {
"System.Text.Encoding": ""
},
"dependencies": {
"Moq": "4.2.1312.1622"
}
},
"dnxcore50": {
}
"Microsoft.Dnx.Compilation.CSharp.Common": "1.0.0-*",
"Microsoft.Extensions.HashCodeCombiner.Sources": {
"type": "build",
"version": "1.0.0-*"
}
},
"resource": [
"../Microsoft.AspNet.Razor.Runtime.Precompilation.Files/*.cs",
"../Microsoft.AspNet.Razor.Runtime.Test/Runtime/TagHelpers/TestTagHelpers/*.cs",
"BadFiles/*.cs"
],
"commands": {
"test": "xunit.runner.aspnet"
},
"frameworks": {
"dnx451": {
"frameworkAssemblies": {
"System.Text.Encoding": ""
}
},
"dnxcore50": {
}
}
}

View File

@ -1,7 +1,6 @@
// 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.
#if !DNXCORE50
using Microsoft.AspNet.Razor.CodeGenerators;
using Microsoft.AspNet.Razor.CodeGenerators.Visitors;
using Moq;
@ -45,4 +44,3 @@ namespace Microsoft.AspNet.Razor.Chunks.Generators
}
}
}
#endif

View File

@ -1,7 +1,6 @@
// 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.
#if !DNXCORE50
#if GENERATE_BASELINES
using System;
#endif
@ -66,4 +65,4 @@ namespace Microsoft.AspNet.Razor.CodeGenerators
}
}
}
#endif

View File

@ -6,9 +6,7 @@ using System.Threading;
using Microsoft.AspNet.Razor.Parser;
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
using Microsoft.AspNet.Razor.Test.Framework;
#if !DNXCORE50
using Moq;
#endif
using Xunit;
namespace Microsoft.AspNet.Razor.Test.Parser
@ -70,7 +68,6 @@ namespace Microsoft.AspNet.Razor.Test.Parser
RunOnEndBlockTest(endBlockCallback => new CallbackVisitor(_ => { }, _ => { }, _ => { }, endBlockCallback));
}
#if !DNXCORE50
[Fact]
public void ListenerCallsOnEndSpanCallbackUsingSynchronizationContextIfSpecified()
{
@ -123,7 +120,6 @@ namespace Microsoft.AspNet.Razor.Test.Parser
Assert.Equal(expected, actual);
});
}
#endif
private static void RunOnStartBlockTest(Func<Action<BlockType>, CallbackVisitor> ctor, Action<BlockType, BlockType> verifyResults = null)
{

View File

@ -8,9 +8,7 @@ using Microsoft.AspNet.Razor.Parser.SyntaxTree;
using Microsoft.AspNet.Razor.Test.Framework;
using Microsoft.AspNet.Razor.Text;
using Microsoft.AspNet.Razor.Tokenizer.Symbols;
#if !DNXCORE50
using Moq;
#endif
using Xunit;
namespace Microsoft.AspNet.Razor.Test.Parser
@ -125,7 +123,6 @@ namespace Microsoft.AspNet.Razor.Test.Parser
Assert.Equal(BlockType.Expression, context.BlockStack.Peek().Type);
}
#if !DNXCORE50
[Fact]
public void EndBlockAddsCurrentBlockToParentBlock()
{
@ -174,7 +171,6 @@ namespace Microsoft.AspNet.Razor.Test.Parser
// Assert
ParserTestBase.EvaluateResults(context.CompleteParse(), expected.Build());
}
#endif
[Fact]
public void SwitchActiveParserSetsMarkupParserAsActiveIfCodeParserCurrentlyActive()

View File

@ -1,7 +1,6 @@
// 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.
#if !DNXCORE50
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNet.Razor.Parser;
@ -77,4 +76,3 @@ namespace Microsoft.AspNet.Razor.Test.Parser
}
}
}
#endif

View File

@ -9,10 +9,8 @@ using Microsoft.AspNet.Razor.Parser;
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
using Microsoft.AspNet.Razor.Compilation.TagHelpers;
using Microsoft.AspNet.Razor.Test.Framework;
#if !DNXCORE50
using Moq;
using Moq.Protected;
#endif
using Xunit;
namespace Microsoft.AspNet.Razor.Test.Parser
@ -66,7 +64,6 @@ namespace Microsoft.AspNet.Razor.Test.Parser
factory.Markup(" baz")));
}
#if !DNXCORE50
[Fact]
public void GetTagHelperDescriptors_IsInvokedToLocateTagHelperDescriptors()
{
@ -89,7 +86,6 @@ namespace Microsoft.AspNet.Razor.Test.Parser
// Assert
parser.Verify();
}
#endif
[Fact]
public void ParseMethodSetsUpRunWithSpecifiedCodeParserMarkupParserAndListenerAndPassesToMarkupParser()

View File

@ -1,7 +1,6 @@
// 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.
#if !DNXCORE50
using System.Collections.Generic;
using System.IO;
using System.Text;
@ -117,8 +116,9 @@ namespace Microsoft.AspNet.Razor.Test
var expected = new CSharpCodeGenerator(codeGeneratorContext);
mockHost.Setup(h => h.DecorateCodeGenerator(It.IsAny<CSharpCodeGenerator>(), codeGeneratorContext))
.Returns(expected);
mockHost
.Setup(h => h.DecorateCodeGenerator(It.IsAny<CSharpCodeGenerator>(), codeGeneratorContext))
.Returns(expected);
var engine = new RazorTemplateEngine(mockHost.Object);
// Act
@ -140,9 +140,10 @@ namespace Microsoft.AspNet.Razor.Test
mockEngine.Object.ParseTemplate(reader, cancelToken: source.Token);
// Assert
mockEngine.Verify(e => e.ParseTemplateCore(It.Is<SeekableTextReader>(l => l.ReadToEnd() == "foo"),
null,
source.Token));
mockEngine.Verify(e => e.ParseTemplateCore(
It.Is<SeekableTextReader>(l => l.ReadToEnd() == "foo"),
null,
source.Token));
}
[Fact]
@ -157,11 +158,21 @@ namespace Microsoft.AspNet.Razor.Test
var src = "Baz";
// Act
mockEngine.Object.GenerateCode(reader, className: className, rootNamespace: ns, sourceFileName: src, cancelToken: source.Token);
mockEngine.Object.GenerateCode(
reader,
className: className,
rootNamespace: ns,
sourceFileName: src,
cancelToken: source.Token);
// Assert
mockEngine.Verify(e => e.GenerateCodeCore(It.Is<SeekableTextReader>(l => l.ReadToEnd() == "foo"),
className, ns, src, null, source.Token));
mockEngine.Verify(e => e.GenerateCodeCore(
It.Is<SeekableTextReader>(l => l.ReadToEnd() == "foo"),
className,
ns,
src,
null,
source.Token));
}
[Fact]
@ -202,7 +213,11 @@ namespace Microsoft.AspNet.Razor.Test
var engine = new RazorTemplateEngine(CreateHost(designTime: true));
// Act
var results = engine.GenerateCode(new StringTextBuffer("foo @bar()"), className: null, rootNamespace: null, sourceFileName: "foo.cshtml");
var results = engine.GenerateCode(
new StringTextBuffer("foo @bar()"),
className: null,
rootNamespace: null,
sourceFileName: "foo.cshtml");
// Assert
Assert.True(results.Success);
@ -311,12 +326,13 @@ namespace Microsoft.AspNet.Razor.Test
public string Checksum { get; set; }
protected internal override GeneratorResults GenerateCodeCore(ITextDocument input,
string className,
string rootNamespace,
string sourceFileName,
string checksum,
CancellationToken? cancelToken)
protected internal override GeneratorResults GenerateCodeCore(
ITextDocument input,
string className,
string rootNamespace,
string sourceFileName,
string checksum,
CancellationToken? cancelToken)
{
Checksum = checksum;
return null;
@ -324,4 +340,3 @@ namespace Microsoft.AspNet.Razor.Test
}
}
}
#endif

View File

@ -9,9 +9,7 @@ using Microsoft.AspNet.Razor.Parser.SyntaxTree;
using Microsoft.AspNet.Razor.Parser.TagHelpers;
using Microsoft.AspNet.Razor.Test.Framework;
using Microsoft.Extensions.Internal;
#if !DNXCORE50
using Moq;
#endif
using Xunit;
namespace Microsoft.AspNet.Razor.Compilation.TagHelpers
@ -20,7 +18,6 @@ namespace Microsoft.AspNet.Razor.Compilation.TagHelpers
{
private static readonly SpanFactory Factory = SpanFactory.CreateCsHtml();
#if !DNXCORE50
[Fact]
public void GetDescriptors_InvokesResolveOnceForAllDirectives()
{
@ -43,7 +40,6 @@ namespace Microsoft.AspNet.Razor.Compilation.TagHelpers
// Assert
resolver.Verify(mock => mock.Resolve(It.IsAny<TagHelperDescriptorResolutionContext>()), Times.Once);
}
#endif
[Fact]
public void GetDescriptors_LocatesTagHelperChunkGenerator_CreatesDirectiveDescriptors()

View File

@ -4,16 +4,13 @@
using System;
using System.Web.WebPages.TestUtils;
using Microsoft.AspNet.Razor.Text;
#if !DNXCORE50
using Moq;
#endif
using Xunit;
namespace Microsoft.AspNet.Razor.Test.Text
{
public class TextChangeTest
{
#if !DNXCORE50
[Fact]
public void ConstructorRequiresNonNegativeOldPosition()
{
@ -149,7 +146,6 @@ namespace Microsoft.AspNet.Razor.Test.Text
Assert.Equal(1, change.NewText.Length);
Assert.Equal(5, change.OldText.Length);
}
#endif
[Fact]
public void OldTextReturnsOldSpanFromOldBuffer()

View File

@ -21,6 +21,7 @@
},
"dnxcore50": {
"dependencies": {
"moq.netcore": "4.4.0-beta8",
"System.Diagnostics.TraceSource": "4.0.0-*",
"System.Reflection.TypeExtensions": "4.0.1-*",
"System.Runtime.Serialization.Primitives": "4.0.11-*"