6

編集

私はドキュメントを正しく保存しているので、この質問の最初の部分は正しくありません。おそらくRavenDBの経験が浅いためです。ただし、単体テストでEmbeddableDocumentStoreを使用しているときに、RavenDBManagementStudioを開くことができるかどうかという疑問が残ります。


NUnitを使用した単体テスト中に、EmbeddableDocumentStoreにドキュメントを保存する際に問題が発生したようです。ドキュメントを実際に保存しているかどうかを確認するために、組み込みデータベースに接続しようとしています。

URL http:// computername:8080 /を開こうとすると(何らかの理由でraven dbは常に私のPCのコンピューター名を使用します)、ブラウザーの読み込みバーが回転し、単体テストを停止してURLを再試行するとChromeが表示します接続できなかったというメッセージが表示されます。コンテキストのコードを次に示します。

[TestFixture]
public class Test2 : IDisposable
{
    private EmbeddableDocumentStore _documentStore;

    [SetUp]
    public void SetUp()
    {
        if (_documentStore != null) return;

        _documentStore = new EmbeddableDocumentStore
        {
            DataDirectory = "Data",
            RunInMemory = true,
            UseEmbeddedHttpServer = true
        };

        _documentStore.Configuration.AnonymousUserAccessMode = AnonymousUserAccessMode.All;

        _documentStore.Initialize();
    }

    [Test]
    public void Test()
    {
        var document = StaticData.getdocument();

        using (var session = _documentStore.OpenSession())
        {
            session.Store(document);
            session.SaveChanges();
        }

        using (var session = _documentStore.OpenSession())
        {
            var test = session.Load<ObjectType>().Length;
            //This is always 0
        }
    }

    public void Dispose()
    {
        _documentStore.Dispose();
    }
}

また、テストプロジェクトのルートにRaven.Studio.xapファイルがあります。

私はVS2012を使用しており、それが違いを生む場合は.Net4.5を使用しています。

4

2 に答える 2

4

どうぞ:

static public void WaitForUserToContinueTheTest(EmbeddableDocumentStore documentStore, bool debug = true)
{
    if (debug && Debugger.IsAttached == false)
        return;

    documentStore.SetStudioConfigToAllowSingleDb();

    documentStore.DatabaseCommands.Put("Pls Delete Me", null,

                                       RavenJObject.FromObject(new { StackTrace = new StackTrace(true) }),
                                       new RavenJObject());

    documentStore.Configuration.AnonymousUserAccessMode = AnonymousUserAccessMode.All;
    using (var server = new HttpServer(documentStore.Configuration, documentStore.DocumentDatabase))
    {
        server.StartListening();
        Process.Start(documentStore.Configuration.ServerUrl); // start the server

        do
        {
            Thread.Sleep(100);
        } while (documentStore.DatabaseCommands.Get("Pls Delete Me") != null && (debug == false || Debugger.IsAttached));
    }
}
于 2012-10-12T20:00:07.407 に答える
0

@Ayende Rahienのソリューションを適用する方法の正確な詳細は彼の答えから欠落しているので、ここで正確な手順を説明します。

  1. UseEmbeddedHttpServerをtrueに設定してEmbeddableDocumentStoreを作成する場合は、WaitForUserToContinueTheTestがサーバーを作成するため、これを削除します。

  2. デバッグするテストコードで、WaitForUserToContinueTheTestメソッドを呼び出します。

  3. WaitForUserToContinueTheTestメソッドの後にVisualStudioでブレークポイントを設定します。

  4. デバッグモードで実行している場合、URL localhost:8080 / raven / studio.htmlまたは:8080 / raven/studio.htmlのブラウザウィンドウが自動的に開きます。

  5. WaitForUserToContinueTheTestのwhileループを終了するには、Raven HTTP GUIを使用して、[ドキュメント]->[すべてのドキュメント]に移動します。右側の[Plsdeleteme]行を右クリックし、[Delete]をクリックします。これで、VisualStudioはテストを続行する必要があります。

(ちなみに、RavenDBチームが単体テストのドキュメントを改善してくれることを願っています。)

于 2014-06-26T09:00:30.100 に答える