Coder Social home page Coder Social logo

matthoneycutt / specsfor Goto Github PK

View Code? Open in Web Editor NEW
196.0 27.0 71.0 85.54 MB

SpecsFor is a light-weight Behavior-Driven Development framework that focuses on ease of use for *developers* by minimizing testing friction.

Home Page: http://specsfor.com

License: MIT License

C# 99.15% PowerShell 0.85%

specsfor's Introduction

Project Description

SpecsFor is another Behavior-Driven Development framework that focuses on ease of use for developers by minimizing testing friction.

Main Features

SpecsFor is a Behavior-Driven Development style framework that puts developer productivity ahead of all other goals. The current release features:

  • AutoMocking - Easily configure and verify behavior.
  • ReSharper Live Templates - Quickly create specs with only a few keystrokes.
  • Clean Separation of Test State - Encapsulate test setup and reuse it across as many specs as you like. Run The Same Specs Multiple Times With Different Contexts - SpecsFor allows you to assert the same things are true given any number of contexts.
  • Mix And Match Contexts - Context can be combined and extended to support complex test setup without code duplication or excess noise in your specs.
  • Declarative Context - Context can be established in many ways, including by simply marking your spec class with a special attribute.
  • Works With Any NUnit Test Runner - No add-ins are needed, SpecsFor is fully compatible with all popular test runners including TestDriven.NET, Resharper, and TeamCity.

Examples

[Given(typeof(TheCarIsNotRunning), typeof(TheCarIsParked))]
[Given(typeof(TheCarIsNotRunning))]
public class when_the_key_is_turned : SpecsFor<Car>
{
    public when_the_key_is_turned(Type[] context) : base(context){}

    protected override void When()
    {
        SUT.TurnKey();
    }

    [Test]
    public void then_it_starts_the_engine()
    {
        GetMockFor<IEngine>()
            .Verify(e => e.Start());
    }
}
public class when_the_key_is_turned_alternate_style : SpecsFor<Car>
{
    protected override void Given()
    {
        Given<TheCarIsNotRunning>();
        Given<TheCarIsParked>();

        base.Given();
    }

    protected override void When()
    {
        SUT.TurnKey();
    }

    [Test]
    public void then_it_starts_the_engine()
    {
        GetMockFor<IEngine>()
            .Verify(e => e.Start());
    }
}

SpecsFor In Action

Check out the docs at http://specsfor.readme.io

Check out the current version in action: http://www.youtube.com/watch?v=MVwguBsR6eA

See an earlier prototype of SpecsFor in action: http://www.youtube.com/view_play_list?p=982492E9FAE3F64A

Read more about SpecsFor at http://trycatchfail.com/blog

specsfor's People

Contributors

deap82 avatar divinci avatar henkeson avatar josephwoodward avatar kradcliffe avatar markmccaigue avatar matthoneycutt avatar milesibastos avatar pagnew avatar paulatkins avatar peitschie avatar robertsimmons avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

specsfor's Issues

StructureMap v3 incompatibility

My main projects all use StructureMap 3 now, but I can't seem to get the test projects up to the same version. When I update StructureMap from 2.6.4.1 to 3.0.3.116, I get a "no suitable method found to override" error anywhere I'm overriding ConfigureContainer,

The odd thing is that I don't see an error in the IDE, only in the Error List. I suspect it's an incompatibility with the definition of IContainer between StructureMap versions.

SpecsFor.Mvc BrowserDriver - Internet Explorer only

Is there is a specific reason that there is only an Internet Explorer browser driver?
I know the Chrome Driver can be a little bit of a pain in Selenium, but we should at least be able to add the Firefox driver easily.

I can create a pull request to add Firefox, but I wanted to create an issue first.

  • Perhaps you are already working on this, or had a good, specific reason for exposing IE only.

Allow overriding of both temporary folder names when publishing to IIS Express

I ran into a problem recently where the action of publishing the target web project failed, due to an MSBuild target not being able to generate a resource file in the SpecsForMvc.TempIntermediateDir path. It turned out, after much head-scratching, that the generated file path was over the Windows MAX_PATH value of 260 characters. In an effort to reduce the length of the file path, I thought I could shorten the path by using .WithTemporaryDirectoryName("ShortDir").

When this didn't work, and after more head-scratching, I realised that "WithTemporaryDirectoryName" rather ambiguously allows you to renamename the publish folder, not the temp folder.
The actual foldername I was attempting to shorten (SpecsForMvc.TempIntermediateDir) had no override.

It would be great if both folder names worked off the value the developer sets.

"Friendly" loading page for SpecsFor.Mvc

The browser should default to a SpecsFor.Mvc page while waiting for IIS Express to spin up and respond to the first request. This will provide a little bit more feedback about what's going on plus it will provide an opportunity to educate users about what SpecsFor.Mvc can do.

problems starting stopping starting host

I have a nunit project where i am testing my website with different authenticators but did not wish to split into spearate test projects.

I am:
setting up a configuration
calling host.start
running tests
calling host.stop
setting up a different configuration
calling host.start
tests fail without opening browser window
calling host.stop

two issues are occuring in this senario (so far)

  1. an error occurs we registering routes. i got around this by clearing the (static) route dictionary during configuration
  2. the Browser driver stops and never starts again.

looking at BrowserDriver.cs, the stop call doesn't set the instance of _driver to null. this is needed to be able to invoke the factory ever again. Please fix!

Testing a site with RequireHttpsAttribute

Just wondering if there's a way to signal specsfor to spin up a https site instead of an http one. Currently it goes to https://localhost which seems to be relying on regular IIS instead of IIS express so that doesn't exist.

Filter.config

    public static void RegisterGlobalFilters(GlobalFilterCollection filters)
    {
        filters.Add(new HandleErrorAttribute());
        filters.Add(new RequireHttpsAttribute());
    }

Setup Method

            var config = new SpecsForMvcConfig();

            config.UseIISExpress()
                .With(Project.Named(@"folder"), @"solution")
                .UseMSBuildExecutableAt(@"C:\program files (x86)\msbuild\12.0\bin\msbuild.exe")
                .CleanupPublishedFiles()
                .ApplyWebConfigTransformForConfig("Debug");

            config.RegisterArea<ApplicationAreaRegistration>();
            config.RegisterArea<AdminAreaRegistration>();
            config.BuildRoutesUsing(r => RouteConfig.RegisterRoutes(r));
            config.UseConventions<BootstrapConventions>();
            config.UseBrowser(BrowserDriver.Chrome);

            this.integrationHost = new SpecsForIntegrationHost(config);
            this.integrationHost.Start();

ShouldLookLikePartial should support more complex expressions

The following fails with a LINQ error:

_widget.ShouldLookLike(() => new Widget
            {
                DueDate = DateTime.Today.AddDays(-7)
            })

The error:

System.ArgumentException : User-defined operator method 'System.DateTime AddDays(Double)' must be static.
at System.Linq.Expressions.Expression.ValidateOperator(MethodInfo method)
at System.Linq.Expressions.Expression.GetMethodBasedCoercionOperator(ExpressionType unaryType, Expression operand, Type convertToType, MethodInfo method)

Using MvcWebApp before any tests are run

Is there a way to call the MvcWebApp before any tests are run? I'd like to do some setup work and it would need to happen before the first test. Is there a way to access the MvcWebApp in the setup method on assembly startup?

3.1.0 release incompatible with current NUnitTestAdapter

Not so much a bug with SpecsFor itself, but possibly something that belongs in the FAQ. Installing SpecsFor 3.1.0 requires NUnit 2.6.3, which will not work with the current version of the NUnitTestAdapter for visual studio. Until a new version of the test adapter comes out, the only workaround I see is to explicitly install SpecsFor v3.0.0 from the package manager console.

If there's nothing new in NUnit 2.6.3 that SpecsFor actually needs, I would suggest changing the required version of NUnit back to 2.6.2, which would also fix the problem.

SpecsFor.MVC: Inheritance Violates Type Constraint

MS Express Web 2012, Windows 8, SpecsFor.Mvc version 2.4.1
Using the first actual test from this blog post, everything builds just fine. When I try to actually run the test, I get the following error:

Test Name: AccountManage_WithoutSession_RedirectsToLogin
Test FullName: MvcApplication8.Tests.UnitTest1.AccountManage_WithoutSession_RedirectsToLogin
Test Source: c:\Users\Calvin\Documents\Visual Studio 2012\Projects\MvcApplication8\MvcApplication8.Tests\UnitTest1.cs : line 22
Test Outcome: Failed
Test Duration: 0:00:00.0062834

