public void GetTotalSpendPerPostcode_DictionaryReturnedFromDA_DictionaryReturned()
        {
            // Create dictionary to be returned
            regionSpends = new Dictionary<string, decimal>
                               {
                                   { Region.EastMidlands.ToString(), 5M },
                                   { Region.EastOfEngland.ToString(), 6M }
                               };
            // Mock query
            query.Setup(q => q.Result).Returns(regionSpends);
            QueryFactory.Setup(f => f.CalcTotalSpendPerPostcode(Practices)).Returns(query.Object);
            // Mock reader
            PrescriptionsReader.Setup(r => r.ExecuteQuery(query.Object));
            // Instantiate service
            PrescriptionsService = new PrescriptionsService(Practices, PrescriptionsReader.Object, QueryFactory.Object);

            // Call method
            var result = PrescriptionsService.GetTotalSpendPerPostcode();

            // Check data returned unchanged
            Assert.IsTrue(result[Region.EastMidlands.ToString()] == 5M && result[Region.EastOfEngland.ToString()] == 6M);
            Assert.AreEqual(regionSpends.Count, 2);
            // Check reader was called
            PrescriptionsReader.VerifyAll();
        }
        public void GetAverageActCostPerRegion_ValidBnfCodeSupplied_CorrectResultsReturned()
        {
            // Mock the queries list
            decimal queryReturnValue = 0M;
            foreach (var r in Region.All)
            {
                var query = new Mock<ICalcAvgCostByCodeByRegion>();
                query.Setup(q => q.Region).Returns(r);
                query.Setup(q => q.Result).Returns(queryReturnValue++);
                QueryFactory.Setup(
                    f => f.CalcAvgCostByCodeByRegion(Data.BnfCode1, It.Is<Region>(m => m.Equals(r)), Practices))
                    .Returns(query.Object);
            }
            // Mock reader
            PrescriptionsReader.Setup(r => r.ExecuteQuery(It.IsAny<List<ICalcAvgCostByCodeByRegion>>()));
            // Instantiate service
            PrescriptionsService = new PrescriptionsService(Practices, PrescriptionsReader.Object, QueryFactory.Object);

            // Call method
            var result = PrescriptionsService.GetAverageActCostPerRegion(Data.BnfCode1);

            // Check returned list is correct
            decimal expectedReturnValue = 0M;
            Assert.AreEqual(result.Count(r => r.Value == expectedReturnValue++), Region.All.Count);
            Assert.AreEqual(result.Count, Region.All.Count);
            // Check DA called
            // PrescriptionsReader.VerifyAll();
        }
        private static void Process(PracticesService practicesService, PrescriptionsService prescriptionService)
        {

            // Find out how many practices there are in London
            Console.WriteLine("How many practices are in London?");
            int practicesInLondon = practicesService.GetPracticeCountByRegion(Region.London);
            Console.WriteLine(practicesInLondon);

            // Find out the average national cost of a peppermint oil prescription
            Console.WriteLine("What was the average actual cost of all peppermint oil prescriptions?");
            decimal averagePepermintOilCost = prescriptionService.GetAverageActCost("0102000T0");
            Console.WriteLine(averagePepermintOilCost.ToString("£0.00"));

            // Find the 5 highest spending postcodes
            Console.WriteLine("Which 5 post codes have the highest actual spend, and how much did each spend in total?");
            // Get postcode spends
            var totalPostcodeSpends = prescriptionService.GetTotalSpendPerPostcode();
            // Get top 5
            var topFive = totalPostcodeSpends.OrderByDescending(p => p.Value).Take(5).ToList();
            // Write to console
            topFive.ForEach(p => Console.WriteLine(p.Key + " " + p.Value.ToString("£0.00")));

            // Find average price of Flucloxacillin
            Console.WriteLine(
                "For each region, what was the average price per prescription of Flucloxacillin,"
                + " and how did this vary from the national mean?");
            // Get average cost per region
            var averageFlucloxacillinRegions = prescriptionService.GetAverageActCostPerRegion("0501012G0");
            // Get average cost for country
            decimal averageFlucloxacillinNational = prescriptionService.GetAverageActCost("0501012G0");
            // Write to console
            Console.WriteLine("National: " + averageFlucloxacillinNational.ToString("£0.00"));
            averageFlucloxacillinRegions.ForEach(
                r =>
                Console.WriteLine(
                    r.Key + " " + r.Value.ToString("£0.00") + "; "
                    + (r.Value - averageFlucloxacillinNational).ToString("£0.00")));

            // Find by region the percentage difference between the NIC and Act Cost for
            Console.WriteLine(
                "For each region for Simeticone, what was the average Actual Cost "
                + "as a percentage of the average Net Ingredient Cost?");
            var actPercentageOfNic = prescriptionService.GetFractionActCostOfNicByRegion("0103050E0");
            actPercentageOfNic.ForEach(r => Console.WriteLine(r.Key + " " + r.Value.ToString("0.00%")));

            Console.ReadLine();
        }
        public void GetAverageActCost_ValidBnfCodeGiven_CorrectAverageCostCalculated()
        {
            // Mock query
            query.Setup(q => q.Result).Returns(5M);
            QueryFactory.Setup(f => f.CalcAvgCostByCode(Data.BnfCode1)).Returns(query.Object);
            // Mock reader
            PrescriptionsReader.Setup(r => r.ExecuteQuery(query.Object));
            // Create instance of service
            PrescriptionsService = new PrescriptionsService(GetPractices(), PrescriptionsReader.Object, QueryFactory.Object);

            // Call service
            var result = PrescriptionsService.GetAverageActCost(Data.BnfCode1);

            // Ensure result is as returned by query
            Assert.AreEqual(result, 5M);
            // Ensure query execution was called
            PrescriptionsReader.VerifyAll();
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Performing startup...");
            //Create instances of practice service and prescription service
            var practicesService = new PracticesService();
            var prescriptionService = new PrescriptionsService(practicesService.Practices);
            Console.WriteLine("Startup completed.");
            if (askBooleanQuestion("Process all at once?"))
            {
                ProcessOnce(practicesService, prescriptionService);
            }
            else
            {
                Process(practicesService, prescriptionService);
            }

            Console.ReadLine();
        }