Unable to discover NUnit test case - c#

I'm trying use Nunit to test my simple program, but I dont know why it cannot discover my test cases... Compile result is pass
Here are my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework;
namespace ConsoleApplication2
{
class FizzBuzz
{
public static string TestTarget(int parameters)
{
return parameters.ToString();
}
}
}
and
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework;
namespace ConsoleApplication2
{
class FizzBuzzTest
{
[TestFixture]
public class fizzBuzzTest
{
[Test]
public void TestCase1()
{
Assert.That(FizzBuzz.TestTarget(1), Is.EqualTo("1222"));
}
}
}
}

If you are using Nunit 3.* you need to install NUnit3 Test Adapter.
For Nunit 2.* - NUnit Test Adapter.
In Visual Studio go to Tools -> Extensions and Update -> Online and find needed adapter.

Related

dotnet test command not finding any test to execute in nUnit

I am using 3.12.0 version of nunit and 3.15.1 version of nunit test adapter.
I have created a project in .net and added a simple code in class to run tests.
From Test->Windows->Test Explorer, I am able to view and run test cases but when I try to run from command line, It is not running anything and not giving any error also.
I am not sure what I am missing. Can anyone suggest what could be the possible reason for this?
screenshot
My code looks like this
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SpecFlow.API.Test
{
public class Class1
{
[SetUp]
public void setupclass()
{
// Console.ReadLine();
}
[Test]
public void setuptest()
{
Assert.Fail("ERROR");
Console.ReadLine();
}
[TearDown]
public void tearDown()
{
Assert.Fail("ERROR");
}
}
}
```
It seems that you are missing the TestFixture attribute
using System;
using NUnit.Framework;
namespace NUnit.Tests
{
// Add TestFixture attribute
[TestFixture]
public class SuccessTests
{
// ...
}
}

Json type is not found within asp.net web api application

I have this controller in my asp.net web api application :
using AutoMapper;
using Microsoft.AspNet.Identity.EntityFramework;
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.Owin;
using Microsoft.Owin.Security;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web;
using System.Web.WebPages.Html;
using System.Threading.Tasks;
using System.Diagnostics;
using System.Text.RegularExpressions;
using System.Net.Mail;
namespace AjTransport.webApi.Controllers
{
public class AccountManageController : ApiController
{
[AllowAnonymous]
public System.Web.Mvc.JsonResult FindUser(string str)
{
var result = UserManager.FindByName(str) ?? UserManager.FindByEmail(str);
return Json(result == null, System.Web.Mvc.JsonRequestBehavior.AllowGet);
}
}
}
The problem is here
return Json(result == null, System.Web.Mvc.JsonRequestBehavior.AllowGet);
the type Json is not found. So I need to know how can I fix this?
Change this
return Json(result == null, System.Web.Mvc.JsonRequestBehavior.AllowGet);
to
return Json(result == null);
Also do not return a System.Web.Mvc.JsonResult, change that to.
public System.Web.Http.Results.JsonResult<bool> FindUser(string str)
This System.Web.Mvc.JsonRequestBehavior.AllowGet is only valid for MVC and not WebAPI (hint, see the name space of the type you are using).
For more info on ApiController.Json method see the link.

Learning WCF - Visual Studio IDE

I am new to WCF and I am using "Learning WCF: A Hands-on Guide" book for now. The book has used VS2008 for the examples, and I am not sure what Visual Studio IDE to use for the examples. I tried using VS Express for Web and it gives the following error:
"HelloIndigo.exe does not contain static Main method suitable at entry point'.
I can understand the cause of the issue, but I am not sure where to add the main method. So I used VS Express for Desktop and it worked fine, but as I kept going in the first chapter I could not proceed as there are no WCF service templates in the VS Express for Desktop version. VS2012 is available only in trial version for free, and it expires in 90 days. So what IDE should I should be using? If the answer is VS Express for Web, then how to fix the error for the example in first chapter?
The example provided in the book is
Host:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ServiceModel;
namespace Host
{
class Program
{
static void Main(string[] args)
{
using (ServiceHost host = new ServiceHost(typeof(HelloIndigo.HelloIndigoService),new Uri("http://localhost:8000/HelloIndigo")))
{
host.AddServiceEndpoint(typeof(HelloIndigo.IHelloIndigoService), new BasicHttpBinding(), "HelloIndigoService");
host.Open();
Console.WriteLine("Please <ENTER> to terminate the service host");
Console.ReadLine();
}
}
}
}
HelloIndigo:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ServiceModel;
namespace HelloIndigo
{
public class HelloIndigoService : IHelloIndigoService
{
public string HelloIndigo()
{
return "Hello Indigo";
}
}
[ServiceContract(Namespace="http://www.thatindigogirl.com/samples/2006/06")]
public interface IHelloIndigoService
{
[OperationContract]
string HelloIndigo();
}
}
Client:
Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ServiceModel;
namespace Client
{
class Program
{
static void Main(string[] args)
{
EndpointAddress ep = new EndpointAddress("http://localhost:8000/HelloIndigo/HelloIndigoService");
IHelloIndigoService proxy = ChannelFactory<IHelloIndigoService>.CreateChannel(new BasicHttpBinding(), ep);
string s = proxy.HelloIndigo();
Console.WriteLine(s);
Console.WriteLine("Please <ENTER> to terminate client");
Console.ReadLine();
}
}
}
ServiceProxy.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ServiceModel;
namespace Client
{
class ServiceProxy
{
}
[ServiceContract(Namespace = "http://www.thatindigogirl.com/samples/2006/06")]
public interface IHelloIndigoService
{
[OperationContract]
string HelloIndigo();
}
}
HelloIndigo should be compiled as a library (DLL) and not an executable. So there should be no Main method - it doesn't have one as a class library.
The point of the Host is that it will host the service library HelloIndigo and start listening for calls on an endpoint for that particular service.
Change HelloIndigo to compile as a class library and add a reference to HelloIndigo in Host. Then start up the Host process.

How to add namespace into Model MVC

I created folder "App_Code" in my project, with simple class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Tools
{
public static class TextTools
{
public static void GenerateHash(string str, int user)
{
}
}
}
My question is: How can I add this namespace "Tools" with all classes and methods to my project? I tried to insert using Tools; in my AccountModels.cs but it isn't working.
Regards
probably you need to add "Tools" in your reference

bringing two projects together

I have a simple window application I am starting and I was given another file I would like to bring into the new project. How do I bring them both together to work as one file?
New Project
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
}
}
}
Other
using System;
using System.Text;
using System.IO;
using System.Net;
namespace CaptchaClient
{
public static class SampleUse
{
public static void SampleSolve()
{
}
}
public class CaptchaSolver
{
}
public enum ResponseState
{
}
}
This screenshots shows the how yo do he procedure
Right click on your project in the Solution Explorer and click Add Existing Item. Then browse to the other class file. Once imported, you might want to change its namespace to the one you are using in your project.

Categories

Resources