public void ClearDb()
 {
     using (var context = new CryptoCognizantContext(options))
     {
         // clear the db
         context.Coin.RemoveRange(context.Coin);
         context.SaveChanges();
     };
 }
        public async Task TestGetIDSuccessfully()
        {
            using (var context = new CryptoCognizantContext(options))
            {
                CoinsController     coinsController = new CoinsController(context, _mapper);
                ActionResult <Coin> result          = await coinsController.GetCoin(0);

                Assert.IsNotNull(result);
            }
        }
 public void SetupDb()
 {
     using (var context = new CryptoCognizantContext(options))
     {
         // populate the db
         context.Coin.Add(coins[0]);
         context.Coin.Add(coins[1]);
         context.SaveChanges();
     }
 }
Beispiel #4
0
        public async Task TestGetIDSuccessfully()
        {
            using (var context = new CryptoCognizantContext(options))
            {
                ExchangesController     exchangesController = new ExchangesController(context);
                ActionResult <Exchange> result = await exchangesController.GetExchange(0);

                Assert.IsNotNull(result);
            }
        }
        public async Task TestPutCoinNoContentStatusCode()
        {
            using (var context = new CryptoCognizantContext(options))
            {
                Boolean newFav = false;
                Coin    coin1  = context.Coin.Where(x => x.IsFavourite == coins[0].IsFavourite).Single();
                coin1.IsFavourite = newFav;

                CoinsController coinsController = new CoinsController(context, _mapper);
                IActionResult   result          = await coinsController.PutCoin(coin1.CoinId, coin1) as IActionResult;

                Assert.IsNotNull(result);
                Assert.IsInstanceOfType(result, typeof(NoContentResult));
            }
        }
Beispiel #6
0
        public async Task TestPutExchangeNoContentStatusCode()
        {
            using (var context = new CryptoCognizantContext(options))
            {
                string   newPairs  = "BTC, NAV, LTC";
                Exchange exchange1 = context.Exchange.Where(x => x.Pairs == exchanges[0].Pairs).Single();
                exchange1.Pairs = newPairs;

                ExchangesController exchangesController = new ExchangesController(context);
                IActionResult       result = await exchangesController.PutExchange(exchange1.ExchangeId, exchange1) as IActionResult;

                Assert.IsNotNull(result);
                Assert.IsInstanceOfType(result, typeof(NoContentResult));
            }
        }
        public async Task TestDeleteSuccessfully()
        {
            using (var context = new CryptoCognizantContext(options))
            {
                CoinsController coinsController = new CoinsController(context, _mapper);

                ActionResult <IEnumerable <Coin> > result1 = await coinsController.GetCoin();

                ActionResult <Coin> delete = await coinsController.DeleteCoin(0);

                ActionResult <IEnumerable <Coin> > result2 = await coinsController.GetCoin();

                // Assert that coin list changes after coin is deleted
                Assert.AreNotEqual(result1, result2);
            }
        }
Beispiel #8
0
        public async Task TestDeleteSuccessfully()
        {
            using (var context = new CryptoCognizantContext(options))
            {
                ExchangesController exchangesController = new ExchangesController(context);

                ActionResult <IEnumerable <Exchange> > result1 = await exchangesController.GetExchange();

                ActionResult <Exchange> delete = await exchangesController.DeleteExchange(0);

                ActionResult <IEnumerable <Exchange> > result2 = await exchangesController.GetExchange();

                // Assert that exchange list changes after exchange is deleted
                Assert.AreNotEqual(result1, result2);
            }
        }
Beispiel #9
0
        public async Task <ActionResult <Coin> > PostCoin([FromBody] SYMDTO data)
        {
            Coin   coin;
            String coinSymbol;

            try
            {
                // Constructing the coin object from our helper function
                coinSymbol = data.SYM;
                coin       = CryptoCompareHelper.getCoinInfo(coinSymbol);
            }
            catch
            {
                return(BadRequest("Invalid Coin Symbol"));
            }

            // Add this coin object to the database
            _context.Coin.Add(coin);
            await _context.SaveChangesAsync();

            // Get the primary key
            int id = coin.CoinId;

            // Insert exchanges in a non-blocking fashion
            CryptoCognizantContext tempContext         = new CryptoCognizantContext();
            ExchangesController    exchangesController = new ExchangesController(tempContext);

            // Add exchanges on another thread
            Task addExchanges = Task.Run(async() =>
            {
                // Get a list of exchanges from CryptoCompareHelper
                List <Exchange> exchanges = new List <Exchange>();
                exchanges = CryptoCompareHelper.getExchanges(coinSymbol);

                for (int i = 0; i < exchanges.Count; i++)
                {
                    // Get the exchange objects from exchanges and assign coinSymbol to CoinSymbol, the primary key of the newly inserted coin
                    Exchange exchange   = exchanges.ElementAt(i);
                    exchange.CoinSymbol = coinSymbol;
                    // Add this exchange to the database
                    await exchangesController.PostExchange(exchange);
                }
            });

            // Return success code and the info on the coin object
            return(CreatedAtAction("GetCoin", new { id = coin.CoinId }, coin));
        }
Beispiel #10
0
        public async Task TestPostSuccessfully()
        {
            using (var context = new CryptoCognizantContext(options))
            {
                ExchangesController exchangesController = new ExchangesController(context);

                Exchange exch = new Exchange()
                {
                    ExchangeId = 3,
                    Pairs      = "USD, USDT, NZD, AUD"
                };

                ActionResult <IEnumerable <Exchange> > result1 = await exchangesController.GetExchange();

                ActionResult <Exchange> post = await exchangesController.PostExchange(exch);

                ActionResult <IEnumerable <Exchange> > result2 = await exchangesController.GetExchange();

                // Assert that exchange list changes after new exchange is posted
                Assert.AreNotEqual(result1, result2);
            }
        }
Beispiel #11
0
 public ExchangesController(CryptoCognizantContext context)
 {
     _context = context;
 }
Beispiel #12
0
 public CoinsController(CryptoCognizantContext context, IMapper mapper)
 {
     _context            = context;
     _mapper             = mapper;
     this.coinRepository = new CoinRepository(new CryptoCognizantContext());
 }
Beispiel #13
0
 public CoinRepository(CryptoCognizantContext context)
 {
     this.context = context;
 }