public void Start()
        {
            if (!TestHelper.GetDlcPath(out string dlcPath))
            {
                return;
            }

            var ope = new UoeDatabaseOperator(dlcPath);

            var tgtDb = GetDb("start");

            ope.Create(tgtDb);
            Assert.IsTrue(tgtDb.Exists());

            Assert.AreEqual(DatabaseBusyMode.NotBusy, ope.GetBusyMode(tgtDb));

            var nextPort = UoeDatabaseOperator.GetNextAvailablePort();

            try {
                ope.Start(tgtDb, "localhost", nextPort.ToString(), new UoeProcessArgs().Append("-minport", "50000", "-maxport", "50100", "-L", "20000") as UoeProcessArgs);

                Assert.AreEqual(DatabaseBusyMode.MultiUser, ope.GetBusyMode(tgtDb));
            } finally {
                ope.Kill(tgtDb);
            }

            Assert.AreEqual(DatabaseBusyMode.NotBusy, ope.GetBusyMode(tgtDb));
        }
        public void Test()
        {
            var serverPort = UoeDatabaseOperator.GetNextAvailablePort(1050);
            var proxyPort  = UoeDatabaseOperator.GetNextAvailablePort(serverPort + 1);

            // hostname to use
            // we need something different than 127.0.0.1 or localhost for the proxy!
            IPHostEntry hostEntry;

            try {
                hostEntry = Dns.GetHostEntry("mylocalhost");
            } catch (Exception) {
                hostEntry = null;
            }
            var host = hostEntry == null ? "127.0.0.1" : "mylocalhost";

            var archiver = Archiver.NewHttpFileServerArchiver();

            Assert.IsNotNull(archiver);

            var baseDir = Path.Combine(TestFolder, "http");

            archiver.SetProxy($"http://{host}:{proxyPort}/", "jucai69d", "julien caillon");
            archiver.SetBasicAuthentication("admin", "admin123");

            var listFiles = GetPackageTestFilesList(TestFolder, $"http://{host}:{serverPort}/server1");

            listFiles.AddRange(GetPackageTestFilesList(TestFolder, $"http://{host}:{serverPort}/server2"));

            var fileServer  = new SimpleHttpFileServer(baseDir, "admin", "admin123");
            var proxyServer = new SimpleHttpProxyServer("jucai69d", "julien caillon");

            var cts   = new CancellationTokenSource();
            var task1 = HttpServer.ListenAsync(serverPort, cts.Token, fileServer.OnHttpRequest, true);
            var task2 = HttpServer.ListenAsync(proxyPort, cts.Token, proxyServer.OnHttpRequest, true);

            PartialTestForHttpFileServer(archiver, listFiles);

            if (!host.Equals("127.0.0.1"))
            {
                Assert.AreEqual(61, proxyServer.NbRequestsHandledOk);
            }

            HttpServer.Stop(cts, task1, task2);
        }
        public void Test()
        {
            var serverHost = @"127.0.0.1";
            var serverIp   = UoeDatabaseOperator.GetNextAvailablePort(2024);
            var ftpUri     = $"ftp://{serverHost}:{serverIp}/";

            // Setup dependency injection
            var services = new ServiceCollection();

            services.Configure <DotNetFileSystemOptions>(opt => opt
                                                         .RootPath = Path.Combine(TestFolder, "archives"));

            services.AddFtpServer(builder => builder
                                  .UseDotNetFileSystem()             // Use the .NET file system functionality
                                  .EnableAnonymousAuthentication()); // allow anonymous logins

            services.Configure <FtpServerOptions>(opt => {
                opt.ServerAddress = serverHost;
                opt.Port          = serverIp;
            });

            using (var serviceProvider = services.BuildServiceProvider()) {
                // Initialize the FTP server
                var ftpServer = serviceProvider.GetRequiredService <IFtpServer>();

                // Start the FTP server
                ftpServer.Start();

                SpinWait.SpinUntil(() => ftpServer.Ready, 5000);

                FtpArchiver archiver = new FtpArchiver();

                var listFiles = GetPackageTestFilesList(TestFolder, ftpUri);

                WholeTest(archiver, listFiles);

                // Stop the FTP server
                ftpServer.Stop();
            }
        }
        public void GetConnectionString()
        {
            if (!TestHelper.GetDlcPath(out string dlcPath))
            {
                return;
            }

            var ope = new UoeDatabaseOperator(dlcPath);
            var db  = GetDb("connec");

            ope.Create(db);

            Assert.IsTrue(ope.GetDatabaseConnection(db).SingleUser);
            Assert.IsTrue(string.IsNullOrEmpty(ope.GetDatabaseConnection(db).Service));
            Assert.AreEqual(null, ope.GetDatabaseConnection(db).LogicalName);
            Assert.AreEqual("test", ope.GetDatabaseConnection(db, "test").LogicalName);

            try {
                ope.Start(db);

                Assert.IsFalse(ope.GetDatabaseConnection(db).SingleUser);
                Assert.IsTrue(string.IsNullOrEmpty(ope.GetDatabaseConnection(db).Service));
            } finally {
                ope.Kill(db);
            }

            try {
                ope.Start(db, null, UoeDatabaseOperator.GetNextAvailablePort().ToString());

                Assert.IsFalse(ope.GetDatabaseConnection(db).SingleUser);
                Assert.IsFalse(string.IsNullOrEmpty(ope.GetDatabaseConnection(db).Service));
                Assert.IsFalse(string.IsNullOrEmpty(ope.GetDatabaseConnection(db).HostName));
            } finally {
                ope.Kill(db);
            }
        }
 public void GetNextAvailablePort()
 {
     Assert.IsTrue(UoeDatabaseOperator.GetNextAvailablePort(0) > 0);
     Assert.IsTrue(UoeDatabaseOperator.GetNextAvailablePort(1025) >= 1025);
 }