Remco;7275 wrote:
Ok, sorry, that's a very different story then. Which test framework are you using? Is it MSTest? How is the initialisation code hooked into the test framework?
Yes, test framework is MSTest. Not sure what you mean by hooked in? But the test code is as follows. (Sorry I can't find away of attaching files)
[TestInitialize]
public void Init()
{
ctx = new CMTContext(ConfigurationManager.ConnectionStrings["DefaultConnectionString"].ConnectionString);
unitOfWork = new UnitOfWork(ctx);
}
[TestMethod]
[TestCategory("Integration")]
public void GetChanges_Returns_Deleted_Entities()
{
var delivery = new DeliveryEntity(
Guid.NewGuid(),
"TEST UNIT OF WORK AUDIT (DELETED RECORDS)",
"USED ON INTEGRATION TEST FOR THE UNIT OF WORK",
"TEST",
new List<Guid> { Guid.NewGuid() },
DeliveryStatus.Active,
new DailyScheduleEntity(DateTime.Parse("19/03/2015 14:00"), 2));
unitOfWork.DeliveryRepository.Add(delivery);
unitOfWork.SaveChanges();
var retrieved = unitOfWork.DeliveryRepository.Find(delivery.Id);
unitOfWork.DeliveryRepository.Delete(retrieved);
var changes = ctx.GetChanges().ToList();
unitOfWork.SaveChanges();
var toCompare = changes.OfType<DeliveryEntity>().SingleOrDefault();
Assert.IsNotNull(toCompare);
Assert.AreEqual(retrieved, toCompare);
}
The code that the test runs is
public void SaveChanges()
{
var entitiesChanged = dbContext.GetChanges().OfType<IAggregate>().ToList();
var user = System.Security.Principal.GenericPrincipal.Current;
if(user == null || !user.Identity.IsAuthenticated) throw new InvalidOperationException("An unexpected exception occured. \nThere is no security principel defined.");
entitiesChanged.ForEach(a => {
var audit = new AuditEntity(
a,
user.Identity.Name
);
AuditRepository.Add(audit);
});
dbContext.SaveChanges();
}
Because the user is not authenticated an exception is thrown.
Hope that helps in identifying the problem.
Cheers,
Lee.