New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgraded to 0.10.0 - failed unit tests, applicaction does not start #520

Closed
alexbeletsky opened this Issue Feb 24, 2012 · 43 comments

Comments

Projects
None yet
3 participants
@alexbeletsky
Contributor

alexbeletsky commented Feb 24, 2012

Just upgraded to Nancy 0.10.0 for IdeaStrike on @Code_52 project.

The port were smooth, just 2 corrections:

  1. RequestStartup now taking 3 parameters.
  2. Request.Headers.AcceptLanguage is now returning IEnumberable<Tuple<>>, not IEnumerable

After changes applied build went fine, but 3 unit tests are failing (same exception):

System.Exception: System.Exception : ConfigurableBootstrapper Exception
---- Nancy.RequestExecutionException : Oh noes!
-------- Nancy.ViewEngines.ViewNotFoundException : Unable to locate view '404'. Currently available view engine extensions: sshtml,html,htm,cshtml,vbhtml
at Nancy.Testing.PassThroughErrorHandler.Handle(HttpStatusCode statusCode, NancyContext context)
at Nancy.NancyEngine.CheckErrorHandler(NancyContext context)
at Nancy.NancyEngine.HandleRequest(Request request)
at Nancy.Testing.Browser.HandleRequest(String method, String path, Action1 browserContext) at Nancy.Testing.Browser.Get(String path, Action1 browserContext)
at IdeaStrike.Tests.IdeaStrikeSpecBase1.Get(String path, Action1 browserContext) in D:\Development\Projects\Ideastrike\tests\IdeaStrike.Tests\IdeaStrikeSpecBase.cs:line 85

If I try to run the application:

Error Compiling Template: (51, 18) The name 'Url' does not exist in the current context)
Error Compiling Template: (61, 33) The name 'Model' does not exist in the current context)
Error Compiling Template: (68, 26) The name 'Model' does not exist in the current context)
Error Compiling Template: (78, 7) The name 'Model' does not exist in the current context)
Error Compiling Template: (83, 31) The name 'Model' does not exist in the current context)
Error Compiling Template: (88, 14) The name 'Model' does not exist in the current context)
Error Compiling Template: (103, 14) The name 'Model' does not exist in the current context)
Error Compiling Template: (118, 14) The name 'Model' does not exist in the current context)
Error Compiling Template: (132, 25) The name 'Model' does not exist in the current context)
Error Compiling Template: (234, 19) The name 'Url' does not exist in the current context)

My fork is located here:

https://github.com/alexanderbeletsky/Ideastrike/tree/nancy010

It will be very easy to pickup and re-produce all those issues;

@grumpydev

This comment has been minimized.

Member

grumpydev commented Feb 24, 2012

This is a side effect of the new strongly typed view option and the "hacky" intellisense we've had people using previously, and one of the breaking changes. Wherever you've had:

@inherits Nancy.ViewEngines.Razor.NancyRazorViewBase

That now needs to be:

@inherits Nancy.ViewEngines.Razor.NancyRazorViewBase<dynamic>

You can obviously use anything in the "dynamic" bit, but using dynamic is effectively the same as just using RazorViewBase in the previous versions.

@alexbeletsky

This comment has been minimized.

Contributor

alexbeletsky commented Feb 24, 2012

Ahhh..

You wrote:

@inherits Nancy.ViewEngines.Razor.NancyRazorViewBase

That now needs to be:

@inherits Nancy.ViewEngines.Razor.NancyRazorViewBase

whats the difference.. ?? :)

I suppose markdown ate generic parameters ? NancyRazorViewBase<>

@grumpydev

This comment has been minimized.

Member

grumpydev commented Feb 24, 2012

Yeah, I fixed it by shoving it in a code block.. very helpful of it :P

@alexbeletsky

This comment has been minimized.

Contributor

alexbeletsky commented Feb 24, 2012

So, I did.. Tests are still failing, on application start I have

Error Compiling Template: (83, 1) The type 'System.Web.IHtmlString' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.)

@grumpydev

This comment has been minimized.

Member

grumpydev commented Feb 24, 2012

Which template is that error from?

@thecodejunkie

This comment has been minimized.

Member

thecodejunkie commented Feb 24, 2012

That is a bit strange. We removed the dependency on System.Web for IHtmlString and provided our own. Are you using your own extensions for IHtmlString?

@alexbeletsky

This comment has been minimized.

Contributor

alexbeletsky commented Feb 24, 2012

@alexbeletsky

This comment has been minimized.

