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

using System;
using EntityData;
using Moq;
using NUnit.Framework;
using QDMSServer;

namespace QDMSTest
{
    [TestFixture]
    public class InstrumentsServerTest
    {
        private InstrumentsServer _instrumentsServer;
        
        // Needed for the heartbeat the checks if the connection is alive.
        private RealTimeDataServer _rtdServer;
        private QDMSClient.QDMSClient _client;
        private Mock<IInstrumentSource> _instrumentSourceMock;
        private Mock<IRealTimeDataBroker> _rtdBrokerMock;

        [SetUp]
        public void SetUp()
        {
            _instrumentSourceMock = new Mock<IInstrumentSource>();
            _instrumentsServer = new InstrumentsServer(5555, _instrumentSourceMock.Object);

            _rtdBrokerMock = new Mock<IRealTimeDataBroker>();
            _rtdServer = new RealTimeDataServer(5554, 5553, _rtdBrokerMock.Object);

            _instrumentsServer.StartServer();
            _rtdServer.StartServer();

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

        [TearDown]
        public void TearDown()
        {
            _instrumentsServer.StopServer();
            _instrumentsServer.Dispose();

            _rtdServer.StopServer();
            _rtdServer.Dispose();

            _client.Dispose();
        }

        [Test]
        public void SearchesForInstrumentsWithTheCorrectParameters()
        {
            _client.FindInstruments(new QDMS.Instrument { Symbol = "SPY", Datasource = new QDMS.Datasource { Name = "Interactive Brokers" }, Type = QDMS.InstrumentType.Stock });

            _instrumentSourceMock.Verify(
                x => x.FindInstruments(
                    It.IsAny<MyDBContext>(),
                    It.Is<QDMS.Instrument>(y => 
                        y.Symbol == "SPY" &&
                        y.Datasource.Name == "Interactive Brokers" &&
                        y.Type == QDMS.InstrumentType.Stock),
                    It.Is<Func<QDMS.Instrument, bool>>(y => y == null)));
        }

        [Test]
        public void RequestForAllInstrumentsIsForwardedCorrectly()
        {
            _client.FindInstruments();

            _instrumentSourceMock.Verify(
                x => x.FindInstruments(
                    It.IsAny<MyDBContext>(), 
                    It.Is<QDMS.Instrument>(y => y == null), 
                    It.Is<Func<QDMS.Instrument, bool>>(y => y == null)));
        }
    }
}<commit_msg>Small fix to instruments server test.<commit_after>﻿// -----------------------------------------------------------------------
// <copyright file="InstrumentsServerTest.cs" company="">
// Copyright 2014 <NAME>
// </copyright>
// -----------------------------------------------------------------------

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

namespace QDMSTest
{
    [TestFixture]
    public class InstrumentsServerTest
    {
        private InstrumentsServer _instrumentsServer;
        
        // Needed for the heartbeat the checks if the connection is alive.
        private RealTimeDataServer _rtdServer;
        private QDMSClient.QDMSClient _client;
        private Mock<IInstrumentSource> _instrumentSourceMock;
        private Mock<IRealTimeDataBroker> _rtdBrokerMock;

        [SetUp]
        public void SetUp()
        {
            _instrumentSourceMock = new Mock<IInstrumentSource>();
            _instrumentsServer = new InstrumentsServer(5555, _instrumentSourceMock.Object);

            _rtdBrokerMock = new Mock<IRealTimeDataBroker>();
            _rtdServer = new RealTimeDataServer(5554, 5553, _rtdBrokerMock.Object);

            _instrumentsServer.StartServer();
            _rtdServer.StartServer();

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

        [TearDown]
        public void TearDown()
        {
            _instrumentsServer.StopServer();
            _instrumentsServer.Dispose();

            _rtdServer.StopServer();
            _rtdServer.Dispose();

            _client.Dispose();
        }

        [Test]
        public void SearchesForInstrumentsWithTheCorrectParameters()
        {
            _client.FindInstruments(new QDMS.Instrument { Symbol = "SPY", Datasource = new QDMS.Datasource { Name = "Interactive Brokers" }, Type = QDMS.InstrumentType.Stock });

            _instrumentSourceMock.Verify(
                x => x.FindInstruments(
                    It.IsAny<MyDBContext>(),
                    It.Is<QDMS.Instrument>(y => 
                        y.Symbol == "SPY" &&
                        y.Datasource.Name == "Interactive Brokers" &&
                        y.Type == QDMS.InstrumentType.Stock),
                    It.Is<Func<QDMS.Instrument, bool>>(y => y == null)));
        }

        [Test]
        public void RequestForAllInstrumentsIsForwardedCorrectly()
        {
            _client.FindInstruments();
            Thread.Sleep(50);

            _instrumentSourceMock.Verify(
                x => x.FindInstruments(
                    It.IsAny<MyDBContext>(), 
                    It.Is<QDMS.Instrument>(y => y == null), 
                    It.Is<Func<QDMS.Instrument, bool>>(y => y == null)));
        }
    }
}
{'fraction_non_alphanumeric': 0.14861505681818182, 'fraction_numerical': 0.013849431818181818, 'mean_word_length': 1.7133911368015415, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 45, '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': '3510311', 'n_tokens_mistral': 1640, 'n_tokens_neox': 1497, 'n_words': 282}