Skip to content
This repository has been archived by the owner on Jul 19, 2024. It is now read-only.

SimpleStubs.generated.cs not generate stubs from shared project. #10

Closed
poplawskidaniel opened this issue Nov 8, 2016 · 12 comments
Closed

Comments

@poplawskidaniel
Copy link
Contributor

Hi.

I tried to use SimpleStubs in some C# UWP project. I added nuget package to it as tutorial section describes. Unfortunatelly SimpleStubs.generates.cs file have only this 3 includes inside:

using System;
using System.Runtime.CompilerServices;
using Etg.SimpleStubs;

I don't know why :(.

I use shared unit test project that is connected to Solution with SimpleStubs.
To be sure I also created public interface inside solution with SimpleStubs without success :( (Still empty generated file).

There are no errors on output just: "SimpleStubs: Generating stubs".
What can be wrong ?

================================== INFOS ======================
Info:
SimpleStubs: v. 2.3.0

Microsoft Visual Studio Professional 2015
Version 14.0.25431.01 Update 3
Microsoft .NET Framework
Version 4.6.01586

Installed Version: Professional

LightSwitch for Visual Studio 2015 00322-50051-85707-AA788
Microsoft LightSwitch for Visual Studio 2015

Visual Basic 2015 00322-50051-85707-AA788
Microsoft Visual Basic 2015

Visual C# 2015 00322-50051-85707-AA788
Microsoft Visual C# 2015

Visual C++ 2015 00322-50051-85707-AA788
Microsoft Visual C++ 2015

Windows Phone SDK 8.0 - ENU 00322-50051-85707-AA788
Windows Phone SDK 8.0 - ENU

Application Insights Tools for Visual Studio Package 7.11.01104.1
Application Insights Tools for Visual Studio

ASP.NET and Web Tools 2015.1 (Beta8) 14.1.11107.0
ASP.NET and Web Tools 2015.1 (Beta8)

ASP.NET Web Frameworks and Tools 2012.2 4.1.41102.0
For additional information, visit http://go.microsoft.com/fwlink/?LinkID=309563

ASP.NET Web Frameworks and Tools 2013 5.2.40314.0
For additional information, visit http://www.asp.net/

Common Azure Tools 1.8
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

JavaScript Language Service 2.0
JavaScript Language Service

JavaScript Project System 2.0
JavaScript Project System

JetBrains ReSharper Ultimate 2016.2.2 Build 106.0.20160913.91321
JetBrains ReSharper Ultimate package for Microsoft Visual Studio. For more information about ReSharper Ultimate, visit http://www.jetbrains.com/resharper. Copyright © 2016 JetBrains, Inc.

Microsoft Azure Mobile Services Tools 1.4
Microsoft Azure Mobile Services Tools

NuGet Package Manager 3.4.4
NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

PreEmptive Analytics Visualizer 1.2
Microsoft Visual Studio extension to visualize aggregated summaries from the PreEmptive Analytics product.

SQL Server Data Tools 14.0.60519.0
Microsoft SQL Server Data Tools

TypeScript 1.8.36.0
TypeScript tools for Visual Studio

Visual Studio Tools for Universal Windows Apps 14.0.25527.01
The Visual Studio Tools for Universal Windows apps allow you to build a single universal app experience that can reach every device running Windows 10: phone, tablet, PC, and more. It includes the Microsoft Windows 10 Software Development Kit.

XamlStylerVSPackage 1.0
XAML Styler.

@nehmebilal
Copy link
Collaborator

Hi @poplawskidaniel,

I have a feeling that you might have installed SimpleStubs to the wrong project in your solution. If SimpleStubs is installed to ProjectA and ProjectB is a dependency of ProjectA, the public interfaces in ProjectB will be stubbed. If you install SimpleStubs to ProjectB and ProjectB has no references, no stubs will be generated.

The other possibility I can think of is that your interfaces are internal.

Please let me know if that's the case.

Thanks

@poplawskidaniel
Copy link
Contributor Author

poplawskidaniel commented Nov 10, 2016

Hi @nehmebilal,
thanks for answer.

I think that I found what is the problem here. Both (App project and Unit tests project) our projects are added as shared reference :( (shared.shproj).

  1. I think that SimpleStubs not support interfaces from shared projects
  2. I cannot install SimpleStub package on shared project

Am I right ?

@nehmebilal
Copy link
Collaborator

@poplawskidaniel No need to install SimpleStubs to a shared project. If you install SimpleStubs to your test project, and the test project has a reference to the shared project (direct reference) or to a project that references the shared project (indirect reference), the stubs will be generated.

Did you make sure that your interface is public? public interface Foo instead of interface Foo. Alternatively you can change the configuration file (SimpleStubs.json) and set "StubInternalInterface" : true as described here.

I hope that helps.

@poplawskidaniel
Copy link
Contributor Author

poplawskidaniel commented Nov 11, 2016

@nehmebilal Thanks.

My interfaces are public for sure.
I've done some investigation and create new fake projects and play with it. My conclusions:

  1. If I create 'normal' project and add it as reference to my test project (with SimpleStubs installed). Stubs are generated OK :).
    BUT
  2. If I create 'shared' project and it as reference to my test project (with SimpleStubs): SimpleStubs cannot find any public interface in shared project and SimpleStubs.generated.cs is empty :(.

Writing 'shared' project I mean special project type in Visual Studio that is named shared project and have shproj extension.

@nehmebilal Can you confirm this by checking on your PC?
Thanks!

@poplawskidaniel poplawskidaniel changed the title SimpleStubs.generated.cs have just 'usings' inside. SimpleStubs.generated.cs not generate stubs from shared project. Nov 11, 2016
@nehmebilal
Copy link
Collaborator

Yes I tried the same yesterday and the stubs were generated for shared projects. Even when I had a dependeny to a normal project that was referecing a shared project (without direct dependency from the test project to the shared project it still worked.

Can you attach your fake project? I'll take a look.

@poplawskidaniel
Copy link
Contributor Author

GenerateStubs.zip

Sure. Thanks! So maybe there is a chance that I'm doing something wrong :).

@nehmebilal
Copy link
Collaborator

nehmebilal commented Nov 12, 2016

@poplawskidaniel Looks like you were right :) If your test project directly depends on a shared project, stubs will not be generated. The reason is that a shared project is like a folder of code that gets copied to the project that is referencing it. For this reason, Roslyn doesn't see it as a dependency of the test project but as if the interfaces belonged in the test project itself.

As a work around, you can create a class library that depends on the shared project and add a reference the class library to your test project. It's actually recommended to put all your stubs in one class library as explained in the Tips and Tricks section. Your dependencies would basically look like the following:

Test Project
| ___ Stubs class library
| ___ | ___Shared Project

Let me know if that works?

@poplawskidaniel
Copy link
Contributor Author

poplawskidaniel commented Nov 15, 2016

@nehmebilal Thank you for answer an idea of work around.
Unfortunately it's not that simple in our project because we have a lot of others dependencies that in such case should also be moved to Stubs class library etc. I will try to do it somehow.

Is it possible in future to add implementation that will work also with shared projects ?

Also some logs from generation of Stubs would be useful.

@poplawskidaniel
Copy link
Contributor Author

Unfortunately I cannot make it work. I don't want to go to details. Simply reason is that our app is a shared project and have a lot of dependencies. Our test project is also shared project that should have reference to the main etc. I give up for now :(.

@nehmebilal
Copy link
Collaborator

@poplawskidaniel Thanks for the update and sorry that didn't work for you. The fact that your test project is a shared project complicates things quite a bit as this is unusual. If it wasn't, you could add a class library and reference all other shared projects from it, then, reference the class library from the test project.

There are two issues we discussed here:

  1. SimpleStubs ignores direct dependencies that are shared projects.
  2. It's not possible to install SimpleStubs to a test project that is a shared project.

Even if we solve 1, 2 is still an issue for you right? Unfortunately 2 might not be possible because shared projects don't get built like normal projects which makes it impossible to inject a build task into them. Besides, NuGet doesn't support installation to shared projects.

@poplawskidaniel
Copy link
Contributor Author

poplawskidaniel commented Nov 15, 2016

@nehmebilal Thanks :)
I found a simple and working solution for me :). I forked your branch and added possibility to generate stubs also from current project (not only reference ones). For default it's disabled but you can add

StubsCurrentProject : true

to configuration file. And it works :D. Now I can just add SimpleStubs to my test project (that reference to our shared projects with code) and stubs are there :D.
I create pull request on this so you can see the changes. If you will have some question, please don't hesitate to ask.
Thanks for your help.

@nehmebilal
Copy link
Collaborator

Resoved by #12, thanks @poplawskidaniel!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants