public void AddsAllSymbolsWhenNoneExist()
            {
                //// SETUP

                // Test Data
                var stock1 = new Stock { Ticker = "FLWS", CompanyName = "1-800 FLOWERS.COM" };
                var stock2 = new Stock { Ticker = "FCTY", CompanyName = "1st Century Bancshares" };
                var stock3 = new Stock { Ticker = "FCCY", CompanyName = "1st Constitution Bancorp (NJ)" };
                var expectedResults = new List<Stock> { stock1, stock2, stock3 };

                // Create a mock generic repository.
                var mockGenericRepository = new Mock<IRepository<Stock>>();
                mockGenericRepository.Setup(mock => mock.FindBy(It.IsAny<Expression<Func<Stock, bool>>>())).Returns((Stock)null);

                // Setup target
                var target = new StockRepository(mockGenericRepository.Object);

                // EXECUTE
                var actualCountAdded = target.TryAddNewStocks(expectedResults);

                // VERIFY
                Assert.AreEqual(expectedResults.Count, actualCountAdded);
                mockGenericRepository.Verify(mock => mock.Add(expectedResults), Times.Once());
                mockGenericRepository.Verify(mock => mock.Add(It.IsAny<Stock>()), Times.Never());
            }
            public void AddsNoSymbolsWhenAllExist()
            {
                //// SETUP

                // Create two record sets that are identical
                var stock1 = new Stock { Ticker = "FLWS", CompanyName = "1-800 FLOWERS.COM" };
                var stock2 = new Stock { Ticker = "FCTY", CompanyName = "1st Century Bancshares" };
                var stock3 = new Stock { Ticker = "FCCY", CompanyName = "1st Constitution Bancorp (NJ)" };
                var preexistingRecords = new List<Stock> { stock1, stock2, stock3 };

                // Create a mock generic repository.
                var mockGenericRepository = new Mock<IRepository<Stock>>();

                var numFindByCalls = 0;
                mockGenericRepository.Setup(mock => mock.FindBy(It.IsAny<Expression<Func<Stock, bool>>>())).Returns(() =>
                {
                    numFindByCalls++;

                    switch (numFindByCalls)
                    {
                        case 1:
                            // Stock 1 is preexisting
                            return stock1;

                        case 2:
                            // Stock 2 is preexisting
                            return stock2;

                        case 3:
                            // Stock 3 does not exist
                            return stock3;

                        default:
                            throw new InvalidOperationException("Too many calls to mock.FindBy.");
                    }
                });

                // Setup target
                var target = new StockRepository(mockGenericRepository.Object);

                // EXECUTE
                var actualCountAdded = target.TryAddNewStocks(preexistingRecords);

                // VERIFY
                Assert.AreEqual(0, actualCountAdded);
                mockGenericRepository.Verify(mock => mock.Add(It.IsAny<Stock>()), Times.Never());
                mockGenericRepository.Verify(mock => mock.Add(It.IsAny<IEnumerable<Stock>>()), Times.Never());
                mockGenericRepository.Verify(mock => mock.FindBy(It.IsAny<Expression<Func<Stock, bool>>>()), Times.Exactly(3));
            }
            public void AddsOnlyNewSymbolsWhenSomeExist()
            {
                //// SETUP

                //// Test Data

                var stock1 = new Stock { Ticker = "FLWS", CompanyName = "1-800 FLOWERS.COM" };
                var stock2 = new Stock { Ticker = "FCTY", CompanyName = "1st Century Bancshares" };
                var stock3 = new Stock { Ticker = "FCCY", CompanyName = "1st Constitution Bancorp (NJ)" };
                var stock4 = new Stock { Ticker = "SRCE", CompanyName = "1st Source Corporation" };

                var preexistingRecords = new List<Stock> { stock1, stock2 };
                var newRecords = new List<Stock> { stock3, stock4 };

                var testData = new List<Stock>();
                testData.AddRange(preexistingRecords);
                testData.AddRange(newRecords);

                // Create a mock generic repository.
                var mockGenericRepository = new Mock<IRepository<Stock>>();

                var numFindByCalls = 0;
                mockGenericRepository.Setup(mock => mock.FindBy(It.IsAny<Expression<Func<Stock, bool>>>())).Returns(() =>
                    {
                        numFindByCalls++;

                        switch (numFindByCalls)
                        {
                            case 1:
                                // Stock 1 is preexisting
                                 return stock1;

                            case 2:
                                // Stock 2 is preexisting
                                return stock2;

                            case 3:
                                // Stock 3 does not exist
                                return (Stock)null;

                            case 4:
                                // Stock 4 does not exist
                                return (Stock)null;

                            default:
                                throw new InvalidOperationException("Too many calls to mock.FindBy.");
                        }
                    });

                // Setup target
                var target = new StockRepository(mockGenericRepository.Object);

                // EXECUTE
                var actualCountAdded = target.TryAddNewStocks(testData);

                // VERIFY
                Assert.AreEqual(newRecords.Count, actualCountAdded);
                mockGenericRepository.Verify(mock => mock.Add(newRecords));
                mockGenericRepository.Verify(mock => mock.Add(It.IsAny<Stock>()), Times.Never());
                mockGenericRepository.Verify(mock => mock.FindBy(It.IsAny<Expression<Func<Stock, bool>>>()), Times.Exactly(4));
            }