public void SortText_Desc_SortDesc() { //Given RegExProvider.Setup(x => x.GetMatches(It.IsAny <string>(), It.IsAny <string>())).Returns(new List <string>() { "1", "2", "3" }); var parameters = new SortParameters() { Asc = false, SortOptions = SortOptions.AlphabeticOrder, Text = "Text" }; //When SortTextModel result = SortService.SortText(parameters); //Then Assert.IsNotNull(result); Assert.AreEqual(3, result.SortedText.Count()); Assert.AreEqual("3", result.SortedText.First()); Assert.AreEqual("2", result.SortedText.ElementAt(1)); Assert.AreEqual("1", result.SortedText.Last()); }
public SortTextModel SortText(SortParameters parameters) { if (parameters == null || parameters.Text == null) { throw new ArgumentNullException(); } var sortStrategy = GetSortStrategy(parameters.SortOptions); SortTextModel result = sortStrategy.Sort(parameters.Text, parameters.Asc); return(result); }
public SortTextModel Sort(string text, bool asc) { if (text == null) { throw new ArgumentNullException(); } IEnumerable <string> matches = regExProvider.GetMatches(text, Match); var result = new SortTextModel() { SortedText = Sort(matches, asc) }; return(result); }