2016-05-18 15 views
15

के लिए Moq.netcore विफल रहा। इसलिए मेरे पास Moq के साथ .NET RC1 पर काम करने का समाधान था, और मैंने आरसी 2 में अपग्रेड कर दिया है, जिसे मैंने पाया कि Moq.netcore को नए प्लेटफ़ॉर्म पर चलाने के लिए बनाया गया था।.Net कोर आरसी 2

मैं अपने NuGet.config

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <packageSources> 
    <add key="contrib" value="https://www.myget.org/F/aspnet-contrib/api/v3/index.json" /> 
    <add key="NuGet" value="https://api.nuget.org/v3/index.json" /> 
    </packageSources> 
</configuration> 

को aspnet-योगदान जोड़ा मैं अपने project.json फाइल करने के लिए moq.netcore जोड़ दिया है।

"dependencies": { 
    "Microsoft.NETCore.App": { 
    "version": "1.0.0-rc2-*", 
    "type": "platform" 
    }, 
    "dotnet-test-xunit": "1.0.0-rc2-173361-36", 
    "moq.netcore": "4.4.0-beta8", 
    "xunit": "2.1.0" 
}, 

"testRunner": "xunit", 

"frameworks": { 
    "netcoreapp1.0": { 
    "imports": [ 
     "dotnet5.6", 
     "portable-net451+win8" 
    ] 
    } 
} 

मूल रूप से मैं Cli Testing Abstractions UnitTests पीछा किया और जब एक नकली वस्तु instantiatin मैं निम्नलिखित त्रुटि मिलती है:

System.IO.FileNotFoundException : 
    Could not load file or assembly 'System.Diagnostics.TraceSource, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. 

    Stack Trace: 
     at Castle.DynamicProxy.Generators.MethodWithInvocationGenerator.BuildProxiedMethodBody(MethodEmitter emitter, ClassEmitter class, ProxyGenerationOptions options, INamingScope namingScope) 
     at Castle.DynamicProxy.Generators.MethodGenerator.Generate(ClassEmitter class, ProxyGenerationOptions options, INamingScope namingScope) 
     at Castle.DynamicProxy.Contributors.CompositeTypeContributor.ImplementMethod(MetaMethod method, ClassEmitter class, ProxyGenerationOptions options, OverrideMethodDelegate overrideMethod) 
     at Castle.DynamicProxy.Contributors.CompositeTypeContributor.Generate(ClassEmitter class, ProxyGenerationOptions options) 
     at Castle.DynamicProxy.Generators.ClassProxyGenerator.GenerateType(String name, Type[] interfaces, INamingScope namingScope) 
     at Castle.DynamicProxy.Generators.BaseProxyGenerator.ObtainProxyType(CacheKey cacheKey, Func`3 factory) 
     at Castle.DynamicProxy.ProxyGenerator.CreateClassProxy(Type classToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options, Object[] constructorArguments, IInterceptor[] interceptors) 
     at Moq.Proxy.CastleProxyFactory.CreateProxy(Type mockType, ICallInterceptor interceptor, Type[] interfaces, Object[] arguments) 
     at Moq.Mock`1.<InitializeInstance>b__19_0() 
     at Moq.Mock`1.OnGetObject() 
     at Moq.MockDefaultValueProvider.ProvideDefault(MethodInfo member) 
     at Moq.QueryableMockExtensions.FluentMock[T,TResult](Mock`1 mock, Expression`1 setup) 
     at lambda_method(Closure) 
     at Moq.Mock.GetInterceptor(Expression fluentExpression, Mock mock) 
     at Moq.Mock.<>c__DisplayClass57_0`2.<SetupGet>b__0() 
+0

"Microsoft.Extensions.Logging.TraceSource" से शुरू project.json में और घटक जोड़ें? –

उत्तर

29

संपादित करें: इस चाल नहीं रह गया है आवश्यक है Moq > 4.6.38-alpha साथ:

"dependencies" { 
    "Moq": "4.6.38-alpha" 
} 

यह बग है संभवतः System.Diagnostics.TraceSource के कारण होने वाली संभावना moq पैकेज द्वारा सीधे संदर्भित नहीं है और इस प्रकार आपके प्रोजेक्ट में पारगमन से आयात नहीं किया जाता है। इस सीमा को हल करने के लिए, आप स्पष्ट रूप से संदर्भित कर सकते हैं System.Diagnostics.TraceSource पैकेज:

{ 
    "buildOptions": { 
    "warningsAsErrors": true 
    }, 

    "dependencies": { 
    "AspNet.Security.OAuth.Validation": { "target": "project" }, 
    "dotnet-test-xunit": "1.0.0-rc2-build10015", 
    "Microsoft.AspNetCore.TestHost": "1.0.0-rc2-final", 
    "Microsoft.Extensions.Caching.Memory": "1.0.0-rc2-final", 
    "Microsoft.Extensions.Logging.Debug": "1.0.0-rc2-final", 
    "Newtonsoft.Json": "8.0.3", 
    "xunit": "2.1.0" 
    }, 

    "frameworks": { 
    "netcoreapp1.0": { 
     "dependencies": { 
     "Microsoft.NETCore.App": { "type": "platform", "version": "1.0.0-rc2-3002702" }, 
     "moq.netcore": "4.4.0-beta8", 
     "System.Diagnostics.TraceSource": "4.0.0-rc2-24027" 
     }, 

     "imports": [ 
     "dnxcore50", 
     "portable-net451+win8" 
     ] 
    }, 

    "net451": { 
     "dependencies": { 
     "Microsoft.NETCore.Platforms": "1.0.1-rc2-24027", 
     "Moq": "4.2.1312.1622" 
     } 
    } 
    }, 

    "testRunner": "xunit" 
} 

:

यहाँ कैसे हम अपने OAuth2 सत्यापन मिडलवेयर परीक्षण परियोजना, कि दोनों नेट डेस्कटॉप और .NET कोर पर चलाता है में उसका उपयोग कर सकें https://github.com/aspnet-contrib/AspNet.Security.OAuth.Extensions/blob/master/test/AspNet.Security.OAuth.Validation.Tests/project.json#L21

+0

हम्म ... मैंने सिस्टम की कोशिश की। डायग्नोस्टिक्स, लेकिन हाँ यह समझ में आता है। थोड़ा अजीब लगता है, लेकिन मैं इसे बीटा में मोक के लिए तैयार कर दूंगा। सहायता के लिए धन्यवाद। –

+1

सिस्टम। डायग्नोस्टिक्स। ट्रेससोर्स Nuget पैकेज प्रबंधक में पाया जा सकता है प्रीरलीज चेक किया गया है। –

+1

यह उल्लेख करने के लिए संपादित किया गया है कि इस चाल को अब Moq 4.6.38-अल्फा के साथ आवश्यक नहीं है। – Pinpoint

संबंधित मुद्दे