Contributor

alexbeletsky commented Feb 24, 2012

It will be great if you just clone

https://github.com/alexanderbeletsky/Ideastrike, take nancy010 branch - you will see 3 UT failures and application unable to start. Tests and app were fine at 0.9

@grumpydev

This comment has been minimized.

Member

grumpydev commented Feb 24, 2012

Ah, ok, we removed the System.Web dependency for v0.10 - you can use our IHtmlString in our razor assembly instead.

@thecodejunkie

This comment has been minimized.

Member

thecodejunkie commented Feb 24, 2012

Let us know if that resolves stuff =)

@alexbeletsky

This comment has been minimized.

Contributor

alexbeletsky commented Feb 24, 2012

Even if I completely comment out the body of .cshtml, the test is still falling:

Stack trace is here: https://gist.github.com/6f38c62d6962b15bcb8b

@alexbeletsky

This comment has been minimized.

Contributor

alexbeletsky commented Feb 24, 2012

@thecodejunkie not able to resolve that yet. finish to make unit tests green first, finish up application run-time issues after.

@alexbeletsky

This comment has been minimized.

Contributor

alexbeletsky commented Feb 24, 2012

Hmm.. No, it definately smth is broken, I could not get what exactly.. After I placed

  <add assembly="System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />

into web.config, new issue appeared:

  Error Compiling Template: (52, 92) The name 'HttpContext' does not exist in the current context)
@grumpydev

This comment has been minimized.

Member

grumpydev commented Feb 24, 2012

It sounds like your project is dependent on System.Web, which would have been added automatically with the old Razor assembly as it also required it, but the new one doesn't so you've probably lost the reference. Try re-referencing System.Web, see if that sorts it.

@alexbeletsky

This comment has been minimized.

Contributor

alexbeletsky commented Feb 24, 2012

No success

@thecodejunkie

This comment has been minimized.

Member

thecodejunkie commented Feb 24, 2012

Are you doing something with your test project? When I try and build it I get failing tests as a result, 6 of them. I am not running the tests, just building the solution ?

edit: found this little gem

<Target Name="AfterBuild" Condition=" '$(Configuration)' == 'Debug' AND $(NCRUNCH) == ''">
    <xunit Assembly="bin\debug\IdeaStrike.Tests.dll" />
</Target>
@alexbeletsky

This comment has been minimized.

Contributor

alexbeletsky commented Feb 24, 2012

yeap, it's included as build process.. I've disabled that, since I'm using NCrunch.. You can just remove those lines if they bother you.

Do you have any clues why tests failing? (once again, app and tests were absolutely fine on 0.9)

Thanks

@thecodejunkie

This comment has been minimized.

Member

thecodejunkie commented Feb 24, 2012

I just tracked it down. You're tests never (ever) really worked. At all ;)

In 0.9 (and below) you get back a blank response when you try to render a view that was not found. In 0.10 we changes that so you get an error back with some diagnostics information to help you troubleshoot it.. its that error you are seeing now.

The problem is that the rootpathprovider that is used for the testing doesnt knwo where your views are, so it never discovers them. You need to implement an IRootPathProvider and give it the rootpath of your main Ideastrike assembly (basically something like typeof(IdeastrikeType).Assembly.FullPath) and configure the ConfigurableBootrapper, using with.RootPathProvider<...>, and it should work

Keep us posted

@alexbeletsky

This comment has been minimized.

Contributor

alexbeletsky commented Feb 24, 2012

I will try that now.. Are you able to run application as well ?

@alexbeletsky

This comment has been minimized.

Contributor

alexbeletsky commented Feb 24, 2012

So, I did that:

class RootPathProvider : IRootPathProvider
{
    public string GetRootPath()
    {
        return Path.GetDirectoryName(typeof (IdeastrikeBootstrapper).Assembly.Location);
    }
}

// ...

                with.RootPathProvider<RootPathProvider>();

Those 3 that was failing, continue to fall :(

EDIT: It is clear why,

That would be the root

"C:\Users\alexander.beletsky\AppData\Local\Temp\ca0b9a13-2c32-4a69-9b1d-a5e8692f0361\ca0b9a13-2c32-4a69-9b1d-a5e8692f0361\assembly\dl3\dc978e3f\6fd7ee26_fdf2cc01"

There are no view inside that folder.

@thecodejunkie

This comment has been minimized.

Member

thecodejunkie commented Feb 24, 2012

Yes, a couple of things. Since we've removed the dependency on System.Web, thus the IHtmlString that was defined in there. You need to

a) update all usages of IHtmlString to use Nancy.ViewEngines.Razor.IHtmlString
b) update all usages of McvHtmlString to use Nancy.ViewEngines.Razor.NonEncodedHtmlString
c) let the razor engine know about system.web, because you guys use HttpContext in your layout.. so you need to add

