コード例 #1
0
        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]);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }