public MockDbCommand(MockDatabase database, Settings settings) { _database = database; _settings = settings; _identity = new Lazy <Dapper.SqlMapper.Identity>(() => DapperCacheInfo.GetIdentity(this, settings.IdentityComparer)); DbParameterCollection = new MockDbParameterCollection(settings); }
private static bool ParametersMatch(object actual, object expected) { if (ReferenceEquals(expected, MockDbParameterCollection.Any)) { return(true); } var actualParams = new MockDbParameterCollection(actual); return(actualParams.Equals(expected)); }
public bool Equals(MockDbParameterCollection executedParameters) { if (executedParameters == null) { return(false); } foreach (var parameter in this) { var executedParameter = (MockDbParameter)executedParameters[parameter.ParameterName]; if (executedParameter == null) { Trace.TraceWarning($"Parameter {parameter.ParameterName} could not be found"); return(false); } if (!ValuesMatch(executedParameter, parameter)) { Trace.TraceWarning($"Parameter {parameter.ParameterName} has a different value, expected {parameter.Value} was {executedParameter.Value}"); return(false); } } foreach (var executedParameter in executedParameters) { var parameter = (MockDbParameter)this[executedParameter.ParameterName]; if (parameter == null) { Trace.TraceWarning($"Parameter {executedParameter.ParameterName} was not expected"); return(false); } if (!ValuesMatch(executedParameter, parameter)) { Trace.TraceWarning($"Parameter {executedParameter.ParameterName} has a different value, expected {parameter.Value} was {executedParameter.Value}"); return(false); } } return(true); }
public static object FromParameters(MockDbParameterCollection parameters) { var builder = TypeBuilder(); foreach (var parameter in parameters) { AddProperty(builder, parameter); } var type = builder.CreateType(); var instance = Activator.CreateInstance(type); foreach (var parameter in parameters) { var propertyInfo = type.GetProperty(parameter.ParameterName); if (propertyInfo == null) { throw new InvalidOperationException($"Could not find property: '{parameter.ParameterName}'"); } propertyInfo.SetValue(instance, parameter.Value); } return(instance); }