public void Process_DataSourceExceptionInEditMode_SetView(Database db, FakeSiteContext siteContext, InvalidDatasourceItemExceptionProcessor processor, [Modest] ExceptionContext exceptionContext, [Substitute] ExceptionArgs exceptionArgs, [Modest] InvalidDataSourceItemException exception) { //Arrange typeof(SiteContext).GetField("displayMode", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(siteContext, DisplayMode.Edit); exceptionArgs.ExceptionContext.ExceptionHandled = false; exceptionArgs.ExceptionContext.Exception = exception; //Act using (new SiteContextSwitcher(siteContext)) { processor.Process(exceptionArgs); //Assert exceptionArgs.ExceptionContext.Result.Should().BeOfType <ViewResult>().Which.ViewName.Should().Be(ViewPath.InfoMessage); exceptionArgs.ExceptionContext.ExceptionHandled.Should().BeTrue(); } }
public void Process_HandledException_DontSetView(FakeSiteContext siteContext, InvalidDatasourceItemExceptionProcessor processor, [Modest] ExceptionContext exceptionContext, [Substitute] ExceptionArgs exceptionArgs) { //Arrange typeof(SiteContext).GetField("displayMode", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(siteContext, DisplayMode.Edit); exceptionArgs.ExceptionContext.ExceptionHandled = true; //Act using (new SiteContextSwitcher(siteContext)) { processor.Process(exceptionArgs); //Assert exceptionArgs.ExceptionContext.Result.Should().BeOfType <EmptyResult>(); } }
public void Process_DataSourceExceptionInNormalMode_HandleException(FakeSiteContext siteContext, InvalidDatasourceItemExceptionProcessor processor, [Modest] ExceptionContext exceptionContext, [Substitute] ExceptionArgs exceptionArgs, [Modest] InvalidDataSourceItemException exception) { //Arrange typeof(SiteContext).GetField("displayMode", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(siteContext, DisplayMode.Normal); exceptionArgs.ExceptionContext.ExceptionHandled = false; exceptionArgs.ExceptionContext.Exception = exception; //Act using (new SiteContextSwitcher(siteContext)) { processor.Process(exceptionArgs); //Assert exceptionArgs.ExceptionContext.ExceptionHandled.Should().BeTrue(); exceptionArgs.ExceptionContext.Result.Should().BeOfType <EmptyResult>(); } }
public void Process_DataSourceException_LogError(Database db, FakeSiteContext siteContext, InvalidDatasourceItemExceptionProcessor processor, [Modest] ExceptionContext exceptionContext, [Substitute] ExceptionArgs exceptionArgs, [Modest] InvalidDataSourceItemException exception, MemoryAppender appender) { //Arrange typeof(SiteContext).GetField("displayMode", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(siteContext, DisplayMode.Edit); BasicConfigurator.Configure(appender); exceptionArgs.ExceptionContext.ExceptionHandled = false; exceptionArgs.ExceptionContext.Exception = exception; //Act using (new SiteContextSwitcher(siteContext)) { processor.Process(exceptionArgs); //Assert appender.Events.Should().Contain(x => x.RenderedMessage.Contains(exception.Message)); } }