Skip to content

Instantly share code, notes, and snippets.

@starteleport
Created February 11, 2013 11:58
MapValue works incorrectly with mapping extensions
#region Types for MapValueTest
public class Person
{
public int Id { get; set; }
public bool IsActive { get; set; }
}
public class SecurityDbMappingSchema : MappingSchema
{
public SecurityDbMappingSchema()
{
Extensions = TypeExtension.GetExtensions("SecurityMap.xml");
}
}
public class SecurityDbManager : DbManager
{
public const string DefaultConnStringName = "ProtoDB";
public SecurityDbManager(string connStringName)
: base(connStringName)
{
InitializeMappingSchema();
}
private void InitializeMappingSchema()
{
MappingSchema = new SecurityDbMappingSchema();
}
public SecurityDbManager()
: this(DefaultConnStringName)
{
}
public Table<Person> Persons
{
get { return GetTable<Person>(); }
}
}
#endregion
private const string ConnString =
"Network Address=192.168.0.128;User ID=pWriter;PWD=pass;Initial Catalog=ProtoDB;Connect Timeout=300";
[TestMethod]
public void TestMapValueAttribute_Passes()
{
string result = null;
DbManager.AddConnectionString("ProtoDB", ConnString);
//Record is assumed to exist
var p = new Person { IsActive = true, Id = 38361 };
using (var db = new SecurityDbManager())
{
db.Update(new[] { p }.AsEnumerable());
db.SetCommand(CommandType.Text, "SELECT [IsActive] FROM [Persons] WHERE [UserId]=" + p.Id);
result = (string) db.ExecuteScalar();
}
Assert.AreEqual("Y", result);
}
[TestMethod]
public void TestMapValueAttribute_Fails()
{
string result = null;
DbManager.AddConnectionString("ProtoDB", ConnString);
//Record is assumed to exist
var p = new Person { IsActive = true, Id = 38361 };
using (var db = new SecurityDbManager())
{
db.Update(p);
db.SetCommand(CommandType.Text, "SELECT [IsActive] FROM [Persons] WHERE [UserId]=" + p.Id);
result = (string)db.ExecuteScalar();
}
Assert.AreEqual("Y", result);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment