Пример #1
0
        public IpCallsStats Create(IEnumerable <DataCountry.Root> apiCountries)
        {
            var calls = new List <CallsByCountry>();

            foreach (var country in apiCountries)
            {
                var callByCountry = new CallsByCountry
                {
                    CountryCode = country.alpha2Code,
                    CountryName = country.name,
                    Latitude    = country.latlng.Count > 0 ? country.latlng[0] : 0,
                    Longitude   = country.latlng.Count > 0 ? country.latlng[1] : 0,
                    Calls       = 0,
                };

                calls.Add(callByCountry);
            }

            var data = new IpCallsStats()
            {
                CallsByCountryInfo = calls
            };

            return(data);
        }
Пример #2
0
        private IpCallsStats GetIpCallsStats()
        {
            var ipCallsStats = new IpCallsStats()
            {
                CallsByCountryInfo = new List <CallsByCountry>()
                {
                    new CallsByCountry()
                    {
                        Calls       = 5,
                        CountryCode = "ES",
                        CountryName = "España",
                        Latitude    = 40,
                        Longitude   = -4,
                    },
                    new CallsByCountry()
                    {
                        Calls       = 10,
                        CountryCode = "BR",
                        CountryName = "Brasil",
                        Latitude    = -10,
                        Longitude   = -55,
                    }
                }
            };

            return(ipCallsStats);
        }
Пример #3
0
        private void UpdateCallsCounter(IpCallsStats stats)
        {
            if (stats == null || stats.CallsByCountryInfo == null)
            {
                return;
            }

            foreach (var country in stats.CallsByCountryInfo)
            {
                var events = _eventRegister.EventsRegisteredByType(country.CountryCode);
                country.Calls = events.Quantity;
            }
        }
Пример #4
0
        public async Task GetIpCallsStatsTest()
        {
            var eventCounter = new EventCounter()
            {
                EventType = "", Quantity = 1
            };
            var register = new Mock <IEventRegister>();

            register.Setup(r => r.EventsRegisteredByType(It.IsAny <String>()))
            .Returns(eventCounter);


            var cache = new Mock <ICache>();
            var stats = new IpCallsStats();

            stats.CallsByCountryInfo = new List <CallsByCountry>()
            {
                new CallsByCountry()
                {
                    Calls = 1
                }
            };

            cache.Setup(c => c.GetAsync(
                            It.IsAny <String>(),
                            It.IsAny <Func <String, Task <IpCallsStats> > >(),
                            null))
            .ReturnsAsync(stats);

            var reqCreator = new Mock <IAPIRequestCreator>();

            var service = new IpReportService(cache.Object, reqCreator.Object, register.Object);

            var ipCalls = await service.GetIpCallsStats();

            Assert.AreEqual(1, ipCalls.CallsByCountryInfo.First().Calls);
        }