public void Should_return_an_error_notification_if_the_Statement_has_only_inactive_accounts()
                {
                    var accounts = new List <Account>
                    {
                        new Account
                        {
                            Inactive = true
                        }
                    };
                    var statement = new Statement
                    {
                        Accounts = accounts
                    };
                    var executionArguments = new ExecutionArguments
                    {
                        Statement = new Notification <Statement>
                        {
                            Item = statement
                        }
                    };
                    var result = new RequireActiveAccountsExist().Check(executionArguments);

                    result.HasErrors.ShouldBeTrue();
                    Regex.IsMatch(result.Errors, RequireActiveAccountsExist.NoActiveAccountsMessageText.MessageTextToRegex()).ShouldBeTrue();
                }
示例#2
0
        public Notification Handle(ICommand command, ExecutionArguments executionArguments)
        {
            var prerequisiteResult = _prerequisiteChecker.Check(command, executionArguments);

            if (prerequisiteResult.HasErrors)
            {
                return(prerequisiteResult);
            }
            var commandResult = command.Execute(executionArguments);

            if (commandResult.HasErrors)
            {
                return(commandResult);
            }
            if (command.ChangesTheStatement())
            {
                var commandHistory = new CommandHistory
                {
                    Command = command.GetType().Name,
                    Args    = executionArguments.Args,
                    Date    = _systemService.CurrentDateTime
                };
                Statement statement = executionArguments.Statement;
                statement.CommandHistory.Add(commandHistory);
            }
            return(commandResult);
        }
        override protected void ExecuteCommand(ArduinoCommand command, ExecutionArguments xargs)
        {
            switch (command.Type)
            {
            case ArduinoCommand.CommandType.START:
                _irCodes.Clear();
                _unknownCodes.Clear();
                _receiving = true;
                if (xargs != null && xargs.Arguments.Count > 0)
                {
                    _commandName = (String)xargs.Arguments[0];
                }
                break;

            case ArduinoCommand.CommandType.STOP:
                _receiving = false;
                break;

            case ArduinoCommand.CommandType.SAVE:
                _receiving = false;
                WriteIRCodes();
                return;
            }
            base.ExecuteCommand(command, xargs);
        }
示例#4
0
        /// <summary>
        ///     Write in collection of entities.
        /// </summary>
        /// <param name="entities">The entities.</param>
        /// <param name="context">The context.</param>
        void IDataTarget.WriteEntities(IEnumerable <EntityEntry> entities, IProcessingContext context)
        {
            Func <DataColumn[]> getColumnsAction = () => new[]
            {
                new DataColumn("UpgradeId", typeof(Guid))
                {
                    AllowDBNull = false
                }
            };

            Func <EntityEntry, DataRow, PopulateRowResult> populateRowAction = (entry, row) =>
            {
                row[0] = entry.EntityId;
                return(PopulateRowResult.Success);
            };

            var executionArguments = new ExecutionArguments <EntityEntry>
            {
                Entries            = entities,
                GetColumnsAction   = getColumnsAction,
                TableName          = "Entities",
                Context            = context,
                PopulateRowAction  = populateRowAction,
                CommandText        = CommandText.TenantMergeTargetWriteEntitiesCommandText,
                ExecuteAction      = ExecuteAction.Writing,
                SetupCommandAction = c => c.AddParameterWithValue("@tenant", TenantId)
            };

            Execute(executionArguments);

            /////
            // Populate the UpgradeId to Id map.
            /////
            PopulateUpgradeIdToIdMap( );
        }
示例#5
0
        public Notification Check(ExecutionArguments executionArguments, int argumentIndex)
        {
            var argument = executionArguments.Args[argumentIndex];

            var result = argument.ToStatementPath();
            return result;
        }
示例#6
0
        /// <summary>
        ///     Write in collection of relationships.
        /// </summary>
        /// <param name="relationships"></param>
        /// <param name="context"></param>
        void IDataTarget.WriteRelationships(IEnumerable <RelationshipEntry> relationships, IProcessingContext context)
        {
            Func <DataColumn[]> getColumnsAction = () => new[]
            {
                new DataColumn("TypeId", typeof(long))
                {
                    AllowDBNull = false
                },
                new DataColumn("FromId", typeof(long))
                {
                    AllowDBNull = false
                },
                new DataColumn("ToId", typeof(long))
                {
                    AllowDBNull = false
                }
            };

            Func <RelationshipEntry, DataRow, PopulateRowResult> populateRowAction = (entry, row) =>
            {
                long val;

                if (!_upgradeToIdMap.TryGetValue(entry.TypeId, out val))
                {
                    return(PopulateRowResult.MissingTypeDependency);
                }

                row[0] = val;

                if (!_upgradeToIdMap.TryGetValue(entry.FromId, out val))
                {
                    return(PopulateRowResult.MissingFromDependency);
                }

                row[1] = val;

                if (!_upgradeToIdMap.TryGetValue(entry.ToId, out val))
                {
                    return(PopulateRowResult.MissingToDependency);
                }

                row[2] = val;
                return(PopulateRowResult.Success);
            };

            var executionArguments = new ExecutionArguments <RelationshipEntry>
            {
                Entries            = relationships,
                GetColumnsAction   = getColumnsAction,
                TableName          = "Relationships",
                Context            = context,
                PopulateRowAction  = populateRowAction,
                CommandText        = CommandText.TenantMergeTargetWriteRelationshipsCommandText,
                ExecuteAction      = ExecuteAction.Writing,
                SetupCommandAction = c => c.AddParameterWithValue("@tenant", TenantId)
            };

            Execute(executionArguments);
        }
