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

@ -29,10 +29,8 @@
"dnx451": { "dnx451": {
"frameworkAssemblies": { "frameworkAssemblies": {
"System.Text.Encoding": "" "System.Text.Encoding": ""
},
"dependencies": {
"Moq": "4.2.1312.1622"
} }
}, },
"dnxcore50": { "dnxcore50": {
} }

View File

@ -1,7 +1,6 @@
// Copyright (c) .NET Foundation. All rights reserved. // 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. // 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;
using Microsoft.AspNet.Razor.CodeGenerators.Visitors; using Microsoft.AspNet.Razor.CodeGenerators.Visitors;
using Moq; 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. // 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. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#if !DNXCORE50
#if GENERATE_BASELINES #if GENERATE_BASELINES
using System; using System;
#endif #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;
using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Microsoft.AspNet.Razor.Parser.SyntaxTree;
using Microsoft.AspNet.Razor.Test.Framework; using Microsoft.AspNet.Razor.Test.Framework;
#if !DNXCORE50
using Moq; using Moq;
#endif
using Xunit; using Xunit;
namespace Microsoft.AspNet.Razor.Test.Parser namespace Microsoft.AspNet.Razor.Test.Parser
@ -70,7 +68,6 @@ namespace Microsoft.AspNet.Razor.Test.Parser
RunOnEndBlockTest(endBlockCallback => new CallbackVisitor(_ => { }, _ => { }, _ => { }, endBlockCallback)); RunOnEndBlockTest(endBlockCallback => new CallbackVisitor(_ => { }, _ => { }, _ => { }, endBlockCallback));
} }
#if !DNXCORE50
[Fact] [Fact]
public void ListenerCallsOnEndSpanCallbackUsingSynchronizationContextIfSpecified() public void ListenerCallsOnEndSpanCallbackUsingSynchronizationContextIfSpecified()
{ {
@ -123,7 +120,6 @@ namespace Microsoft.AspNet.Razor.Test.Parser
Assert.Equal(expected, actual); Assert.Equal(expected, actual);
}); });
} }
#endif
private static void RunOnStartBlockTest(Func<Action<BlockType>, CallbackVisitor> ctor, Action<BlockType, BlockType> verifyResults = null) 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.Test.Framework;
using Microsoft.AspNet.Razor.Text; using Microsoft.AspNet.Razor.Text;
using Microsoft.AspNet.Razor.Tokenizer.Symbols; using Microsoft.AspNet.Razor.Tokenizer.Symbols;
#if !DNXCORE50
using Moq; using Moq;
#endif
using Xunit; using Xunit;
namespace Microsoft.AspNet.Razor.Test.Parser namespace Microsoft.AspNet.Razor.Test.Parser
@ -125,7 +123,6 @@ namespace Microsoft.AspNet.Razor.Test.Parser
Assert.Equal(BlockType.Expression, context.BlockStack.Peek().Type); Assert.Equal(BlockType.Expression, context.BlockStack.Peek().Type);
} }
#if !DNXCORE50
[Fact] [Fact]
public void EndBlockAddsCurrentBlockToParentBlock() public void EndBlockAddsCurrentBlockToParentBlock()
{ {
@ -174,7 +171,6 @@ namespace Microsoft.AspNet.Razor.Test.Parser
// Assert // Assert
ParserTestBase.EvaluateResults(context.CompleteParse(), expected.Build()); ParserTestBase.EvaluateResults(context.CompleteParse(), expected.Build());
} }
#endif
[Fact] [Fact]
public void SwitchActiveParserSetsMarkupParserAsActiveIfCodeParserCurrentlyActive() public void SwitchActiveParserSetsMarkupParserAsActiveIfCodeParserCurrentlyActive()

View File

@ -1,7 +1,6 @@
// Copyright (c) .NET Foundation. All rights reserved. // 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. // 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.Collections.Generic;
using System.Linq; using System.Linq;
using Microsoft.AspNet.Razor.Parser; 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.Parser.SyntaxTree;
using Microsoft.AspNet.Razor.Compilation.TagHelpers; using Microsoft.AspNet.Razor.Compilation.TagHelpers;
using Microsoft.AspNet.Razor.Test.Framework; using Microsoft.AspNet.Razor.Test.Framework;
#if !DNXCORE50
using Moq; using Moq;
using Moq.Protected; using Moq.Protected;
#endif
using Xunit; using Xunit;
namespace Microsoft.AspNet.Razor.Test.Parser namespace Microsoft.AspNet.Razor.Test.Parser
@ -66,7 +64,6 @@ namespace Microsoft.AspNet.Razor.Test.Parser
factory.Markup(" baz"))); factory.Markup(" baz")));
} }
#if !DNXCORE50
[Fact] [Fact]
public void GetTagHelperDescriptors_IsInvokedToLocateTagHelperDescriptors() public void GetTagHelperDescriptors_IsInvokedToLocateTagHelperDescriptors()
{ {
@ -89,7 +86,6 @@ namespace Microsoft.AspNet.Razor.Test.Parser
// Assert // Assert
parser.Verify(); parser.Verify();
} }
#endif
[Fact] [Fact]
public void ParseMethodSetsUpRunWithSpecifiedCodeParserMarkupParserAndListenerAndPassesToMarkupParser() public void ParseMethodSetsUpRunWithSpecifiedCodeParserMarkupParserAndListenerAndPassesToMarkupParser()

