2009 Advent Calendar December 7th


Now that we have a working transaction from yesterday we need to add the important object to it. So let’s use the initial implementation of the important object:

1: public class ImportantObject
2: {
3: public void ImportantMethod()
4: {
5: // Do things.
6: }
7: }

Then we want a new test on the transaction:

1: public class Given_a_transaction
2: {
3: private Transaction _transaction = new Transaction(new ImportantObject(), new FakeLock());
4:  
5: [Fact]
6: void It_should_return_an_ImportantObject()
7: {
8: Assert.NotNull(_transaction.ImportantObject);
9: }
10: }

And the implementation:

1: public class Transaction : IDisposable
2: {
3: private readonly Lock _lock;
4: public ImportantObject ImportantObject { get; private set; }
5:  
6: public Transaction(ImportantObject importantObject, Lock aLock)
7: {
8: ImportantObject = importantObject;
9: _lock = aLock;
10: _lock.Lock();
11: }
12:  
13: public void Dispose()
14: {
15: _lock.Unlock();
16: }
17: }

Comments (0)