예제 #1
0
        public override bool CompareTargetDataToDb(string key, string fileName = null, Table tableData = null,
                                                   TestDataResultOperationType operationType = default)
        {
            var featureTestData = GenerateDataFromTable(tableData);
            var fileTestData    = GenerateDataFromFile(fileName, key);
            var allBreaks       = _breakRepository.GetAll().ToList();

            switch (operationType)
            {
            case TestDataResultOperationType.Add:
            {
                featureTestData.AddRange(fileTestData);
                if (allBreaks.Count != featureTestData.Count)
                {
                    return(false);
                }

                foreach (var entity in featureTestData)
                {
                    if (allBreaks.Count(c => c.ExternalBreakRef == entity.ExternalBreakRef) != 1)
                    {
                        return(false);
                    }

                    var storedBreak = allBreaks.FirstOrDefault(c => c.ExternalBreakRef == entity.ExternalBreakRef);
                    if (!CompareBreak(entity, storedBreak))
                    {
                        return(false);
                    }
                }

                var resultSchedules = TestDataImporter.GetDataFromFile <Schedule>(fileName, "Schedules").ToList();
                var allSchedules    = _scheduleRepository.GetAll().ToList();
                if (allSchedules.Count != resultSchedules.Count)
                {
                    return(false);
                }

                foreach (var schedule in resultSchedules)
                {
                    var storedSchedule = allSchedules.FirstOrDefault(c => c.SalesArea == schedule.SalesArea && c.Date == schedule.Date);
                    var storedRefs     = storedSchedule.Breaks.Select(b => b.ExternalBreakRef).OrderBy(b => b);
                    var targetRefs     = schedule.Breaks.Select(b => b.ExternalBreakRef).OrderBy(b => b);
                    if (!storedRefs.SequenceEqual(targetRefs))
                    {
                        return(false);
                    }
                }

                var resultSpots = TestDataImporter.GetDataFromFile <Schedule>(fileName, "Spots").ToList();
                var allSpots    = _spotRepository.GetAll();

                return(allSpots.Count() == resultSpots.Count);
            }

            default:
                return(false);
            }
        }
예제 #2
0
        public Dictionary <string, int> Get()
        {
            var breakcount     = _breakrepo.GetAll().Count();
            var spotCountcount = _spotrepo.GetAll().Count();
            var progcount      = _programmerepo.GetAll().Count();
            var campaigncount  = _campaignrepo.GetAll().Count();
            var productcount   = _productRepository.GetAll().Count();
            var clashcount     = _clashRepository.GetAll().Count();

            var items = new Dictionary <string, int> {
                { "Breaks", breakcount }, { "Spots", spotCountcount }, { "Programmes", progcount }, { "Campaigns", campaigncount }, { "Product", productcount }, { "Clash", clashcount }
            };

            return(items);
        }
예제 #3
0
        /// <summary>
        /// Creates recommendations data
        /// </summary>
        /// <param name="numberOfSpots">Number of spots to generate data for</param>
        /// <returns></returns>
        public List <Recommendation> Create(int numberOfSpots)
        {
            var recommendations = new List <Recommendation>();

            _random = new Random();
            DateTime processorDateTime = DateTime.UtcNow;

            // Load data
            var spots      = _spotRepository.GetAll();                                                     // Doesn't actually return all
            var salesAreas = _salesAreaRepository.GetAll();
            var programmes = _programmeRepository.GetAll();                                                // Doesn't actually return all

            numberOfSpots = (numberOfSpots > spots.ToList().Count ? spots.ToList().Count : numberOfSpots); // If insufficient spots then return max number

            if (!spots.Any())
            {
                throw new ArgumentException("Cannot generate fake recommendations data because there are no spots in the database");
            }
            if (!programmes.Any())
            {
                throw new ArgumentException("Cannot generate fake recommendations data because there are no programmes in the database");
            }

            // Add data for each spot
            int programmeIndex = -1;

            for (int spotIndex = 0; spotIndex < numberOfSpots; spotIndex++)
            {
                programmeIndex++;
                programmeIndex = (programmeIndex >= programmes.ToList().Count - 1 ? 0 : programmeIndex);
                var spot      = spots.ToList()[spotIndex];
                var salesArea = salesAreas.Where(x => x.Name.Equals(spot.SalesArea)).First();
                var programme = programmes.ToList()[++programmeIndex];

                recommendations.Add(CreateRecommendation(spots.ToList()[spotIndex], salesArea, programme, processorDateTime));
            }
            return(recommendations);
        }
예제 #4
0
 public List <Spot> GetAll()
 {
     return(_spotRepository.GetAll());
 }
예제 #5
0
        public IEnumerable <Spot> Get()
        {
            var spots = _repository.GetAll();

            return(spots);
        }
예제 #6
0
 public IEnumerable <Spot> GetAll() => _repository.GetAll();