<razor disableAutoIncludeModelNamespace="false">
    <assemblies>
        <add assembly="System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    </assemblies>
    <namespaces>
        <add namespace="System.Web" />
    </namespaces>
</razor>

to your web.config (you already have that section so you just need to complement it with the system.web stuff)

As for the tests.. I will have a look a bit later.. pretty sure its just (still) using a (slightly) invalid path

@alexbeletsky

This comment has been minimized.

Contributor

alexbeletsky commented Feb 24, 2012

This article helped me a lot!

http://iamnotmyself.com/2012/01/03/testing-rendered-output-of-nancyfx-with-the-razor-view-engine-gotchas/

As soon as I changed corresponding views to 'Copy if newer' it start to work!

Now, I'll update application :)

@thecodejunkie

This comment has been minimized.

Member

thecodejunkie commented Feb 24, 2012

It's not pretty, but it works ;)

public class CustomRootPathProvider : IRootPathProvider
{
    public string GetRootPath()
    {
        return Path.Combine(Environment.CurrentDirectory, @"..\..\..\..\src\Ideastrike.Nancy");
    }
}

We've added an issue to make rootpath providers and testing really Super-Duper-Happy-Path!

@alexbeletsky

This comment has been minimized.

Contributor

alexbeletsky commented Feb 24, 2012

What should be used instead of HtmlHelper ?

@thecodejunkie

This comment has been minimized.

Member

thecodejunkie commented Feb 24, 2012

we have our own HtmlHelper that you can add extension methods to. Anything specific?

@alexbeletsky

This comment has been minimized.

Contributor

alexbeletsky commented Feb 24, 2012

It's just a HtmlHelper from MVC, I suppose

public static IHtmlString Markdown(this HtmlHelper helper, string text)

so I had to use the reference: using System.Web.Mvc;

It that right ?

@alexbeletsky

This comment has been minimized.

Contributor

alexbeletsky commented Feb 24, 2012

OK, current status:

the Home page is currently rendered. But that's it. All other pages giving:

Server Error in '/' Application.

Sequence contains no elements

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.InvalidOperationException: Sequence contains no elements

Apparantely view could not be located. It works for "Home" since I changed it to "Copy if newer" for tests.

@thecodejunkie

This comment has been minimized.

Member

thecodejunkie commented Feb 24, 2012

did you try my bootstrapper?

On Fri, Feb 24, 2012 at 3:53 PM, Alexander Beletsky <
reply@reply.github.com

wrote:

OK, current status:

the Home page is currently rendered. But that's it. All other pages giving:

Server Error in '/' Application.

Sequence contains no elements

Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: Sequence contains
no elements

Apparantely view could not be located. It works for "Home" since I changed
it to "Copy if newer" for tests.


Reply to this email directly or view it on GitHub:
#520 (comment)

@alexbeletsky

This comment has been minimized.

Contributor

alexbeletsky commented Feb 24, 2012

did you try my bootstrapper?

No, what do you mean here ? What I did is added RootPath for tests:

https://github.com/alexanderbeletsky/Ideastrike/commit/9ab53dfbef15be663085c9366484333339d14a41

@thecodejunkie

This comment has been minimized.

Member

thecodejunkie commented Feb 24, 2012

I mean to say rootpathprovider

If I use this rootpathprovider #520 (comment)

then all but one test pass (a 404 test fails.. dont have time to debug until tonight)

the site appears to run.. i can get to home and login pages.. but not been able to sign in and try because code52.rpxnow.com takes FOREVER to load .. will try again later tonight

@alexbeletsky

This comment has been minimized.

Contributor

alexbeletsky commented Feb 24, 2012

then all but one test pass (a 404 test fails.. dont have time to debug until tonight)

it really the problem, but it's also the problem in test. I fixed that, but not it's just 404 is not called.

class RootPathProvider : IRootPathProvider
{
    public string GetRootPath()
    {
        return Path.GetDirectoryName(typeof (IdeastrikeBootstrapper).Assembly.Location);
    }
}

that one works fine for tests.. Should it be used for application bootstrapper as well ?

EDIT: and your version breaks all my test :).. that's strange.. )

