public void Check_null_return(Tuple<string, TestAction> test)
 {
     var exception = Assert.Throws<ActionResultAssertionException>(() =>
         test.Item2(_controller.WithCallTo(c => c.Null()))
     );
     Assert.That(exception.Message, Is.EqualTo(string.Format("Received null action result when expecting {0}.", test.Item1)));
 }
 public void Check_return_type(Tuple<string, TestAction> test)
 {
     var exception = Assert.Throws<ActionResultAssertionException>(() =>
         test.Item2(_controller.WithCallTo(c => c.RandomResult()))
     );
     Assert.That(exception.Message, Is.EqualTo(string.Format("Expected action result to be a {0}, but instead received a RandomResult.", test.Item1)));
 }
Example #3
0
        /// <summary>
        /// Creates the executor which can resolve a passed type and hand it
        /// to the closure
        /// </summary>
        /// <param name="stateValuePair">The state value pair.</param>
        /// <returns>a lambda lifted closure</returns>
        private static Func<Tuple<IResolveTypes, object>, object, object, object> CreateExecutor(Tuple<Type, Func<object, object, object, object>> stateValuePair)
        {
            return (resolver, name, value) =>
                       {
                           object item = null;

                           if (stateValuePair.Item1 != null)
                               item = resolver.Item1.Resolve(stateValuePair.Item1);

                           return stateValuePair.Item2(resolver.Item2, item, value);
                       };
        }
        internal bool Execute(
            bool skipIfNoChanges, bool formValuesChanged, Action<EwfValidation, IEnumerable<string>> validationErrorHandler, bool performValidationOnly = false,
            Tuple<Action, Action> actionMethodAndPostModificationMethod = null)
        {
            var validationNeeded = validations.Any() && ( !skipIfNoChanges || formValuesChanged );
            if( validationNeeded ) {
                var topValidator = new Validator();
                foreach( var validation in validations ) {
                    if( topValidations.Contains( validation ) )
                        validation.Method( AppRequestState.Instance.EwfPageRequestState.PostBackValues, topValidator );
                    else {
                        var validator = new Validator();
                        validation.Method( AppRequestState.Instance.EwfPageRequestState.PostBackValues, validator );
                        if( validator.ErrorsOccurred )
                            topValidator.NoteError();
                        validationErrorHandler( validation, validator.ErrorMessages );
                    }
                }
                if( topValidator.ErrorsOccurred )
                    throw new DataModificationException( Translation.PleaseCorrectTheErrorsShownBelow.ToSingleElementArray().Concat( topValidator.ErrorMessages ).ToArray() );
            }

            var skipModification = !modificationMethods.Any() || ( skipIfNoChanges && !formValuesChanged );
            if( performValidationOnly || ( skipModification && actionMethodAndPostModificationMethod == null ) )
                return validationNeeded;

            DataAccessState.Current.DisableCache();
            try {
                if( !skipModification ) {
                    foreach( var method in modificationMethods )
                        method();
                }
                if( actionMethodAndPostModificationMethod != null )
                    actionMethodAndPostModificationMethod.Item1();
                DataAccessState.Current.ResetCache();
                AppRequestState.Instance.PreExecuteCommitTimeValidationMethodsForAllOpenConnections();
                if( actionMethodAndPostModificationMethod != null )
                    actionMethodAndPostModificationMethod.Item2();
            }
            catch {
                AppRequestState.Instance.RollbackDatabaseTransactions();
                DataAccessState.Current.ResetCache();
                throw;
            }

            return true;
        }
		private Button CreateButton(Tuple<string, Func<bool>> buttonInfo)
		{
			TextImageButtonFactory buttonFactory = new TextImageButtonFactory();

			buttonFactory.FixedHeight = this.FixedHeight;
			buttonFactory.normalFillColor = this.normalFillColor;
			buttonFactory.normalTextColor = this.normalTextColor;
			buttonFactory.hoverTextColor = this.hoverTextColor;
			buttonFactory.hoverFillColor = this.hoverFillColor;
			buttonFactory.borderWidth = 1;
			buttonFactory.normalBorderColor = this.normalBorderColor;
			buttonFactory.hoverBorderColor = this.hoverBorderColor;

			Button button = buttonFactory.Generate(buttonInfo.Item1, normalImageName: imageName, centerText: true);

			button.Click += (object sender, EventArgs e) =>
			{
				buttonInfo.Item2();
			};

			return button;
		}
		private void EmitExceptionBlockCore( Action<TracingILGenerator, Label> tryBlockEmitter, Tuple<Type, Action<TracingILGenerator, Label, Type>> firstCatchBlockEmitter, Tuple<Type, Action<TracingILGenerator, Label, Type>>[] remainingCatchBlockEmitters, Action<TracingILGenerator, Label> finallyBlockEmitter )
		{
			var endOfExceptionBlock = this.BeginExceptionBlock();
			tryBlockEmitter( this, endOfExceptionBlock );
			if ( firstCatchBlockEmitter != null )
			{
				this.BeginCatchBlock( firstCatchBlockEmitter.Item1 );
				firstCatchBlockEmitter.Item2( this, endOfExceptionBlock, firstCatchBlockEmitter.Item1 );
			}

			foreach ( var catchBlockEmitter in remainingCatchBlockEmitters )
			{
				this.BeginCatchBlock( catchBlockEmitter.Item1 );
				firstCatchBlockEmitter.Item2( this, endOfExceptionBlock, catchBlockEmitter.Item1 );
			}

			if ( finallyBlockEmitter != null )
			{
				this.BeginFinallyBlock();
				finallyBlockEmitter( this, endOfExceptionBlock );
			}

			this.EndExceptionBlock();
		}
Example #7
0
 private Action ap_cmb(Tuple<Action, Action> code)
 {
     return delegate() { code.Item1(); code.Item2(); };
 }