public void Should_Throw_Exception_Trying_To_Add_Existing_Word(string word, string userIp) { _wordsRepository .When(x => x.AddNewWord(word)) .Do(x => { if (_dummyWordsRepository.GetWords().Contains(new WordModel(word))) { throw new Exception(); } }); Assert.Throws <Exception>(() => _dictionaryService.AddWord(word, userIp)); }
public IEnumerable <LanguageDto> GetLanguage(string text) //IEnumerable<string> { if (string.IsNullOrEmpty(text) || text.Length < 3) { return(null); } var dictionary = _dictionaryService.GetLanguage(text); if (dictionary == null) { var first = new LanguageExpertise(); IEnumerable <Language> languages = first.DetectLanguage(text); var language = languages.OrderByDescending(x => x.Percent).First(); _dictionaryService.AddWord(text, language.Name); return(languages.Select(l => new LanguageDto { Name = l.Name, Percentage = l.Percent }).ToList()); } else { return(new List <LanguageDto>() { new LanguageDto() { Name = dictionary.Language, Percentage = 100 } }); } }