private static async Task <ConfigEntityResult> TryExtractConfigEntityAsync(string initiatingMethod, CommandContext context, CommandTypes storeType, Func <ConfigEntity, ConfigEntity> adjustEntity)
        {
            // get config entity if exists
            var config = await context.StorageEngine.GetEntityByNameAsync(context.ConfigurationEntryKey);

            if (config == null)
            {
                return(new ConfigEntityResult
                {
                    Success = false,
                    ThrowError = () => SanityChecks.NotFound(context.ConfigurationEntryKey, initiatingMethod)
                });
            }
            // for diff checking
            var before = new ConfigEntity
            {
                Id    = config.Id,
                Name  = new string(config.Name.ToCharArray()),
                Value = new string(config.Value.ToCharArray())
            };

            // callback for entity
            config = adjustEntity(config);

            config.CrudOperationName = storeType;
            bool isSuccess = await context.StorageEngine.StoreEntityAsync(config);

            if (!isSuccess)
            {
                return(new ConfigEntityResult
                {
                    ThrowError = () => SanityChecks.StorageFailed <ConfigEntity>
                                 (
                        context.CommandType.ToString(),
                        initiatingMethod
                                 ),
                    Success = false
                });
            }

            return(new ConfigEntityResult
            {
                Before = before,
                Entity = config,
                Success = true
            });
        }
        ///<summary>
        /// Actual Query to get Data from the StorageModel
        ///</summary>
        internal static async Task <OperationResult> QueryConfigEntityAsync(QueryContext context)
        {
            string methName = $"{nameof(AllQueries)}.{nameof(QueryConfigEntityAsync)}";

            SanityChecks.CheckNull(context, methName, "QueryContext");
            SanityChecks.IsSameOperationType(QueryTypes.ValueRequest.ToString(), context.QueryType.ToString());

            // check if exists
            var config = await context.StorageEngine.GetEntityByNameAsync(context.ConfigurationEntryKey);

            if (config == null)
            {
                return(SanityChecks.NotFound(context.ConfigurationEntryKey, methName));
            }

            // return entity
            return(OperationResult.Success(config));
        }
        ///<summary>
        /// Actual Query for all Config Entities using the StorageModel.
        ///</summary>
        internal static async Task <OperationResult> QueryAllConfigEntityValuesAsync(QueryContext context)
        {
            string methName = $"{nameof(AllQueries)}.{nameof(QueryConfigEntityAsync)}";

            SanityChecks.CheckNull(context, methName, "QueryContext");
            SanityChecks.IsSameOperationType(QueryTypes.AllValues.ToString(), context.QueryType.ToString());

            // check if exists
            var configs = await context.StorageEngine.AllEntitesAsync();

            if (configs == null || configs.Any() == false)
            {
                return(SanityChecks.NotFound(context.ConfigurationEntryKey, methName));
            }

            // return entity
            var collection = new ConfigCollection {
                 WrappedConfigEntities = configs
            };

            return(OperationResult.Success(collection));
        }
Example #4
0
        public void NotFoundReturnsOperationResultFailure()
        {
            var operationResult = SanityChecks.NotFound("fullname", "methodname");

            Assert.Equal(ResultType.NotFound, operationResult.ResultType);
        }