Example #1
0
        public async Task ReturnCorrectCountOfSongsWhenThePassedQueryContainsNonEmptySearchTerm()
        {
            int expectedSongsCount = 1;

            var songs = new[]
            {
                new Song()
                {
                    IsApproved = false, Title = "Aenean tempus"
                },
                new Song()
                {
                    IsApproved = false, Title = "Odio lacus"
                },
                new Song()
                {
                    IsApproved = false, Title = "Fusce eu libero"
                },
                new Song()
                {
                    IsApproved = true, Title = "Aenean elementum"
                }
            }
            .AsQueryable()
            .BuildMock();

            var songRepositoryStub = new Mock <IEfRepository <Song> >();

            songRepositoryStub
            .Setup(x => x.All(It.IsAny <bool>()))
            .Returns(songs.Object);

            GetSongsCount query = new GetSongsCount()
            {
                Approved   = false,
                SearchInfo = new SearchInfo("aenean")
            };

            // Arrange
            GetSongsCountQueryService sut =
                new GetSongsCountQueryService(songRepositoryStub.Object);

            // Act
            int actualSongsCount = await sut.ExecuteAsync(query);

            // Assert
            Assert.AreEqual(expectedSongsCount, actualSongsCount);
        }
Example #2
0
        public async Task ReturnTheCorrectCountOfUnapprovedSongsOnlyWhenInvoked()
        {
            int expectedSongsCount = 3;

            var songs = new[]
            {
                new Song()
                {
                    IsApproved = false, Title = string.Empty
                },
                new Song()
                {
                    IsApproved = false, Title = string.Empty
                },
                new Song()
                {
                    IsApproved = false, Title = string.Empty
                },
                new Song()
                {
                    IsApproved = true, Title = string.Empty
                }
            }
            .AsQueryable()
            .BuildMock();

            var songRepositoryStub = new Mock <IEfRepository <Song> >();

            songRepositoryStub
            .Setup(x => x.All(It.IsAny <bool>()))
            .Returns(songs.Object);

            GetSongsCount query = new GetSongsCount()
            {
                Approved   = false,
                SearchInfo = new SearchInfo(null)
            };

            // Arrange
            GetSongsCountQueryService sut =
                new GetSongsCountQueryService(songRepositoryStub.Object);

            // Act
            int actualSongsCount = await sut.ExecuteAsync(query);

            // Assert
            Assert.AreEqual(expectedSongsCount, actualSongsCount);
        }
Example #3
0
        public void SavePassedSongRepositoryWhenIsNotNull()
        {
            var songRepositoryStub = new Mock <IEfRepository <Song> >();

            // Arrange && Act
            GetSongsCountQueryService sut =
                new GetSongsCountQueryService(
                    songRepository: songRepositoryStub.Object);

            // Assert
            var actualSongProvider = sut.GetType()
                                     .GetFields(BindingFlags.Instance | BindingFlags.NonPublic)
                                     .First(fi => fi.FieldType == typeof(IEfRepository <Song>))
                                     .GetValue(sut);

            Assert.AreSame(songRepositoryStub.Object, actualSongProvider);
        }