public void TestParse_1y1m1q_NegativeException() { string tenor = "1y1m1q"; Assert.ThrowsException <FormatException>(() => { Tenor res = Tenor.Parse(tenor); }); }
public void TestParse_1d1w1m1y_PositiveResult() { string tenor = "1d1w1m1y"; Tenor res = Tenor.Parse(tenor); Assert.AreEqual(1, res.Years); Assert.AreEqual(1, res.Months); Assert.AreEqual(1, res.Weeks); Assert.AreEqual(1, res.Days); }
/// <summary> /// Attempts to convert the second parameter value to a comparable type of the first parameter. /// </summary> /// <param name="typeInstanceToMatch">Instance of a the target comparable type.</param> /// <param name="value">Value to convert.</param> /// <returns>Converted value as an <see cref="IComparable"/>.</returns> /// <exception cref="InvalidCastException">Thrown if the value cannot be converted to the target type.</exception> /// <exception cref="FormatException">Thrown if the value cannot be converted into a valid numeric type.</exception> public static IComparable ConvertToComparableType(object typeInstanceToMatch, string value) { // If we don't have a valid type to convert to, then best leave the value alone. if (typeInstanceToMatch == null) { return(value); } string type = typeInstanceToMatch.GetType().FullName; switch (type) { case "System.Decimal": return(Convert.ToDecimal(value)); case "System.Boolean": return(ConvertToBool(value)); case "System.Int32": return(Convert.ToInt32(value)); case "System.UInt32": return(Convert.ToUInt32(value)); case "System.Char": return(Convert.ToChar(value)); case "System.DateTime": return(FixDateTime.Parse(value, CultureInfo.InvariantCulture)); case "System.String": return(value); case "Atdl4net.Model.Reference.IsoCountryCode": return(value.ParseAsEnum <IsoCountryCode>()); case "Atdl4net.Model.Reference.IsoCurrencyCode": return(value.ParseAsEnum <IsoCurrencyCode>()); case "Atdl4net.Model.Reference.IsoLanguageCode": return(value.ParseAsEnum <IsoLanguageCode>()); case "Atdl4net.Model.Types.Support.MonthYear": return(MonthYear.Parse(value)); case "Atdl4net.Model.Types.Support.Tenor": return(Tenor.Parse(value)); case "Atdl4net.Model.Controls.Support.EnumState": return(value); default: throw ThrowHelper.New <InvalidCastException>(ExceptionContext, ErrorMessages.DataConversionError1, value, type); } }
public void TestDateTimeOffset_OPAdd_Sub_1y1m1w1d_PositiveResult() { // set string strtenor = "1y1m1w1d"; Tenor tenor = Tenor.Parse(strtenor); var expected = DateTimeOffset.UtcNow; // Action var testdate = expected + tenor; testdate = testdate - tenor; //Assertion Assert.AreEqual(expected, testdate); }
public void TestDateTime_Add_Sub_1y1m1w1d_PositiveResult() { // set string strtenor = "1y1m1w1d"; Tenor tenor = Tenor.Parse(strtenor); var expected = DateTime.UtcNow; // Action var testdate = expected.Add(tenor); testdate = testdate.Subsctract(tenor); //Assertion Assert.AreEqual(expected, testdate); }