示例#7
0
        public Notification Check(ExecutionArguments executionArguments, int argumentIndex)
        {
            var argument = executionArguments.Args[argumentIndex];

            var result = argument.ToStatementPath();

            return(result);
        }
 public Notification Check(ICommand command, ExecutionArguments executionArguments)
 {
     var result = command.GetCommandExecutionPrerequisites()
                      .OrderBy(x => x.Order)
                      .Select(x => x.Check(executionArguments))
                      .FirstOrDefault(x => !x.IsValid) ?? Notification.Empty;
     return result;
 }
        public Notification Check(ExecutionArguments executionArguments)
        {
            if (executionArguments.Statement.HasErrors)
            {
                return executionArguments.Statement;
            }

            return Notification.Empty;
        }
示例#10
0
        public Notification Check(ExecutionArguments executionArguments)
        {
            if (executionArguments.Statement.HasErrors)
            {
                return(executionArguments.Statement);
            }

            return(Notification.Empty);
        }
示例#11
0
        public Notification Check(ICommand command, ExecutionArguments executionArguments)
        {
            var result = command.GetCommandExecutionPrerequisites()
                         .OrderBy(x => x.Order)
                         .Select(x => x.Check(executionArguments))
                         .FirstOrDefault(x => !x.IsValid) ?? Notification.Empty;

            return(result);
        }
 public Notification Check(ExecutionArguments executionArguments)
 {
     var args = executionArguments.Args;
     if (args.Length < _expectedNumberOfAdditionalArgs)
     {
         return Notification.ErrorFor(_messageText);
     }
     return Notification.Empty;
 }
示例#13
0
                public void Before_first_test()
                {
                    var executionArguments = new ExecutionArguments
                    {
                        Args = new[] { "a" }
                    };

                    _result = new RequireExactlyNArgs(1)
                              .Check(executionArguments);
                }
示例#14
0
                public void Before_first_test()
                {
                    var executionArguments = new ExecutionArguments
                    {
                        Args = new[] { "a", "b", "c" }
                    };

                    _result = new RequireAtLeastNArgs(2)
                              .Check(executionArguments);
                }
        public Notification Check(ExecutionArguments executionArguments)
        {
            Statement statement = executionArguments.Statement;
            if (!statement.AccountTypes.Any())
            {
                return Notification.ErrorFor(NoAccountTypesMessageText, typeof(AccountType).GetPluralUIDescription());
            }

            return Notification.Empty;
        }
示例#16
0
                public void Before_first_test()
                {
                    var executionArguments = new ExecutionArguments
                    {
                        Args = new string[] { }
                    };

                    _result = new RequireAtLeastNArgs(1, TooFewArgumentsCustomMessageText)
                              .Check(executionArguments);
                }
        public Notification Check(ExecutionArguments executionArguments)
        {
            var applicationSettings = executionArguments.ApplicationSettings;
            if (applicationSettings.HasErrors)
            {
                return applicationSettings;
            }

            return Notification.Empty;
        }
示例#18
0
                public void Before_first_test()
                {
                    var executionArguments = new ExecutionArguments
                    {
                        Args = new[] { "a", "b" }
                    };

                    _result = new RequireAtMostNArgs(1, TooManyArgumentsCustomMessageText)
                              .Check(executionArguments);
                }
示例#19
0
        public Notification Check(ExecutionArguments executionArguments)
        {
            var args = executionArguments.Args;

            if (args.Length != _expectedNumberOfAdditionalArgs)
            {
                return(Notification.ErrorFor(_messageText));
            }
            return(Notification.Empty);
        }
