public async Task When_Passing_No_Preferred_Language_Then_Codes_Are_Translated_And_Default_Language_Is_Used()
        {
            // ARRANGE
            InitializeFakeObjects();
            var translationCodes = new List <string>
            {
                "translation_code"
            };
            var defaultLanguage = "EN";
            var translation     = new Models.Translation
            {
                Code  = "code",
                Value = "value"
            };

            _simpleIdentityServerConfiguratorFake.Setup(s => s.DefaultLanguageAsync())
            .Returns(Task.FromResult(defaultLanguage));
            _translationRepositoryFake.Setup(t => t.GetAsync(It.IsAny <string>(),
                                                             It.IsAny <string>()))
            .Returns(Task.FromResult(translation));;

            // ACT
            var result = await _translationManager.GetTranslationsAsync(string.Empty, translationCodes);

            // ASSERT
            Assert.True(result.Count == 1);
            Assert.True(result.First().Key == translation.Code && result.First().Value == translation.Value);
        }
 protected TranslationBase(ITranslationApi translationApi, ILoggerFactory loggerFactory, Models.Translation supportedTranslation, string translationUrl)
 {
     _loggerFactory        = loggerFactory;
     _logger               = _loggerFactory.CreateLogger <ITranslationProvider>();
     _supportedTranslation = supportedTranslation;
     _translationUrl       = translationUrl;
     _translationApi       = translationApi;
 }
Beispiel #3
0
 public int SaveItem(Models.Translation item)
 {
     if (item.Id != 0)
     {
         database.Update(item);
         return(item.Id);
     }
     else
     {
         return(database.Insert(item));
     }
 }
Beispiel #4
0
        public TranslationEditViewModel(Models.Translation translation)
        {
            if (translation == null)
            {
                throw new ArgumentNullException(nameof(translation));
            }

            Id            = translation.Id;
            Title         = translation.Title;
            Version       = translation.Version;
            Description   = translation.Description;
            ContentMarkup = translation.ContentMarkup;
            State         = translation.State;
            UrlName       = translation.UrlName;
            UpdatedAt     = translation.UpdatedAt;
            ContentId     = translation.ContentId;
        }
 public new bool SupportsTranslation(Models.Translation translation)
 {
     return(base.SupportsTranslation(translation));
 }
 protected bool SupportsTranslation(Models.Translation requestedTranslation)
 {
     return(requestedTranslation == _supportedTranslation);
 }
 public bool GivenInCorrectTranslation_WhenChecked_TranslationProviderReturnsFalse(ITranslationProvider translationProvider, Models.Translation requestedTranslation)
 {
     // Act
     return(translationProvider.SupportsTranslation(requestedTranslation));
 }
        protected override void Seed(OrdBase.Models.TranslationDb context)
        {
            try {
                //
                // @doc html lan codes - https://www.w3schools.com/tags/ref_language_codes.asp
                //
                var language1 = new Language {
                    Name = "Norwegian", ShortName = "no-nb"
                };
                var language2 = new Language {
                    Name = "Swedish", ShortName = "sv"
                };
                var language3 = new Language {
                    Name = "Danish", ShortName = "da"
                };
                var language4 = new Language {
                    Name = "English", ShortName = "en"
                };

                context.Language.AddOrUpdate(language1, language2, language3, language4);

                var client1 = new Client {
                    Name = "FMSF", ApiKey = "1"
                };
                var client2 = new Client {
                    Name = "DIFI", ApiKey = "2"
                };
                var client3 = new Client {
                    Name = "Skatteetaten", ApiKey = "3"
                };

                context.Client.AddOrUpdate(client1, client2, client3);

                var translation1 = new Models.Translation {
                    ClientName = "FMSF", LanguageShortName = "en", Container = "Main", AccessKey = "hello_world", Text = "Hello World", IsComplete = true,
                };
                var translation2 = new Models.Translation {
                    ClientName = "FMSF", LanguageShortName = "no-nb", Container = "Main", AccessKey = "hello_world", Text = "Hallo verden", IsComplete = false,
                };
                var translation3 = new Models.Translation {
                    ClientName = "DIFI", LanguageShortName = "en", Container = "Special", AccessKey = "this_is_me", Text = "This is me!", IsComplete = false,
                };
                var translation4 = new Models.Translation {
                    ClientName = "DIFI", LanguageShortName = "no-nb", Container = "Special", AccessKey = "this_is_me", Text = "Dette er meg!", IsComplete = true,
                };

                context.Translation.AddOrUpdate(translation1, translation2, translation3, translation4);
                context.SaveChanges();
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                      eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                          ve.PropertyName, ve.ErrorMessage);
                    }
                }
                throw;
            }
        }
        public async Task <string> GivenValidData_WhenRequested_ThenWorkerReturnsTranslatedItem(IPokespeareWorker pokespeareWorker, string pokemonName, Models.Translation requestedTranslation)
        {
            // Act
            var translatedPokemon = await pokespeareWorker.TranslatePokemon(pokemonName, requestedTranslation);

            // Assert
            return(translatedPokemon.Content.Description.FirstOrDefault());
        }