public void GetDoubleVariable_TypeOfAccessGlobal_ReturnException(string key, Type type, string value, TypeOfAccess typeOfAccess) { variableContext.SetVariable(key, type, value, typeOfAccess); Action act = () => variableContext.SetVariable(key, type, value, typeOfAccess); act .Should().Throw <ArgumentException>() .WithMessage($"Element with key: \"{key}\" has already created with type 'Global'"); }
public void SetVariable_GlobalAndLocal_ReturnVariables(string key, Type type, string value, TypeOfAccess typeOfAccess) { variableContext.SetVariable(key, type, key, TypeOfAccess.Global); variableContext.SetVariable(key, type, value, typeOfAccess); variableContext.Variables[key].TypeOfAccess.Should().Be(TypeOfAccess.Local); variableContext.Variables[key].Value.Should().Be(value); }
public void SetVariable_LocalAndDefault_ReturnVariables(string key, Type type, string value, TypeOfAccess typeOfAccess) { variableContext.SetVariable(key, type, key, TypeOfAccess.Default); variableContext.SetVariable(key, type, value, typeOfAccess); variableContext.Variables[key].TypeOfAccess.Should().Be(typeOfAccess); variableContext.Variables[key].Value.Should().Be(value); }
public void SetVariable_KeyIsNull_ReturnVariables(string key, Type type, string value, TypeOfAccess typeOfAccess) { variableContext.SetVariable(key, type, value, typeOfAccess); variableContext.Variables.Count.Should().Be(3); }
public void SetVariable_KeyIsNull_ReturnVariables(string key, Type type, string value, TypeOfAccess typeOfAccess) { Action act = () => variableContext.SetVariable(key, type, value, typeOfAccess); act .Should().Throw <ArgumentNullException>() .WithMessage($"Key is null (Parameter 'key')"); }
public void SetVariable(string key, Type type, object value, TypeOfAccess accessType = TypeOfAccess.Local) { var varName = GetVariableName(key); if (string.IsNullOrWhiteSpace(varName)) { Log.Logger().LogInformation($"Key: \"{key}\" is empty"); return; } if (Variables.ContainsKey(varName)) { switch (Variables[varName].TypeOfAccess) { case TypeOfAccess.Global: { switch (accessType) { case TypeOfAccess.Local: { Log.Logger().LogInformation($"Element with key: \"{key}\" and '{Variables[varName].TypeOfAccess}' type has been replaced with type '{accessType}'"); break; } case TypeOfAccess.Default: { Log.Logger().LogInformation($"Element with key: \"{key}\" has already created with type '{Variables[varName].TypeOfAccess}'"); return; } case TypeOfAccess.Global: { Log.Logger().LogWarning($"Element with key: \"{key}\" has already created with type 'Global'"); throw new ArgumentException($"Element with key: \"{key}\" has already created with type 'Global'"); } } break; } case TypeOfAccess.Default: { switch (accessType) { case TypeOfAccess.Local: { Log.Logger().LogInformation($"Element with key: \"{key}\" and '{Variables[varName].TypeOfAccess}' type has been replaced with type '{accessType}'"); break; } } break; } } } var vars = Variables; var variable = new Variable() { Type = type, Value = value, TypeOfAccess = accessType }; vars.AddOrUpdate(varName, variable, (k, v) => variable); Variables = vars; }