Пример #1
0
        public void Calling_DialCodeService_WithToId_And_WithoutCurrentTime_Should_NotReturnCurrentTime()
        {
            // Arrange
            var osloId = new LocationId ("norway/oslo");

            // Act
            var service = new DialCodeService (Config.AccessKey, Config.SecretKey);
            service.IncludeCurrentTime = false;
            var result = service.GetDialCode (osloId);

            // Assert
            Assert.IsTrue (result.Locations.All (x => x.Time == null));
        }
Пример #2
0
        public void Calling_DialCodeService_WithToId_And_WithFromId_Should_ReturnTheCorrectDialCode()
        {
            // Arrange
            var osloId = new LocationId("norway/oslo");
            var newYorkId = new LocationId("usa/new-york");

            // Act
            var service = new DialCodeService (Config.AccessKey, Config.SecretKey);
            var result = service.GetDialCode (osloId, newYorkId);

            // Assert
            Assert.IsTrue (result.Locations.Any (x => x.Geography.Country.Name == "Norway"));
            Assert.IsTrue (result.Locations.Any (x => x.Geography.Country.Name == "United States"));
        }
Пример #3
0
        public void Calling_DialCodeService_WithToId_And_WithFromId_And_WithNumber_Should_ReturnTheCorrectDialCode()
        {
            // Arrange
            var osloId = new LocationId ("norway/oslo");
            var newYorkId = new LocationId ("usa/new-york");
            var sampleNumber = 1234567;

            // Act
            var service = new DialCodeService (Config.AccessKey, Config.SecretKey);
            var result = service.GetDialCode (osloId, newYorkId, sampleNumber);

            var intl = result.Compositions [0];
            var ctry = result.Compositions [1];
            var local = result.Compositions [2];

            var newYork = result.Locations [0];
            var oslo = result.Locations [1];

            // Assert
            Assert.AreEqual (intl.PhoneNumberElement, PhoneNumberElementType.InternationalPrefix);
            Assert.AreEqual ("011", intl.Number);
            Assert.IsNotNull (intl.Description);
            Assert.IsNotEmpty (intl.Description);

            Assert.AreEqual (local.PhoneNumberElement, PhoneNumberElementType.LocalNumber);
            Assert.AreEqual (sampleNumber.ToString (), local.Number);
            Assert.IsNotNull (local.Description);
            Assert.IsNotEmpty (local.Description);

            Assert.AreEqual (ctry.PhoneNumberElement, PhoneNumberElementType.CountryPrefix);
            Assert.AreEqual ("47", ctry.Number);
            Assert.IsNotNull (ctry.Description);
            Assert.IsNotEmpty (ctry.Description);

            Assert.IsNotNull (oslo.Time);
            Assert.IsNotNull (oslo.Time.ISO);
            Assert.IsNotNull (oslo.Time.Timezone);

            Assert.IsNotNull (newYork.Time);
            Assert.IsNotNull (newYork.Time.ISO);
            Assert.IsNotNull (newYork.Time.Timezone);

            Assert.IsTrue (result.Locations.Any (x => x.Geography.Country.Name == "Norway"));
            Assert.IsTrue (result.Locations.Any (x => x.Geography.Country.Name == "United States"));

            Assert.AreEqual ("011 47 1234567", result.Number);
        }
Пример #4
0
        public void Calling_AstronomyService_WithEnddate_Should_ReturnCorrectAstronomyInfo()
        {
            // Arrange
            var startDate = new DateTime (2014, 1, 1);
            var endDate = new DateTime (2014, 1, 30);
            var type = AstronomyObjectType.Moon;
            var place = new LocationId("usa/anchorage");

            // Act
            var service = new AstronomyService (Config.AccessKey, Config.SecretKey);
            var result = service.GetAstronomicalInfo (type, place, startDate);

            // Assert
            Assert.IsTrue (result.All (x => x.Objects.All (y => y.Days.All (z => z.Date.HasValue))));
            Assert.IsTrue (result.All (x => x.Objects.All (y => y.Days.All (z => z.Date.Value.Date >= startDate && z.Date.Value.Date <= endDate))));
            Assert.IsTrue (result.All (x => x.Geography.Country.Name == "United States"));
        }
Пример #5
0
        public void Calling_AstronomyService_WithISOTime_Should_ReturnsCorrectAstronomyInfo()
        {
            // Arrange
            var startDate = new DateTime (2014, 1, 1);
            var endDate = new DateTime (2014, 1, 30);
            var type = AstronomyObjectType.Sun;
            var place = new LocationId("norway/oslo");

            // Act
            var service = new AstronomyService (Config.AccessKey, Config.SecretKey);
            service.IncludeISOTime = true;
            var result = service.GetAstronomicalInfo (type, place, startDate, endDate);

            Assert.IsTrue (result.All (x => x.Objects.All (y => y.Days.All (z => z.Date.HasValue))));
            Assert.IsTrue (result.All (x => x.Objects.All (y => y.Days.ToList ().Count > 1)));
            Assert.IsTrue (result.All (x => x.Objects.All (y => y.Days.All (z => z.Date.Value.Date >= startDate.Date))));
            Assert.IsTrue (result.All (x => x.Objects.All (y => y.Days.All (z => !z.Events.All (a => a.ISOTime.Year == 1)))));
            Assert.IsTrue (result.All (x => x.Objects.All (y => y.Days.All (z => z.Events.Any (a => a.ISOTime.Month == 1)))));
        }
Пример #6
0
        public void Calling_AstronomyService_WithEnddate_And_SeveralInclusions_Should_ReturnsCorrectAstronomyInfo()
        {
            // Arrange
            var startDate = new DateTime (2014, 1, 1);
            var endDate = new DateTime (2014, 1, 30);
            var type = AstronomyObjectType.Sun;
            var place = new LocationId ("norway/oslo");

            // Act
            var service = new AstronomyService (Config.AccessKey, Config.SecretKey);
            service.Types = AstronomyEventClass.AstronomicalTwilight | AstronomyEventClass.NauticalTwilight;
            var result = service.GetAstronomicalInfo (type, place, startDate, endDate);

            Assert.IsTrue (result.All (x => x.Objects.All (y => y.Days.All (z => z.Date.HasValue))));
            Assert.IsTrue (result.All (x => x.Objects.All (y => y.Days.ToList().Count > 1)));
            Assert.IsTrue (result.All (x => x.Objects.All (y => y.Days.All (z => z.Date.Value.Date >= startDate.Date))));
            Assert.IsTrue (result.All (x => x.Objects.All (y => y.Days.All (z => z.Events.All (a =>
               a.Type == AstronomyEventCode.AstronomicalTwilightEnds || a.Type == AstronomyEventCode.AstronomicalTwilightStarts
               || a.Type == AstronomyEventCode.NauticalTwilightStarts || a.Type == AstronomyEventCode.NauticalTwilightEnds
            )))));
        }
Пример #7
0
        /// <summary>
        /// Retrieves the current time for place by ID.
        /// </summary>
        /// <returns>
        /// The current time for place.
        /// </returns>
        /// <param name='placeId'>
        /// Place identifier.
        /// </param>
        public IList<Location> CurrentTimeForPlace(LocationId placeId)
        {
            if (placeId == null)
                throw new ArgumentException ("A required argument is null or empty");

            var id = placeId.GetIdAsString ();
            if(string.IsNullOrEmpty(id))
                throw new ArgumentException ("A required argument is null or empty");

            var args = GetArguments (id);
            return CallService(args, x => (Location)x);
        }
Пример #8
0
 public void Setup()
 {
     fromCoords = new LocationId(new Coordinates (59.913m, 10.752m));
     fromId = new LocationId (fromFormat);
     toUsId = new LocationId (toUsFormat);
     toArticId = new LocationId (toArticFormat);
 }
Пример #9
0
        public void Calling_AstronomyService_WithLatLong_Should_ReturnCorrectAstronomyInfo()
        {
            // Arrange
            var startDate = new DateTime (2014, 1, 1);
            var type = AstronomyObjectType.Sun;
            var place = new LocationId ("norway/oslo");

            // Act
            var service = new AstronomyService (Config.AccessKey, Config.SecretKey);
            service.IncludeCoordinates = true;
            var result = service.GetAstronomicalInfo (type, place, startDate);

            // Assert
            Assert.IsTrue (result.All (x => x.Objects.All (y => y.Days.All (z => z.Date.HasValue))));
            Assert.IsTrue (result.All (x => x.Objects.All (y => y.Days.All (z => z.Date.Value.Date >= startDate.Date))));
            Assert.IsTrue (result.All (x => x.Geography.Coordinates.Latitude == 59.913m));
            Assert.IsTrue (result.All (x => x.Geography.Coordinates.Longitude == 10.740m));
        }
Пример #10
0
        public void Calling_AstronomyService_WithRadiusTime_Should_ReturnsCorrectAstronomyInfo()
        {
            // Arrange
            var startDate = new DateTime (2014, 1, 1);
            var type = AstronomyObjectType.Sun;
            var drammenCoords = new LocationId(new Coordinates (59.743m, 10.204m));

            // Act
            var service = new AstronomyService (Config.AccessKey, Config.SecretKey);
            service.Radius = 50;
            var result = service.GetAstronomicalInfo (type, drammenCoords, startDate);

            Assert.IsTrue (result.All (x => x.Objects.All (y => y.Days.All (z => z.Date.HasValue))));
            Assert.IsTrue (result.All (x => x.Objects.All (y => y.Days.ToList ().Count >= 1)));
            Assert.IsTrue (result.All (x => x.Geography.Country.Name == "Norway"));
            Assert.IsTrue (result.All (x => x.Geography.Name == "Drammen"));
        }
Пример #11
0
        public void Calling_AstronomyService_WithoutLatLong_Should_ReturnsCorrectAstronomyInfo()
        {
            // Arrange
            var startDate = new DateTime (2014, 1, 1);
            var endDate = new DateTime (2014, 1, 30);
            var type = AstronomyObjectType.Sun;
            var place = new LocationId("norway/oslo");

            // Act
            var service = new AstronomyService (Config.AccessKey, Config.SecretKey);
            service.IncludeCoordinates = false;
            var result = service.GetAstronomicalInfo (type, place, startDate, endDate);

            Assert.IsTrue (result.All (x => x.Objects.All (y => y.Days.All (z => z.Date.HasValue))));
            Assert.IsTrue (result.All (x => x.Objects.All (y => y.Days.ToList ().Count > 1)));
            Assert.IsTrue (result.All (x => x.Objects.All (y => y.Days.All (z => z.Date.Value.Date >= startDate.Date))));
            Assert.IsTrue (result.All (x => x.Geography.Coordinates == null));
        }
Пример #12
0
        public void Calling_AstronomyService_WithoutEnddate_ReturnsCorrectAstronomyInfo()
        {
            // Arrange
            var startDate = new DateTime (2014, 1, 1);
            var type = AstronomyObjectType.Sun;
            var place = new LocationId ("usa/anchorage");

            // Act
            var service = new AstronomyService (Config.AccessKey, Config.SecretKey);
            var result = service.GetAstronomicalInfo (type, place, startDate);
            var anchorage = result.SingleOrDefault ();

            // Assert
            Assert.IsTrue (anchorage.Objects.All (y => y.Days.All (z => z.Date.HasValue)));
            Assert.IsTrue (anchorage.Objects.All (y => y.Days.All (z => z.Date.Value.Date >= startDate.Date)));
            Assert.AreEqual ("United States", anchorage.Geography.Country.Name);
            Assert.AreEqual ("us", anchorage.Geography.Country.Id);
            Assert.AreEqual (61.188m, anchorage.Geography.Coordinates.Latitude);
            Assert.AreEqual (-149.887m, anchorage.Geography.Coordinates.Longitude);
            Assert.IsTrue (anchorage.Objects.All (x => x.Days.All (y => y.Events.All (z => z.Azimuth > 0m))));
            Assert.AreEqual ("18", anchorage.Id);
        }
Пример #13
0
        public void Calling_AstronomyService_WithoutEnddate_And_OnlyOneInclusions_Should_ReturnCorrectAstronomyInfo()
        {
            // Arrange
            var startDate = new DateTime (2014, 1, 1);
            var type = AstronomyObjectType.Sun;
            var place = new LocationId("norway/oslo");

            // Act
            var service = new AstronomyService (Config.AccessKey, Config.SecretKey);
            service.Types = AstronomyEventClass.Meridian;
            var result = service.GetAstronomicalInfo (type, place, startDate);

            // Assert
            Assert.IsTrue (result.All (x => x.Objects.All (y => y.Days.All (z => z.Date.HasValue))));
            Assert.IsTrue (result.All (x => x.Objects.All (y => y.Days.ToList().Count == 1)));
            Assert.IsTrue (result.All (x => x.Objects.All (y => y.Days.All (z => z.Date.Value.Date >= startDate.Date))));
            Assert.IsTrue (result.All (x => x.Objects.All (y => y.Days.All (z => z.Events.All (a =>
               a.Type == AstronomyEventCode.Meridian || a.Type == AstronomyEventCode.AntiMeridian
            )))));

            Assert.IsTrue (result.All (x => x.Geography.Country.Name == "Norway"));
        }
Пример #14
0
        /// <summary>
        /// Gets the specified object type (Moon, Sun) for a specified place by start date.
        /// </summary>
        /// <returns>
        /// A list of astronomical information.
        /// </returns>
        /// <param name='objectType'>
        /// The astronomical object type (Moon or Sun)
        /// </param>
        /// <param name='placeId'>
        /// Place identifier.
        /// </param>
        /// <param name='startDate'>
        /// Start date.
        /// </param>
        /// <param name='endDate'>
        /// End date.
        /// </param>
        public IList<AstronomyLocation> GetAstronomicalInfo(AstronomyObjectType objectType, LocationId placeId, DateTime startDate, DateTime endDate)
        {
            if (placeId == null || startDate.Year == 0 || endDate.Year == 0)
                throw new ArgumentException ("A required argument is null or empty");

            var id = placeId.GetIdAsString ();
            if (string.IsNullOrEmpty (id))
                throw new ArgumentException ("A required argument is null or empty");

            if (endDate.Ticks < startDate.Ticks)
                throw new QueriedDateOutOfRangeException ("End date cannot be before Start date");

            var args = GetOptionalArguments();
            args.Set ("placeid", id);
            args.Set ("object", objectType.ToString ().ToLower ());
            args.Set ("startdt", startDate.ToString ("yyyy-MM-dd"));
            args.Set ("enddt", endDate.ToString ("yyyy-MM-dd"));

            return CallService (args, x => (AstronomyLocation)x);
        }
Пример #15
0
        public void Calling_DialCodeService_WithToId_And_WithoutLatLong_Should_NotReturnLocations()
        {
            // Arrange
            var osloId = new LocationId ("norway/oslo");

            // Act
            var service = new DialCodeService (Config.AccessKey, Config.SecretKey);
            service.IncludeCoordinates = false;
            var result = service.GetDialCode (osloId);

            // Assert
            Assert.IsTrue (result.Locations.All (x => x.Geography.Coordinates == null));
        }
Пример #16
0
        public void Calling_DialCodeService_WithToId_And_WithoutLocation_Should_NotReturnLocations()
        {
            // Arrange
            var osloId = new LocationId ("norway/oslo");

            // Act
            var service = new DialCodeService (Config.AccessKey, Config.SecretKey);
            service.IncludeLocations = false;
            var result = service.GetDialCode (osloId);

            // Assert
            Assert.AreEqual (0, result.Locations.Count);
        }