1616using NUnit . Framework . Interfaces ;
1717using Xamarin . ProjectTools ;
1818using System . Xml . XPath ;
19+ using Humanizer ;
1920
2021namespace Xamarin . Android . Build . Tests
2122{
@@ -41,13 +42,23 @@ public void BeforeDeploymentTests ()
4142
4243 proj = new XamarinFormsAndroidApplicationProject ( ) ;
4344 proj . SetAndroidSupportedAbis ( "armeabi-v7a" , "x86" , "x86_64" ) ;
45+ proj . SetProperty ( "_FastDeploymentDiagnosticLogging" , "True" ) ;
46+ proj . PackageReferences . Add ( new Package {
47+ Id = "Humanizer" ,
48+ Version = "*" ,
49+ } ) ;
4450 var mainPage = proj . Sources . First ( x => x . Include ( ) == "MainPage.xaml.cs" ) ;
45- var source = mainPage . TextContent ( ) . Replace ( "InitializeComponent ();" , @"InitializeComponent ();
51+ var source = mainPage . TextContent ( )
52+ . Replace ( "using System;" , @"using System;
53+ using Humanizer;
54+ using System.Globalization;" )
55+ . Replace ( "InitializeComponent ();" , @"InitializeComponent ();
4656 Console.WriteLine ($""TimeZoneInfoNative={Java.Util.TimeZone.Default.ID}"");
4757 Console.WriteLine ($""TimeZoneInfo={TimeZoneInfo.Local.DisplayName}"");
4858 Console.WriteLine ($""LocaleNative={Java.Util.Locale.Default.Language}-{Java.Util.Locale.Default.Country}"");
4959 Console.WriteLine ($""CurrentCulture={System.Globalization.CultureInfo.CurrentCulture.Name}"");
5060 Console.WriteLine ($""Strings.SomeString={Strings.SomeString}"");
61+ Console.WriteLine ($""Humanizer={DateTime.UtcNow.AddHours(-30).Humanize()}"");
5162 myLabel.Text = Strings.SomeString;
5263" ) ;
5364 source = source . Replace ( "Console.WriteLine (\" Button was Clicked!\" );" , @"Console.WriteLine (""Button was Clicked!"");
@@ -433,6 +444,18 @@ public void CheckLocalizationIsCorrect (string locale)
433444 Assert . IsTrue ( WaitForActivityToStart ( proj . PackageName , "MainActivity" , logFile , timeout : 120 ) , "Activity should have started" ) ;
434445 string line = "" ;
435446 string logCatFile = Path . Combine ( Root , builder . ProjectDirectory , $ "locale-logcat-{ locale . Replace ( "/" , "-" ) } .log") ;
447+ var culture = new CultureInfo ( locale ) ;
448+ string expectedHumanized = DateTime . UtcNow . AddHours ( - 30 ) . Humanize ( culture : culture ) ;
449+ Assert . IsTrue ( MonitorAdbLogcat ( ( l ) => {
450+ if ( l . Contains ( "Humanizer=" ) ) {
451+ line = l ;
452+ bool result = l . Contains ( $ "{ expectedHumanized } ") ;
453+ if ( l . Contains ( "Humanizer=" ) && ! result )
454+ return false ;
455+ return result ;
456+ }
457+ return false ;
458+ } , logCatFile , timeout : 30 ) , $ "Humanizer should have been '{ expectedHumanized } '. We found : { line } ") ;
436459 ClickButton ( proj . PackageName , "myXFButton" , "CLICK ME" ) ;
437460 Assert . IsTrue ( MonitorAdbLogcat ( ( l ) => {
438461 if ( l . Contains ( "StringsClick=" ) || l . Contains ( "Strings.SomeString=" ) ) {
0 commit comments