Result Message:
Test method MvcApplication8.Tests.UnitTest1.AccountManage_WithoutSession_RedirectsToLogin threw exception:
System.Security.VerificationException: Method SpecsFor.Mvc.MvcWebApp.NavigateTo: type argument 'MvcApplication8.Controllers.AccountController' violates the constraint of type parameter 'TController'.
Result StackTrace: at MvcApplication8.Tests.UnitTest1.AccountManage_WithoutSession_RedirectsToLogin()

The definition of NavigateTo:
public void NavigateTo(Expression<Action> action) where TController : System.Web.Mvc.Controller;

What confuses me is that AccountController inherits directly from System.Web.Mvc.Controller, so NavigateTo shouldn't have any trouble with it, right?

Selenium DriverServiceNotFoundException

This issue pertains to SpecsFor.Mvc in particular.

When I start up VS for the first time, Selenium will often throw an exception:

SetUp : OpenQA.Selenium.DriverServiceNotFoundException : The IEDriverServer.exe file does not exist in the current directory or in a directory on the PATH environment variable. The driver can be downloaded at http://code.google.com/p/selenium/downloads/list.
   at OpenQA.Selenium.DriverService.FindDriverServiceExecutable(String executableName, Uri downloadUrl)
   at OpenQA.Selenium.IE.InternetExplorerDriver..ctor(InternetExplorerOptions options)
   at SpecsFor.Mvc.BrowserDriver.<.cctor>b__1()
   at SpecsFor.Mvc.BrowserDriver.GetDriver()
   at SpecsFor.Mvc.MvcWebApp..ctor()
   at GoBlog.IntegrationTest.LoginControllerTest.SetUp() in LoginControllerTest.cs: line 17

Sometimes restarting VS will do the trick but not always. I am wondering if this is a common issue and how to proceed?

Great library by the way Matt!

Update: Uninstalling and then re-installing the SpecsFor.Mvc package seems to work.

Change path lookup of MSBuild.exe for Visual Studio 2012

With reference to the issue on Stack Overflow on http://stackoverflow.com/questions/24824203/specsfor-mvc-msbuild-exe-not-building-publishing-project-correctly-in-visual.

