예제 #1
0
        public void WriteTick_Succeeds()
        {
            //Arrange
            var(dbFile, path, fileName) = SetupTempDb();

            var sqliteReg = new SQLiteRegistry(path, fileName);
            var randomCurrencyPairName = GetRandomCurrencyPairName(dbFile);

            (_, _, int currencyPairId)    = sqliteReg.GetCurrencyPairIdByName(randomCurrencyPairName);
            (_, int[] commandPortNumbers) = sqliteReg.GetAvailableCommandPortNumbers();
            int randomCommandPortNumber = commandPortNumbers[new Random().Next(0, commandPortNumbers.Length - 1)];

            (_, int[] feederPortNumbers) = sqliteReg.GetAvailableFeederPortNumbers();
            int    randomFeederPortNumber = feederPortNumbers[new Random().Next(0, feederPortNumbers.Length - 1)];
            string accountId = Guid.NewGuid().ToString();
            int    sessionId = 1;

            sqliteReg.RegisterSession(accountId, sessionId, currencyPairId, randomCommandPortNumber, randomFeederPortNumber);
            var tickWriter = sqliteReg.GetTickWriter(accountId, currencyPairId);
            var timestamp  = Timestamp.FromDateTime(DateTime.UtcNow);

            //Act
            var result = tickWriter.Write(timestamp.dateTime, timestamp.milliseconds, 1, 2);

            //Assert
            Assert.True(result.success);
        }
예제 #2
0
        public void ReuseCommandPortNumberOfDeadSession_Succeds()
        {
            //Arrange
            var(dbFile, path, fileName) = SetupTempDb();

            var sqliteReg = new SQLiteRegistry(path, fileName);
            var randomCurrencyPairName = GetRandomCurrencyPairName(dbFile);

            (_, _, int currencyPairId)    = sqliteReg.GetCurrencyPairIdByName(randomCurrencyPairName);
            (_, int[] commandPortNumbers) = sqliteReg.GetAvailableCommandPortNumbers();
            int randomCommandPortNumber = commandPortNumbers[new Random().Next(0, commandPortNumbers.Length - 1)];

            (_, int[] feederPortNumbers) = sqliteReg.GetAvailableFeederPortNumbers();
            int    randomFeederPortNumber = feederPortNumbers[new Random().Next(0, feederPortNumbers.Length - 1)];
            string accountId = Guid.NewGuid().ToString();
            int    sessionId = 1;

            sqliteReg.RegisterSession(accountId, sessionId, currencyPairId, randomCommandPortNumber, randomFeederPortNumber);

            //Act
            var portNumberResult = sqliteReg.ReuseCommandPortNumber(accountId, sessionId, currencyPairId);

            //Assert
            Assert.False(portNumberResult > 0);

            TearDownTempDb(dbFile);
        }
예제 #3
0
        public void GetLastTickOnEmptyTickFolder_Fails()
        {
            //Arrange
            var(dbFile, path, fileName) = SetupTempDb();

            var sqliteReg = new SQLiteRegistry(path, fileName);
            var randomCurrencyPairName = GetRandomCurrencyPairName(dbFile);

            (_, _, int currencyPairId)    = sqliteReg.GetCurrencyPairIdByName(randomCurrencyPairName);
            (_, int[] commandPortNumbers) = sqliteReg.GetAvailableCommandPortNumbers();
            int randomCommandPortNumber = commandPortNumbers[new Random().Next(0, commandPortNumbers.Length - 1)];

            (_, int[] feederPortNumbers) = sqliteReg.GetAvailableFeederPortNumbers();
            int    randomFeederPortNumber = feederPortNumbers[new Random().Next(0, feederPortNumbers.Length - 1)];
            string accountId = Guid.NewGuid().ToString();
            int    sessionId = 1;

            sqliteReg.RegisterSession(accountId, sessionId, currencyPairId, randomCommandPortNumber, randomFeederPortNumber);
            var tickWriter = sqliteReg.GetTickWriter(accountId, currencyPairId);

            //Act
            var result = tickWriter.LastTick;

            //Assert
            Assert.False(result.success);
        }
예제 #4
0
        public void GetTickUriOnNewDbPth_ShouldNotExist()
        {
            //Arrange
            var(dbFile, path, fileName) = SetupTempDb();

            var sqliteReg = new SQLiteRegistry(path, fileName);
            var randomCurrencyPairName = GetRandomCurrencyPairName(dbFile);

            (_, _, int currencyPairId)    = sqliteReg.GetCurrencyPairIdByName(randomCurrencyPairName);
            (_, int[] commandPortNumbers) = sqliteReg.GetAvailableCommandPortNumbers();
            int randomCommandPortNumber = commandPortNumbers[new Random().Next(0, commandPortNumbers.Length - 1)];

            (_, int[] feederPortNumbers) = sqliteReg.GetAvailableFeederPortNumbers();
            int    randomFeederPortNumber = feederPortNumbers[new Random().Next(0, feederPortNumbers.Length - 1)];
            string accountId = Guid.NewGuid().ToString();
            int    sessionId = 1;

            sqliteReg.RegisterSession(accountId, sessionId, currencyPairId, randomCommandPortNumber, randomFeederPortNumber);
            var tickWriter = sqliteReg.GetTickWriter(accountId, currencyPairId);

            //Act
            var tickUri = tickWriter.TickUri;

            //Assert
            Assert.False(Directory.Exists(tickUri));
        }
예제 #5
0
        public void GetCurrencyPairByNameWithNoExistingName_Fails()
        {
            //Arrange
            var(dbFile, path, fileName) = SetupTempDb();
            var sqliteReg = new SQLiteRegistry(path, fileName);
            var nonExistingCurrencyPairName = "USDPHP";

            //Act
            (bool success, string message, int currencyPairId) = sqliteReg.GetCurrencyPairIdByName(nonExistingCurrencyPairName);

            //Assert
            Assert.False(success);
            Assert.True(message != null);

            TearDownTempDb(dbFile);
        }
예제 #6
0
        public void GetCurrencyPairByNameWithExistingName_Succeeds()
        {
            //Arrange
            var(dbFile, path, fileName) = SetupTempDb();

            var sqliteReg = new SQLiteRegistry(path, fileName);
            var randomCurrencyPairName = GetRandomCurrencyPairName(dbFile);

            //Act
            (bool success, string message, int currencyPairId) = sqliteReg.GetCurrencyPairIdByName(randomCurrencyPairName);

            //Assert
            Assert.True(success);
            Assert.True(currencyPairId > 0);

            TearDownTempDb(dbFile);
        }
예제 #7
0
        public void SQLiteRegistryInstantiation_InitializesDbSuccessfully()
        {
            //Arrange
            var(dbFile, path, fileName) = SetupTempDb();

            //Act
            var sqliteReg = new SQLiteRegistry(path, fileName);

            //Assert
            var result = SQLiteDbHelper.Query(dbFile, "SELECT name FROM sqlite_master WHERE type = 'table'");

            Assert.Contains(result, s => s["name"].ToString() == "Sessions");
            Assert.Contains(result, s => s["name"].ToString() == "ReservedPorts");
            var reservedPortsResult = SQLiteDbHelper.Query(dbFile, "SELECT COUNT(*) AS cnt FROM ReservedPorts");

            Assert.Contains(reservedPortsResult, s => (long)(s["cnt"]) > 0);
            Assert.Contains(result, s => s["name"].ToString() == "CurrencyPairs");
            var currencyPairsResult = SQLiteDbHelper.Query(dbFile, "SELECT COUNT(*) AS cnt FROM CurrencyPairs");

            Assert.Contains(currencyPairsResult, s => (long)(s["cnt"]) > 0);

            TearDownTempDb(dbFile);
        }