public static void CleanupTestTrack() { int deleteResult = -1; MessagingContext context = null; #region Clean database of records added during test try { using (context = new MessagingContext(connectionStringName)) { MessagePing recordToDelete = context.FindOne(new object[] { recordId }); bool recordIsNotAvailable = null != recordToDelete; if (recordIsNotAvailable) { context.Remove(recordToDelete); deleteResult = context.SaveChanges(); } } } catch { } finally { if (null != context) { context.Dispose(); } } #endregion }
public void UpdateRecordToDatabase() { #region Test Setup MessagePing testSubject; #endregion #region Test using (var context = new MessagingContext(connectionStringName)) { try { testSubject = AssertRecordExistence(recordId, context); } catch (AssertFailedException) { AddRecordsToDatabase(); testSubject = AssertRecordExistence(recordId, context); } testSubject.Message = updatedMessage; context.SaveChanges(); } testSubject = null; using (var context = new MessagingContext(connectionStringName)) { testSubject = context.FindOne(new object[] { recordId }); Assert.IsNotNull(testSubject, "Record not found in database"); Assert.IsTrue(updatedMessage == testSubject.Message, "Record was not updated"); } #endregion }
private MessagePing AssertRecordExistence(Guid recordId, MessagingContext context) { MessagePing testSubject; testSubject = context.FindOne(new object[] { recordId }); try { Assert.IsNotNull(testSubject, "Record not found in database"); } catch { testSubject = SeedRecord(); } return testSubject; }
public void GetMessageRecordFromDatabase() { #region Test Setup MessagePing testSubject; #endregion #region Test using (var context = new MessagingContext(connectionStringName)) { var checkRecordExistence = AssertRecordExistence(recordId, context); testSubject = context.FindOne(new object[] { recordId }); Assert.IsNotNull(testSubject, "Record not found in database"); Assert.IsTrue(recordId == testSubject.Id, "Record found in the database did not match record id"); } #endregion }