public void RemoveBy_ObjectToRemove_Removed() { try { // Drop the email templates table if it exists already DataAccess.RunSqlCommandFromFile("DROP_EmailTemplate"); // Create the email templates table DataAccess.RunSqlCommandFromFile("CREATE_EmailTemplate"); // Insert into the table var id0 = DataAccess.RunSqlCommand( "INSERT INTO [EmailTemplate] ([emailName],[emailBody]) VALUES ('New Order Placed','We have recieved your order. It will be processed shortly.');SELECT SCOPE_IDENTITY()"); var id1 = DataAccess.RunSqlCommand( "INSERT INTO [EmailTemplate] ([emailName],[emailBody]) VALUES ('Order Shipped','We have dispatched your order.');SELECT SCOPE_IDENTITY()"); // Create new repository var repository = new EmailTemplateRepository(); // Attempt to find a couple of objects // Check the values of item 0 var result0 = repository.FindById(Convert.ToInt64(id0)); Assert.IsNotNull(result0); Assert.AreEqual("New Order Placed", result0.EmailName); Assert.AreEqual("We have recieved your order. It will be processed shortly.", result0.EmailBody); // Check the values of item 1 var result1 = repository.FindById(Convert.ToInt64(id1)); Assert.IsNotNull(result1); Assert.AreEqual("Order Shipped", result1.EmailName); Assert.AreEqual("We have dispatched your order.", result1.EmailBody); // Attempt to remove repository.RemoveBy(Convert.ToInt64(id0)); // Select count from table, it should be one object count = DataAccess.RunSqlCommand("SELECT COUNT(*) FROM [EmailTemplate];"); Assert.AreEqual(1, count); // Select top identifier from table, it should be equal to the value in the id1 variable object id = Convert.ToDecimal(DataAccess.RunSqlCommand("SELECT TOP 1 [id] FROM [EmailTemplate];")); Assert.AreEqual(id1, id); } finally { // Drop the email templates table if it still exists DataAccess.RunSqlCommandFromFile("DROP_EmailTemplate"); } }
public void FindBy_GivenID_ObjectFound() { try { // Drop the email templates table if it exists already DataAccess.RunSqlCommandFromFile("DROP_EmailTemplate"); // Create the email templates table DataAccess.RunSqlCommandFromFile("CREATE_EmailTemplate"); // Insert into the table object id0 = DataAccess.RunSqlCommand("INSERT INTO [EmailTemplate] ([emailName],[emailBody]) VALUES ('New Order Placed','We have recieved your order. It will be processed shortly.');SELECT SCOPE_IDENTITY()"); object id1 = DataAccess.RunSqlCommand("INSERT INTO [EmailTemplate] ([emailName],[emailBody]) VALUES ('Order Shipped','We have dispatched your order.');SELECT SCOPE_IDENTITY()"); // Create new repository var repository = new EmailTemplateRepository(); // Attempt to find a couple of objects // Check the values of item 0 var result0 = repository.FindById(Convert.ToInt64(id0)); Assert.IsNotNull(result0); Assert.AreEqual("New Order Placed", result0.EmailName); Assert.AreEqual("We have recieved your order. It will be processed shortly.", result0.EmailBody); // Check the values of item 1 var result1 = repository.FindById(Convert.ToInt64(id1)); Assert.IsNotNull(result1); Assert.AreEqual("Order Shipped", result1.EmailName); Assert.AreEqual("We have dispatched your order.", result1.EmailBody); } finally { // Drop the email templates table if it still exists DataAccess.RunSqlCommandFromFile("DROP_EmailTemplate"); } }