private Crate Get_Google_Sheet_Data_v1_PackCrate_ConfigurationControls(Tuple <string, string> spreadsheetTuple) { var activityUi = new Get_Google_Sheet_Data_v1.ActivityUi(); activityUi.SpreadsheetList.ListItems = new[] { new ListItem { Key = spreadsheetTuple.Item1, Value = spreadsheetTuple.Item2 } }.ToList(); activityUi.SpreadsheetList.selectedKey = spreadsheetTuple.Item1; activityUi.SpreadsheetList.Value = spreadsheetTuple.Item2; return(PackControlsCrate(activityUi.Controls.ToArray())); }
/// <summary> /// Configuration for Get_Google_Sheet_Data activity. Select spreadsheet value based on spreadsheetName inside SpeadSheet DropDownLIst /// </summary> /// <param name="getFromGoogleSheetActivityDTO"></param> /// <param name="spreadsheetName"></param> /// <param name="includeFixtureAuthToken"></param> /// <param name="worksheetName"></param> /// <returns>Get_Google_Sheet_Data activityDTO</returns> public async Task <ActivityDTO> ConfigureGetFromGoogleSheetActivity(ActivityDTO getFromGoogleSheetActivityDTO, string spreadsheetName, bool includeFixtureAuthToken, string worksheetName = null) { using (var crateStorage = _baseHubITest.Crate.GetUpdatableStorage(getFromGoogleSheetActivityDTO)) { var controlsCrate = crateStorage.CratesOfType <StandardConfigurationControlsCM>().First(); var activityUi = new Get_Google_Sheet_Data_v1.ActivityUi(); activityUi.SyncWith(controlsCrate.Content); crateStorage.Remove <StandardConfigurationControlsCM>(); var spreadsheetUri = activityUi.SpreadsheetList.ListItems.Where(x => x.Key == spreadsheetName).Select(x => x.Value).FirstOrDefault(); Assert.IsNotNullOrEmpty(spreadsheetUri, $"Default Google account doesn't contain spreadsheet '{spreadsheetName}'"); //set spreadsheet name as selected inside SpreadSheetList dropdown activityUi.SpreadsheetList.selectedKey = spreadsheetName; activityUi.SpreadsheetList.Value = spreadsheetUri; crateStorage.Add(Crate <StandardConfigurationControlsCM> .FromContent(controlsCrate.Label, new StandardConfigurationControlsCM(activityUi.Controls.ToArray()))); } if (!string.IsNullOrEmpty(worksheetName)) { //in case we don't want to use default worksheet, provide a worksheetName to be set into the activity getFromGoogleSheetActivityDTO = await _baseHubITest.HttpPostAsync <ActivityDTO, ActivityDTO>(_baseHubITest.GetHubApiBaseUrl() + "activities/save", getFromGoogleSheetActivityDTO); getFromGoogleSheetActivityDTO = await _baseHubITest.HttpPostAsync <ActivityDTO, ActivityDTO>(_baseHubITest.GetHubApiBaseUrl() + "activities/configure", getFromGoogleSheetActivityDTO); using (var crateStorage = _baseHubITest.Crate.GetUpdatableStorage(getFromGoogleSheetActivityDTO)) { var controlsCrate = crateStorage.CratesOfType <StandardConfigurationControlsCM>().First(); var activityUi = new Get_Google_Sheet_Data_v1.ActivityUi(); activityUi.SyncWith(controlsCrate.Content); crateStorage.Remove <StandardConfigurationControlsCM>(); var worksheetUri = activityUi.WorksheetList.ListItems.Where(x => x.Key == worksheetName).Select(x => x.Value).FirstOrDefault(); Assert.IsNotNullOrEmpty(worksheetUri, $"Default Google account doesn't contain worksheet '{worksheetName}' for the spreadsheet '{spreadsheetName}'"); activityUi.WorksheetList.selectedKey = worksheetName; activityUi.WorksheetList.Value = worksheetUri; crateStorage.Add(Crate <StandardConfigurationControlsCM> .FromContent(controlsCrate.Label, new StandardConfigurationControlsCM(activityUi.Controls.ToArray()))); } } getFromGoogleSheetActivityDTO = await _baseHubITest.HttpPostAsync <ActivityDTO, ActivityDTO>(_baseHubITest.GetHubApiBaseUrl() + "activities/save", getFromGoogleSheetActivityDTO); //add a possibility to use FixtureData for newly created activitis, or to remain the usage of already associated default token from google if (includeFixtureAuthToken) { getFromGoogleSheetActivityDTO.AuthToken = FixtureData.GetGoogleAuthorizationToken(); } getFromGoogleSheetActivityDTO = await _baseHubITest.HttpPostAsync <ActivityDTO, ActivityDTO>(_baseHubITest.GetHubApiBaseUrl() + "activities/configure", getFromGoogleSheetActivityDTO); return(getFromGoogleSheetActivityDTO); }