2012-10-24 10 views
1

우리 프로젝트에서 Db4o를 사용하고 있습니다.자동 테스트 용 Db4o 데이터베이스

테스트 된 오브젝트의 지속성에 대한 자동 테스트가 있습니다. 문제는 데이터베이스를 두 번 열거 나 만들 수 없다는 것입니다. 개체 컨테이너를 가져 오는 두 가지 도우미 메서드가 있습니다. 그러나 메서드가 두 번째 호출 될 때 "ArgumentException : 구성이 이미 사용되었습니다." 던졌습니다. 이전의 객체 보관소를 닫고 처리했습니다.

내가 뭘 잘못 했니?

CODE : 당신은 더 이상 사용되지 db4o는 방법을 사용하는

public static IObjectContainer GetEmptyTestingDatabase() { 
    var tempDir = Environment.GetFolderPath(Environment.SpecialFolder.InternetCache); 
    string dbFilePath = Path.Combine(tempDir, "UNIT-TESTING.db4o"); 
    if (File.Exists(dbFilePath)) { 
     File.Delete(dbFilePath); 
    } 

    var cfg = Db4oFactory.Configure(); 
    cfg.Add(new TransparentPersistenceSupport(new DeactivatingRollbackStrategy())); 
    cfg.Add(new TransparentActivationSupport()); 

    var db = Db4oFactory.OpenFile(cfg, dbFilePath); 
    return db; 
} 
public static IObjectContainer GetMemoryDatabase() { 
    string dbFileName = Guid.NewGuid().ToString().ToString(); 

    var cfg = Db4oFactory.Configure(); 
    cfg.Storage = new Db4objects.Db4o.IO.PagingMemoryStorage(); 
    cfg.Add(new TransparentPersistenceSupport(new DeactivatingRollbackStrategy())); 
    cfg.Add(new TransparentActivationSupport()); 

    var db = Db4oFactory.OpenFile(cfg, dbFileName); 
    return db; 
} 

답변

1

. 문제는 Db4oFactory.Configure()가 정적 구성 객체를 반환한다는 것입니다. 이 방법은 이전 버전과의 호환성을 위해서만 존재합니다.

새로운 db4o 버전을 사용하는 경우 Db4oEmbedded.NewConfiguration()을 대신 사용하십시오. 그렇지 않으면 (Db4oFactory.NewConfiguration()을 사용하여 이전 db4o 버전을 계속 사용해야하는 경우에도 작동해야 함).

+0

감사! 나는 오래된 예를보아야 만한다. – TcKs