示例#20
0
                public void Before_first_test()
                {
                    var executionArguments = new ExecutionArguments
                    {
                        Args = new string[] { }
                    };

                    _result = new RequireAtLeastNArgs(1)
                              .Check(executionArguments);
                }
        public Notification Check(ExecutionArguments executionArguments)
        {
            Statement statement = executionArguments.Statement;
            if (statement.SelectedAccount == null)
            {
                return Notification.ErrorFor(AccountNeedsToBeSelected.ReplaceTypeReferencesWithUIDescriptions(false));
            }

            return Notification.Empty;
        }
                public void Should_return_a_success_notification_if_the_Statement_result_does_not_have_errors()
                {
                    var executionArguments = new ExecutionArguments
                    {
                        ApplicationSettings = Notification.Empty.ToNotification <ApplicationSettings>()
                    };
                    var result = new RequireApplicationSettings().Check(executionArguments);

                    result.IsValid.ShouldBeTrue();
                }
                public void Should_return_an_error_notification_if_the_Statement_result_has_warnings()
                {
                    var executionArguments = new ExecutionArguments
                    {
                        ApplicationSettings = Notification.WarningFor("pretend").ToNotification <ApplicationSettings>()
                    };
                    var result = new RequireApplicationSettingsAlreadyInitialized().Check(executionArguments);

                    result.HasErrors.ShouldBeTrue();
                }
示例#24
0
                    public void Before_first_test()
                    {
                        var executionArguments = new ExecutionArguments
                        {
                            Args = new[] { "a", "b", "c" }
                        };

                        _result = new PrerequisiteChecker()
                                  .Check(new CommandWithMultiplePrerequisites(), executionArguments);
                    }
示例#25
0
                protected override void Before_first_test()
                {
                    var executionArguments = new ExecutionArguments
                    {
                        Args = new[] { FilePath },
                    };
                    var validator = IoC.Get <IsAFilePath>();

                    _result = validator.Check(executionArguments, 0);
                }
                public void Should_return_an_error_notification_if_the_Statement_result_has_errors()
                {
                    var executionArguments = new ExecutionArguments
                    {
                        ApplicationSettings = Notification.ErrorFor("pretend").ToNotification <ApplicationSettings>()
                    };
                    var result = new RequireApplicationSettings().Check(executionArguments);

                    result.IsValid.ShouldBeFalse();
                }
        public Notification Check(ExecutionArguments executionArguments)
        {
            Statement statement = executionArguments.Statement;
            if (!statement.TaxReportingCategories.Any())
            {
                return Notification.ErrorFor(NoTaxReportingCategoriesMessageText, typeof(TaxReportingCategory).GetPluralUIDescription());
            }

            return Notification.Empty;
        }
示例#28
0
        public Notification Check(ExecutionArguments executionArguments)
        {
            Statement statement = executionArguments.Statement;

            if (!statement.Accounts.Any(x => !x.Inactive))
            {
                return(Notification.ErrorFor(NoActiveAccountsMessageText, typeof(Account).GetPluralUIDescription()));
            }

            return(Notification.Empty);
        }
                protected override void Before_first_test()
                {
                    var validator          = IoC.Get <IsATaxabilityTypeKey>();
                    var executionArguments = new ExecutionArguments
                    {
                        Args      = new[] { "Bob", TaxabilityType.Taxfree.Key },
                        Statement = new Statement()
                    };

                    _result = validator.Check(executionArguments, 1);
                }
示例#30
0
        public Notification Check(ExecutionArguments executionArguments)
        {
            var applicationSettings = executionArguments.ApplicationSettings;

            if (applicationSettings.HasWarnings)
            {
                return(Notification.ErrorFor(applicationSettings.Warnings));
            }

            return(Notification.Empty);
        }
示例#31
0
                protected override void Before_first_test()
                {
                    _executionArguments = Subcutaneous.FromCommandline()
                                          .Init("x:")
                                          .ClearOutput()
                                          .CreateExecutionArguments(Init.GetDefaultAccountTypes().First().Name, NewAccountName);

                    var command = IoC.Get <ChangeAccountTypeName>();

                    _result = command.Execute(_executionArguments);
                }
        public Notification Check(ExecutionArguments executionArguments)
        {
            Statement statement = executionArguments.Statement;

            if (!statement.TaxReportingCategories.Any())
            {
                return(Notification.ErrorFor(NoTaxReportingCategoriesMessageText, typeof(TaxReportingCategory).GetPluralUIDescription()));
            }

            return(Notification.Empty);
        }
        public Notification Check(ExecutionArguments executionArguments)
        {
            Statement statement = executionArguments.Statement;

            if (statement.SelectedAccount == null)
            {
                return(Notification.ErrorFor(AccountNeedsToBeSelected.ReplaceTypeReferencesWithUIDescriptions(false)));
            }

            return(Notification.Empty);
        }
示例#34
0
                    public void Before_first_test()
                    {
                        var executionArguments = new ExecutionArguments
                        {
                            Args = new[] { "a" },
                            ApplicationSettings = Notification.ErrorFor("pretend").ToNotification <ApplicationSettings>()
                        };

                        _result = new PrerequisiteChecker()
                                  .Check(new CommandWithMultiplePrerequisites(), executionArguments);
                    }
