There are lots of small fixes and improvements across the SpecsFor suite today. Let’s take a look!
[more]
SpecsFor 4.4.0
First, the Any.NonNullValueOf partial matcher now works with nullable types!
SUT.ShouldLookLike(() => new TestObject { OptionalDate = Any.NonNullValueOf<DateTime?>() })
I also added two new Should extension methods for checking IEnumerables for ascending/descending values:
Assert.DoesNotThrow(() => new[] { 1,2,3,4}.ShouldBeAscending()); Assert.DoesNotThrow(() => new[] { 4,3,2,1 }.ShouldBeDescending());
There’s also a new method you can hook in to if you need to customize something before each individual test case: BeforeEachTest!
public class some_spec : SpecsFor<object> { protected override void BeforeEachTest() { //This will run before each [Test] method. } //... }
SpecsFor<Web> Helpers 1.6.1
There was a bug hiding in the creation of FakeHtmlHelper. This is fixed now!
SpecsFor<Mvc> 4.7.0
I closed out a slew of Github requests and issues in SpecsFor<Mvc> today:
You can now configure the size of the browser window using the SpecsForMvcConfiguration object:
var config = new SpecsForMvcConfig(); config.SetBrowserWindowSize(width: 1024, height: 768);
The publish and intermediate directories used to build the app-under-test are now separately configurable:
var config = new SpecsForMvcConfig(); config.UseIISExpress() .WithIntermediateDirectory("SomeDir") .WithPublishDirectory("SomeDir") .With(Project.Named("SpecsFor.Mvc.Demo")) .CleanupPublishedFiles() .ApplyWebConfigTransformForConfig("Test");
You can now grab a field’s validation message to inspect its contents:
SUT.FindFormFor<LogOnModel>() .Field(x => x.UserName) .HasValidationMessage() .Text.ShouldEqual("The User name field is required.");
You can customize the convention used to locate a validation message by creating your own IElementConventions and plugging them in. You can also subclass the DefaultElementConventions class and override the FindValidationMessageUsingNameFor method with your own implementation. Here’s the default implementation:
public virtual By FindValidationMessageUsingNameFor<TModel, TProp>(Expression<Func<TModel, TProp>> property) where TModel : class { var name = ExpressionHelper.GetExpressionText(property); return By.CssSelector($"[data-valmsg-for='{name}']"); }
It’s a small change, but you can now override the BrowserDriver’s preconfigured instances with your own, so feel free to plug in your own settings for Internet Explorer, Firefox, etc.
Finally, the Project.Named helper is now much more intelligent in how it searches for the target project’s solution. It should automatically discover many common organization conventions now.
var config = new SpecsForMvcConfig(); config.UseIISExpress() .UsePort(44300) .UseHttps() //This is now *much* more intelligent! .With(Project.Named("SpecsFor.Mvc.Demo")) .CleanupPublishedFiles() .ApplyWebConfigTransformForConfig("Test");
As always, if you run into any problems, please let me know!