Пример #1
0
        public void RepositoryContainsAds_ShouldReturnAds()
        {
            // arrange
            AdRepositoryMock.Setup(m => m.Get()).Returns(new List <Ad>
            {
                new Ad {
                    Body = "meh"
                }
            });
            var sut = new AdService(AdRepositoryMock.Object);
            // act
            var result = sut.Get(OrderAdBy.Time);

            // assert
            Assert.NotEmpty(result);
        }
Пример #2
0
        public void RepositoryContainsAds_ShouldReturnSortedAds()
        {
            // arrange
            var secondOldest = new Ad
            {
                Subject = "secondOldest",
                Created = new DateTime(2001, 01, 25)
            };
            var oldest = new Ad
            {
                Subject = "oldest",
                Created = new DateTime(2000, 04, 12)
            };
            var newest = new Ad
            {
                Subject = "newest",
                Created = new DateTime(2019, 08, 11)
            };
            var secondNewest = new Ad
            {
                Subject = "secondNewest",
                Created = new DateTime(2018, 09, 29)
            };
            var ads = new List <Ad> {
                secondOldest, oldest, newest, secondNewest
            };

            AdRepositoryMock.Setup(m => m.Get()).Returns(ads);
            var sut = new AdService(AdRepositoryMock.Object);
            // act
            var result = sut.Get(OrderAdBy.Time).Select(a => a.Created);
            // assert
            var sorted =
                new List <Ad> {
                newest, secondNewest, secondOldest, oldest
            }
            .Select(a => a.Created);

            Assert.True(sorted.SequenceEqual(result));
        }