示例#35
0
                protected override void Before_first_test()
                {
                    var command            = IoC.Get <IsTheNameOfAnExistingAccountType>();
                    var executionArguments = new ExecutionArguments
                    {
                        Args      = new[] { AccountTypeName },
                        Statement = new Statement()
                    };

                    _result = command.Check(executionArguments, 0);
                }
示例#36
0
                protected override void Before_first_test()
                {
                    var validator          = IoC.Get <IsTheIndexOfAnExistingAccount>();
                    var executionArguments = new ExecutionArguments
                    {
                        Args      = new[] { AccountIndex.ToString() },
                        Statement = new Statement()
                    };

                    _result = validator.Check(executionArguments, 0);
                }
示例#37
0
                protected override void Before_first_test()
                {
                    _executionArguments = Subcutaneous.FromCommandline()
                                          .Init(@"x:\previous.statement")
                                          .ClearOutput()
                                          .CreateExecutionArguments(ExpectedAccountName, _expectedTaxabilityType.Key);

                    var command = IoC.Get <AddAccountType>();

                    _result = command.Execute(_executionArguments);
                }
示例#38
0
// ReSharper disable MemberCanBeMadeStatic.Global
        public ExecutionArguments CreateExecutionArguments(params string[] parameters)
// ReSharper restore MemberCanBeMadeStatic.Global
        {
            var executionArguments = new ExecutionArguments
            {
                ApplicationSettings = IoC.Get <ApplicationSettingsService>().Load(),
                Args      = parameters,
                Statement = IoC.Get <IStorageService>().Load()
            };

            return(executionArguments);
        }
        public Notification Check(ExecutionArguments executionArguments, int argumentIndex)
        {
            var argument = executionArguments.Args[argumentIndex];

            Statement statement = executionArguments.Statement;
            if (!statement.TaxReportingCategories.Any(x => x.Name == argument))
            {
                return Notification.ErrorFor(NameDoesNotExistMessageText, typeof(TaxReportingCategory).GetSingularUIDescription());
            }

            return Notification.Empty;
        }
        public Notification Check(ExecutionArguments executionArguments, int argumentIndex)
        {
            var argument = executionArguments.Args[argumentIndex];

            var taxabilityType = TaxabilityType.GetFor(argument);
            if (taxabilityType == null)
            {
                return Notification.ErrorFor(InvalidTaxabilityType, executionArguments.Args[1], typeof(TaxabilityType).GetSingularUIDescription());
            }

            return Notification.Empty;
        }
        public Notification Check(ExecutionArguments executionArguments, int argumentIndex)
        {
            var argument = executionArguments.Args[argumentIndex];

            Statement statement = executionArguments.Statement;
            if (!statement.AccountTypes.GetIndexedValues().Select(x => x.Index.ToString()).Any(x => x == argument))
            {
                return Notification.ErrorFor(IndexDoesNotExistMessageText, typeof(AccountType).GetSingularUIDescription());
            }

            return Notification.Empty;
        }
示例#42
0
 public Notification ApplyTo(ExecutionArguments executionArguments, int argumentIndex, IList<Type> argumentValidatorTypes)
 {
     var requestedValidators = _validators.Where(x => argumentValidatorTypes.Contains(x.GetType()));
     foreach (var argumentValidator in requestedValidators)
     {
         var result = argumentValidator.Check(executionArguments, argumentIndex);
         if (result.HasErrors)
         {
             return result;
         }
     }
     return Notification.Empty;
 }
示例#43
0
        public Notification ApplyTo(ExecutionArguments executionArguments, int argumentIndex, IList<Type> argumentValidatorTypes)
        {
            var requestedValidators = _validators.Where(x => argumentValidatorTypes.Contains(x.GetType()));

            foreach (var argumentValidator in requestedValidators)
            {
                var result = argumentValidator.Check(executionArguments, argumentIndex);
                if (!result.HasErrors)
                {
                    return Notification.ErrorFor(ErrorMessageText, argumentValidator.GetType().GetSingularUIDescription());
                }
            }
            return Notification.Empty;
        }
示例#44
0
        public Notification ApplyTo(ExecutionArguments executionArguments, int argumentIndex, IList<Type> argumentValidatorTypes)
        {
            var requestedValidators = _validators.Where(x => argumentValidatorTypes.Contains(x.GetType()));

            var errors = Notification.ErrorFor(ErrorMessageText);
            foreach (var argumentValidator in requestedValidators)
            {
                var result = argumentValidator.Check(executionArguments, argumentIndex);
                if (!result.HasErrors)
                {
                    return result;
                }
                else
                {
                    errors.Add(result);
                }
            }
            return errors;
        }