public void TestCreate() { var theme = new NatalChartDefinition(); Assert.NotNull(theme.BirthDate); Assert.NotNull(theme.Planets); Assert.Equal(15, theme.Planets.Count); }
public void TestCalculateNatalChart() { var mockProvider = new Mock <IEphemerisProvider>(); mockProvider.Setup(p => p.CalcEclipticNutation(It.IsAny <EphemerisTime>())).Returns(new EclipticNutationValues { MeanEclipticObliquity = 1, NutationLongitude = 2, NutationObliquity = 3, TrueEclipticObliquity = 4 }); var provider = mockProvider.Object; using (var engine = new AstroEngine(provider)) { var def = new NatalChartDefinition { Name = "Test", BirthPlacePosition = new GeoPosition { Longitude = 47.2, Latitude = 3.23, Altitude = 123 }, PositionCenter = PositionCenter.Topocentric }; def.BirthDate.Year = 2015; def.BirthDate.Month = 6; def.BirthDate.Day = 7; def.BirthDate.Hour = 14; def.BirthDate.Minute = 6; def.BirthDate.TimeZone = TimeZoneInfo.FindSystemTimeZoneById("Romance Standard Time"); def.Planets.Add(Planet.EclipticNutation); def.Planets.Add(Planet.Earth); Assert.Equal(17, def.Planets.Count); var theme = engine.CalculateNatalChart(def); Assert.Same(def, theme.Definition); Assert.Equal(0, theme.JulianDay); Assert.Equal(new DateTime(), theme.UniversalTime); Assert.Equal(0d, theme.EphemerisTime); Assert.Equal(0d, theme.DeltaTSec); Assert.Equal(3.14666666666667, (Double)theme.SideralTime, 14); Assert.Equal(47.2, (Double)theme.SideralTimeInDegrees, 14); Assert.Equal(47.2, (Double)theme.ARMC, 14); Assert.Equal(1, theme.MeanEclipticObliquity); Assert.Equal(2, theme.NutationLongitude); Assert.Equal(3, theme.NutationObliquity); Assert.Equal(4, theme.TrueEclipticObliquity); Assert.Equal(14, theme.Planets.Count); Assert.Throws <ArgumentNullException>(() => engine.CalculateNatalChart(null)); } }
/// <summary> /// Création du viewmodel /// </summary> public NatalChartDefinitionViewModel(ITimeZoneProvider tzProvider) { Definition = new NatalChartDefinition(); Definition.BirthPlacePosition = new GeoPosition(); Definition.BirthDate.SetDate(DateTimeOffset.Now); this.BirthDateTimeZone = TimeZoneInfo.Local; // Liste des genres ListGenders = new List <KeyValuePair <Gender, string> >(); ListGenders.Add(new KeyValuePair <Gender, string>(Gender.Female, Locales.Gender_Female_Caption)); ListGenders.Add(new KeyValuePair <Gender, string>(Gender.Male, Locales.Gender_Male_Caption)); // Liste des mode d'heures d'été ListDayLightDefinitions = new List <KeyValuePair <DayLightDefinition, string> >(); ListDayLightDefinitions.Add(new KeyValuePair <DayLightDefinition, string>(DayLightDefinition.FromTimeZone, Locales.DayLight_FromTimeZone_Caption)); ListDayLightDefinitions.Add(new KeyValuePair <DayLightDefinition, string>(DayLightDefinition.On, Locales.DayLight_On_Caption)); ListDayLightDefinitions.Add(new KeyValuePair <DayLightDefinition, string>(DayLightDefinition.Off, Locales.DayLight_Off_Caption)); // Liste des fuseaux horaire ListTimeZoneInfos = new List <KeyValuePair <TimeZoneInfo, String> >(); ListTimeZoneInfos.Add(new KeyValuePair <TimeZoneInfo, string>(null, Locales.TimeZone_Custom_Caption)); if (tzProvider != null) { ListTimeZoneInfos.AddRange(tzProvider.GetTimeZones().Select(tz => new KeyValuePair <TimeZoneInfo, String>(tz, tz.DisplayName))); } // Liste des systèmes de maisons ListHouseSystems = new List <KeyValuePair <HouseSystem, string> >(); foreach (HouseSystem hs in Enum.GetValues(typeof(HouseSystem))) { ListHouseSystems.Add(new KeyValuePair <HouseSystem, string>(hs, hs.GetCaptionString())); } // Liste des positions ListPositionCenters = new List <KeyValuePair <PositionCenter, string> >(); foreach (PositionCenter pc in Enum.GetValues(typeof(PositionCenter))) { ListPositionCenters.Add(new KeyValuePair <PositionCenter, string>(pc, pc.GetCaptionString())); } }
/// <summary> /// Initialisation /// </summary> public void Initialize(NatalChartDefinition definition) { Definition = definition ?? new NatalChartDefinition(); RaisePropertyChanged(""); }
public async Task TestSerializeDeserialize() { NatalChartDefinition def = new NatalChartDefinition { Name = "Nom", BirthPlaceName = "Lieu de naissance", BirthPlacePosition = new GeoPosition(123.45, 543.21, 999), Gender = Gender.Female, HouseSystem = HouseSystem.Placidus, PositionCenter = PositionCenter.Topocentric }; def.BirthDate.SetDate(DateTimeOffset.Now); NatalChartDefinition actual; NatalChartSerializer ser = new NatalChartSerializer(); Assert.Null(ser.TimeZoneProvider); using (var str = new MemoryStream()) { await ser.Serialize(def, str); str.Seek(0, SeekOrigin.Begin); actual = await ser.Deserialize(str); } Assert.Equal(def.Name, actual.Name); Assert.Equal(def.BirthDate, actual.BirthDate); Assert.Equal(def.BirthPlaceName, actual.BirthPlaceName); Assert.Equal(def.BirthPlacePosition.ToString(), actual.BirthPlacePosition.ToString()); Assert.Equal(def.Gender, actual.Gender); Assert.Equal(def.HouseSystem, actual.HouseSystem); Assert.Equal(def.PositionCenter, actual.PositionCenter); Assert.Equal(def.Planets.Count, actual.Planets.Count); var tzpMock = new Mock <ITimeZoneProvider>(); tzpMock.Setup(p => p.FindTimeZone(It.IsAny <String>())).Returns <String>(s => TimeZoneInfo.GetSystemTimeZones().FirstOrDefault(t => t.StandardName == s) ?? TimeZoneInfo.FindSystemTimeZoneById(s)); var tzp = tzpMock.Object; ser = new NatalChartSerializer(tzp); Assert.Same(tzp, ser.TimeZoneProvider); def.BirthDate.SetDate(DateTime.Now); using (var str = new MemoryStream()) { await ser.Serialize(def, str); str.Seek(0, SeekOrigin.Begin); actual = await ser.Deserialize(str); } Assert.Equal(def.Name, actual.Name); Assert.Equal(def.BirthDate, actual.BirthDate); Assert.Equal(def.BirthPlaceName, actual.BirthPlaceName); Assert.Equal(def.BirthPlacePosition.ToString(), actual.BirthPlacePosition.ToString()); Assert.Equal(def.Gender, actual.Gender); Assert.Equal(def.HouseSystem, actual.HouseSystem); Assert.Equal(def.PositionCenter, actual.PositionCenter); Assert.Equal(def.Planets.Count, actual.Planets.Count); String xml = @" <natal-chart> <birth-date> <date>12/06/2015</date> <utc-offset>None</utc-offset> </birth-date> </natal-chart> "; using (var str = new MemoryStream(Encoding.UTF8.GetBytes(xml))) { await Assert.ThrowsAsync <FormatException>(() => ser.Deserialize(str)); } xml = @" <natal-chart> <planets> <planet id='Moon'/> <planet id='18'/> </planets> </natal-chart> "; using (var str = new MemoryStream(Encoding.UTF8.GetBytes(xml))) { actual = await ser.Deserialize(str); } Assert.Equal(1, actual.Planets.Count); Assert.Equal(18, actual.Planets[0].Id); xml = @" <natal-chart> <birth-place-position> <altitude>None</altitude> <longitude>1E</longitude> <latitude>2N</latitude> </birth-place-position> </natal-chart> "; using (var str = new MemoryStream(Encoding.UTF8.GetBytes(xml))) { actual = await ser.Deserialize(str); } Assert.Equal(1, actual.BirthPlacePosition.Longitude); Assert.Equal(2, actual.BirthPlacePosition.Latitude); Assert.Equal(0, actual.BirthPlacePosition.Altitude); await Assert.ThrowsAsync <ArgumentNullException>(() => ser.Serialize(null, null)); await Assert.ThrowsAsync <ArgumentNullException>(() => ser.Serialize(def, null)); await Assert.ThrowsAsync <ArgumentNullException>(() => ser.Deserialize(null)); }