Ehsan Akbar
Ehsan Akbar

Reputation: 7299

ravenTestDriver in xunit returns Unable to start the RavenDB Server

I try to test a simple code with RavenTestDriver in .net6 here is my code :

 public class RavenDBTestDriver : RavenTestDriver
        {

            //This allows us to modify the conventions of the store we get from 'GetDocumentStore'
            protected override void PreInitialize(IDocumentStore documentStore)
            {
                documentStore.Conventions.MaxNumberOfRequestsPerSession = 50;
          
        }

            [Fact]
            public void MyFirstTest()
            {
                ConfigureServer(new TestServerOptions
                {
                    //DataDirectory = "C:\\RavenDBTestDir",
                    CommandLineArgs = new System.Collections.Generic.List<string> { "--RunInMemory=true", },
                    FrameworkVersion = null,
                });

                using (var store = GetDocumentStore())
                {
                    store.ExecuteIndex(new TestDocumentByName());
                    using (var session = store.OpenSession())
                    {
                        session.Store(new TestDocument { Name = "Hello world!" });
                        session.Store(new TestDocument { Name = "Goodbye..." });
                        session.SaveChanges();
                    }
                    WaitForIndexing(store); //If we want to query documents sometime we need to wait for the indexes to catch up
                    WaitForUserToContinueTheTest(store);//Sometimes we want to debug the test itself, this redirect us to the studio
                    using (var session = store.OpenSession())
                    {
                        var query = session.Query<TestDocument, TestDocumentByName>().Where(x => x.Name == "hello").ToList();
                        Assert.Single(query);
                    }
                }
            }
        public class TestDocumentByName : AbstractIndexCreationTask<TestDocument>
        {
            public TestDocumentByName()
            {
                Map = docs => from doc in docs select new { doc.Name };
                Indexes.Add(x => x.Name, FieldIndexing.Search);
            }
        }

        public class TestDocument
        {
            public string Name { get; set; }
        }
    }

But when I run the test I get this error :

 System.InvalidOperationException : Unable to start the RavenDB Server
    Error:
    It was not possible to find any compatible framework version
    The framework 'Microsoft.NETCore.App', version '6.0.1' (x64) was not found.
      - The following frameworks were found:
          5.0.7 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
          6.0.0-preview.6.21352.12 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
          6.0.0 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
    
    You can resolve the problem by installing the specified framework and/or SDK.
    
    The specified framework can be found at:
      - https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=6.0.1&arch=x64&rid=win10-x64
    
    

  Stack Trace: 
    EmbeddedServer.RunServer() line 299
    EmbeddedServer.GetServerUriAsync(CancellationToken token) line 185
    <<RunSync>b__0>d.MoveNext() line 106
    --- End of stack trace from previous location ---
    AsyncHelpers.RunSync[T](Func`1 task) line 125
    RavenTestDriver.RunServer() line 274
    Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
    Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
    Lazy`1.CreateValue()
    Lazy`1.get_Value()
    RavenTestDriver.GetDocumentStore(GetDocumentStoreOptions options, String database) line 78
    RavenDBTestDriver.MyFirstTest() line 34

Upvotes: 3

Views: 414

Answers (1)

Ehsan Akbar
Ehsan Akbar

Reputation: 7299

Finally because I don't want to change my .net version, I installed the

"RavenDB.TestDriver" Version="5.2.0"

Upvotes: 3

Related Questions