public static void Connector_PATCH_InvalidPatch() { var Connector1 = new Connector( Connector_Id.Parse("1"), ConnectorTypes.IEC_62196_T2, ConnectorFormats.SOCKET, PowerTypes.AC_3_PHASE, 400, 30, 12, new Tariff_Id[] { Tariff_Id.Parse("DE*GEF*T0001"), Tariff_Id.Parse("DE*GEF*T0002") }, URL.Parse("https://open.charging.cloud/terms"), DateTime.Parse("2020-09-21T00:00:00Z") ); var patchResult = Connector1.TryPatch(JObject.Parse(@"{ ""standard"": ""I-N-V-A-L-I-D!"" }")); Assert.IsNotNull(patchResult); Assert.IsFalse(patchResult.IsSuccess); Assert.IsTrue(patchResult.IsFailed); Assert.IsNotNull(patchResult.ErrorResponse); Assert.AreEqual("Invalid JSON merge patch of a connector: Invalid 'connector standard'!", patchResult.ErrorResponse); Assert.IsNotNull(patchResult.PatchedData); Assert.AreEqual(Connector_Id.Parse("1"), patchResult.PatchedData.Id); Assert.AreEqual(ConnectorTypes.IEC_62196_T2, patchResult.PatchedData.Standard); Assert.AreEqual(ConnectorFormats.SOCKET, patchResult.PatchedData.Format); Assert.AreEqual(PowerTypes.AC_3_PHASE, patchResult.PatchedData.PowerType); Assert.AreEqual(400, patchResult.PatchedData.MaxVoltage); Assert.AreEqual(30, patchResult.PatchedData.MaxAmperage); Assert.AreEqual(12, patchResult.PatchedData.MaxElectricPower); Assert.AreEqual(2, patchResult.PatchedData.TariffIds.Count()); Assert.AreEqual(Tariff_Id.Parse("DE*GEF*T0001"), patchResult.PatchedData.TariffIds.First()); Assert.AreEqual(Tariff_Id.Parse("DE*GEF*T0002"), patchResult.PatchedData.TariffIds.Skip(1).First()); Assert.AreEqual(URL.Parse("https://open.charging.cloud/terms"), patchResult.PatchedData.TermsAndConditionsURL); Assert.AreEqual("2020-09-21T00:00:00.000Z", patchResult.PatchedData.LastUpdated.ToIso8601()); }
public static void Connector_PATCH_RemoveTariffIdArray() { var Connector1 = new Connector( Connector_Id.Parse("1"), ConnectorTypes.IEC_62196_T2, ConnectorFormats.SOCKET, PowerTypes.AC_3_PHASE, 400, 30, 12, new Tariff_Id[] { Tariff_Id.Parse("DE*GEF*T0001"), Tariff_Id.Parse("DE*GEF*T0002") }, URL.Parse("https://open.charging.cloud/terms"), DateTime.Parse("2020-09-21T00:00:00Z") ); var patchResult = Connector1.TryPatch(JObject.Parse(@"{ ""tariff_ids"": null, ""last_updated"": ""2020-10-15T00:00:00Z"" }")); Assert.IsNotNull(patchResult); Assert.IsTrue(patchResult.IsSuccess); Assert.IsFalse(patchResult.IsFailed); Assert.IsNull(patchResult.ErrorResponse); Assert.IsNotNull(patchResult.PatchedData); Assert.AreEqual(Connector_Id.Parse("1"), patchResult.PatchedData.Id); Assert.AreEqual(ConnectorTypes.IEC_62196_T2, patchResult.PatchedData.Standard); Assert.AreEqual(ConnectorFormats.SOCKET, patchResult.PatchedData.Format); Assert.AreEqual(PowerTypes.AC_3_PHASE, patchResult.PatchedData.PowerType); Assert.AreEqual(400, patchResult.PatchedData.MaxVoltage); Assert.AreEqual(30, patchResult.PatchedData.MaxAmperage); Assert.AreEqual(12, patchResult.PatchedData.MaxElectricPower); Assert.AreEqual(0, patchResult.PatchedData.TariffIds.Count()); Assert.AreEqual(URL.Parse("https://open.charging.cloud/terms"), patchResult.PatchedData.TermsAndConditionsURL); Assert.AreEqual("2020-10-15T00:00:00.000Z", patchResult.PatchedData.LastUpdated.ToIso8601()); }
public static void Session_SerializeDeserialize_Test01() { #region Define Session1 var Session1 = new Session( CountryCode.Parse("DE"), Party_Id.Parse("GEF"), Session_Id.Parse("Session0001"), DateTime.Parse("2020-08-21T00:00:00.000Z"), // Start 1.11M, // KWh new CDRToken( Token_Id.Parse("1234"), TokenTypes.RFID, Contract_Id.Parse("Contract0815") ), AuthMethods.AUTH_REQUEST, Location_Id.Parse("LOC0001"), EVSE_UId.Parse("EVSE0001"), Connector_Id.Parse("C1"), Currency.EUR, SessionStatusTypes.ACTIVE, DateTime.Parse("2020-08-22T00:00:00.000Z"), // End AuthorizationReference.Parse("Auth1234"), Meter_Id.Parse("Meter0001"), // OCPI Computer Science Extentions new EnergyMeter( Meter_Id.Parse("Meter0815"), "EnergyMeter Model #1", "hw. v1.80", "fw. v1.20", "Energy Metering Services", null, null ), // OCPI Computer Science Extentions new TransparencySoftware[] { new TransparencySoftware( "Chargy Transparency Software Desktop Application", "v1.00", LegalStatus.LegallyBinding, OpenSourceLicenses.GPL3, "GraphDefined GmbH", URL.Parse("https://open.charging.cloud/logo.svg"), URL.Parse("https://open.charging.cloud/Chargy/howto"), URL.Parse("https://open.charging.cloud/Chargy"), URL.Parse("https://github.com/OpenChargingCloud/ChargyDesktopApp") ), new TransparencySoftware( "Chargy Transparency Software Mobile Application", "v1.00", LegalStatus.ForInformationOnly, OpenSourceLicenses.GPL3, "GraphDefined GmbH", URL.Parse("https://open.charging.cloud/logo.svg"), URL.Parse("https://open.charging.cloud/Chargy/howto"), URL.Parse("https://open.charging.cloud/Chargy"), URL.Parse("https://github.com/OpenChargingCloud/ChargyMobileApp") ) }, new ChargingPeriod[] { new ChargingPeriod( DateTime.Parse("2020-04-12T18:21:49Z"), new CDRDimension[] { new CDRDimension( CDRDimensions.ENERGY, 1.33M ) }, Tariff_Id.Parse("DE*GEF*T0001") ), new ChargingPeriod( DateTime.Parse("2020-04-12T18:21:50Z"), new CDRDimension[] { new CDRDimension( CDRDimensions.TIME, 5.12M ) }, Tariff_Id.Parse("DE*GEF*T0002") ) }, // Total Costs new Price( 1.12, 2.24 ), DateTime.Parse("2020-09-21T00:00:00.000Z") ); #endregion var JSON = Session1.ToJSON(); Assert.AreEqual("DE", JSON["country_code"].Value <String>()); Assert.AreEqual("GEF", JSON["party_id"].Value <String>()); Assert.AreEqual("Session0001", JSON["id"].Value <String>()); Assert.AreEqual("2020-08-21T00:00:00.000Z", JSON["start_date_time"].Value <String>()); Assert.AreEqual("2020-08-22T00:00:00.000Z", JSON["end_date_time"].Value <String>()); Assert.AreEqual(1.11, JSON["kwh"].Value <Decimal>()); Assert.AreEqual("1234", JSON["cdr_token"]["uid"].Value <String>()); Assert.AreEqual("RFID", JSON["cdr_token"]["type"].Value <String>()); Assert.AreEqual("Contract0815", JSON["cdr_token"]["contract_id"].Value <String>()); Assert.AreEqual("AUTH_REQUEST", JSON["auth_method"].Value <String>()); Assert.AreEqual("Auth1234", JSON["authorization_reference"].Value <String>()); Assert.AreEqual("LOC0001", JSON["location_id"].Value <String>()); Assert.AreEqual("EVSE0001", JSON["evse_uid"].Value <String>()); Assert.AreEqual("C1", JSON["connector_id"].Value <String>()); Assert.AreEqual("Meter0001", JSON["meter_id"].Value <String>()); Assert.AreEqual("EUR", JSON["currency"].Value <String>()); //Assert.AreEqual("Stadtwerke Jena-Ost", JSON["charging_periods"]["xxx"].Value<String>()); Assert.AreEqual(1.12, JSON["total_cost"]["excl_vat"].Value <Decimal>()); Assert.AreEqual(2.24, JSON["total_cost"]["incl_vat"].Value <Decimal>()); Assert.AreEqual("ACTIVE", JSON["status"].Value <String>()); Assert.AreEqual("2020-09-21T00:00:00.000Z", JSON["last_updated"].Value <String>()); Assert.IsTrue(Session.TryParse(JSON, out Session Session2, out String ErrorResponse)); Assert.IsNull(ErrorResponse); Assert.AreEqual(Session1.CountryCode, Session2.CountryCode); Assert.AreEqual(Session1.PartyId, Session2.PartyId); Assert.AreEqual(Session1.Id, Session2.Id); Assert.AreEqual(Session1.Start.ToIso8601(), Session2.Start.ToIso8601()); Assert.AreEqual(Session1.End.Value.ToIso8601(), Session2.End.Value.ToIso8601()); Assert.AreEqual(Session1.kWh, Session2.kWh); Assert.AreEqual(Session1.CDRToken, Session2.CDRToken); Assert.AreEqual(Session1.AuthMethod, Session2.AuthMethod); Assert.AreEqual(Session1.AuthorizationReference, Session2.AuthorizationReference); Assert.AreEqual(Session1.LocationId, Session2.LocationId); Assert.AreEqual(Session1.EVSEUId, Session2.EVSEUId); Assert.AreEqual(Session1.ConnectorId, Session2.ConnectorId); Assert.AreEqual(Session1.MeterId, Session2.MeterId); Assert.AreEqual(Session1.EnergyMeter, Session2.EnergyMeter); Assert.AreEqual(Session1.TransparencySoftwares, Session2.TransparencySoftwares); Assert.AreEqual(Session1.Currency, Session2.Currency); Assert.AreEqual(Session1.ChargingPeriods, Session2.ChargingPeriods); Assert.AreEqual(Session1.TotalCosts, Session2.TotalCosts); Assert.AreEqual(Session1.Status, Session2.Status); Assert.AreEqual(Session1.LastUpdated.ToIso8601(), Session2.LastUpdated.ToIso8601()); }
public static void Tariff_SerializeDeserialize_Test01() { var TariffA = new Tariff( CountryCode.Parse("DE"), Party_Id.Parse("GEF"), Tariff_Id.Parse("TARIFF0001"), Currency.EUR, new TariffElement[] { new TariffElement( new PriceComponent[] { PriceComponent.ChargingTime( TimeSpan.FromSeconds(300), 2.00M, 0.10M ) }, new TariffRestrictions [] { new TariffRestrictions( Time.FromHourMin(08, 00), // Start time Time.FromHourMin(18, 00), // End time DateTime.Parse("2020-12-01"), // Start timestamp DateTime.Parse("2020-12-31"), // End timestamp 1.12M, // MinkWh 5.67M, // MaxkWh 1.34M, // MinCurrent 8.89M, // MaxCurrent 1.49M, // MinPower 9.91M, // MaxPower TimeSpan.FromMinutes(10), // MinDuration TimeSpan.FromMinutes(30), // MaxDuration new DayOfWeek[] { DayOfWeek.Monday, DayOfWeek.Tuesday }, ReservationRestrictionTypes.RESERVATION ) } ) }, TariffTypes.PROFILE_GREEN, new DisplayText[] { new DisplayText(Languages.de, "Hallo Welt!"), new DisplayText(Languages.en, "Hello world!"), }, URL.Parse("https://open.charging.cloud"), new Price( // Min Price 1.10, 1.26 ), new Price( // Max Price 2.20, 2.52 ), DateTime.Parse("2020-12-01"), // Start timestamp DateTime.Parse("2020-12-31"), // End timestamp new EnergyMix( true, new EnergySource[] { new EnergySource( EnergySourceCategories.SOLAR, 80 ), new EnergySource( EnergySourceCategories.WIND, 20 ) }, new EnvironmentalImpact[] { new EnvironmentalImpact( EnvironmentalImpactCategories.CARBON_DIOXIDE, 0.1 ) }, "Stadtwerke Jena-Ost", "New Green Deal" ), DateTime.Parse("2020-09-22") ); var JSON = TariffA.ToJSON(); Assert.AreEqual("DE", JSON["country_code"].Value <String>()); Assert.AreEqual("GEF", JSON["party_id"].Value <String>()); Assert.AreEqual("TARIFF0001", JSON["id"].Value <String>()); Assert.IsTrue(Tariff.TryParse(JSON, out Tariff TariffB, out String ErrorResponse)); Assert.IsNull(ErrorResponse); Assert.AreEqual(TariffA.CountryCode, TariffB.CountryCode); Assert.AreEqual(TariffA.PartyId, TariffB.PartyId); Assert.AreEqual(TariffA.Id, TariffB.Id); Assert.AreEqual(TariffA.Currency, TariffB.Currency); Assert.AreEqual(TariffA.TariffElements, TariffB.TariffElements); Assert.AreEqual(TariffA.TariffType, TariffB.TariffType); Assert.AreEqual(TariffA.TariffAltText, TariffB.TariffAltText); Assert.AreEqual(TariffA.TariffAltURL, TariffB.TariffAltURL); Assert.AreEqual(TariffA.MinPrice, TariffB.MinPrice); Assert.AreEqual(TariffA.MaxPrice, TariffB.MaxPrice); Assert.AreEqual(TariffA.Start, TariffB.Start); Assert.AreEqual(TariffA.End, TariffB.End); Assert.AreEqual(TariffA.EnergyMix, TariffB.EnergyMix); Assert.AreEqual(TariffA.LastUpdated.ToIso8601(), TariffB.LastUpdated.ToIso8601()); }
public static void CDR_SerializeDeserialize_Test01() { #region Defined CDR1 var CDR1 = new CDR(CountryCode.Parse("DE"), Party_Id.Parse("GEF"), CDR_Id.Parse("CDR0001"), DateTime.Parse("2020-04-12T18:20:19Z"), DateTime.Parse("2020-04-12T22:20:19Z"), new CDRToken( Token_Id.Parse("1234"), TokenTypes.RFID, Contract_Id.Parse("C1234") ), AuthMethods.AUTH_REQUEST, new CDRLocation( Location_Id.Parse("LOC0001"), "Biberweg 18", "Jena", "Deutschland", GeoCoordinate.Parse(10, 20), EVSE_UId.Parse("DE*GEF*E*LOC0001*1"), EVSE_Id.Parse("DE*GEF*E*LOC0001*1"), Connector_Id.Parse("1"), ConnectorTypes.IEC_62196_T2, ConnectorFormats.SOCKET, PowerTypes.AC_3_PHASE, "Name?", "07749" ), Currency.EUR, new ChargingPeriod[] { new ChargingPeriod( DateTime.Parse("2020-04-12T18:21:49Z"), new CDRDimension[] { new CDRDimension( CDRDimensions.ENERGY, 1.33M ) }, Tariff_Id.Parse("DE*GEF*T0001") ), new ChargingPeriod( DateTime.Parse("2020-04-12T18:21:50Z"), new CDRDimension[] { new CDRDimension( CDRDimensions.TIME, 5.12M ) }, Tariff_Id.Parse("DE*GEF*T0002") ) }, // Total costs new Price( 10.00, 11.60 ), // Total Energy 50.00M, // Total time TimeSpan.FromMinutes(30), Session_Id.Parse("0815"), AuthorizationReference.Parse("Auth0815"), Meter_Id.Parse("Meter0815"), // OCPI Computer Science Extentions new EnergyMeter( Meter_Id.Parse("Meter0815"), "EnergyMeter Model #1", "hw. v1.80", "fw. v1.20", "Energy Metering Services", null, null ), // OCPI Computer Science Extentions new TransparencySoftware[] { new TransparencySoftware( "Chargy Transparency Software Desktop Application", "v1.00", LegalStatus.LegallyBinding, OpenSourceLicenses.GPL3, "GraphDefined GmbH", URL.Parse("https://open.charging.cloud/logo.svg"), URL.Parse("https://open.charging.cloud/Chargy/howto"), URL.Parse("https://open.charging.cloud/Chargy"), URL.Parse("https://github.com/OpenChargingCloud/ChargyDesktopApp") ), new TransparencySoftware( "Chargy Transparency Software Mobile Application", "v1.00", LegalStatus.ForInformationOnly, OpenSourceLicenses.GPL3, "GraphDefined GmbH", URL.Parse("https://open.charging.cloud/logo.svg"), URL.Parse("https://open.charging.cloud/Chargy/howto"), URL.Parse("https://open.charging.cloud/Chargy"), URL.Parse("https://github.com/OpenChargingCloud/ChargyMobileApp") ) }, new Tariff[] { new Tariff( CountryCode.Parse("DE"), Party_Id.Parse("GEF"), Tariff_Id.Parse("TARIFF0001"), Currency.EUR, new TariffElement[] { new TariffElement( new PriceComponent[] { PriceComponent.ChargingTime( TimeSpan.FromSeconds(300), 2.00M, 0.10M ) }, new TariffRestrictions [] { new TariffRestrictions( Time.FromHourMin(08, 00), // Start time Time.FromHourMin(18, 00), // End time DateTime.Parse("2020-12-01"), // Start timestamp DateTime.Parse("2020-12-31"), // End timestamp 1.12M, // MinkWh 5.67M, // MaxkWh 1.34M, // MinCurrent 8.89M, // MaxCurrent 1.49M, // MinPower 9.91M, // MaxPower TimeSpan.FromMinutes(10), // MinDuration TimeSpan.FromMinutes(30), // MaxDuration new DayOfWeek[] { DayOfWeek.Monday, DayOfWeek.Tuesday }, ReservationRestrictionTypes.RESERVATION ) } ) }, TariffTypes.PROFILE_GREEN, new DisplayText[] { new DisplayText(Languages.de, "Hallo Welt!"), new DisplayText(Languages.en, "Hello world!"), }, URL.Parse("https://open.charging.cloud"), new Price( // Min Price 1.10, 1.26 ), new Price( // Max Price 2.20, 2.52 ), DateTime.Parse("2020-12-01"), // Start timestamp DateTime.Parse("2020-12-31"), // End timestamp new EnergyMix( true, new EnergySource[] { new EnergySource( EnergySourceCategories.SOLAR, 80 ), new EnergySource( EnergySourceCategories.WIND, 20 ) }, new EnvironmentalImpact[] { new EnvironmentalImpact( EnvironmentalImpactCategories.CARBON_DIOXIDE, 0.1 ) }, "Stadtwerke Jena-Ost", "New Green Deal" ), DateTime.Parse("2020-09-22") ) }, new SignedData( EncodingMethod.GraphDefiened, new SignedValue[] { new SignedValue( SignedValueNature.START, "PlainStartValue", "SignedStartValue" ), new SignedValue( SignedValueNature.INTERMEDIATE, "PlainIntermediateValue", "SignedIntermediateValue" ), new SignedValue( SignedValueNature.END, "PlainEndValue", "SignedEndValue" ) }, 1, // Encoding method version null, // Public key "https://open.charging.cloud/pools/1/stations/1/evse/1/publicKey" ), // Total Fixed Costs new Price( 20.00, 23.10 ), // Total Energy Cost new Price( 20.00, 23.10 ), // Total Time Cost new Price( 20.00, 23.10 ), // Total Parking Time TimeSpan.FromMinutes(120), // Total Parking Cost new Price( 20.00, 23.10 ), // Total Reservation Cost new Price( 20.00, 23.10 ), "Remark!", InvoiceReference_Id.Parse("Invoice:0815"), true, // IsCredit CreditReference_Id.Parse("Credit:0815"), DateTime.Parse("2020-09-12") ); #endregion var JSON = CDR1.ToJSON(); Assert.AreEqual("DE", JSON["country_code"].Value <String>()); Assert.AreEqual("GEF", JSON["party_id"].Value <String>()); Assert.AreEqual("CDR0001", JSON["id"].Value <String>()); Assert.IsTrue(CDR.TryParse(JSON, out CDR CDR2, out String ErrorResponse)); Assert.IsNull(ErrorResponse); Assert.AreEqual(CDR1.CountryCode, CDR2.CountryCode); Assert.AreEqual(CDR1.PartyId, CDR2.PartyId); Assert.AreEqual(CDR1.Id, CDR2.Id); Assert.AreEqual(CDR1.Start.ToIso8601(), CDR2.Start.ToIso8601()); Assert.AreEqual(CDR1.End.ToIso8601(), CDR2.End.ToIso8601()); Assert.AreEqual(CDR1.CDRToken, CDR2.CDRToken); Assert.AreEqual(CDR1.AuthMethod, CDR2.AuthMethod); Assert.AreEqual(CDR1.Location, CDR2.Location); Assert.AreEqual(CDR1.Currency, CDR2.Currency); Assert.AreEqual(CDR1.ChargingPeriods, CDR2.ChargingPeriods); Assert.AreEqual(CDR1.TotalCosts, CDR2.TotalCosts); Assert.AreEqual(CDR1.TotalEnergy, CDR2.TotalEnergy); Assert.AreEqual(CDR1.TotalTime, CDR2.TotalTime); Assert.AreEqual(CDR1.SessionId, CDR2.SessionId); Assert.AreEqual(CDR1.AuthorizationReference, CDR2.AuthorizationReference); Assert.AreEqual(CDR1.MeterId, CDR2.MeterId); Assert.AreEqual(CDR1.EnergyMeter, CDR2.EnergyMeter); Assert.AreEqual(CDR1.TransparencySoftwares, CDR2.TransparencySoftwares); Assert.AreEqual(CDR1.Tariffs, CDR2.Tariffs); Assert.AreEqual(CDR1.SignedData, CDR2.SignedData); Assert.AreEqual(CDR1.TotalFixedCosts, CDR2.TotalFixedCosts); Assert.AreEqual(CDR1.TotalEnergyCost, CDR2.TotalEnergyCost); Assert.AreEqual(CDR1.TotalTimeCost, CDR2.TotalTimeCost); Assert.AreEqual(CDR1.TotalParkingTime, CDR2.TotalParkingTime); Assert.AreEqual(CDR1.TotalParkingCost, CDR2.TotalParkingCost); Assert.AreEqual(CDR1.TotalReservationCost, CDR2.TotalReservationCost); Assert.AreEqual(CDR1.Remark, CDR2.Remark); Assert.AreEqual(CDR1.InvoiceReferenceId, CDR2.InvoiceReferenceId); Assert.AreEqual(CDR1.Credit, CDR2.Credit); Assert.AreEqual(CDR1.CreditReferenceId, CDR2.CreditReferenceId); Assert.AreEqual(CDR1.LastUpdated.ToIso8601(), CDR2.LastUpdated.ToIso8601()); }
public static void Tariff0004() { var tariff = new Tariff(Tariff_Id.Parse("11"), Currency.EUR, TariffUrl: new Uri("https://company.com/tariffs/11"), TariffElements: new List <TariffElement>() { // 2.50 euro start tariff new TariffElement( PriceComponent.FlatRate(2.50M) ), // 1.00 euro per hour charging tariff for less than 32A (paid per 15 minutes) new TariffElement( PriceComponent.ChargingTime(1.00M, TimeSpan.FromSeconds(900)), TariffRestriction.MaxPower(32M) ), // 2.00 euro per hour charging tariff for more than 32A on weekdays (paid per 10 minutes) new TariffElement( PriceComponent.ChargingTime(2.00M, TimeSpan.FromSeconds(600)), new TariffRestriction(Power: DecimalMinMax.FromMin(32M), DayOfWeek: Enumeration.Create( DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday, DayOfWeek.Friday )) ), // 1.25 euro per hour charging tariff for more then 32A during the weekend (paid per 10 minutes) new TariffElement( PriceComponent.ChargingTime(1.25M, TimeSpan.FromSeconds(600)), new TariffRestriction(Power: DecimalMinMax.FromMin(32M), DayOfWeek: Enumeration.Create( DayOfWeek.Saturday, DayOfWeek.Sunday )) ), // Parking on weekdays: between 09:00 and 18:00: 5 euro(paid per 5 minutes) new TariffElement( PriceComponent.ParkingTime(5M, TimeSpan.FromSeconds(300)), new TariffRestriction(Time: TimeRange.From(9).To(18), DayOfWeek: Enumeration.Create( DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday, DayOfWeek.Friday )) ), // Parking on saturday: between 10:00 and 17:00: 6 euro (paid per 5 minutes) new TariffElement( PriceComponent.ParkingTime(6M, TimeSpan.FromSeconds(300)), new TariffRestriction(Time: TimeRange.From(10).To(17), DayOfWeek: new DayOfWeek[] { DayOfWeek.Saturday }) ) } ); var expected = new JObject(new JProperty("id", "11"), new JProperty("currency", "EUR"), new JProperty("tariff_alt_url", "https://company.com/tariffs/11"), new JProperty("elements", new JArray( // 2.50 euro start tariff new JObject( new JProperty("price_components", new JArray( new JObject( new JProperty("type", "FLAT"), new JProperty("price", "2.50"), new JProperty("step_size", 1) ))) ), // 1.00 euro per hour charging tariff for less than 32A (paid per 15 minutes) new JObject( new JProperty("price_components", new JArray( new JObject( new JProperty("type", "TIME"), new JProperty("price", "1.00"), new JProperty("step_size", 900) ))), new JProperty("restrictions", new JArray( new JObject( new JProperty("max_power", "32.00") ) )) ), // 2.00 euro per hour charging tariff for more than 32A on weekdays (paid per 10 minutes) new JObject( new JProperty("price_components", new JArray( new JObject( new JProperty("type", "TIME"), new JProperty("price", "2.00"), new JProperty("step_size", 600) ))), new JProperty("restrictions", new JArray( new JObject( new JProperty("min_power", "32.00"), new JProperty("day_of_week", new JArray("MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY")) ) )) ), // 1.25 euro per hour charging tariff for more then 32A during the weekend (paid per 10 minutes) new JObject( new JProperty("price_components", new JArray( new JObject( new JProperty("type", "TIME"), new JProperty("price", "1.25"), new JProperty("step_size", 600) ))), new JProperty("restrictions", new JArray( new JObject( new JProperty("min_power", "32.00"), new JProperty("day_of_week", new JArray("SATURDAY", "SUNDAY")) ) )) ), // Parking on weekdays: between 09:00 and 18:00: 5 euro(paid per 5 minutes) new JObject( new JProperty("price_components", new JArray( new JObject( new JProperty("type", "PARKING_TIME"), new JProperty("price", "5.00"), new JProperty("step_size", 300) ))), new JProperty("restrictions", new JArray( new JObject( new JProperty("start_time", "09:00"), new JProperty("end_time", "18:00"), new JProperty("day_of_week", new JArray("MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY")) ) )) ), // Parking on saturday: between 10:00 and 17:00: 6 euro (paid per 5 minutes) new JObject( new JProperty("price_components", new JArray( new JObject( new JProperty("type", "PARKING_TIME"), new JProperty("price", "6.00"), new JProperty("step_size", 300) ))), new JProperty("restrictions", new JArray( new JObject( new JProperty("start_time", "10:00"), new JProperty("end_time", "17:00"), new JProperty("day_of_week", new JArray("SATURDAY")) ) )) ) ))); Assert.AreEqual(expected.ToString(), tariff.ToJSON().ToString()); }
public static void EVSE_SerializeDeserialize_Test01() { #region Define EVSE1 var EVSE1 = new EVSE( EVSE_UId.Parse("DE*GEF*E*LOC0001*1"), StatusTypes.AVAILABLE, new Connector[] { new Connector( Connector_Id.Parse("1"), ConnectorTypes.IEC_62196_T2, ConnectorFormats.SOCKET, PowerTypes.AC_3_PHASE, 400, 30, 12, new Tariff_Id[] { Tariff_Id.Parse("DE*GEF*T0001"), Tariff_Id.Parse("DE*GEF*T0002") }, URL.Parse("https://open.charging.cloud/terms"), DateTime.Parse("2020-09-21T00:00:00Z") ), new Connector( Connector_Id.Parse("2"), ConnectorTypes.IEC_62196_T2_COMBO, ConnectorFormats.CABLE, PowerTypes.AC_3_PHASE, 400, 20, 8, new Tariff_Id[] { Tariff_Id.Parse("DE*GEF*T0003"), Tariff_Id.Parse("DE*GEF*T0004") }, URL.Parse("https://open.charging.cloud/terms"), DateTime.Parse("2020-09-21T00:00:00Z") ) }, EVSE_Id.Parse("DE*GEF*E*LOC0001*1"), new StatusSchedule[] { new StatusSchedule( StatusTypes.INOPERATIVE, DateTime.Parse("2020-09-22T00:00:00.000Z"), DateTime.Parse("2020-09-23T00:00:00.000Z") ), new StatusSchedule( StatusTypes.OUTOFORDER, DateTime.Parse("2020-12-30T00:00:00.000Z"), DateTime.Parse("2020-12-31T00:00:00.000Z") ) }, new CapabilityTypes[] { CapabilityTypes.RFID_READER, CapabilityTypes.RESERVABLE }, "1. Stock", GeoCoordinate.Parse(10.1, 20.2), "Ladestation #1", new DisplayText[] { DisplayText.Create(Languages.de, "Bitte klingeln!"), DisplayText.Create(Languages.en, "Ken sent me!") }, new ParkingRestrictions[] { ParkingRestrictions.EV_ONLY, ParkingRestrictions.PLUGGED }, new Image[] { new Image( URL.Parse("http://example.com/pinguine.jpg"), ImageFileType.jpeg, ImageCategories.OPERATOR, 100, 150, URL.Parse("http://example.com/kleine_pinguine.jpg") ), new Image( URL.Parse("http://example.com/wellensittiche.jpg"), ImageFileType.png, ImageCategories.ENTRANCE, 200, 300, URL.Parse("http://example.com/kleine_wellensittiche.jpg") ) }, DateTime.Parse("2020-09-18T00:00:00Z") ); #endregion var JSON = EVSE1.ToJSON(); Assert.AreEqual("DE*GEF*E*LOC0001*1", JSON["uid"].Value <String>()); Assert.AreEqual("AVAILABLE", JSON["status"].Value <String>()); Assert.AreEqual("1", JSON["connectors"] [0]["id"].Value <String>()); Assert.AreEqual("2", JSON["connectors"] [1]["id"].Value <String>()); Assert.AreEqual("DE*GEF*E*LOC0001*1", JSON["evse_id"].Value <String>()); Assert.AreEqual("INOPERATIVE", JSON["status_schedule"] [0]["status"].Value <String>()); Assert.AreEqual("2020-09-22T00:00:00.000Z", JSON["status_schedule"] [0]["period_begin"].Value <String>()); Assert.AreEqual("2020-09-23T00:00:00.000Z", JSON["status_schedule"] [0]["period_end"].Value <String>()); Assert.AreEqual("OUTOFORDER", JSON["status_schedule"] [1]["status"].Value <String>()); Assert.AreEqual("2020-12-30T00:00:00.000Z", JSON["status_schedule"] [1]["period_begin"].Value <String>()); Assert.AreEqual("2020-12-31T00:00:00.000Z", JSON["status_schedule"] [1]["period_end"].Value <String>()); Assert.AreEqual("RFID_READER", JSON["capabilities"] [0].Value <String>()); Assert.AreEqual("RESERVABLE", JSON["capabilities"] [1].Value <String>()); Assert.AreEqual("1. Stock", JSON["floor_level"].Value <String>()); Assert.AreEqual("10.1000000", JSON["coordinates"] ["latitude"].Value <String>()); Assert.AreEqual("20.2000000", JSON["coordinates"] ["longitude"].Value <String>()); Assert.AreEqual("Ladestation #1", JSON["physical_reference"].Value <String>()); Assert.AreEqual("de", JSON["directions"] [0]["language"].Value <String>()); Assert.AreEqual("Bitte klingeln!", JSON["directions"] [0]["text"].Value <String>()); Assert.AreEqual("en", JSON["directions"] [1]["language"].Value <String>()); Assert.AreEqual("Ken sent me!", JSON["directions"] [1]["text"].Value <String>()); Assert.AreEqual("EV_ONLY", JSON["parking_restrictions"][0].Value <String>()); Assert.AreEqual("PLUGGED", JSON["parking_restrictions"][1].Value <String>()); Assert.AreEqual("http://example.com/pinguine.jpg", JSON["images"] [0]["url"].Value <String>()); Assert.AreEqual("http://example.com/kleine_pinguine.jpg", JSON["images"] [0]["thumbnail"].Value <String>()); Assert.AreEqual("OPERATOR", JSON["images"] [0]["category"].Value <String>()); Assert.AreEqual("jpeg", JSON["images"] [0]["type"].Value <String>()); Assert.AreEqual(100, JSON["images"] [0]["width"].Value <UInt16>()); Assert.AreEqual(150, JSON["images"] [0]["height"].Value <UInt16>()); Assert.AreEqual("http://example.com/wellensittiche.jpg", JSON["images"] [1]["url"].Value <String>()); Assert.AreEqual("2020-09-18T00:00:00.000Z", JSON["last_updated"].Value <String>()); Assert.IsTrue(EVSE.TryParse(JSON, out EVSE EVSE2, out String ErrorResponse)); Assert.IsNull(ErrorResponse); Assert.AreEqual(EVSE1.UId, EVSE2.UId); Assert.AreEqual(EVSE1.Status, EVSE2.Status); Assert.AreEqual(EVSE1.Connectors, EVSE2.Connectors); Assert.AreEqual(EVSE1.EVSEId, EVSE2.EVSEId); Assert.AreEqual(EVSE1.StatusSchedule, EVSE2.StatusSchedule); Assert.AreEqual(EVSE1.Capabilities, EVSE2.Capabilities); Assert.AreEqual(EVSE1.FloorLevel, EVSE2.FloorLevel); Assert.AreEqual(EVSE1.Coordinates, EVSE2.Coordinates); Assert.AreEqual(EVSE1.PhysicalReference, EVSE2.PhysicalReference); Assert.AreEqual(EVSE1.Directions, EVSE2.Directions); Assert.AreEqual(EVSE1.ParkingRestrictions, EVSE2.ParkingRestrictions); Assert.AreEqual(EVSE1.Images, EVSE2.Images); Assert.AreEqual(EVSE1.LastUpdated.ToIso8601(), EVSE2.LastUpdated.ToIso8601()); }