11 comments

I tried the following but ResolveResultWithInfo returned by the call invokedExpression.Reference.Resolve(); has a Info property value of NOT_RESOLVED.

How do I get the correctly resolved type?

Screenshot of the debug value is shown below the code


ta

Ollie


protected override void Run(IInvocationExpression expression, ElementProblemAnalyzerData data, IHighlightingConsumer consumer)
        {
            var invokedExpression = expression.InvokedExpression as IReferenceExpression;
            if (invokedExpression == null)
            {
                return;
            }

            var resolveResult = invokedExpression.Reference.Resolve();
            var name = invokedExpression.Reference.GetName();

            IMethod method = null;

            var methodDeclaration = resolveResult.DeclaredElement as IMethodDeclaration;
            if (methodDeclaration != null)
            {
                method = methodDeclaration as IMethod;
            }

            if (method == null)
            {
                method = resolveResult.DeclaredElement as IMethod;
            }

            if (method == null)
            {
                return;
            }
        }
    }


return type 2.png

0

Hi Ollie. I'm just looking into this - do you have an example of the code you're trying to analyse? Is it just a simple method call, or a variable assignment, or something else?

Thanks
Matt

0

Test file not in front of me - it's at home but the call is something like this...

namespace ClassLibrary2
{
    using System.Reactive.Linq;

    public class Class1
    {
        public void Test()
        {
            Observable.Return(42).Select(n => n);
        }
    }
}


0

OK. The dev team have confirmed that your code should be ok, and the error you're seeing is most likely because the test code is a non-compilable state. Have you made sure your test is marked as .net 4, and that it's including the system.reactive dlls? Without those, the PSI won't be able to correctly identify the return type of the method.

0

Matt - thanks for the reply

'you're seeing is most likely because the test code is a non-compilable state.' - I made sure the test file compiled and had the correct the .NEt 4 attribute, I'll double check later when I get home.


ta

Ollie

0

I can confirm the test file looks like this and is included in the test assembly to make sure it compiles correctly.


namespace Resharper._7._1.ReactivePlugin.Tests
{
    using System.Reactive.Linq;

    class Program2
    {
        public static void Main()
        {
            var tmp = Observable.Return(42).Select(n => n);
        }
    }
}


I also can confirm the .Net 4 attribute has been applied to the fixture and indivdual tests:


namespace Resharper._7._1.ReactivePlugin.Tests
{
    using JetBrains.Application.Settings;
    using JetBrains.ReSharper.Daemon;
    using JetBrains.ReSharper.Daemon.CSharp;
    using JetBrains.ReSharper.TestFramework;
    using NUnit.Framework;

    [TestFixture]
    [TestNetFramework4]
    public class HighlightingTests : CSharpHighlightingTestBase
    {
        protected override bool HighlightingPredicate(IHighlighting highlighting, IContextBoundSettingsStore settingsstore)
        {
            return highlighting is ReactiveSchedulerHighlighting;
        }

        protected override string RelativeTestDataPath
        {
            get { return @"highlighting"; }
        }

        [Test]
        [TestNetFramework4]
        [TestCase("file02.cs")]
        public void Test(string testName)
        {
            DoTestFiles(testName);
        }
    }
}





Any more ideas what might be wrong?




ta



Ollie
0

I can also confirm the Reactive Extensions assemblies have been included via the current NuGet package.


ta

Ollie

0

Hi Ollie. This issue is that the test project that the ReSharper test environment creates hasn't loaded the RX libraries, and so the file isn't in a compilable state, and can't resolve the reference to Observable.Return.

You can fix this using the TestReferencesAttribute on your test, including the relevant dlls. Unfortunately, it looks like you need to provide a fully qualified path, which can make the tests somewhat brittle:

        [Test]
        [TestNetFramework4]
        [TestCase("file02.cs")]
        [TestReferences(@"C:\Users\Matt\Code\scratch\ReSharperPlugIn7\ReSharperPlugIn7.Tests\bin\Debug\System.Reactive.Interfaces.dll",
            @"C:\Users\Matt\Code\scratch\ReSharperPlugIn7\ReSharperPlugIn7.Tests\bin\Debug\System.Reactive.Core.dll",
            @"C:\Users\Matt\Code\scratch\ReSharperPlugIn7\ReSharperPlugIn7.Tests\bin\Debug\System.Reactive.Linq.dll",
            @"C:\Users\Matt\Code\scratch\ReSharperPlugIn7\ReSharperPlugIn7.Tests\bin\Debug\System.Reactive.PlatformServices.dll")]
        public void Test(string testName)
        {
            DoTestFiles(testName);
        }


You can also use environment variables in the string, e.g. "%RX_ROOT%\System.Reactive.Interfaces.dll", or you can create a derived instance of TestRreferencesAttribute that contains logic to find the rx dlls.

I'll speak to the dev team to see if there's a nicer way of handling this.

Thanks
Matt
0

Matt,

Thanks for providing a solution, agreed does make the tests some what brittle, but I'm only wanting to test Reactive Extensions anyway so not a big issue.

I think i might derive off TestRreferencesAttribute and load Rx libraries required.

I'd be interested to hear if the dev team come up with any other solutions.


ta

Ollie

0

There are a few ways to get this a bit cleaner. Firstly, you could use the ExtraAssemblyResolveFoldersCookie to provide a path to look in for the files mentioned in TestReferences. This looks like this:

[TestReferences("System.Reactive.Interfaces", "System.Reactive.Core", "System.Reactive.Linq", "System.Reactive.PlatformServices")]
public void Test(string testName)
{
    using (new ExtraAssemblyResolveFoldersCookie(new FileSystemPath(@"C:\Path\To\Files")))
    {
        DoTestFiles(testName);
    }
}


As for the location of the files, you can use the test's base class's BaseTestDataPath or TestDataPath2 properties to get you the test\data or test\data\{whatever} path (in your example, this last is test\data\highlighting). You can easily add the rx assemblies under these folders. The test framework alos sets up the %BASE_TEST_DATA% and %TEST_DATA% environment variables to match these properties, so you could use these env vars in the TestReferences attribute (or derived attribute - check out TestExtendedAspAttribute). This is essentially the technique that ReSharper's own tests use, for example, check out the various versions of TestMvcAttribute (TestMvc2Attribute, TestMvc3Attribute, etc) which use WebTestUtil.GetReferencedAssemblies() to both set up environment variables and also return the list of assemblies to reference (all containing the just set up env var).
0

Matt,

Thanks for all the help - I've managed to get something working.


ta

Ollie

0

Please sign in to leave a comment.