public void CheckNullThrowsArgumentException(string value, bool shouldThrow) { if (shouldThrow) { Assert.Throws <ArgumentException>(() => SanityChecks.CheckNull(value, "test-method")); } else { SanityChecks.CheckNull(value, "test-method"); } }
/// <summary> /// Trnasforms the given direction from shading space into world space and normalizes it. /// Assumes the shading normal is a valid normal (i.e. normalized). /// </summary> public static Vector3 ShadingToWorld(Vector3 shadingNormal, Vector3 shadingDirection) { SanityChecks.IsNormalized(shadingDirection); ComputeBasisVectors(shadingNormal, out var tangent, out var binormal); Vector3 dir = shadingDirection.Z * shadingNormal + shadingDirection.X * tangent + shadingDirection.Y * binormal; return(dir); }
/// <summary> /// Trnasforms the given direction into normalized shading space. /// Assumes that both the direction and the shading normal are normalized. /// </summary> public static Vector3 WorldToShading(Vector3 shadingNormal, Vector3 worldDirection) { SanityChecks.IsNormalized(worldDirection); ComputeBasisVectors(shadingNormal, out var tangent, out var binormal); float z = Vector3.Dot(shadingNormal, worldDirection); float x = Vector3.Dot(tangent, worldDirection); float y = Vector3.Dot(binormal, worldDirection); return(new Vector3(x, y, z)); }
internal byte *ProcessString(WCString pString) { if (!Initialized) { Initializer.Initialize(this); } if (Settings.SanityCheck && SanityChecks.IsBadCodePtr(pString)) { return(pString); } var String = pString; foreach (var Rld in Reloads) { var New = Rld.BeforeReload(String, true); if (New != null) { String = New; } } var Rst = ProcessString((string)String); if (Rst == null) { return(String); } var Output = (WCString)Rst; foreach (var Rld in Reloads) { var New = Rld.AfterReload(pString, Output, true); if (New != null) { Output = New; } } if (Settings.Overwrite && Output != null && ((string)Output) != null) { return((WCString)Alloc.Overwrite(Output.ToArray(), pString)); } if (Settings.HeapAlloc && Output != null && ((string)Output) != null) { return((WCString)Alloc.CreateHeap(Output.ToArray())); } return(Output); }
///<summary> /// Actual Crud.Update method using CommandContext and StorageEngine ///</summary> internal static async Task <OperationResult> UpdateAsync(CommandContext context) { string methName = $"{nameof(AllCommands)}.{nameof(UpdateAsync)}"; SanityChecks.CheckNull(context, methName); SanityChecks.IsSameOperationType(CommandTypes.UpdateValue.ToString(), context.CommandType.ToString()); var configEntity = await TryExtractConfigEntityAsync(methName, context, CommandTypes.UpdateValue, c => { c.Value = context.ChangeRequest.Value; return(c); }); if (configEntity.Success == false) { return(configEntity.ThrowError()); } // return result return(OperationResult.Success(configEntity.Entity)); }
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 Crud.Delete method using CommandContext and StorageEngine ///</summary> internal static async Task <OperationResult> DeleteAsync(CommandContext context) { string methName = $"{nameof(AllCommands)}.{nameof(DeleteAsync)}"; SanityChecks.CheckNull(context, methName); SanityChecks.IsSameOperationType(CommandTypes.Delete.ToString(), context.CommandType.ToString()); var configEntityResult = await TryExtractConfigEntityAsync(methName, context, CommandTypes.Delete, c => c); if (configEntityResult.Success == false) { return(configEntityResult.ThrowError()); } // return result return(OperationResult.Success(configEntityResult.Entity)); }
///<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)); }
///<summary> /// Actual Crud.Create Command using the CommandContext and the StorageEngine ///</summary> internal static async Task <OperationResult> CreateAsync(CommandContext context) { string methName = $"{nameof(AllCommands)}.{nameof(CreateAsync)}"; SanityChecks.CheckNull(context, methName); SanityChecks.IsSameOperationType(CommandTypes.Create.ToString(), context.CommandType.ToString()); // create a new entity from key and value var entity = GenerateConfigEntityFromChangeRequest(context.ChangeRequest); bool success = false; entity.CrudOperationName = CommandTypes.Create; // try store success = await context.StorageEngine.StoreEntityAsync(entity); if (!success) { return(SanityChecks.StorageFailed <ConfigEntity>(context.CommandType.ToString(), methName)); } return(OperationResult.Success(entity)); }
public void StorageFailedThrowsOperationFailure() { var operationResult = SanityChecks.StorageFailed <string>("fullname", "methodname"); Assert.Equal(ResultType.Forbidden, operationResult.ResultType); }
public void NotFoundReturnsOperationResultFailure() { var operationResult = SanityChecks.NotFound("fullname", "methodname"); Assert.Equal(ResultType.NotFound, operationResult.ResultType); }
public void NotSupportedReturnsOeprationResultFailure() { var operationResult = SanityChecks.NotSupported("fullname", "methodname"); Assert.Equal(ResultType.BadRequest, operationResult.ResultType); }