Skip to content

Commit

Permalink
- Cleaned up FakeUsers to always create a unique Identity.
Browse files Browse the repository at this point in the history
- TestBase now only disposes of the Embeddable Document Store during
  a TearDown. No need to implement IDisposable because this would -again- get called
  after all the tests have been run and the class was finally being removed.
  • Loading branch information
PureKrome committed Dec 30, 2011
1 parent e28528c commit 47d0c32
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
4 changes: 2 additions & 2 deletions Code/RavenOverflow.FakeData/FakeUsers.cs
Expand Up @@ -13,9 +13,9 @@ public static User CreateAFakeUser()
{
return Builder<User>
.CreateNew()
.With(x => x.FullName = string.Format("{0} {1}", GetRandom.FirstName(), GetRandom.LastName()))
.With(x => x.Id = null)
.And(x => x.FullName = string.Format("{0} {1}", GetRandom.FirstName(), GetRandom.LastName()))
.And(x => x.DisplayName = x.FullName.Replace(' ', '.'))
.And(x => x.Id = string.Format("Users/{0}", x.DisplayName))
.And(x => x.Email = GetRandom.Email())
.And(x => x.CreatedOn = GetRandom.DateTime(DateTime.UtcNow.AddMonths(-1), DateTime.UtcNow))
.And(x => x.Score = GetRandom.PositiveInt(50000))
Expand Down
36 changes: 21 additions & 15 deletions Code/RavenOverflow.Tests/TestBase.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using CuttingEdge.Conditions;
using NUnit.Framework;
Expand All @@ -14,7 +15,7 @@

namespace RavenOverflow.Tests
{
public abstract class TestBase : IDisposable
public abstract class TestBase
{
protected IDocumentStore DocumentStore { get; private set; }

Expand Down Expand Up @@ -45,9 +46,26 @@ public void InitaliseDocumentStore()
}

[TearDown]
public void DisposeDocumentStore()
public void Dispose()
{
Dispose();
if (DocumentStore == null)
{
return;
}

// Check to see if we had any errors, like an index wasn't found or something.
var statistics = DocumentStore.DatabaseCommands.GetStatistics();
if (statistics.Errors != null && statistics.Errors.Length > 0)
{
// Lets write out each error to the unit test console.
foreach (var serverError in statistics.Errors)
{
Debug.WriteLine(serverError.Error);
throw new InvalidOperationException("There were some errors with the Document Store.");
}
}

DocumentStore.Dispose();
}

private static void CreateSeedData(IDocumentStore documentStore)
Expand Down Expand Up @@ -100,17 +118,5 @@ public void BeforeQueryExecuted(IDocumentQueryCustomization queryCustomization)
}

#endregion

#region Implementation of IDisposable

public void Dispose()
{
if (DocumentStore != null)
{
DocumentStore.Dispose();
}
}

#endregion
}
}

0 comments on commit 47d0c32

Please sign in to comment.