public void UpdateTranslate_should_update_translate()
        {
            var dto        = TranslateFakeData.GetFakedUpdatedTranslate();
            var translate  = Substitute.For <Translator>();
            var repository = Substitute.For <ITranslationRepository>();

            repository.GetById(dto.Id).Returns(translate);

            var sut = new TranslationService(repository);

            sut.ModifyTranslate(dto);

            var language     = new LanguageBuilder().WithAbbrevation(dto.LanguageAbbr).Build();
            var phraseType   = new PhraseTypeBuilder().WithName(dto.PhraseType).Build();
            var phrase       = new PhraseBuilder().WithId(dto.PhraseId).WithPhraseType(phraseType).Build();
            var translations = new List <Domain.Entities.Translation>()
            {
                new Domain.Entities.Translation(language, dto.Translation)
            };
            var expectedTranslate = new TranslateBuilder()
                                    .WithId(dto.Id)
                                    .WithPhrase(phrase)
                                    .WithTranslations(translations).Build();

            translate.Received().Update(phrase, translations);
        }
        public void Repository_should_save_translate()
        {
            var repository = new TranslationRepository(DbContext);

            var phraseType   = new PhraseType(7, "commodity", "کالا");
            var phrase       = new Phrase(15, "گندم", phraseType);
            var language     = new Language(1, "انگلیسی", "English", "EN");
            var translations = new List <Domain.Entities.Translation>()
            {
                new Domain.Entities.Translation(0, language, "Wheat")
            };
            var translatedPhrase = new TranslateBuilder()
                                   .WithPhrase(phrase)
                                   .WithTranslations(translations).Build();

            repository.Save(translatedPhrase);

            var id = translatedPhrase.Id;

            DbContext.ClearChangeTracker();


            var result = repository.GetById(id);

            Assert.Equal(result, translatedPhrase, new TranslatorEqualityComparer());
        }
示例#3
0
        public ITranslator <TSchema> Create(TranslateFactoryContext <TSchema> context)
        {
            var builder = new TranslateBuilder <TSchema>(context);

            _specification.Apply(builder);

            return(builder.Build());
        }
示例#4
0
        protected override async Task Do()
        {
            TranslateBuilder.NO_CACHE = NoCache;

            var builder = new TranslateBuilder(NotabenoidLogin, NotabenoidPassword, BookId, GameDir, TranslateDir);

            if (Res != null)
            {
                await builder.Build(Res);
            }
            else
            {
                await builder.Build();
            }
        }
        public void CreateTranslate_should_save_translate()
        {
            var dto        = TranslateFakeData.GetFakedCreatedTranslate();
            var repository = Substitute.For <ITranslationRepository>();
            var sut        = new TranslationService(repository);

            sut.CreateTranslate(dto);

            var language     = new LanguageBuilder().WithAbbrevation(dto.LanguageAbbr).Build();
            var translations = new List <Domain.Entities.Translation>()
            {
                new Domain.Entities.Translation(language, dto.Translation)
            };

            var phraseType        = new PhraseTypeBuilder().WithName(dto.PhraseType).Build();
            var phrase            = new PhraseBuilder().WithId(dto.PhraseId).WithPhraseType(phraseType).Build();
            var expectedTranslate = new TranslateBuilder()
                                    .WithPhrase(phrase)
                                    .WithTranslations(translations).Build();

            repository.Received(1).Save(ArgExt.Compare(expectedTranslate, new TranslatorEqualityComparer()));
        }
 public TranslatorTests()
 {
     _sutBuilder = new TranslateBuilder();
 }