コード例 #1
0
        public async Task AddWordToDictionary_GetWithExampleReturnsSame()
        {
            MongoTestHelper.DropAllCollections();
            var dictionaryRepo = new DictionaryRepo(MongoTestHelper.Database);
            var examplesRepo   = new ExamplesRepo(MongoTestHelper.Database);
            var service        = new DictionaryService(dictionaryRepo, examplesRepo);
            var example        = new Example
            {
                Direction        = TranlationDirection.EnRu,
                Id               = ObjectId.GenerateNewId(),
                OriginWord       = "table",
                TranslatedWord   = "стол",
                OriginPhrase     = "What the table?",
                TranslatedPhrase = "Какого стола?"
            };
            var word = new DictionaryWord
            {
                Id            = ObjectId.GenerateNewId(),
                Word          = "table",
                Language      = Language.En,
                Source        = TranslationSource.Yadic,
                Transcription = "qweqwe",
                Translations  = new[]
                {
                    new DictionaryTranslation
                    {
                        Word     = "Стол",
                        Language = Language.Ru,
                        Examples = new []
                        {
                            new DictionaryReferenceToExample()
                            {
                                ExampleId     = example.Id,
                                ExampleOrNull = example,
                            }
                        }
                    }
                }
            };
            await service.AddNewWord(word);

            var translations = await service.GetTranslationsWithExamples("table");

            Assert.AreEqual(1, translations.Count);
            var translation = translations[0];

            Assert.AreEqual(word.Source, translation.Source);
            Assert.AreEqual(word.Transcription, translation.EnTranscription);
            Assert.AreEqual(word.Word, translation.EnWord);
            Assert.AreEqual(word.Translations[0].Word, translation.RuWord);

            Assert.AreEqual(example.OriginWord, translation.Examples[0].OriginWord);
            Assert.AreEqual(example.OriginPhrase, translation.Examples[0].OriginPhrase);
            Assert.AreEqual(example.TranslatedWord, translation.Examples[0].TranslatedWord);
            Assert.AreEqual(example.TranslatedPhrase, translation.Examples[0].TranslatedPhrase);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: NatShep/TestingGit
        private static void Main()
        {
            TaskScheduler.UnobservedTaskException +=
                (sender, args) => Console.WriteLine($"Unobserved ex {args.Exception}");

            _settings = ReadConfiguration();

            var yandexDictionaryClient   = new YandexDictionaryApiClient(_settings.YadicapiKey, _settings.YadicapiTimeout);
            var yandexTranslateApiClient = new YandexTranslateApiClient(_settings.YatransapiKey, _settings.YatransapiTimeout);

            var client = new MongoClient(_settings.MongoConnectionString);
            var db     = client.GetDatabase("SayWhatDb");

            var userWordRepo   = new UserWordsRepo(db);
            var dictionaryRepo = new DictionaryRepo(db);
            var userRepo       = new UsersRepo(db);
            var examplesRepo   = new ExamplesRepo(db);

            userWordRepo.UpdateDb();
            dictionaryRepo.UpdateDb();
            userRepo.UpdateDb();
            examplesRepo.UpdateDb();

            _userWordService   = new UsersWordsService(userWordRepo, examplesRepo);
            _dictionaryService = new DictionaryService(dictionaryRepo, examplesRepo);
            _userService       = new UserService(userRepo);


            _addWordService = new AddWordService(
                _userWordService,
                yandexDictionaryClient,
                yandexTranslateApiClient,
                _dictionaryService,
                _userService);

            QuestionSelector.Singletone = new QuestionSelector(_dictionaryService);

            Console.WriteLine("Dic started");

            _botClient = new TelegramBotClient(_settings.TelegramToken);
            var me = _botClient.GetMeAsync().Result;

            Console.WriteLine(
                $"Hello, World! I am user {me.Id} and my name is {me.FirstName}."
                );

            _botClient.OnUpdate  += BotClientOnOnUpdate;
            _botClient.OnMessage += Bot_OnMessage;

            _botClient.StartReceiving();
            // workaround for infinity awaiting
            new TaskCompletionSource <bool>().Task.Wait();
            // it will never happens
            _botClient.StopReceiving();
        }
コード例 #3
0
 public SearchService()
 {
     this._repo = new DictionaryRepo();
 }
コード例 #4
0
        public Task Update <T>(T model) where T : BaseDictionary
        {
            var repo = new DictionaryRepo <T>(_context);

            return(repo.Update(model));
        }
コード例 #5
0
        public Task <T> Add <T>(T model) where T : BaseDictionary
        {
            var repo = new DictionaryRepo <T>(_context);

            return(repo.Add(model));
        }
コード例 #6
0
 public void Intitalize()
 {
     MongoTestHelper.DropAllCollections();
     _repo = new DictionaryRepo(MongoTestHelper.Database);
     _repo.UpdateDb().Wait();
 }
コード例 #7
0
 public DictionaryService(DictionaryRepo repository, ExamplesRepo exampleRepository)
 {
     _dicRepository     = repository;
     _exampleRepository = exampleRepository;
 }