Created
August 4, 2016 23:17
-
-
Save lchanmann/236fe84f12653aa656d78cb12a8148be to your computer and use it in GitHub Desktop.
DatabaseFixture.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class DatabaseFixture | |
| { | |
| public TransactionScope transactionScope; | |
| public DatabaseFixture() | |
| { | |
| ConnectionString = "Your ConnectionString"; | |
| } | |
| public string ConnectionString { get; set; } | |
| [SetUp] | |
| public void SetUp() | |
| { | |
| transactionScope = new TransactionScope(TransactionScopeOption.RequiresNew, new TimeSpan(0, 5, 0)); | |
| } | |
| [TearDown] | |
| public void TearDown() | |
| { | |
| transactionScope.Dispose(); | |
| } | |
| } | |
| [TestFixture] | |
| public class MemberRepositoryFixture: DatabaseFixture | |
| { | |
| [Test] | |
| public void ShouldCreateAndFindMember() | |
| { | |
| var member = CreateMember(); | |
| using (var repository = new MemberRepository(this.ConnectionString)) | |
| { | |
| repository.Create(member); | |
| repository.SubmitChanges(); | |
| } | |
| using (var repository = new MemberRepository(this.ConnectionString)) | |
| { | |
| var found = repository.FindById(member.Id); | |
| Assert.IsNotNull(found); | |
| Assert.AreEqual(found.Id, member.Id); | |
| Assert.AreEqual(found.FirstName, member.FirstName); | |
| Assert.AreEqual(found.LastName, member.LastName); | |
| Assert.AreEqual(found.Gender, member.Gender); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment