Created
March 9, 2012 20:30
-
-
Save bltavares/2008502 to your computer and use it in GitHub Desktop.
C# Trasactional Tests
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
using System; | |
using System.Text; | |
using System.Collections.Generic; | |
using System.Linq; | |
using Microsoft.VisualStudio.TestTools.UnitTesting; | |
namespace Test | |
{ | |
[TestClass] | |
public class TestTransactionClass : TransactionalTest | |
{ | |
[TestMethod] | |
public void TestThereIsNoUser() | |
{ | |
var expected = db.Users.Any(); | |
Assert.IsFalse(expected); | |
} | |
[TestMethod] | |
public void TestUserCreation() | |
{ | |
var user = Fixtures.UserFixture.GenerateDefault<User>(); | |
db.SaveChanges(); | |
var expected = db.Users.Any(c => c.Name == user.Name); | |
Assert.IsTrue(expected); | |
} | |
[TestMethod] | |
public void TestTeamCreation() | |
{ | |
var team = Fixtures.TeamFixture.GenerateDefault<Team>(); | |
db.SaveChanges(); | |
var expected = db.Teams.Any(c => c.Id == team.Id); | |
Assert.IsTrue(expected); | |
} | |
[TestMethod] | |
public void TestTeamPlayerCreation() | |
{ | |
var name = "Bruno"; | |
var player = Fixtures.TeamPlayerFixture.GenerateDefault<TeamPlayer>(new { Name = name }); | |
db.SaveChanges(); | |
var expected = db.TeamPlayers.Any(c => c.Name == name); | |
Assert.IsTrue(expected); | |
} | |
} | |
} |
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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using Microsoft.VisualStudio.TestTools.UnitTesting; | |
using System.Transactions; | |
namespace Test | |
{ | |
public class TransactionalTest | |
{ | |
protected TransactionScope scope; | |
protected Entities db; | |
[TestInitialize] | |
public void SetUpNewTransaction() | |
{ | |
scope = new TransactionScope(TransactionScopeOption.RequiresNew); | |
db = new Entities(); | |
Fixtures.FixtureRepo.db = db; | |
} | |
[TestCleanup] | |
public void DisposeDatabase() | |
{ | |
Fixtures.FixtureRepo.db = null; | |
db.AcceptAllChanges(); | |
db.Dispose(); | |
scope.Dispose(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment