public void TestRemovalOfCompositeKeys_Commit() { UserProduct retrievedUP = null; using (ADOCRUDContext context = new ADOCRUDContext(connectionString)) { UserProduct up = new UserProduct(); up.UserId = userId; up.ProductId = productId; context.Insert <UserProduct>(up); context.Commit(); } using (ADOCRUDContext context = new ADOCRUDContext(connectionString)) { // Makes sure user product being retreived exists UserProduct up = context.QueryItems <UserProduct>("select * from dbo.UserProduct where UserId = @userId and ProductId = @productId", new { userId = userId, productId = productId }).FirstOrDefault(); Assert.IsTrue(up != null && up.UserId == userId && up.ProductId == productId); context.Remove(up); context.Commit(); retrievedUP = context.QueryItems <UserProduct>("select * from dbo.UserProduct where UserId = @userId and ProductId = @productId", new { userId = userId, productId = productId }).FirstOrDefault(); } Assert.IsTrue(retrievedUP == null, "A problem occurred when trying to remove a composite key"); }
public void TestInsert_NonNullablePropertiesWithValues() { NonNullable n = new NonNullable(); n.Integer64Value = 64; n.ByteValue = 1; n.ByteArrayValue = new byte[4]; n.ByteArrayValue[0] = 0; n.ByteArrayValue[1] = 1; n.ByteArrayValue[2] = 2; n.ByteArrayValue[3] = 3; n.BoolValue = true; n.CharValue = "a"; n.DateTimeValue = Convert.ToDateTime("01/11/1984"); n.DateTimeOffsetValue = DateTimeOffset.MaxValue; n.DecimalValue = 1.11m; n.FloatValue = 22; n.DoubleValue = 33; n.Integer32Value = 44; n.Single = 55; n.Integer16Value = 16; n.GuidValue = guid; n.StringValue = "Something"; using (ADOCRUDContext context = new ADOCRUDContext(connectionString)) { context.Insert(n); context.Commit(); } NonNullable retrievedItem = null; using (ADOCRUDContext context = new ADOCRUDContext(connectionString)) { retrievedItem = context.QueryItems <NonNullable>("select * from Nullable where id = @id", new { id = n.Id }).FirstOrDefault(); } Assert.IsTrue(n != null && n.Integer64Value == 64 && n.ByteValue == 1 && n.ByteArrayValue[0] == 0 && n.ByteArrayValue[1] == 1 && n.ByteArrayValue[2] == 2 && n.ByteArrayValue[3] == 3 && n.BoolValue == true && n.CharValue == "a" && n.DateTimeValue == Convert.ToDateTime("01/11/1984") && n.DateTimeOffsetValue == DateTimeOffset.MaxValue && n.DecimalValue == 1.11m && n.FloatValue == 22 && n.DoubleValue == 33 && n.Integer32Value == 44 && n.Single == 55 && n.Integer16Value == 16 && n.GuidValue == guid && n.StringValue == "Something", "Insert of values in non nullable properties failed"); }
public void TestInsert_NullablePropertiesWithNullValues() { Models.Nullable n = new Models.Nullable(); n.Integer64Value = null; n.ByteValue = null; n.ByteArrayValue = null; n.BoolValue = null; n.CharValue = null; n.DateTimeValue = null; n.DateTimeOffsetValue = null; n.DecimalValue = null; n.FloatValue = null; n.DoubleValue = null; n.Integer32Value = null; n.Single = null; n.Integer16Value = null; n.GuidValue = null; n.StringValue = null; using (ADOCRUDContext context = new ADOCRUDContext(connectionString)) { context.Insert(n); context.Commit(); } Models.Nullable retrievedItem = null; using (ADOCRUDContext context = new ADOCRUDContext(connectionString)) { retrievedItem = context.QueryItems <Models.Nullable>("select * from Nullable where id = @id", new { id = n.Id }).FirstOrDefault(); } Assert.IsTrue(n != null && !n.Integer64Value.HasValue && !n.ByteValue.HasValue && n.ByteArrayValue == null && !n.BoolValue.HasValue && string.IsNullOrEmpty(n.CharValue) && !n.DateTimeValue.HasValue && !n.DateTimeOffsetValue.HasValue && !n.DecimalValue.HasValue && !n.FloatValue.HasValue && !n.DoubleValue.HasValue && !n.Integer32Value.HasValue && !n.Single.HasValue && !n.Integer16Value.HasValue && !n.GuidValue.HasValue && string.IsNullOrEmpty(n.StringValue), "Insert of null values in nullable properties failed"); }
public void TestMultipleDBCallsOnSingleTransaction_Commit() { Product p1 = null; Product p2 = null; Product retreivedProduct1 = null; Product retreivedProduct2 = null; using (ADOCRUDContext context = new ADOCRUDContext(connectionString)) { p1 = new Product(); p1.CategoryId = 1; p1.Name = "Football"; p1.Description = "NFL Size"; p1.Price = 9.99m; p2 = new Product(); p2.CategoryId = 2; p2.Name = "Shirt"; p2.Description = "Made from cotton"; p2.Price = 15.99m; context.Insert <Product>(p1); context.Insert <Product>(p2); context.Commit(); } using (ADOCRUDContext context = new ADOCRUDContext(connectionString)) { retreivedProduct1 = context.QueryItems <Product>("select * from dbo.Product where Id = @id", new { id = p1.Id }).FirstOrDefault(); retreivedProduct2 = context.QueryItems <Product>("select * from dbo.Product where Id = @id", new { id = p2.Id }).FirstOrDefault(); } Assert.IsTrue(retreivedProduct1 != null && retreivedProduct1.Id > 0 && retreivedProduct1.Name == "Football" && retreivedProduct1.Description == "NFL Size" && retreivedProduct1.Price == 9.99m, "An error occurred on first insert"); Assert.IsTrue(retreivedProduct2 != null && retreivedProduct2.Id > 0 && retreivedProduct2.Name == "Shirt" && retreivedProduct2.Description == "Made from cotton" && retreivedProduct2.Price == 15.99m, "An error occurred on 2nd insert"); }
public void TestInsertOfCompositeKeys_Commit() { UserProduct retrievedUserProduct = null; using (ADOCRUDContext context = new ADOCRUDContext(connectionString)) { UserProduct ur = new UserProduct(); ur.UserId = userId; ur.ProductId = productId; context.Insert <UserProduct>(ur); context.Commit(); retrievedUserProduct = context.QueryItems <UserProduct>("select * from UserProduct where userId = @userId and productId = @productId", new { userId = userId, productId = productId }).FirstOrDefault(); } Assert.IsTrue(retrievedUserProduct != null && retrievedUserProduct.UserId == userId && retrievedUserProduct.ProductId == productId, "An error occurred while inserting a composite key int crosswalk"); }
public void TestRemove_Commit() { using (ADOCRUDContext context = new ADOCRUDContext(connectionString)) { Product p = context.QueryItems <Product>("select * from dbo.Product where Id = @id", new { id = productId }).FirstOrDefault(); Assert.IsTrue(p != null && p.Id > 0); context.Remove(p); context.Commit(); } using (ADOCRUDContext context = new ADOCRUDContext(connectionString)) { Product p = context.QueryItems <Product>("select * from dbo.Product where Id = @id", new { id = productId }).FirstOrDefault(); Assert.IsTrue(p == null); } }
public void TestNestedConnections_Commit() { Product p = null; Product retreivedProduct = null; using (ADOCRUDContext context = new ADOCRUDContext(connectionString)) { using (ADOCRUDContext context2 = new ADOCRUDContext(connectionString)) { p = context2.QueryItems <Product>("select * from dbo.Product where Id = @id", new { id = productId }).FirstOrDefault(); } p.Name = "Bowling ball"; context.Update <Product>(p); context.Commit(); retreivedProduct = context.QueryItems <Product>("select * from dbo.Product where Id = @id", new { id = productId }).FirstOrDefault(); } Assert.IsTrue(retreivedProduct != null && retreivedProduct.Name == "Bowling ball", "An error occurred with nested connections"); }
public void TestUpdate_Commit() { using (ADOCRUDContext context = new ADOCRUDContext(ConfigurationManager.ConnectionStrings["UnitTestDB"].ToString())) { Product p = context.QueryItems <Product>("select * from Product where Id = @id", new { id = productId }).First(); p.Name = "Waffle Maker"; p.CategoryId = 3; p.Description = "Makes waffles"; p.Price = 29.99m; context.Update <Product>(p); context.Commit(); Product retreivedProduct = context.QueryItems <Product>("select * from dbo.Product where Id = @id", new { id = p.Id }).FirstOrDefault(); Assert.IsTrue(retreivedProduct != null && retreivedProduct.Id == p.Id && retreivedProduct.CategoryId == 3 && p.Name == "Waffle Maker" && p.Description == "Makes waffles" && p.Price == 29.99m, "An error occurred on update"); } }
public void TestInsert_Commit() { using (ADOCRUDContext context = new ADOCRUDContext(connectionString)) { Product p = new Product(); p.CategoryId = 1; p.Name = "Basketball"; p.Description = "NBA Size"; p.Price = 59.99m; context.Insert <Product>(p); context.Commit(); Product retreivedProduct = context.QueryItems <Product>("select * from dbo.Product where Id = @id", new { id = p.Id }).FirstOrDefault(); Assert.IsTrue(retreivedProduct != null && retreivedProduct.Id > 0 && retreivedProduct.CategoryId == 1 && retreivedProduct.Name == "Basketball" && retreivedProduct.Description == "NBA Size" && retreivedProduct.Price == 59.99m, "An error occurred on insert"); } }