SpecsFor

{"id":"54471fc9e12a270800028adc","name":"SpecsFor","subdomain":"specsfor","versions":[{"version":"1.0","version_clean":"1.0.0","codename":"","is_stable":true,"is_beta":false,"is_hidden":false,"is_deprecated":false,"_id":"54471fc9e12a270800028adf","releaseDate":"2014-10-22T03:08:57.750Z"}],"current_version":{"version_clean":"1.0.0","version":"1.0"},"oauth":{"enabled":false},"api":{"name":"","url":"","contenttype":"form","auth":"","explorer":true,"proxyEnabled":true,"jwt":false,"authextra":[],"headers":[],"object_definitions":[]},"apiAlt":[],"plan_details":{"name":"Developer Hub","is_active":true,"cost":59,"versions":10000,"custom_domain":true,"custom_pages":true,"whitelabel":false,"errors":false,"password":true,"landing_page":true,"stylesheet":true,"javascript":false,"html":true,"extra_html":false,"admins":true},"intercom":"","intercom_secure_emailonly":false,"flags":{"allow_hub2":false,"hub2":false,"migrationRun":false,"oauth":false,"swagger":false,"correctnewlines":false,"speedyRender":false,"allowXFrame":false,"jwt":false,"hideGoogleAnalytics":false,"stripe":false,"disableDiscuss":false,"autoSslGeneration":true,"newApiExplorer":false,"newSearch":true,"useReactApp":false,"allowApiExplorerJsonEditor":false,"alwaysShowDocPublishStatus":false,"dashReact":false,"directGoogleToStableVersion":false,"disableAnonForum":false,"enterprise":false,"graphql":false,"internalSamlFlow":false,"metricsV2":true,"migrationSwaggerRun":false,"newEditor":false,"newMarkdownBetaProgram":true,"oldMarkdown":false,"rdmdCompatibilityMode":false,"singleProjectEnterprise":false,"staging":false,"translation":false},"asset_base_url":""}
  • Documentation
  • Support
    PopularNewestOpen

    General


    Problem with 2015/4.5

    I see that there's a fork project that says it's for VS 2015 and .Net 4.6, but I'm on a project using 4.5, and I can't seem to get SpecsFor.MVC working. The regular version fails to install right, complaining that the browser drivers already exist. I can push past that by trying the install multiple times, but I still don't end up with a SpecsFor.Mvc reference in the project, even though the NuGet package seems to think it should be there. I tried the fork project, but didn't have any better luck there since it wants to reference a higher version of the System.Web.Mvc assembly. Is there anything else I should try?

    Solved!
    Posted in  General  by  Mel Grubb
    Tue Feb 02 2016 13:10:18 GMT+0000 (Coordinated Universal Time)
    2,395 views
    14 comments
    HTTP Headers

    Hello Is there a way to detect the header response, when the form is submitted? For example SUT.FindFormFor<RegistrationViewModel>() .Field(x => x.Email) .SetValueTo("[email protected]") .Field(x => x.Password) .SetValueTo("12345") .Submit(); At this point, if the response is HTTP 500, the testing goes on. "When" does not fail. Is there a way to assert that the response must be HTTP 200?

    Solved!
    Posted in  General  by  Motig
    Tue Feb 03 2015 22:27:30 GMT+0000 (Coordinated Universal Time)
    2,221 views
    2 comments
    Constructor will be called before calling Given()-method

    Hello, I am using SpecsFor in Version 4.4.0. My application logic has a constructor and uses a Unity-Container like this: namespace SpecsFor_Unity { public class Program { static void Main(string[] args) { } public Program(object anyParameter, IUnityContainer unityContainer) { var foo = unityContainer.Resolve<IFoo>(); if (foo == null) { throw new ArgumentNullException(nameof(foo)); } } public void DoSomething() { } } } My test class Looks like this: namespace SpecsFor_Unity_Test { public class UnitTest1 : SpecsFor<Program> { protected override void Given() { var unityContainer = new UnityContainer(); unityContainer.RegisterType<IFoo, Foo>(); var program = new Program(new object(), unityContainer); } protected override void When() { SUT.DoSomething(); } [Test] public void then_check_anything() { } } } The problem is: the ArgumentNullException will be thrown after resolving unity reference, because constructor is called before Given()-method. I expected that constructor of Program is called within Given()-method. What am I doing wrong? Thanks in advance! Kind regards, Stefan

    Posted in  General  by  Stefan Petry
    Mon Mar 21 2016 12:18:31 GMT+0000 (Coordinated Universal Time)
    1,514 views
    2 comments
    Windows Authentication not working

    Hi, how do you tell your framework to use windows authentication with the IIS Express host. <authentication mode="Windows" /> <authorization> <deny users="?" /> </authorization> My tests are failing, since the page returns Error message 401.2.: Unauthorized: Logon failed due to server configuration. With the authorization set to None, allow all users, it works as expected. Thanks, Stevo

    Posted in  General  by  Stefan Zilik
    Wed Feb 11 2015 09:28:51 GMT+0000 (Coordinated Universal Time)
    1,454 views
    2 comments
    Primitive dependencies

    Moq has a way of specifying values for primitive dependencies. Is there any way to explain this to SpecsFor without completely taking over the SUT construction via InitializeClassUnderTest? In my case, I'm mocking out a repository that takes some paging and result limits at construction time. As such, I need to provide an integer to the constructor or face an error like "Int32 limit = Required primitive dependency is not explicitly defined"

    Solved!
    Posted in  General  by  Mel Grubb
    Mon Jan 18 2016 20:57:26 GMT+0000 (Coordinated Universal Time)
    1,338 views
    2 comments
    Telerik JustMock

    Do you see any issues with using Specs for and Telerik's JustMock mocking library? We have a dependency on it for Fakes of legacy code.

    Solved!
    Posted in  General  by  Jarrod
    Mon Mar 16 2015 13:08:14 GMT+0000 (Coordinated Universal Time)
    1,326 views
    1 comments
    SpecsFor<object?>

    I have a test I need to write that is for a static method on a static class. Since I don't need a SUT to be created, I don't really have anything to put between the angle brackets on the base class. I could just not inherit from SpecsFor at all, but then I have one mutant test that doesn't match the others in terms of style. I'd like to keep the pattern of overriding Given and When for consistency with my other tests. Is there an established or generally accepted pattern for this? I can inherit from SpecsFor<object> and it doesn't seem to complain, but can I count on this in the future?

    Posted in  General  by  Mel Grubb
    Thu May 11 2017 14:52:37 GMT+0000 (Coordinated Universal Time)
    1,279 views
    2 comments
    Theory

    How does this library interact with Theories. I'd like to have multiple datapoints for my tests.

    Solved!
    Posted in  General  by  Damian Reeves
    Mon Jun 01 2015 14:21:27 GMT+0000 (Coordinated Universal Time)
    1,274 views
    2 comments
    Installation - SpecsFor

    Hi Matt: I've spent a frustrating couple of hours trying to install SpecsFor on a new test project in Visual Studion 2015. It first gave me the error that Moq or one of the dependencies was not the same one referenced in the assembly. I then ran the command Add-BindingRedirect in the package manager for the test project. Now I'm getting the message that SetUp : SpecsFor.WhenSpecificationException : An error occurred during the spec 'When' phase. -------------------------------------------------------------------- System.InvalidOperationException: No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlClient'. Make sure the provider is registered in the 'entityFramework' section of the application config file. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information. I note that a couple of the dependencies seem to have new major versions which are not referenced by your package. I think for now I'll abandon SpecsFor and just install the latest versions of Moq, Nunit and Should... Regards, Roger

    Solved!
    Posted in  General  by  Roger Mantews
    Wed Feb 17 2016 15:17:24 GMT+0000 (Coordinated Universal Time)
    1,239 views
    6 comments
    WCF

    Any issues/recommendations/suggestions with using SpecsFor with WCF? I'm using vanilla nunit however i'm really liking SpecsFor and would like to migrate those tests into this framework. Thanks Sean

    Solved!
    Posted in  General  by  Sean Rock
    Tue Oct 13 2015 10:37:58 GMT+0000 (Coordinated Universal Time)
    1,200 views
    4 comments
    Verification of list parameters

    I'm trying to verify a call was made to a repository AddRange method. I can verify the method was called at all like this: ``` GetMockFor<IThingRepository>() .Verify(x => x.AddRange(It.IsAny<IEnumerable<Thing>>()), Times.Once); ``` I can verify that it was passed the expected two objects using some of Moq's partial matching like this: ``` GetMockFor<IThingRepository>() .Verify(x => x.AddRange(It.Is<IEnumerable<Thing>>(y => y.Count() == 2 && y.Any(z => z.ThingType == ThingType.Foo) && y.Any(z => z.ThingType == ThingType.Bar)))); ``` What I can't seem to do is get it to work using a more understandable partial matching syntax like this: ``` GetMockFor<IThingRepository>() .Verify(x => x.AddRange(Looks.Like(() => new[] { new Thing {ThingType = ThingType.Foo}, new Thing {ThingType = ThingType.Bar}, }))); ``` In every case, the code runs but the verify fails saying the method was never called. I looked through the documentation examples, and while they cover the partial matching functionality, they don't have an example of partial matching a collection of things like this. I know the partial matching can do hierarchies, but what about collections? I've even tried replacing the objects in the list with their own individual Looks.Likes: ``` GetMockFor<IThingRepository>() .Verify(x => x.AddRange( Looks.Like(() => new[] { Looks.Like(()=>new Thing {ThingType = ThingType.Foo}), Looks.Like(()=>new Thing {ThingType = ThingType.Bar}), }))); ``` Because of the way this particular code is written, the order of the elements being added is predictable, so I've eliminated that variable, although a partial match that could ignore ordering would be pretty awesome. What am I doing wrong here?

    Solved!
    Posted in  General  by  Mel Grubb
    Wed Mar 02 2016 15:36:59 GMT+0000 (Coordinated Universal Time)
    1,199 views
    5 comments
    ShouldLookLike for a List

    How can I assert a list, something like below: myResult.ShouldLookLike(() => new List<MyObject>(){ new MyObject(){ //resultId is Guid, so this should be ignore ObjectName = "result name 1", ObjectValue = "object value 1" }, new MyObject(){ //resultId is Guid, so this should be ignore ObjectName = "result name 2", ObjectValue = "object value 2" } }

    Solved!
    Posted in  General  by  TranVoNB
    Thu Oct 22 2015 10:32:25 GMT+0000 (Coordinated Universal Time)
    1,166 views
    3 comments
    Using ConfigureContainer to pass an IEnumerable<T> isn't playing nice

    I'm trying to write a spec for a class that takes as its ctor parameter an IEnumerable<T> object. I'm overriding ConfigureContainer and specifying a List<T> of real objects however the sut isn't seeing those values. Any ideas?

    Solved!
    Posted in  General  by  Sean Rock
    Fri Nov 17 2017 12:20:15 GMT+0000 (Coordinated Universal Time)
    1,157 views
    6 comments
    Any advice for use with Knockout?

    I'm on a project now that uses Knockout on the front-end, but I'm hopelessly addicted to SpecsFor.Mvc. I imagine that if the on-page controls follow the same naming convention as MVC would have, then SpecsFor would still be able to find them and use them. As I understand it from the MvcTemplates package, the magic is in wrapping a span around the controls and naming it after the property on the viewmodel. Is this correct? Are there any examples of workable patterns for integrating with Knockout? How about other front-end technologies like Angular?

    Posted in  General  by  Mel Grubb
    Mon Jan 11 2016 14:28:02 GMT+0000 (Coordinated Universal Time)
    1,156 views
    1 comments
    BeforeEachSpec?

    There is an AfterEachSpec, but no matching BeforeEachSpec. Given and When seem to run once per fixture if I'm not mistaken, or at least they appear to be working that way. I have a specific mock that I want to set up differently for one test. Yes, I know that's technically a new context, and I should build a new fixture, but that's would be so heavy in this case that I opted for a simpler text fixture with the individual tests taking some responsibility for tweaking the mocks. Don't you judge me... stop looking at me like that! I am NOT doing it wrong! Okay, fine, I'm doing it wrong. Anyway, I'm seeing the mock behavior bleed over from one test to another depending on their execution order. What I'd like is to set up the 99% behavior in a BeforeEachSpec, and tweak it in just the one test that deviates.

    Solved!
    Posted in  General  by  Mel Grubb
    Tue Jan 05 2016 16:02:24 GMT+0000 (Coordinated Universal Time)
    1,129 views
    3 comments
    How to upgrade SpecFor to use the Latest NUnit

    Want to run tests in VSTS. No tests seems to be running.

    Posted in  General  by  Deepali Khandekar
    Sat Apr 28 2018 03:02:27 GMT+0000 (Coordinated Universal Time)
    1,113 views
    1 comments
    RowTests?

    Are there any examples of using SpecsFor with NUnit's RowTests? (Now called TestCase, I believe) I'd like to replace some SpecFlow (ewww) tests with SpecsFor, but they're making heavy use of the table inputs. The modern NUnit equivalent seems to be the TestCase attribute, but where would it go? It's normally used in place of the [Test] attribute, but the parameters really should be going to the When method. I could just ditch the When, use TestCase and be done with it, but I guess I'm looking for the "yup, that's how you do it" here.

    Posted in  General  by  Mel Grubb
    Thu Apr 04 2019 12:54:34 GMT+0000 (Coordinated Universal Time)
    891 views
    4 comments
    Ask a Question

    Categories

    • All Categories
    • General
    readme.io
    Fork me on GitHub