public async Task Should_update_language() { // STEP 0: Add app. await CreateAppAsync(); // STEP 1: Add languages. await AddLanguageAsync("de"); await AddLanguageAsync("it"); // STEP 3: Update German language. var updateRequest = new UpdateLanguageDto { Fallback = new List <string> { "it" }, IsOptional = true }; var languages_2 = await _.Apps.PutLanguageAsync(appName, "de", updateRequest); var language_2_DE = languages_2.Items.Find(x => x.Iso2Code == "de"); Assert.Equal(updateRequest.Fallback, language_2_DE.Fallback); Assert.Equal(updateRequest.IsOptional, language_2_DE.IsOptional); }
public async Task Should_delete_language() { // STEP 0: Add app. await CreateAppAsync(); // STEP 1: Add languages. await AddLanguageAsync("de"); await AddLanguageAsync("it"); // STEP 2: Update Italian language. var updateRequest = new UpdateLanguageDto { Fallback = new List <string> { "de" }, IsOptional = true }; await _.Apps.PutLanguageAsync(appName, "it", updateRequest); // STEP 3: Remove language. var languages_2 = await _.Apps.DeleteLanguageAsync(appName, "de"); var language_2_IT = languages_2.Items.Find(x => x.Iso2Code == "it"); // Fallback language must be removed. Assert.Empty(language_2_IT.Fallback); Assert.Equal(new string[] { "en", "it" }, languages_2.Items.Select(x => x.Iso2Code).ToArray()); }
public async Task <IActionResult> PutLanguage(string app, string language, [FromBody] UpdateLanguageDto request) { var command = request.ToCommand(ParseLanguage(language)); var response = await InvokeCommandAsync(command); return(Ok(response)); }
public IActionResult UpdateLanguage(UpdateLanguageDto entity) { try { string json = System.IO.File.ReadAllText(@"wwwroot/image/" + entity.fileName); dynamic jsonObj = Newtonsoft.Json.JsonConvert.DeserializeObject(json); jsonObj[entity.key] = entity.newValue; string output = Newtonsoft.Json.JsonConvert.SerializeObject(jsonObj, Newtonsoft.Json.Formatting.Indented); System.IO.File.WriteAllText(@"wwwroot/image/" + entity.fileName, output); return(Ok()); } catch (Exception ex) { throw; } }
public async Task Should_update_master_language() { // STEP 0: Add app. await CreateAppAsync(); // STEP 1: Add languages. await AddLanguageAsync("de"); await AddLanguageAsync("it"); // STEP 2: Update Italian language. var updateRequest = new UpdateLanguageDto { Fallback = new List <string> { "de" }, IsOptional = true }; await _.Apps.PutLanguageAsync(appName, "it", updateRequest); // STEP 3: Change master language to Italian. var masterRequest = new UpdateLanguageDto { IsMaster = true }; var languages_4 = await _.Apps.PutLanguageAsync(appName, "it", masterRequest); var language_4_IT = languages_4.Items.Find(x => x.Iso2Code == "it"); var language_4_EN = languages_4.Items.Find(x => x.Iso2Code == "en"); Assert.True(language_4_IT.IsMaster); // Old master language is unset. Assert.False(language_4_EN.IsMaster); // Master language cannot be optional. Assert.False(language_4_IT.IsOptional); // Fallback for new master language must be removed. Assert.Empty(language_4_IT.Fallback); }
public async Task Should_manage_languages() { var appName = Guid.NewGuid().ToString(); // STEP 1: Add app. var createRequest = new CreateAppDto { Name = appName }; await _.Apps.PostAppAsync(createRequest); // STEP 2: Add languages. await _.Apps.PostLanguageAsync(appName, new AddLanguageDto { Language = "de" }); await _.Apps.PostLanguageAsync(appName, new AddLanguageDto { Language = "it" }); await _.Apps.PostLanguageAsync(appName, new AddLanguageDto { Language = "fr" }); var languages_1 = await _.Apps.GetLanguagesAsync(appName); var languageEN_1 = languages_1.Items.First(x => x.Iso2Code == "en"); Assert.Equal(new string[] { "en", "de", "fr", "it" }, languages_1.Items.Select(x => x.Iso2Code).ToArray()); Assert.True(languageEN_1.IsMaster); // STEP 3: Update German language. var updateRequest1 = new UpdateLanguageDto { Fallback = new string[] { "fr", "it" }, IsOptional = true }; var languages_2 = await _.Apps.PutLanguageAsync(appName, "de", updateRequest1); var languageDE_2 = languages_2.Items.First(x => x.Iso2Code == "de"); Assert.Equal(new string[] { "fr", "it" }, languageDE_2.Fallback.ToArray()); Assert.True(languageDE_2.IsOptional); // STEP 4: Update Italian language. var updateRequest2 = new UpdateLanguageDto { Fallback = new string[] { "fr", "de" } }; var languages_3 = await _.Apps.PutLanguageAsync(appName, "it", updateRequest2); var languageDE_3 = languages_3.Items.First(x => x.Iso2Code == "it"); Assert.Equal(new string[] { "fr", "de" }, languageDE_3.Fallback.ToArray()); // STEP 5: Change master language. var masterRequest = new UpdateLanguageDto { IsMaster = true }; var languages_4 = await _.Apps.PutLanguageAsync(appName, "it", masterRequest); var languageIT_4 = languages_4.Items.First(x => x.Iso2Code == "it"); var languageEN_4 = languages_4.Items.First(x => x.Iso2Code == "en"); Assert.True(languageIT_4.IsMaster); Assert.False(languageIT_4.IsOptional); Assert.False(languageEN_4.IsMaster); Assert.Empty(languageIT_4.Fallback); Assert.Equal(new string[] { "it", "de", "en", "fr" }, languages_4.Items.Select(x => x.Iso2Code).ToArray()); // STEP 6: Remove language. var languages_5 = await _.Apps.DeleteLanguageAsync(appName, "fr"); var languageDE_5 = languages_5.Items.First(x => x.Iso2Code == "de"); Assert.Equal(new string[] { "it" }, languageDE_5.Fallback.ToArray()); Assert.Equal(new string[] { "it", "de", "en" }, languages_5.Items.Select(x => x.Iso2Code).ToArray()); }
public async Task <IActionResult> Update(string app, string language, [FromBody] UpdateLanguageDto request) { await CommandBus.PublishAsync(request.ToCommand(ParseLanguage(language))); return(NoContent()); }
public async Task <IActionResult> Update([FromRoute] int id, [FromBody] UpdateLanguageDto updateLanguageDto) { return(GetResponseOnlyResultMessage(await Mediator.Send(new UpdateLanguageCommand { Id = id, Name = updateLanguageDto.Name, Code = updateLanguageDto.Code }))); }