public void ForCurrentCulture_CultureWithObsoleteCulture_EventRaised() { using (CultureReseter.Set("ee-EE")) { Action moneyWithObsoleteCurrency = () => Money.ForCurrentCulture(decimal.Zero); Assert.That(moneyWithObsoleteCurrency, Must.Raise.ObsoleteEvent()); } }
public void ToString_SingleRatio_PaddedOne() { using (CultureReseter.Set(CultureInfo.InvariantCulture)) { var singleBag = new RatioCollection(1m); Assert.That(singleBag.ToString(), Is.EqualTo("< 1 >")); } }
public void ForCurrentCulture_OutdatedCulture_Exception() { using (CultureReseter.Set("bg-BG")) { Assert.That(() => Money.ForCurrentCulture(decimal.Zero), Throws.ArgumentException.With.Message.Contains("BGL"), "Framework returns wrong ISOCurrencySymbol (BGL instead of BGN)"); } }
public void ForCurrentCulture_DefinedCulture_PropertiesSet() { using (CultureReseter.Set("da-DK")) { Money subject = Money.ForCurrentCulture(100); Assert.That(subject.Amount, Is.EqualTo(100m)); Assert.That(subject.CurrencyCode, Is.EqualTo(CurrencyIsoCode.DKK)); } }
public void Set_Both_CultureAndUiSetToSame() { CultureInfo ci = Culture.Get("dv-MV"); using (CultureReseter.Set(ci)) { Assert.That(CultureInfo.CurrentCulture, Is.EqualTo(ci)); Assert.That(CultureInfo.CurrentUICulture, Is.EqualTo(ci)); } }
public void ToString_Remainder_DenominationsAndRemainder() { var subject = new ChangeSolution(new[] { new Denomination(2) }, new Money(5, CurrencyIsoCode.EUR)); using (CultureReseter.Set(CultureInfo.InvariantCulture)) { Assert.That(subject.ToString(), Is.EqualTo("< < 1 * 2 > > + < 5,00 € >")); } }
public void ToString_CultureIndependant() { using (CultureReseter.Set("es-ES")) { var subject = new ExchangeRate(CurrencyIsoCode.EUR, CurrencyIsoCode.USD, 1.25m); Assert.That(subject.ToString(), Is.EqualTo("EUR/USD 1.25"), "invariant number representation"); Assert.That(1.25m.ToString(), Is.EqualTo("1,25"), "even decimals use commas in spanish"); } }
public void Week_WeekCalendar_MakesDifference() { using (CultureReseter.Set("da-DK")) { var thuInFirstWeek = 3.January(2008).InUtc(); Assert.That(thuInFirstWeek.Week(CalendarWeekRule.FirstDay), Is.EqualTo(1)); Assert.That(thuInFirstWeek.Week(CalendarWeekRule.FirstFourDayWeek), Is.EqualTo(1)); Assert.That(thuInFirstWeek.Week(CalendarWeekRule.FirstFullWeek), Is.EqualTo(53), "last week from previous year"); } }
public void ToString_NoRemainder_OnlyDenominations() { var subject = new ChangeSolution(new[] { new Denomination(2) }, Money.Zero(CurrencyIsoCode.EUR)); using (CultureReseter.Set(CultureInfo.InvariantCulture)) { Assert.That(subject.ToString(), Is.EqualTo("< < 1 * 2 > >")); } }
public void Ctor_BigRatio_Exception() { using (CultureReseter.Set(CultureInfo.InvariantCulture)) { Assert.That(() => new Ratio(2.3m), Throws.InstanceOf <ArgumentOutOfRangeException>() .With.Property("ParamName").EqualTo("value").And .With.Property("ActualValue").EqualTo(2.3m) .With.Message.Contains("0") .With.Message.Contains("1")); } }
public void ToString_CustomFormatsAndProviders_AppliesToRatios() { using (CultureReseter.Set(CultureInfo.InvariantCulture)) { var bag = new RatioCollection(0.5m, .4m, .05m, .05m); var snailDecimalSeparator = (NumberFormatInfo)CultureInfo.InvariantCulture.NumberFormat.Clone(); snailDecimalSeparator.NumberDecimalSeparator = "@"; Assert.That(bag.ToString(".000", snailDecimalSeparator), Is.EqualTo("< @500 | @400 | @050 | @050 >")); } }
public void LastDayOfWeek_DependsOnCulture() { using (CultureReseter.Set("pt-BR")) { Assert.That(Time.LastDayOfWeek(), Is.EqualTo(DayOfWeek.Saturday)); } using (CultureReseter.Set("es-ES")) { Assert.That(Time.LastDayOfWeek(), Is.EqualTo(DayOfWeek.Sunday)); } }
public void ToString_FormattedNumber_HonorsFormatBeingCultureIndependent() { using (CultureReseter.Set("es-ES")) { Assert.That(new DecimalPercentage(33.3m).ToString("{0:000.0000}"), Is.EqualTo("033.3000 %")); } using (CultureReseter.Set("en-US")) { Assert.That(new DecimalPercentage(33.3m).ToString("{0:000.0000}"), Is.EqualTo("033.3000 %")); } }
public void ToString_CultureIndependent() { using (CultureReseter.Set("es-ES")) { Assert.That(new DecimalPercentage(33.343m).ToString(), Is.EqualTo("33.343 %")); } using (CultureReseter.Set("en-US")) { Assert.That(new DecimalPercentage(33.3112m).ToString(), Is.EqualTo("33.3112 %")); } }
public void AssertBounds_IncorrectlyOrderedBounds_Exception() { using (CultureReseter.Set(_platformAgnostic)) { Assert.That(() => Range <char> .AssertBounds('z', 'a'), throwsBoundException('a', "a")); Assert.That(() => Range <int> .AssertBounds(1, -1), throwsBoundException(-1, "-1")); Assert.That(() => Range <TimeSpan> .AssertBounds(1.Hours(), 3.Seconds()), throwsBoundException(3.Seconds(), "00:00:03")); Assert.That(() => Range <DateTime> .AssertBounds(9.September(2010), 11.March(1977)), throwsBoundException(11.March(1977), "11-03-1977")); } }
public void Explore() { using (CultureReseter.Set("da-DK")) { Assert.That(2001.IsLeapYear(), Is.False); Assert.That(25.October(2012).InUtc().Week(), Is.EqualTo(43)); Assert.That(DayOfWeek.Monday.DaysTill(DayOfWeek.Thursday), Is.EqualTo(3)); Assert.That(DayOfWeek.Monday.DaysSince(DayOfWeek.Friday), Is.EqualTo(3)); Assert.That(/* Mon */ 16.June(2008).InUtc().Previous(DayOfWeek.Thursday), Is.EqualTo(12.June(2008).InUtc() /* Thu */)); Assert.That(/* Thu */ 12.June(2008).InUtc().Next(DayOfWeek.Monday), Is.EqualTo(16.June(2008).InUtc() /* Mon */)); Assert.That(12.June(2008).At(15.Hours().Minutes(43).Seconds(10)).InUtc() .BeginningOfDay(), Is.EqualTo(12.June(2008).At(Time.MidNight).InUtc())); Assert.That(12.June(2008).InUtc().BeginningOfWeek(), Is.EqualTo(9.June(2008).InUtc())); Assert.That(12.June(2008).InUtc().BeginningOf(Period.Year), Is.EqualTo(1.January(2008).InUtc())); Assert.That(12.June(2008).InUtc().EndOfWeek(), Is.EqualTo(15.June(2008).At(Time.EndOfDay).InUtc())); Assert.That(11.March(1977).InUtc().Difference(14.March(1977).InUtc()), Is.EqualTo(3.Days())); DateTimeOffset firstFebruary = 1.February(2008).InUtc(), fifthFebruary = 5.February(2008).InUtc(); Assert.That(firstFebruary.DiffersFrom(fifthFebruary).InAtLeast(2.Days()), Is.True); Assert.That(firstFebruary.DiffersFrom(fifthFebruary).InAtMost(4.Days()), Is.True); Assert.That(firstFebruary.DiffersFrom(fifthFebruary).InLessThan(1.Weeks()), Is.True); Assert.That(firstFebruary.DiffersFrom(fifthFebruary).InMoreThan(Time.OneHour), Is.True); Assert.That(firstFebruary.DiffersFrom(firstFebruary).InNothing(), Is.True); Assert.That(firstFebruary.DiffersFrom(fifthFebruary).InSomething(), Is.True); using (TimeReseter.Set(10.February(2000).At(Time.Noon).In(1.Hours()))) { Assert.That(2.Days().Ago(), Is.EqualTo(8.February(2000).At(Time.Noon).In(Time.Offset))); Assert.That(2.Days().FromNow(), Is.EqualTo(12.February(2000).At(Time.Noon).In(Time.Offset))); Assert.That(9.February(2000).In(Time.Offset).Elapsed(), Is.EqualTo(1.Days().Hours(12))); } Assert.That(TimeSpan.Zero.Describe(), Is.EqualTo("now")); Assert.That(59.Seconds().Describe(), Is.EqualTo("59 seconds")); Assert.That(1.Minutes().Seconds(1).Describe(), Is.EqualTo("about 1 minute")); Assert.That(3.Minutes().Seconds(31).Describe(), Is.EqualTo("about 4 minutes")); Assert.That(3.Hours().Minutes(3).Seconds(1).Describe(), Is.EqualTo("about 3 hours")); Assert.That(2.Days().Minutes(1).Seconds(1).Describe(), Is.EqualTo("about 2 days")); Assert.That(2.Days().Minutes(1).Seconds(1).AsLapseDescription(), Is.EqualTo("about 2 days ago")); Assert.That(1.January(2008).At(15.Hours()).AsOffset(3.Hours()), Is.EqualTo(new DateTimeOffset(2008, 1, 1, 15, 0, 0, 3.Hours()))); Assert.That(1.January(2008).At(15.Hours()).AsUtcOffset(), Is.EqualTo(new DateTimeOffset(2008, 1, 1, 15, 0, 0, 0.Hours()))); Assert.That(25.October(2012).At(15.Hours().Minutes(55)).InUtc().SetTime(15, 56, 0), Is.EqualTo(25.October(2012).At(15.Hours().Minutes(56)).InUtc())); } }
public void Week_Culture_MakesDifferenceAsPerFirstDayOfWeek() { using (CultureReseter.Set("da-DK")) { var thuInFirstWeek = 3.January(2008).InUtc(); Assert.That(thuInFirstWeek.Week(CalendarWeekRule.FirstFullWeek), Is.EqualTo(53), "last week from previous year"); } using (CultureReseter.Set("pt-BR")) { var thuInFirstWeek = 3.January(2008).InUtc(); Assert.That(thuInFirstWeek.Week(CalendarWeekRule.FirstFullWeek), Is.EqualTo(52), "last week from previous year"); } }
public void ToString_ValueString_AsPerCurrentCulture() { var pointTwo = new Denomination(.2m); using (CultureReseter.Set("en-US")) { Assert.That(pointTwo.ToString(), Is.EqualTo("0.2"), "US decimals with a dot"); } using (CultureReseter.Set("da-DK")) { Assert.That(pointTwo.ToString(), Is.EqualTo("0,2"), "DK decimals with a comma"); } }
public void Ctor_PoorlyConstructed_Exception() { using (CultureReseter.Set(_platformAgnostic)) { Assert.That(() => new Range <int>(5, 1), throwsBoundException(1, "1")); Assert.That(() => new Range <int>(-1, -5), throwsBoundException(-5, "-5")); Assert.That(() => new Range <TimeSpan>(3.Seconds(), 2.Seconds()), throwsBoundException(2.Seconds(), "00:00:02")); Assert.That(() => new Range <DateTime>(11.March(1977), 31.October(1952)), throwsBoundException(31.October(1952), "31-10-1952")); } }
public void ToString_PipeSeparatedRatiosAsPerCurrentCulture() { var bag = new RatioCollection(0.5m, .4m, .05m, .05m); using (CultureReseter.Set("en-US")) { Assert.That(bag.ToString(), Is.EqualTo("< 0.5 | 0.4 | 0.05 | 0.05 >"), "US decimals with a dot"); } using (CultureReseter.Set("da-DK")) { Assert.That(bag.ToString(), Is.EqualTo("< 0,5 | 0,4 | 0,05 | 0,05 >"), "DK decimals with a comma"); } }
public void ToString_ValueString_AsPerCurrentCulture() { var subject = .5m.Xxx().MakeOptimalChange(.1m, .3m, .2m); using (CultureReseter.Set("en-US")) { Assert.That(subject.ToString(), Is.EqualTo("< < 1 * 0.3 > | < 1 * 0.2 > >"), "US decimals with a dot"); } using (CultureReseter.Set("da-DK")) { Assert.That(subject.ToString(), Is.EqualTo("< < 1 * 0,3 > | < 1 * 0,2 > >"), "DK decimals with a comma"); } }
public void ToString_ValueString_AsPerCurrentCulture() { var threeOfPointTwo = new QuantifiedDenomination(new Denomination(.2m), 3u); using (CultureReseter.Set("en-US")) { Assert.That(threeOfPointTwo.ToString(), Is.EqualTo("< 3 * 0.2 >"), "US decimals with a dot"); } using (CultureReseter.Set("da-DK")) { Assert.That(threeOfPointTwo.ToString(), Is.EqualTo("< 3 * 0,2 >"), "DK decimals with a comma"); } }
public void Set_BothChange_ResetToPreviousValues() { CultureInfo culture = Culture.GetFromThread(); CultureInfo uICulture = Culture.GetUIFromThread(); // valid test point if code does not run in Maldives using (CultureReseter.Set(Culture.Get("dv-MV"), Culture.Get("dv"))) { Assert.That(Culture.GetFromThread(), Is.Not.EqualTo(culture)); Assert.That(Culture.GetUIFromThread(), Is.Not.EqualTo(uICulture)); } Assert.That(Culture.GetFromThread(), Is.EqualTo(culture)); Assert.That(Culture.GetUIFromThread(), Is.EqualTo(uICulture)); }
public void ToString_ValueString_AsPerCurrentCulture() { var denominations = new[] { new Denomination(2), new Denomination(.2m), new Denomination(.2m) }; var subject = new ChangeSolution(denominations, Money.Zero(CurrencyIsoCode.EUR)); using (CultureReseter.Set("en-US")) { Assert.That(subject.ToString(), Is.EqualTo("< < 1 * 2 > | < 2 * 0.2 > >"), "US decimals with a dot"); } using (CultureReseter.Set("da-DK")) { Assert.That(subject.ToString(), Is.EqualTo("< < 1 * 2 > | < 2 * 0,2 > >"), "DK decimals with a comma"); } }
public void CompareTo_NonGenericDifferentTypes() { using (CultureReseter.Set("en-US")) { Assert.That(() => fiver.CompareTo("asd"), Throws.ArgumentException); Assert.That(() => fiver.CompareTo(5), Throws.ArgumentException, "no implicit comparison"); Assert.That(() => fiver.CompareTo(5m), Throws.ArgumentException, "no implicit comparison"); } using (CultureReseter.Set("en-GB")) { Assert.That(() => fiver.CompareTo("asd"), Throws.ArgumentException); Assert.That(() => fiver.CompareTo(5), Throws.ArgumentException, "no implicit comparison"); Assert.That(() => fiver.CompareTo(5m), Throws.ArgumentException, "no implicit comparison"); } }
public void LastDayOfWeek_WithFirstDay_DoesNotDependOnCulture() { DayOfWeek usLastDay, esLastDay; var firstDay = DayOfWeek.Thursday; using (CultureReseter.Set("en-US")) { usLastDay = Time.LastDayOfWeek(firstDay); } using (CultureReseter.Set("es-ES")) { esLastDay = Time.LastDayOfWeek(firstDay); } Assert.That(usLastDay, Is.EqualTo(esLastDay)); Assert.That(usLastDay, Is.EqualTo(DayOfWeek.Wednesday)); }
public void Set_NeutralNonNeutralCombinations_NoException() { CultureInfo neutral = Culture.Get("en"), nonNeutral = Culture.Get("en-GB"); Assert.That(() => CultureReseter.Set(nonNeutral, nonNeutral), Throws.Nothing); Assert.That(() => CultureReseter.Set("en-GB", "es-ES"), Throws.Nothing); Assert.That(() => CultureReseter.Set(nonNeutral, neutral), Throws.Nothing); Assert.That(() => CultureReseter.Set("en-US", "es"), Throws.Nothing); Assert.That(() => CultureReseter.Set(neutral, neutral), Throws.Nothing); Assert.That(() => CultureReseter.Set(neutral), Throws.Nothing); Assert.That(() => CultureReseter.Set("es", "es"), Throws.Nothing); Assert.That(() => CultureReseter.Set("es"), Throws.Nothing); Assert.That(() => CultureReseter.Set(CultureInfo.InvariantCulture), Throws.Nothing); Assert.That(() => CultureReseter.Set(CultureInfo.InvariantCulture, CultureInfo.InvariantCulture), Throws.Nothing); }
public void ToString_FactorRepresentation_CultureIndependent() { float qualityFactor = .33f; var subject = new Quality(qualityFactor); string dotCultureRepresentation, commaCultureRepresentation; using (CultureReseter.Set("en-US")) { dotCultureRepresentation = subject.ToString(); } using (CultureReseter.Set("da-DK")) { commaCultureRepresentation = subject.ToString(); } Assert.That(dotCultureRepresentation, Is.EqualTo(commaCultureRepresentation)); }
public void EndOfWeek_DependsOnCulture() { var thu12Jun = 12.June(2008).At(_baseTime).InUtc(); DateTimeOffset weekEnd; using (CultureReseter.Set("pt-BR")) { weekEnd = thu12Jun.EndOfWeek(); Assert.That(weekEnd.DayOfWeek, Is.EqualTo(DayOfWeek.Saturday)); assertEndDayDate(weekEnd, 2008, 6, 14); } using (CultureReseter.Set("es-ES")) { weekEnd = thu12Jun.EndOfWeek(); Assert.That(weekEnd.DayOfWeek, Is.EqualTo(DayOfWeek.Sunday)); assertEndDayDate(weekEnd, 2008, 6, 15); } }
public void BeginningOfWeek_DependsOfCulture() { var thu12Jun = 12.June(2008).At(_baseTime).InUtc(); DateTimeOffset weekStart; using (CultureReseter.Set("pt-BR")) { weekStart = thu12Jun.BeginningOfWeek(); Assert.That(weekStart.DayOfWeek, Is.EqualTo(DayOfWeek.Sunday)); assertDate(weekStart, 2008, 6, 8); } using (CultureReseter.Set("es-ES")) { weekStart = thu12Jun.BeginningOfWeek(); Assert.That(weekStart.DayOfWeek, Is.EqualTo(DayOfWeek.Monday)); assertDate(weekStart, 2008, 6, 9); } }