@alexbeletsky

This comment has been minimized.

Contributor

alexbeletsky commented Feb 24, 2012

Cleared - the exception occurs on

@Html.Partial("Shared/Templates/upload.html")
@Html.Partial("Shared/Templates/download.html")

If I remove that, everything is fine. I'll probably need to create separate issue for that.

@thecodejunkie

This comment has been minimized.

Member

thecodejunkie commented Feb 24, 2012

Could you please clarify.. is this the reason of the remaining failing unit
test? Partial should be working =/

On Fri, Feb 24, 2012 at 4:26 PM, Alexander Beletsky <
reply@reply.github.com

wrote:

Cleared - the exception occurs on

@Html.Partial("Shared/Templates/upload.html")
@Html.Partial("Shared/Templates/download.html")

If I remove that, everything is fine. I'll probably need to create
separate issue for that.


Reply to this email directly or view it on GitHub:
#520 (comment)

@thecodejunkie

This comment has been minimized.

Member

thecodejunkie commented Feb 24, 2012

The only failing test I have here is

IdeaStrike.Tests.IdeaModuleTests.when_viewing_the_idea_page.it_should_set_the_status_code_to_ok_for_the_idea_page

The test is expecting everything to work out, but when I check the module. Granted it does complain about not being able to locate the 404 view which is an issue in itself. Still, the test makes a false assertion so it's probably wrong as well?

Get["/{id}"] = parameters =>
        {
            int id = parameters.id;
            var idea = _ideas.Get(id);
            if (idea == null)
                return View["404"];

the idea is null so it returns the 404 view

EDIT: So if the code is changed to return View["Views/Shared/404"]; then the test works (still a false positive since it's the wrong assertion that is making it pass) .. I checked your bootstrapper and there is nothing that defines a custom view location convention for Shared .. so if you just want to return 404 then you need to define one

https://github.com/NancyFx/Nancy/wiki/View-location-conventions

@alexbeletsky

This comment has been minimized.

Contributor

alexbeletsky commented Feb 24, 2012

Could you please clarify.. is this the reason of the remaining failing unit
test? Partial should be working =/

No. Now we are talking about many things at the same time. Please leave the tests now :)

The problem I'm talking about - if I try to open /idea/new I got exception;

#520 (comment)

and the reason for that is PartialView. If I just remove partials, it's being opened fine (but obviously does not work :)

@thecodejunkie

This comment has been minimized.

Member

thecodejunkie commented Feb 24, 2012

Yeah I will look into that later.. turns out I need sqlexpress
installed..didnt have that at home

the test feedback and route bug is still relevant ;)

On Fri, Feb 24, 2012 at 6:34 PM, Alexander Beletsky <
reply@reply.github.com

wrote:

Could you please clarify.. is this the reason of the remaining failing
unit
test? Partial should be working =/

No. Now we are talking about many things at the same time. Please leave
the tests now :)

The problem I'm talking about - if I try to open /idea/new I got exception;

#520 (comment)

and the reason for that is PartialView. If I just remove partials, it's
being opened fine (but obviously does not work :)


Reply to this email directly or view it on GitHub:
#520 (comment)

@thecodejunkie

This comment has been minimized.

Member

thecodejunkie commented Feb 26, 2012

Turns out this is quite easy. Change the extension, on your partials, from .html to .cshtml and of you go.

@alexbeletsky

This comment has been minimized.

Contributor

alexbeletsky commented Feb 26, 2012

great, I'll try it asap;

thanks for your help!

@alexbeletsky

This comment has been minimized.

Contributor

alexbeletsky commented Feb 27, 2012

Confirmed. Renaming of partial helped!

@thecodejunkie

This comment has been minimized.

Member

thecodejunkie commented Feb 27, 2012

Any remaining issues?

On Mon, Feb 27, 2012 at 10:38 AM, Alexander Beletsky <
reply@reply.github.com

wrote:

Confirmed. Renaming of partial helped!


Reply to this email directly or view it on GitHub:
#520 (comment)

@alexbeletsky

This comment has been minimized.

Contributor

alexbeletsky commented Feb 27, 2012

Thanks a lot to @thecodejunkie and @grumpydev it stablized now. I created a pull request

Code52/Ideastrike#92

so, I hope over issues could be found after further testing. This one might be closed, I suppose;

@thecodejunkie

This comment has been minimized.

Member

thecodejunkie commented Feb 27, 2012

Glad it worked out (and that we had no bugs hehe)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment