mardi 30 décembre 2014

Unit Test project is insisting that it requires a reference to EntityFramework

I have an issue that just came up in a unit test project insisting that it requires a reference of EntityFramework, I am convinced it doesn’t need it. Other projects are referencing the project/extension method that the unit test project is referencing/testing and using the extension method just fine without a reference to EntityFramework.


I have found that if I simply execute the extension method as a static method in the unit test project then the unit test project compiles just fine – just completely baffled. I did not see anything informative in the build output.


This does not compile:



[TestMethod]
public void BuildsEmptyRadioButtonList()
{
var htmlHelper = Creator.GetHelper();

var radioButtonList = htmlHelper.RadioButtonList("RadioGaga", new SelectListItem[0]);

var expected = MvcHtmlString.Create(@"...");
Assert.AreEqual(expected.ToHtmlString(), radioButtonList.ToHtmlString());
}


Build output:



1>------ Build started: Project: HA.Shared.Utilities.Mvc.Tests, Configuration: Debug Any CPU ------
1>C:\hatfs\Web2014\4-Test\Source\HA.Shared.Utilities.Mvc.Tests\HtmlHelperRadioExtensionsTests.cs(25,17,25,20): error CS0012: The type 'System.Data.Entity.IDbSet`1<T0>' is defined in an assembly that is not referenced. You must add a reference to assembly 'EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
========== Build: 0 succeeded, 1 failed, 8 up-to-date, 0 skipped ==========


The error is pointing to the “var” in the line that starts with “var radioButtonList”, I tried changing the “var” to “IHtmlString” with no change.


This does compile:



[TestMethod]
public void BuildsEmptyRadioButtonList()
{
var htmlHelper = Creator.GetHelper();

var radioButtonList = HtmlHelperRadioExtensions.RadioButtonList(htmlHelper, "RadioGaga", new SelectListItem[0]);

var expected = MvcHtmlString.Create(@"...");
Assert.AreEqual(expected.ToHtmlString(), radioButtonList.ToHtmlString());
}


Build output:



1>------ Build started: Project: HA.Shared.Utilities.Mvc.Tests, Configuration: Debug Any CPU ------
1> HA.Shared.Utilities.Mvc.Tests -> C:\hatfs\Web2014\4-Test\Source\HA.Shared.Utilities.Mvc.Tests\bin\Debug\HA.Shared.Utilities.Mvc.Tests.dll
========== Build: 1 succeeded, 0 failed, 8 up-to-date, 0 skipped ==========


The signature of the RadioButtonList method is: public static MvcHtmlString RadioButtonList( this HtmlHelper htmlHelper, string name, IEnumerable<SelectListItem> listItems, object radioButtonHtmlAttributes = null, object labelHtmlAttributes = null, bool vertical = false)


Aucun commentaire:

Enregistrer un commentaire