public void Should_call_conventions_with_model() { // Given const string viewName = "foo.html"; var viewModel = new object(); object modelPassedToFirstConvention = null; object modelPassedToSecondConvention = null; var resolver = new DefaultViewResolver( this.viewLocator, new Func<string, dynamic, ViewLocationContext, string>[] { (name, model, path) => { modelPassedToFirstConvention = model; return string.Empty; }, (name, model, path) => { modelPassedToSecondConvention = model; return string.Empty; } }); // When resolver.GetViewLocation(viewName, viewModel, new ViewLocationContext()); // Then modelPassedToFirstConvention.ShouldBeSameAs(viewModel); modelPassedToSecondConvention.ShouldBeSameAs(viewModel); }
public void return_viewlocationresult_when_view_could_be_located() { // Given const string viewName = "foo.html"; var resolver = new DefaultViewResolver( this.viewLocator, new ViewLocationConventions(new Func<string, dynamic, ViewLocationContext, string>[] { (name, model, path) => "bar.html" })); var locatedView = new ViewLocationResult("name", "location", "extension", GetEmptyContentReader()); A.CallTo(() => this.viewLocator.LocateView(A<string>.Ignored)).Returns(locatedView); // When var result = resolver.GetViewLocation(viewName, null, this.viewLocationContext); // Then result.ShouldBeSameAs(locatedView); }
public void Should_call_conventions_with_viewname() { // Given const string viewName = "foo.html"; string viewNamePassedToFirstConvention = null; string viewNamePassedToSecondConvention = null; var resolver = new DefaultViewResolver( this.viewLocator, new ViewLocationConventions(new Func<string, dynamic, ViewLocationContext, string>[] { (name, model, path) => { viewNamePassedToFirstConvention = viewName; return string.Empty; }, (name, model, path) => { viewNamePassedToSecondConvention = viewName; return string.Empty; } })); // When resolver.GetViewLocation(viewName, null, this.viewLocationContext); // Then viewNamePassedToFirstConvention.ShouldEqual(viewName); viewNamePassedToSecondConvention.ShouldEqual(viewName); }
public void Should_return_null_when_no_view_could_be_located() { // Given const string viewName = "foo.html"; var resolver = new DefaultViewResolver( this.viewLocator, new ViewLocationConventions(new Func<string, dynamic, ViewLocationContext, string>[] { (name, model, path) => "bar.html" })); A.CallTo(() => this.viewLocator.LocateView(A<string>.Ignored, A<NancyContext>.Ignored)).Returns(null); // When var result = resolver.GetViewLocation(viewName, null, this.viewLocationContext); // Then result.ShouldBeNull(); }
public void Should_catch_exceptions_that_are_thrown_by_conventions() { // Given const string viewName = "foo.html"; var resolver = new DefaultViewResolver( this.viewLocator, new ViewLocationConventions(new Func<string, dynamic, ViewLocationContext, string>[] { (name, model, path) => { throw new Exception(); } })); // When var exception = Record.Exception(() => resolver.GetViewLocation(viewName, null, this.viewLocationContext)); // Then exception.ShouldBeNull(); }
public void Should_not_invoke_viewlocator_when_conventions_returns_empty_view_name() { // Given const string viewName = "foo.html"; var resolver = new DefaultViewResolver( this.viewLocator, new ViewLocationConventions(new Func<string, dynamic, ViewLocationContext, string>[] { (name, model, path) => string.Empty })); // When resolver.GetViewLocation(viewName, null, this.viewLocationContext); // Then A.CallTo(() => this.viewLocator.LocateView(A<string>.Ignored, A<NancyContext>.Ignored)).MustNotHaveHappened(); }
public void Should_invoke_view_locator_with_context() { // Given var resolver = new DefaultViewResolver( this.viewLocator, new ViewLocationConventions(new Func<string, dynamic, ViewLocationContext, string>[] { (name, model, path) => "bar.html" })); // When resolver.GetViewLocation("foo.html", null, this.viewLocationContext); // Then A.CallTo(() => this.viewLocator.LocateView(A<string>.Ignored, this.viewLocationContext.Context)).MustHaveHappened(); }
public void Should_invoke_viewlocator_with_viewname_from_conventions() { // Given const string viewName = "foo.html"; var resolver = new DefaultViewResolver( this.viewLocator, new ViewLocationConventions(new Func<string, dynamic, ViewLocationContext, string>[] { (name, model, path) => "bar.html" })); // When resolver.GetViewLocation(viewName, null, this.viewLocationContext); // Then A.CallTo(() => this.viewLocator.LocateView("bar.html", A<NancyContext>.Ignored)).MustHaveHappened(); }
public void Should_call_conventions_with_viewlocationcontext() { // Given const string viewName = "foo.html"; var context = this.viewLocationContext; ViewLocationContext modulePathPassedToFirstConvention = null; ViewLocationContext modulePathPassedToSecondConvention = null; var resolver = new DefaultViewResolver( this.viewLocator, new ViewLocationConventions(new Func<string, dynamic, ViewLocationContext, string>[] { (name, model, viewLocationContext) => { modulePathPassedToFirstConvention = viewLocationContext; return string.Empty; }, (name, model, viewLocationContext) => { modulePathPassedToSecondConvention = viewLocationContext; return string.Empty; } })); // When resolver.GetViewLocation(viewName, null, context); // Then modulePathPassedToFirstConvention.ShouldBeSameAs(context); modulePathPassedToSecondConvention.ShouldBeSameAs(context); }