Cannot use Moq library - c#

I am using VS13 Community Edition I want to use Moq in my project. To do so, I went to Nuget Package Manager and searched Moq but no relevant result was there. But I found library named 'Moq: an enjoyable mocking library' and I installed that in my project. But I cannot use it in my project.
Screens
How I installed library
Error

It seems that although you downloaded the NuGet package, something did not succeed as the DLL wasn't added to your references.
Two things you should do:
Make sure it downloaded succesfully
Manually add a reference to Moq.dll.
I suggest looking at the Package Manager Console provided with VS for more detail.

Check you have add the Moq library as a referance in your unit test application.
I think You removed the Moq reference from your project.
From your 2nd image I get their isn't any reference for using Moq.
Please check if you add the reference like below picture.
If you are not able to see it means. Just follow the bellow.
Please note you have to check in you Installed application menu in below link not in online menu as you did in your 1 image.
In your Project please uninstall the Moq library first. like in below picture.
Then you have to install the Moq again from the online menu like below.
After installing the Moq library now you can able to use the Moq Reference.

Related

Using NUnit with Installing Package or using DLL

I'm using an application that uses Visual Studio and C# for it's built-in scripting. I want to use NUnit for testing but the environment doesn't understand nuget packages or add-on dll's so it discards anything that isn't source code each time it saves and reloads a project.
I was hoping that I might be able to get around this by including the full NUnit source code in a folder in the C# project and perhaps using something like the lite-runner to run the tests.
Any advise on how to achieve this?

How to control NuGet packages in Android Class Library?

The setup is like this:
A Xamarin.Android application, which depends on Android class library
(at least that's what the template is called in VS)
Said class
library, the purpose of which (not entirely relevant, but FYI) is
interfacing with a REST service and has a dependance on the famous
Newtonsoft.Json NuGet package.
An NUnit test project for said
library.
IDE is Visual Studio 2017, latest version.
If you build and deploy the app on the phone, everything is fine.
However, if you try to run tests from the tests project, it says that it can't find the Newtonsoft library.
I've even managed to find a sort of reason: when the library gets built, it's dependancies aren't packed inside, and they are not copied to build directory.
When .apk is built for the phone, the dependancies ARE getting packed inside.
However, when NUnit project builds itself, it only takes the library, and the dependancies are nowhere to be found.
However, there's no interface to control the behaviour of NuGet "Package Reference" type dependencies (blue ones), the properties window is empty for them. And I found no way to add NuGet packages to this kind of project as a ".config" type of dependancy (grey one).
There is a workaround - you can add the Newtonsoft package to the NUnit test project, then it gets copied to the build directory and the Android library works with it, however it doesn't feel right to me. Tests don't need that reference and it has no business in that project.
How to control NuGet packages in Android Class Library?
Your workaround is the correct solution, you don't need to worry too much about it.
That is because the Newtonsoft package is not used directly in your NUnit test project, so Visual Studio / MSBuild doesn't know if your test project needs this Newtonsoft library. In order to avoid reference pollution in NUnit test project, Visual Studio / MSBuild tries to only bring references over into NUnit test project that it detects as being required by project Xamarin.Android application.
So, to resolve this issue, we often add Newtonsoft to the test project or give a copy task to copy it to the test project.
See This Thread for some more details.
Looking for an answer to another question I now found info that my described behaviour is a known problem, described by .NET developers here:
https://github.com/dotnet/standard/issues/481

Cannot import NUnit (already added via nuget)

I'm attempting to write tests with NUnit3 as part of some tech-debt migrations. I created a new project within an existing solution. Using nuget I added NUnit and NUnit.Console as per the instructions on github. (I also added the NUnit 3 Test Adapter extension to Visual Studio 2015, but I'm fairly sure that has no bearing on my current situation).
After adding the nuget packages I attempted to import the TestFixture attribute, however, visual studio isn't recognizing the NUnit.Framework namespace and I can't import anything.
The only thing I could thing to fix it was to add the reference manually. There too I was blocked by NUnit not being available.
I'm somewhat at a loss as to how to move forward. How do I proceed and fix the missing reference?
Update: The project I created was of type Unit Test Project, however I've gone ahead and create a Console Application and Class Library. I attempted to add NUnit via nuget to each of them and all of them have had the same result.
Update: Other nuget dependencies seem to install correctly with no discernable difference.
This is only a pseudo solution, as I don't know what the actual issue is. If anyone else comes across a better fix than my work-around I'll be glad to select it if it works for me down the line.
At the time of this writing, the latest version is 3.4.1. I forced nuget to downgrade to 3.4.0 for both the packages NUnit and NUnit.Console and violĂ  the namespace is available as you'd expect any nuget package.

C# Universal App: add github repository as dependency

we are developing a SDK. We want developers being able to integrate this SDK into their projects. I know that in Visual Studio it is possible to create a new project as class library to later integrate the .dll file.
But is there any other possibility than integrating the .dll or adding the classes manually? Something like a dependency on a Github repository maybe?
Thank you!
You have options:
Make a nuget for your SDK
Open source your SDK on GitHub, write a readme, let developer pull your repo and add to their project manually
(NOT RECOMMEND) make an extension and let developer download it. Or provide a .dll file for them to add to their projects.
The reason I dont recommend making an extension is: It makes CI and testing a lots harder. You cant easily install dependency extension on CI environment.

Where do you find GoogleOAuth2AuthenticationOptions?

I feel like I am missing something pretty basic however I have had a solid effort at resolving it.
Basically I am trying to follow this question's answer here: https://stackoverflow.com/a/22694372/768952
It makes use of a GoogleOAuth2AuthenticationOptions object, which from my Googling should be located here within the .net4.5 framework: Microsoft.Owin.Security.Google.GoogleOAuth2AuthenticationOptions
However my MVC project is .net 4.5 and it's not there! Despite this saying it should be: http://www.symbolsource.org/Public/Metadata/NuGet/Project/Microsoft.Owin.Security.Google/2.1.0-rc1/Release/.NETFramework,Version%3Dv4.5/Microsoft.Owin.Security.Google/Microsoft.Owin.Security.Google/GoogleOAuth2AuthenticationHandler.cs?ImageName=Microsoft.Owin.Security.Google
So where on earth is GoogleOAuth2AuthenticationOptions? haha
The solution was as simple as updating the version of Microsoft.Owin.Security.Google in Nuget.
If you're using the 3.0.0 version of Microsoft.Owin.Security.Google, you have to turn on the Google+ API in the Google Developer Console. (http://blogs.msdn.com/b/webdev/archive/2014/07/02/changes-to-google-oauth-2-0-and-updates-in-google-middleware-for-3-0-0-rc-release.aspx)
You should get Microsoft.Owin.Security.Google.
In Visual Studio do the following: open Tools -> Library Package Manager -> Manage NuGet Packages for Solution ... then in search text box put Microsoft.Owin.Security.Google and choose Microsoft.Owin.Security.Google package, press "Install" to install it.
Install "Microsoft.Owin" the same way.

Categories

Resources