<commit_before>﻿// -----------------------------------------------------------------------
// <copyright file="HistoricalDataServerTest.cs" company="">
// Copyright 2014 <NAME>
// </copyright>
// -----------------------------------------------------------------------

using Moq;
using NUnit.Framework;
using QDMSServer;

namespace QDMSTest
{
    [TestFixture]
    public class HistoricalDataServerTest
    {
        private HistoricalDataServer _server;
        private QDMSClient.QDMSClient _client;
        private Mock<IHistoricalDataBroker> _brokerMock;

        [SetUp]
        public void SetUp()
        {
            _brokerMock = new Mock<IHistoricalDataBroker>();
            _server = new HistoricalDataServer(5557, _brokerMock.Object);
            _client = new QDMSClient.QDMSClient("testingclient", "127.0.0.1", 5554, 5555, 5556, 5557);
        }

        [TearDown]
        public void TearDown()
        {
            _server.Dispose();
            _client.Dispose();
        }

        [Test]
        public void HistoricalDataRequestsAreForwardedToTheBroker()
        {
            Assert.IsTrue(false);
        }
    }
}
<commit_msg>Wrote HistoricalDataRequestsAreForwardedToTheBroker test, it passes.<commit_after>﻿// -----------------------------------------------------------------------
// <copyright file="HistoricalDataServerTest.cs" company="">
// Copyright 2014 <NAME>
// </copyright>
// -----------------------------------------------------------------------

using System;
using System.Threading;
using Moq;
using NUnit.Framework;
using QDMS;
using QDMSServer;

namespace QDMSTest
{
    [TestFixture]
    public class HistoricalDataServerTest
    {
        private HistoricalDataServer _hdServer;
        private RealTimeDataBroker _rtServer;
        private QDMSClient.QDMSClient _client;
        private Mock<IHistoricalDataBroker> _brokerMock;

        [SetUp]
        public void SetUp()
        {
            _brokerMock = new Mock<IHistoricalDataBroker>();

            //also need the real time server to keep the "heartbeat" going
            _rtServer = new RealTimeDataBroker(5555, 5554);
            _rtServer.StartServer();

            _hdServer = new HistoricalDataServer(5557, _brokerMock.Object);
            _hdServer.StartServer();

            _client = new QDMSClient.QDMSClient("testingclient", "127.0.0.1", 5554, 5555, 5556, 5557);
            _client.Connect();
        }

        [TearDown]
        public void TearDown()
        {
            _hdServer.Dispose();
            _rtServer.Dispose();
            _client.Dispose();
        }

        [Test]
        public void HistoricalDataRequestsAreForwardedToTheBroker()
        {
            var instrument = new Instrument
            {
                ID = 1,
                Symbol = "SPY",
                Datasource = new Datasource { ID = 1, Name = "MockSource" }
            };

            instrument.Exchange = new Exchange()
            {
                ID = 1,
                Name = "Exchange",
                Timezone = "Eastern Standard Time"
            };

            var request = new HistoricalDataRequest(instrument, BarSize.OneDay, new DateTime(2012, 1, 1), new DateTime(2013, 1, 1));

            _client.RequestHistoricalData(request);

            Thread.Sleep(500);

            _brokerMock.Verify(x => x.RequestHistoricalData(
                It.Is<HistoricalDataRequest>(r => 
                    r.Instrument.ID == 1 && 
                    r.Frequency == BarSize.OneDay &&
                    r.StartingDate == new DateTime(2012, 1, 1) &&
                    r.EndingDate == new DateTime(2013, 1, 1))), Times.Once);
        }
    }
}

{'fraction_non_alphanumeric': 0.16938997821350762, 'fraction_numerical': 0.02696078431372549, 'mean_word_length': 1.5524669909659485, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2971803', 'n_tokens_mistral': 1071, 'n_tokens_neox': 958, 'n_words': 208}