public void Should_Return_Null_For_Invalid_Id()
        {
            // arrange
            IConnectionRepository connectionRepository = this.GetConnectionRepository();

            // act
            ConnectionModel retrievedConnection = connectionRepository.GetConnection(1);

            // assert
            Assert.IsNull(retrievedConnection);
        }
        public void Should_Return_Item_For_Valid_Id()
        {
            // arrange
            IConnectionRepository connectionRepository = this.GetConnectionRepository();
            ConnectionModel       connection           = new ConnectionModel();

            connection.ConnectionId = 1;
            connectionRepository.AddConnection(connection);

            // act
            ConnectionModel retrievedConnection = connectionRepository.GetConnection(1);

            // assert
            Assert.IsTrue(retrievedConnection.ConnectionId == 1);
        }
        public void Should_Allow_Remoe()
        {
            // arrange
            IConnectionRepository connectionRepository = this.GetConnectionRepository();
            ConnectionModel       connection           = new ConnectionModel();

            connection.ConnectionId = 1;
            connectionRepository.AddConnection(connection);

            // act
            connectionRepository.RemoveConnection(connection);
            ConnectionModel retrievedConnection = connectionRepository.GetConnection(1);

            // assert
            Assert.IsNull(retrievedConnection);
        }
예제 #4
0
        public string GetConnection(string baseUrl)
        {
            Uri    u = new Uri(baseUrl);
            string DBString;
            string cacheKey = $"{_options.Value.CacheConnStrKey}_{u.Host}";

            //Check weather connection in Cache
            if (!_cacheProvider.TryGetValue <string>(cacheKey, out DBString))
            {
                //Retrieve Connection String from Repo
                DBString = _connectionRepository.GetConnection(baseUrl);
                if (!string.IsNullOrEmpty(DBString))
                {
                    //Add to Cache
                    _cacheProvider.Add(cacheKey, DBString, 0);
                }
            }

            return(DBString);
        }
 public Connection GetConnection(string user1, string user2)
 {
     return(_repo.GetConnection(user1, user2));
 }