示例#1
0
        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();
            }
        }
示例#2
0
        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>();
            }
        }
示例#3
0
        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>();
            }
        }
示例#4
0
        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));
            }
        }