Visual Studio 2012 has a new version of MSBuild.exe (Read more on http://blogs.msdn.com/b/visualstudio/archive/2013/07/24/msbuild-is-now-part-of-visual-studio.aspx) which is found in C:\Program Files (x86)\MSBuild\12.0\Bin rather than C:\Windows\Microsoft.NET\Framework64\v4.0.30319.

In my situation, the version of C:\Windows\Microsoft.NET\Framework64\v4.0.30319\ is throwing an error to build solution so one would need to change the path to the new version.

Thanks for your help!

UrlMapsTo has two url builds, only one is used

The function has this code:

var url = BuildUrlFromExpression(helper.ViewContext.RequestContext, helper.RouteCollection, action);
var expectedUrl = MvcWebApp.BaseUrl + helper.BuildUrlFromExpression(action);
return (Browser.Url == expectedUrl);

https://github.com/MattHoneycutt/SpecsFor/blob/master/SpecsFor.Mvc/MvcWebApp.cs#L152

The url variable has the more robust code that supports areas where as expectedUrl just uses the standard out of the box html helper. Should expectedUrl be removed and use url for the comparison instead? I can do the PR just wanted to make sure that I wasn't missing anything.

Updating NuGet packages breaks SpecsFor.Mvc

Updated all my NuGet packages, and SpecsFor.Mvc is now looking for an old version of WebDriver. (2.25.1.0 instead of 2.33.0.0) Adding the obvious bindingRedirect to App.config doesn't seem to change anything.

SpecsFor.MVC radio buttons

Is there a way to select a radio button field? I'm not seeing one, thinking that something like this http://stackoverflow.com/a/26191022/1062633 could be an option, but wasn't sure how that fits into the overall vision of the field validation. The main issue I see is that the FluentField assumes a single field for each model property.

Controller which is part of an area does not have route rendered correctly.

I have the following configuration:

Console.WriteLine("Creating config");
var config = new SpecsForMvcConfig();

 ////SpecsFor.Mvc can spin up an instance of IIS Express to host your app 
 ////while the specs are executing.
 Console.WriteLine("Registering IIS Express");
 config.UseIISExpress()
 //To do that, it needs to know the name of the project to test...
 .With(Project.Named("AppointmentReminder"))
  //And optionally, it can apply Web.config transformations if you want 
  //it to.
  .ApplyWebConfigTransformForConfig("IntergrationTests");



  Console.WriteLine("Registering Areas");
  config.RegisterArea<CustomerAreaRegistration>();
  config.RegisterArea<SettingsAreaRegistration>();

  //In order to leverage the strongly-typed helpers in SpecsFor.Mvc,
   //you need to tell it about your routes.  Here we are just calling
  //the infrastructure class from our MVC app that builds the RouteTable.
  Console.WriteLine("Registering Routes");
  config.BuildRoutesUsing(r => RouteConfig.RegisterRoutes(r));

  ///Setup intergration Db
  Console.WriteLine("Setting up db");
  config.Use<SetUpDatabase>();

  //SpecsFor.Mvc can use either Internet Explorer or Firefox.  Support
  //for Chrome is planned for a future release.
  Console.WriteLine("Setting up browser driver");
  config.UseBrowser(BrowserDriver.InternetExplorer);

  //The host takes our configuration and performs all the magic.  We
  //need to keep a reference to it so we can shut it down after all
  //the specifications have executed.
   Console.WriteLine("Starting host");
   _host = new SpecsForIntegrationHost(config);
   _host.Start();

And the following Area registrations

 namespace MyApp
 {
  public class CustomerAreaRegistration : AreaRegistration
  {
    public override string AreaName
    {
        get
        {
            return "Customer";
        }
    }

    public override void RegisterArea(AreaRegistrationContext context)
    {
        context.MapRoute(
            "Customer_default",
            "Customer/{controller}/{action}/{id}",
            new { area = "Customer", action = "defaultAction", id = UrlParameter.Optional            ,
            new string[] { "MyApp.Areas.Customer.Controllers" } 

           );
       }
   }
}

namespace MyApp
{
 public class SettingsAreaRegistration : AreaRegistration
 {
     public override string AreaName
     {
         get
         {
             return "Settings";
         }
     }

     public override void RegisterArea(AreaRegistrationContext context)
     {
         context.MapRoute(
             "Settings_default",
            "Settings/{controller}/{action}/{id}",
            new { action = "Index", id = UrlParameter.Optional }
         );
     }
 }

}

The controller Register is in the Customer Area so:

//arrange
var app = new MvcWebApp();
app.NavigateTo<RegisterController>(controller => controller.CustomerDetails());

Should map to \Customer\Register but it maps to \Register. I looked at the NavigateTo method and it uses
var url = helper.BuildUrlFromExpression(action);
to generate the route.

So in my app a wrote the extension method.

public static string GetRoute(this HtmlHelper value)
    {
        return value.BuildUrlFromExpression<RegisterController>(c => c.CustomerDetails());
    }

to check if the fakes you were using were causing any problems, it renders the route as:

/Register

So either my area configuration mapping is missing something or the BuildUrlFromExpression which you are using to generate URLs, does not honor areas, which is causing SpecsFor.Mvc to not map routes correctly.

The versions I am using are:

package id="SpecsFor" version="3.0.0" targetFramework="net45"
package id="SpecsFor.Mvc" version="2.2.0" targetFramework="net45"

Incidentally I have the a couple of assembly redirects in my app.config, which i copied from my web.config, otherwise when I try to use NavigateTo it complains that the type of my controller does not map the constraint for TController, as I am using MVC 4 on .net 4.5. I have also tried calling RegisterArea before and after BuildRoutesUsing .

Cheers
John

Seeding User Data with Entity Framework

Matt -

This is not a question about SpecsFor, but rather about setting up seed data with Entity Framework (specifically a Test User)

I'm trying to get my SpecsFor.MVC working on a default MVC Template (5.2.2). I'm also writing the test using SpecsFor.

Here is a gist of the code I am using:https://gist.github.com/ChuckBryan/7266adbbfd1f9aa21c19#file-seeddataconfig

Any thoughts would be greatly appreciated.

Otherwise, everything else is working as expected (e.g. "driving" of the browser, etc). I think I have this last copper mile for the Transaction and I should be good.

Thanks

Chuck

ShouldLookLike should return all errors when performing a partial match

There's a small inconsistency between the way ShouldLookLike behaves when given a concrete object and a lambda. With a concrete object, all properties that are not equal are included in the failure message. When using a lambda expression for partial comparison, only the first mismatch is included in the failure message.

Expected and Actual wrong way round in RouteTestingExtentsions AssertSameStringAs()

In the AssertSameStringAs method in SpecsFor.Mvc.Helpers.RouteTestingExtensions, the exception that is generated has the Expected and Actual the wrong way around.

Example test just to show the issue:

SUT.NavigateTo<AccountController>(c => c.Register());
SUT.Route.ShouldMapTo<HomeController>(c => c.Index());

The exception currently shows: 'Expected Account but was Home'

When it should be: 'Expected Home but was Account'

Wrong browser gets launched, resulting in universal test failure

I'm using the latest preview of V3, but I saw this happening with V2 as well. Periodically, SpecsFor.Mvc will get stuck launching the wrong browser. I've configured my project to use Chrome, and when I first start my computer and run the my integration tests, it works. But then something happens - I'm not sure what - and it gets stuck using IE. Beyond that, it doesn't actually work with IE - IE launches, but nothing happens, and the tests all fail, with this error:

Test method Payboard.Web.IntegrationTests.AccountTests.Register_Logout_Login threw exception: 
OpenQA.Selenium.NoSuchElementException: Unable to find element with id == OrganizationName
    at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
   at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(String mechanism, String value)
   at OpenQA.Selenium.Remote.RemoteWebDriver.FindElementById(String id)
   at OpenQA.Selenium.By.<>c__DisplayClass2.<Id>b__0(ISearchContext context)
   at OpenQA.Selenium.By.FindElement(ISearchContext context)
   at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(By by)
   at SpecsFor.Mvc.MvcWebApp.FindElementByExpression(Expression`1 property)
   at SpecsFor.Mvc.FluentField`2..ctor(FluentForm`1 fluentForm, MvcWebApp webApp, Expression`1 property)
   at SpecsFor.Mvc.FluentForm`1.Field(Expression`1 property)
   at Payboard.Web.IntegrationTests.AccountTests.Register() in AccountTests.cs: line 70
   at Payboard.Web.IntegrationTests.AccountTests.Register_Logout_Login() in AccountTests.cs: line 63

SpecsForMvc.TestSite folder not being created

Hi. I have two Windows 8.1 machines, both with VS2013 and msbuild configured the same as far a I can see. When I run my functional specs on each machine, one machine creates the SpecsForMvc.TestSite and tests run as expected, the other machine doesn't create it and all the tests fail. Here is the msbuild output from the successful deployment and here is the unsuccessful output. For some reason the unsuccessful one skips the deployment to SpecsForMvc.TestSite. Any suggestions would be appreciated, thanks.

Issue With StructureMap Version and NuGet Package

It looks like the current 1.1.7 version of the project that is on NuGet requires specifically 2.6.2 of StructureMap and StructureMap.AutoMocking, but the NuGet package specifies >=2.6.2.

I start a brand new project and add the SpecsFlow reference via NuGet. It installs 2.6.3 of SM and SM.AM. Once I build a test and run it, I get the following error:

SetUp : System.IO.FileLoadException : Could not load file or assembly 'StructureMap.AutoMocking, Version=2.6.2.0, Culture=neutral, PublicKeyToken=e60ad81abae3c223' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Using SpecsFor.Mvc with MVC 5.1

Hi Matt,

Firstly this is an awesome framework so thanks for creating it. I'm really looking forward to writing some AA tests to make our development and testing process smoother and higher quality. I have got it working with MVC 5 but the project I am currently working on is using MVC 5.1 and when I try and run the SepcsFor.MVC tests I get an error about the version of MVC not being 5.0. Is there a version which is compatible with MVC 5.1? If not how would I go about solving this issue?

I have posted my question here but too have had no replies so far: http://stackoverflow.com/questions/21711230/using-specsfor-mvc-with-mvc-5-1

Thanks in advance for your help.

Adam

MSBuild Error when trying to test?

I have a standard n-tiered web application with several projects (core, application, webapi, EntityFramework and web). The SpecFor testing project has a dependency on the web project. When I try to run the tests, I get the following error. Any thoughts?

"C:...\xxxx.UnitSpecs.csproj" (default target) (1) ->
(_CopyFilesMarkedCopyLocal target) ->
C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(3797,5): error MSB3027: Could not copy "C:...\xxxx.Web\bin\xxxx.Web.dll" to "bin\Debug\xxxx.Web.dll". Exceeded retry count of 10. Failed. [C:...\xxxx.UnitSpecs\xxxx.UnitSpecs.csproj]
C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(3797,5): error MSB3021: Unable to copy file "C:...\xxxx.Web\bin\xxxx.Web.dll" to "bin\Debug\xxxx.Web.dll". The process cannot access the file 'bin\Debug\xxxx.Web.dll' because it is being used by another process. [C:...\xxxx.UnitSpecs\xxxx.UnitSpecs.csproj]

Issue parsing email address with plus symbol

If an email is sent to an address like [email protected] the resulting address in the To field of the MailMessageEx will end up as [email protected].

I've created a fork which passes the addressList string directly to the Add method of the MailItemCollection, instead of splitting with the regex and calling Add with the individual addresses, and an extra test with an example of one of the previously problematic email addresses. I can send a PR if that sounds like something you'd like to integrate? Thanks!

Feature request: IIS deployment directory cleanup option

I would like to have the option of having the IIS shutdown routine clean up the deployment directory. This would make it so that i did not have to manually delete my database between test fixtures running.

there is even a comment in the code in the IIS action that contains this...

Get SpecFor for .Net 3.5

Hello Matt,

My name is Rene, would you please check if you can get a build for .Net 3.5 framework? Because I'm developing a project and I'm restricted to use that .Net Framework.

Thanks a lot!!

Default Constructor problem

Very lovely framework, I hope we can make it the standard !
I'm using latest version 2.2 from a fork of your code.

I have a non-default constructor for my entity under test. When testing I get this exception thrown

SetUp : System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation.
----> System.ArgumentException : Can not instantiate proxy of class: MyApp.Core.Domain.Model.Entity.
Could not find a parameterless constructor.
Parameter name: constructorArguments

Then I use this trick mention here : http://specsfor.com/help.cshtml

protected override void InitializeClassUnderTest()
{
SUT = new Shared().CreateEntity();
}

For full code ... check here https://gist.github.com/1528815

The output is now
When_transaction_is_on_hold : InconclusiveTransaction created !
When condition met

which does not show the test line "Okay, Can not pay" ...

I'm I missing something here ?

The strange thing is when I use a public default constructor for my entity and I remove the InitializeClassUnderTest() method,
I'm getting this exception:

SetUp : StructureMap.StructureMapException : StructureMap Exception Code: 202
No Default Instance defined for PluginFamily MyApp.Core.Domain.Model.Entity, MyApp.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
at StructureMap.BuildSession.<.ctor>b__0(Type t)
at StructureMap.Util.Cache2.get_Item(KEY key) at StructureMap.BuildSession.CreateInstance(Type pluginType) at StructureMap.Container.GetInstance() at StructureMap.AutoMocking.AutoMocker1.get_ClassUnderTest()
at SpecsFor.SpecsFor1.InitializeClassUnderTest() at SpecsFor.SpecsFor1.SetupEachSpec()

Any hints my help here ... thanks for your efforts

Big problem attempting to re-initialize in the same app domain

have two separate intializations of this framework within one project has several issues which are extremely difficult to work around due to internal static state in some of the base objects.

in specific the static list object inside of the MvcWebApp that keeps track of all "execute before each test" actions does NOT get reset when a new object is instanced. this has to be manually done otherwise you will end up executing your seed routine twice, three times, fours times (however many test fixtures in your assembly use this framework).

Call MvcWebApp.PreTestCallback.Clear() before you set up a new SpecsForMvcConfig for the next test fixture.

Coming to this conclusion involved much confusion and debugging with the library source. I'm just trying to test my site without have 50 test assemblies and a complicated nunit project file. :(

Add ability to get validation messages created using ValidationMessageFor

It would be really nice to be able to get validation messages made using MVC's Html.ValidationMessageFor in the same way we can get the display, or form field, etc. Right now I have to use a css selector to find it with a hardcoded name which makes that test not quite as robust as my other tests. If there's a better way to do it now I wasn't able to find it.

Using Windows Authentication with SpecsFor.Mvc should be (much) easier.

Right now, using Windows Auth requires a custom applicationHost.config file for IIS Express. It'd rather it be as simple as this:

        var config = new SpecsForMvcConfig();
        config.UseIISExpress()
            //.ApplicationHostConfigurationFile(@"applicationhost.config")
            .UseWindowsAuthentication()
            .With(Project.Named("WindowsAuthSampleApp"));

Controller base class workaround in Route.ShouldMapTo possibly needed

I created a base class:

public abstract class MyController : Controller
{
}

When using the ShouldMapTo function:

SUT.Route.ShouldMapTo MyController (c => c.Index());

I get an intellisense error saying that the type 'MyController' must be convertible to 'System.Mvc.Controller' in order to use it as parameter 'TController' in the generic method ...

Should I extend MvcWebApp and tell it to use MyController for the type?

Add ability to set drivers in BrowserDriver

It would be super helpful if we were able to set our own versions of a driver inside of BrowserDriver within SpecsFor.MVC. I'd like to be able to set my own browser capabilities and point it to a driver location and I can't do that right now.

Getting "Unable to find solution file, traversed up to 'C:\'" error on build server

I have a test suite that is more or less working on my local machine, following the examples on this project and the SpecsFor.MVC site. I'm having trouble getting it to work on the TFS build server, though. It would appear that the tests are failing during setup, when SpecsFor.MVC tries to use the Project.Named method to find the web project.

Here is the complete error message:
SetUp : System.InvalidOperationException : Unable to find solution file, traversed up to 'C:'. Your test runner may be using shadow-copy to create a clone of your working directory. The Project.Named method does not currently support this behavior. You must manually specify the path to the project to be tested instead.

I get what the message is saying, but haven't found a good solution to the problem yet. If one is known, for instance TFS build settings that would stop it from using a shadow copy of the site in some Guid-named temporary folder, then it would be nice if that were added to the examples, or a faq of some kind.

Add ability to send custom state information to RegisterArea

The current implementation to support area registration need to allow custom state information, which might be needed for some applications.

The current Action to register looks like this:

public void RegisterArea() where T : AreaRegistration, new()
{
AddNewAction(() =>
{
var reg = new T();
reg.RegisterArea(new AreaRegistrationContext(reg.AreaName, RouteTable.Routes));
});
}

I was thinking if we can change this to:

public void RegisterArea(object state = null) where T : AreaRegistration, new()
{
AddNewAction(() =>
{
var reg = new T();
reg.RegisterArea(new AreaRegistrationContext(reg.AreaName, RouteTable.Routes, state));
});
}
It will then allow to pass any custom that might be needed under certain circumstances.

Problem with newest StructureMap

At first I thought this was a problem in the newest StructureMap, but it's looking more like a weird drug interaction between the newest StructureMap and the newest SpecsFor. I'm getting the error "The lazily-initialized type does not have a public, parameterless constructor." for several of my tests.

I have a sample project that illustrates the problem. It has two identical tests in it. One uses SpecsFor, and the other is just plain NUnit. If you take the v3.0.0 version of StructureMap that will be installed by the SpecsFor package, everything runs fine. You can update the StructureMap.Automocking.Moq assembly all the way to the newest version and everything will continue to work just fine. As soon as the main StructureMap reference is updated to anything beyond v3.0.3.116, however, the error will appear.

Unfortunately, because I'm on a state project with draconian firewall rules, I can't push or pull anything in or out of GitHub. I can mail you the sample project if you like, though. The zipped up project references SpecsFor v4.0.2 and StructureMap v3.0.0. If you run the tests, they'll both pass. If you then update the SM reference, only the pure NUnit test will continue passing.

Testing broken by MVC 5

I've upgraded a project to MVC 5 that uses SpecsFor.Mvc. Each of my integration tests now fails with the same error:

Result Message: Class Initialization method AssetPortal.IntegrationTests.InvoicesTests.InvoicesTestsInitialize threw exception. System.TypeAccessException: System.TypeAccessException: Attempt by security transparent method 'Microsoft.Web.Mvc.LinkExtensions.BuildUrlFromExpression(System.Web.Mvc.HtmlHelper, System.Linq.Expressions.Expression1<System.Action1<!!0>>)' to access security critical type 'System.Web.Mvc.HtmlHelper' failed..
Result StackTrace:
at Microsoft.Web.Mvc.LinkExtensions.BuildUrlFromExpression[TController](HtmlHelper helper, Expression1 action) at SpecsFor.Mvc.MvcWebApp.NavigateTo[TController](Expression1 action)
at AssetPortal.IntegrationTests.TestsBase.LoginToSite() in d:\Data\Visual Studio Projects\Include Software\AssetPortal\AssetPortal.IntegrationTests\IntegrationTests\TestsBase.cs:line 37

More information on the change in MVC 5 here: http://forums.asp.net/t/1939805.aspx

SpecsFor strong name

I'm using SpecsFor in a signed tests library. Now i have to sign SpecsFor and Should libraries by myself. Please can you sign SpecsFor nuget package?

AuthenticateBeforeEachTestUsing - Authenticate Only Runs Once

I've tried this using both the VS MSTest test runner and using a 3rd-party test runner with the same results.

I'm using config.AuthenticateBeforeEachTestUsing and then I implement IHandleAuthentication and Authenticate(). I have a project with four different unit test classes (marked TestClass) with over 20 test methods, marked with the TestMethod attribute. However, placing a breakpoint in Authenticate I see it is only called once before all tests run.

Is this by-design? I would have thought with the method name AuthenticateBeforeEachTestUsing that it would authenticate before each test, not just once before all tests.

SpecsFor.MVC Exception while installing through PM

Windows 8, MS VS 2012 Web Express

PM> Install-Package SpecsFor.Mvc
Attempting to resolve dependency 'Mvc3Futures (≥ 3.0.20105.0)'.
Attempting to resolve dependency 'MvcContrib.Mvc3.TestHelper-ci (≥ 3.0.100.0)'.
Attempting to resolve dependency 'RhinoMocks (≥ 3.6)'.
Attempting to resolve dependency 'Selenium.WebDriver (≥ 2.25.1)'.
Attempting to resolve dependency 'Newtonsoft.Json (≥ 4.5)'.
Attempting to resolve dependency 'DotNetZip (≥ 1.9.1.8)'.
Successfully installed 'Mvc3Futures 3.0.20105.0'.
Successfully installed 'RhinoMocks 3.6.1'.
Successfully installed 'MvcContrib.Mvc3.TestHelper-ci 3.0.100.0'.
Successfully installed 'Newtonsoft.Json 4.5.11'.
Successfully installed 'DotNetZip 1.9.1.8'.
Successfully installed 'Selenium.WebDriver 2.25.1'.
Successfully installed 'SpecsFor.Mvc 2.4.1'.
Successfully added 'Mvc3Futures 3.0.20105.0' to WebSite1.
Successfully added 'RhinoMocks 3.6.1' to WebSite1.
Successfully added 'MvcContrib.Mvc3.TestHelper-ci 3.0.100.0' to WebSite1.
Successfully added 'Newtonsoft.Json 4.5.11' to WebSite1.
Successfully added 'DotNetZip 1.9.1.8' to WebSite1.
Successfully added 'Selenium.WebDriver 2.25.1' to WebSite1.
Successfully added 'SpecsFor.Mvc 2.4.1' to WebSite1.
Exception calling "Item" with "1" argument(s): "The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))"
At C:\users\calvin\documents\visual studio 2012\Projects\WebSite1\packages\SpecsFor.Mvc.2.4.1\tools\install.ps1:5 char:5

  • if (!$project.Properties.Item("PostBuildEvent").Value.Contains($PostBuildEvent)) ...
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    • FullyQualifiedErrorId : ComMethodTargetInvocation

Specs4Mvc fails during SetUp - 'build failed'

I've followed the blog post verbatim, when I call: _host.Start();, it fails when a 'Build Failed' exception.

I can see the project has been built into the bin\debug\SpecsForMvc.TestSite and of course the project builds and runs fine on it's own. Any ideas?

MVC4 CheckBoxFor can't be found

Line in test:
this.SUT.FindFormFor().Field(m => m.Administrator).Click

Line in Razor:
@Html.CheckBoxFor(model => model.Administrator)

Throws "Can't find element" Exception

The model property:
public bool Administrator { get; set; }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.