public void EnsureInputCanBeSortedCorrectly() { var nameController = new NameController(_mockSortFactory.Object); Mock <ISort> mockSort = new Mock <ISort>(); var testData = new [] { new FullName { LastName = "Lewis", GivenNames = new[] { "Vaughn" } }, new FullName { LastName = "Parsons", GivenNames = new[] { "Janet" } } }; mockSort.Setup(obj => obj.Sort(It.IsAny <FullName[]>())).Returns(testData); _mockSortFactory.Setup(obj => obj.Get(It.IsAny <SortType>())). Returns(mockSort.Object); var res = nameController.SortName(new SortNameRequest { NameContent = "Janet Parsons" }); Assert.NotNull(res); Assert.NotNull(res.Value); Assert.Equal("Vaughn Lewis", res.Value.SortedNames[0]); Assert.Equal("Janet Parsons", res.Value.SortedNames[1]); }
public void EnsureThrowExceptionWhenInputIsNullOrEmpty(string input) { var nameController = new NameController(_mockSortFactory.Object); var res = Assert.Throws <BusinessException>(() => nameController.SortName(new SortNameRequest { NameContent = input, SortType = SortType.LastNameThenGivenName })); Assert.Equal("No name to be sorted.", res.Message); }
public void EnsureThrowExceptionWhenNoSorterCreatedFromFactory() { var nameController = new NameController(_mockSortFactory.Object); _mockSortFactory.Setup(obj => obj.Get(It.IsAny <SortType>())). Returns((ISort)null); var res = Assert.Throws <BusinessException>(() => nameController.SortName(new SortNameRequest { NameContent = "Janet Parsons" })); Assert.Equal("No name sorter found that can handle requested sort type.", res.Message); }