66using System . Text ;
77using System . Threading ;
88using System . Threading . Tasks ;
9+ using Microsoft . AspNetCore . Hosting ;
10+ using Microsoft . Extensions . Hosting ;
911using Microsoft . Extensions . Logging ;
1012using Microsoft . Extensions . Options ;
1113using Newtonsoft . Json . Linq ;
@@ -1470,6 +1472,70 @@ public void GetTargetLanguage_Success()
14701472 Assert . AreEqual ( targetWritingSystemTag , actual ) ;
14711473 }
14721474
1475+ [ Test ]
1476+ public void GetTranslationBuildConfig_AddsTagForDev ( )
1477+ {
1478+ // Set up test environment
1479+ var env = new TestEnvironment { Environment = { EnvironmentName = Environments . Development } } ;
1480+
1481+ // SUT
1482+ TranslationBuildConfig actual = env . Service . GetTranslationBuildConfig (
1483+ new ServalData ( ) ,
1484+ servalConfig : null ,
1485+ new BuildConfig ( ) ,
1486+ corporaSyncInfo : [ ]
1487+ ) ;
1488+ Assert . AreEqual ( MachineProjectService . TagDevelopment , ( string ) ( actual . Options as JObject ) ? [ "tags" ] ) ;
1489+ }
1490+
1491+ [ Test ]
1492+ public void GetTranslationBuildConfig_AddsTagForTest ( )
1493+ {
1494+ // Set up test environment
1495+ var env = new TestEnvironment ( ) ;
1496+
1497+ // SUT
1498+ TranslationBuildConfig actual = env . Service . GetTranslationBuildConfig (
1499+ new ServalData ( ) ,
1500+ servalConfig : null ,
1501+ new BuildConfig ( ) ,
1502+ corporaSyncInfo : [ ]
1503+ ) ;
1504+ Assert . AreEqual ( MachineProjectService . TagTest , ( string ) ( actual . Options as JObject ) ? [ "tags" ] ) ;
1505+ }
1506+
1507+ [ Test ]
1508+ public void GetTranslationBuildConfig_AddsTagForStaging ( )
1509+ {
1510+ // Set up test environment
1511+ var env = new TestEnvironment { Environment = { EnvironmentName = Environments . Staging } } ;
1512+
1513+ // SUT
1514+ TranslationBuildConfig actual = env . Service . GetTranslationBuildConfig (
1515+ new ServalData ( ) ,
1516+ servalConfig : null ,
1517+ new BuildConfig ( ) ,
1518+ corporaSyncInfo : [ ]
1519+ ) ;
1520+ Assert . AreEqual ( MachineProjectService . TagStaging , ( string ) ( actual . Options as JObject ) ? [ "tags" ] ) ;
1521+ }
1522+
1523+ [ Test ]
1524+ public void GetTranslationBuildConfig_AddsTagForProduction ( )
1525+ {
1526+ // Set up test environment
1527+ var env = new TestEnvironment { Environment = { EnvironmentName = Environments . Production } } ;
1528+
1529+ // SUT
1530+ TranslationBuildConfig actual = env . Service . GetTranslationBuildConfig (
1531+ new ServalData ( ) ,
1532+ servalConfig : null ,
1533+ new BuildConfig ( ) ,
1534+ corporaSyncInfo : [ ]
1535+ ) ;
1536+ Assert . AreEqual ( MachineProjectService . TagProduction , ( string ) ( actual . Options as JObject ) ? [ "tags" ] ) ;
1537+ }
1538+
14731539 [ Test ]
14741540 public void GetTranslationBuildConfig_DoesNotSpecifyAdditionalTrainingDataIfNoFilesSpecified ( )
14751541 {
@@ -1514,6 +1580,49 @@ public void GetTranslationBuildConfig_MergesFastTrainingConfiguration()
15141580 Assert . AreEqual ( 20 , ( int ) ( actual . Options as JObject ) ? [ "max_steps" ] ) ;
15151581 }
15161582
1583+ [ Test ]
1584+ public void GetTranslationBuildConfig_MergesTagFromServalConfig ( )
1585+ {
1586+ // Set up test environment
1587+ var env = new TestEnvironment { Environment = { EnvironmentName = Environments . Production } } ;
1588+ const string tag = "my_project" ;
1589+ const string servalConfig = $$ """ {"tags":"{{ tag }} "}""" ;
1590+
1591+ // SUT
1592+ TranslationBuildConfig actual = env . Service . GetTranslationBuildConfig (
1593+ new ServalData ( ) ,
1594+ servalConfig ,
1595+ new BuildConfig ( ) ,
1596+ corporaSyncInfo : [ ]
1597+ ) ;
1598+ Assert . AreEqual (
1599+ new JArray ( tag , MachineProjectService . TagProduction ) ,
1600+ ( ( JArray ) ( actual . Options as JObject ) ? [ "tags" ] )
1601+ ) ;
1602+ }
1603+
1604+ [ Test ]
1605+ public void GetTranslationBuildConfig_MergesTagsFromServalConfig ( )
1606+ {
1607+ // Set up test environment
1608+ var env = new TestEnvironment { Environment = { EnvironmentName = Environments . Production } } ;
1609+ const string tag1 = "my_first_tag" ;
1610+ const string tag2 = "my_second_tag" ;
1611+ const string servalConfig = $$ """ {"tags":["{{ tag1 }} ", "{{ tag2 }} "]}""" ;
1612+
1613+ // SUT
1614+ TranslationBuildConfig actual = env . Service . GetTranslationBuildConfig (
1615+ new ServalData ( ) ,
1616+ servalConfig ,
1617+ new BuildConfig ( ) ,
1618+ corporaSyncInfo : [ ]
1619+ ) ;
1620+ Assert . AreEqual (
1621+ new JArray ( tag1 , tag2 , MachineProjectService . TagProduction ) ,
1622+ ( ( JArray ) ( actual . Options as JObject ) ? [ "tags" ] )
1623+ ) ;
1624+ }
1625+
15171626 [ Test ]
15181627 public void GetTranslationBuildConfig_NoScriptureRange ( )
15191628 {
@@ -3849,6 +3958,7 @@ private class TestEnvironment
38493958 public TestEnvironment ( TestEnvironmentOptions ? options = null )
38503959 {
38513960 options ??= new TestEnvironmentOptions ( ) ;
3961+ Environment = Substitute . For < IWebHostEnvironment > ( ) ;
38523962 ExceptionHandler = Substitute . For < IExceptionHandler > ( ) ;
38533963 MockLogger = new MockLogger < MachineProjectService > ( ) ;
38543964 CorporaClient = Substitute . For < ICorporaClient > ( ) ;
@@ -4103,6 +4213,7 @@ public TestEnvironment(TestEnvironmentOptions? options = null)
41034213 Service = Substitute . ForPartsOf < MachineProjectService > (
41044214 CorporaClient ,
41054215 DataFilesClient ,
4216+ Environment ,
41064217 ExceptionHandler ,
41074218 FileSystemService ,
41084219 MockLogger ,
@@ -4119,6 +4230,7 @@ public TestEnvironment(TestEnvironmentOptions? options = null)
41194230 public MachineProjectService Service { get ; }
41204231 public ICorporaClient CorporaClient { get ; }
41214232 public IDataFilesClient DataFilesClient { get ; }
4233+ public IWebHostEnvironment Environment { get ; }
41224234 public IFileSystemService FileSystemService { get ; }
41234235 public IParatextService ParatextService { get ; }
41244236 public SFMemoryRealtimeService RealtimeService { get ; }
0 commit comments