Created
April 11, 2012 20:13
-
-
Save cromwellryan/2362133 to your computer and use it in GitHub Desktop.
No Smiles Dynamic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Dynamic; | |
using System.Linq; | |
using System.Web.Mvc; | |
namespace MvcApplication1.Controllers | |
{ | |
public class SmokeTestController : Controller | |
{ | |
private readonly Func<SmokeTestResult>[] smokeTests; | |
public SmokeTestController(Func<SmokeTestResult>[] smokeTests) | |
{ | |
this.smokeTests = smokeTests; | |
} | |
public ActionResult Index() | |
{ | |
dynamic testResults = from test in smokeTests | |
let result = test() | |
select new | |
{ | |
ClassName = result.GetType().Name.Replace("TestResult", "") | |
}; | |
dynamic viewModel = new ExpandoObject(); | |
viewModel.TestResults = testResults; | |
return View(viewModel); | |
} | |
} | |
public class FailureTestResult : SmokeTestResult | |
{ | |
} | |
public class SmokeTestResult | |
{ | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Web.Mvc; | |
using FluentAssertions; | |
using MvcApplication1.Controllers; | |
namespace MvcApplication1.Tests | |
{ | |
using TestFixture = Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute; | |
using Test = Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute; | |
[TestFixture] | |
public class SmokeTestTests | |
{ | |
[Test] | |
public void ShouldMakeMeSmile() | |
{ | |
Func<SmokeTestResult> failingTest = () => new FailureTestResult(); | |
var results = new SmokeTestController(new[] { failingTest }).Index().As<ViewResult>(); | |
dynamic viewmodel = results.Model; | |
viewmodel.TestResults.First().Should().BeEquivalent("failure"); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Test Name: ShouldMakeMeSmile | |
Test FullName: MvcApplication1.Tests.SmokeTestTests.ShouldMakeMeSmile | |
Test Source: c:\Users\ryan.cromwell\Documents\Visual Studio 11\Projects\MvcApplication1\MvcApplication1\Tests\SmokeTestTests.cs : line 16 | |
Test Outcome: Failed | |
Test Duration: 0:00:00.5489077 | |
Result Message: | |
Test method MvcApplication1.Tests.SmokeTestTests.ShouldMakeMeSmile threw exception: | |
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'object' does not contain a definition for 'First' | |
Result StackTrace: | |
at CallSite.Target(Closure , CallSite , Object ) | |
at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0) | |
at MvcApplication1.Tests.SmokeTestTests.ShouldMakeMeSmile() in c:\Users\ryan.cromwell\Documents\Visual Studio 11\Projects\MvcApplication1\MvcApplication1\Tests\SmokeTestTests.cs:line 23 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment