Exemplo n.º 1
0
        public async Task StoredDataInfoReqWorks()
        {
            _dataStorageMock.Setup(x => x.GetStorageInfo(It.Is <int>(id => id == 1)))
            .Returns <int>(x =>
                           new List <StoredDataInfo>()
            {
                new StoredDataInfo()
                {
                    InstrumentID = x, Frequency = BarSize.OneDay, EarliestDate = new DateTime(2000, 1, 1), LatestDate = DateTime.Now
                }
            });

            //Set up the repo
            InstrumentRepoMock
            .Setup(x => x.FindInstruments(It.IsAny <Expression <Func <Instrument, bool> > >()))
            .Returns(async() => await Task.FromResult(_data.AsQueryable().Where(x => x.ID == 1).ToList()));

            //make the request
            var response = await Browser.Get("/instruments/1/storageinfo", with =>
            {
                with.HttpRequest();
                with.Query("Symbol", "QQQ"); //must use with.Query() for parameters
            });

            //make sure everything is nominal
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
        }
Exemplo n.º 2
0
        public async Task InstrumentSearchWorks()
        {
            //Set up the repo
            InstrumentRepoMock
            .Setup(x => x.FindInstruments(It.IsAny <Instrument>()))
            .Returns <Instrument>(async inst => await Task.FromResult(_data.AsQueryable().Where(x => x.Symbol == inst.Symbol).ToList()));

            //make the request
            var response = await Browser.Get("/instruments/search", with =>
            {
                with.HttpRequest();
                with.Query("Symbol", "QQQ"); //must use with.Query() for parameters
            });

            //make sure everything is nominal
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            string s           = response.Body.AsString();
            var    instruments = JsonConvert.DeserializeObject <List <Instrument> >(s);

            Assert.AreEqual(1, instruments.Count);
            Assert.AreEqual("QQQ", instruments[0].Symbol);
        }
Exemplo n.º 3
0
        public async Task PredicateSearchWorks()
        {
            //Set up the repo
            InstrumentRepoMock
            .Setup(x => x.FindInstruments(It.IsAny <Expression <Func <Instrument, bool> > >()))
            .Returns <Expression <Func <Instrument, bool> > >(f => Task.FromResult(_data.AsQueryable().Where(f).ToList()));

            //make the request
            Expression <Func <Instrument, bool> > filter = i => i.ID == 1 && i.Symbol == "SPY";
            var response = await Browser.Get("/instruments/predsearch", with =>
            {
                with.HttpRequest();
                with.Query("SerializedFilter", filter.Serialize()); //must use with.Query() for parameters
            });

            //make sure everything is nominal
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            string s           = response.Body.AsString();
            var    instruments = JsonConvert.DeserializeObject <List <Instrument> >(s);

            Assert.AreEqual(1, instruments.Count);
            Assert.AreEqual("SPY", instruments[0].Symbol);
        }