View File

@ -1,7 +1,6 @@
// Copyright (c) .NET Foundation. All rights reserved. // 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. // 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.Collections.Generic;
using System.IO; using System.IO;
using System.Text; using System.Text;
@ -117,7 +116,8 @@ namespace Microsoft.AspNet.Razor.Test
var expected = new CSharpCodeGenerator(codeGeneratorContext); var expected = new CSharpCodeGenerator(codeGeneratorContext);
mockHost.Setup(h => h.DecorateCodeGenerator(It.IsAny<CSharpCodeGenerator>(), codeGeneratorContext)) mockHost
.Setup(h => h.DecorateCodeGenerator(It.IsAny<CSharpCodeGenerator>(), codeGeneratorContext))
.Returns(expected); .Returns(expected);
var engine = new RazorTemplateEngine(mockHost.Object); var engine = new RazorTemplateEngine(mockHost.Object);
@ -140,7 +140,8 @@ namespace Microsoft.AspNet.Razor.Test
mockEngine.Object.ParseTemplate(reader, cancelToken: source.Token); mockEngine.Object.ParseTemplate(reader, cancelToken: source.Token);
// Assert // Assert
mockEngine.Verify(e => e.ParseTemplateCore(It.Is<SeekableTextReader>(l => l.ReadToEnd() == "foo"), mockEngine.Verify(e => e.ParseTemplateCore(
It.Is<SeekableTextReader>(l => l.ReadToEnd() == "foo"),
null, null,
source.Token)); source.Token));
} }
@ -157,11 +158,21 @@ namespace Microsoft.AspNet.Razor.Test
var src = "Baz"; var src = "Baz";
// Act // 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 // Assert
mockEngine.Verify(e => e.GenerateCodeCore(It.Is<SeekableTextReader>(l => l.ReadToEnd() == "foo"), mockEngine.Verify(e => e.GenerateCodeCore(
className, ns, src, null, source.Token)); It.Is<SeekableTextReader>(l => l.ReadToEnd() == "foo"),
className,
ns,
src,
null,
source.Token));
} }
[Fact] [Fact]
@ -202,7 +213,11 @@ namespace Microsoft.AspNet.Razor.Test
var engine = new RazorTemplateEngine(CreateHost(designTime: true)); var engine = new RazorTemplateEngine(CreateHost(designTime: true));
// Act // 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
Assert.True(results.Success); Assert.True(results.Success);
@ -311,7 +326,8 @@ namespace Microsoft.AspNet.Razor.Test
public string Checksum { get; set; } public string Checksum { get; set; }
protected internal override GeneratorResults GenerateCodeCore(ITextDocument input, protected internal override GeneratorResults GenerateCodeCore(
ITextDocument input,
string className, string className,
string rootNamespace, string rootNamespace,
string sourceFileName, string sourceFileName,
@ -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.Parser.TagHelpers;
using Microsoft.AspNet.Razor.Test.Framework; using Microsoft.AspNet.Razor.Test.Framework;
using Microsoft.Extensions.Internal; using Microsoft.Extensions.Internal;
#if !DNXCORE50
using Moq; using Moq;
#endif
using Xunit; using Xunit;
namespace Microsoft.AspNet.Razor.Compilation.TagHelpers namespace Microsoft.AspNet.Razor.Compilation.TagHelpers
@ -20,7 +18,6 @@ namespace Microsoft.AspNet.Razor.Compilation.TagHelpers
{ {
private static readonly SpanFactory Factory = SpanFactory.CreateCsHtml(); private static readonly SpanFactory Factory = SpanFactory.CreateCsHtml();
#if !DNXCORE50
[Fact] [Fact]
public void GetDescriptors_InvokesResolveOnceForAllDirectives() public void GetDescriptors_InvokesResolveOnceForAllDirectives()
{ {
@ -43,7 +40,6 @@ namespace Microsoft.AspNet.Razor.Compilation.TagHelpers
// Assert // Assert
resolver.Verify(mock => mock.Resolve(It.IsAny<TagHelperDescriptorResolutionContext>()), Times.Once); resolver.Verify(mock => mock.Resolve(It.IsAny<TagHelperDescriptorResolutionContext>()), Times.Once);
} }
#endif
[Fact] [Fact]
public void GetDescriptors_LocatesTagHelperChunkGenerator_CreatesDirectiveDescriptors() public void GetDescriptors_LocatesTagHelperChunkGenerator_CreatesDirectiveDescriptors()

View File

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

View File

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