Пример #1
0
        public void Call_UserTwitterUserRepository_All_Once()
        {
            // Arrange
            this.userTwitterUserRepositoryStub
            .Setup(x => x.All)
            .Returns(
                new List <UserTwitterUser>()
            {
                new UserTwitterUser()
                {
                    UserId = "userId"
                }
            }.AsQueryable()
                )
            .Verifiable();

            var favouriteUserService = new global::RTWTR.Service.Data.FavouriteUserService(
                this.saverStub.Object,
                this.mapperStub.Object,
                this.userTwitterUserRepositoryStub.Object
                );

            // Act
            favouriteUserService.GetUserFavourites("userId");

            // Assert
            this.userTwitterUserRepositoryStub.Verify(
                x => x.All,
                Times.Once
                );
        }
Пример #2
0
        public void Return_UserFavourites_When_UserIdIsValid()
        {
            // Arrange
            this.userTwitterUserRepositoryStub
            .Setup(x => x.All)
            .Returns(
                new List <UserTwitterUser>()
            {
                new UserTwitterUser()
                {
                    UserId = "userId"
                }
            }.AsQueryable()
                );

            this.mapperStub
            .Setup(x => x.MapTo <List <TwitterUserDto> >(It.IsAny <IQueryable <TwitterUser> >()))
            .Returns(
                new List <TwitterUserDto>()
            {
                new TwitterUserDto()
                {
                    Name = "twitterUser"
                }
            }
                );

            var favouriteUserService = new global::RTWTR.Service.Data.FavouriteUserService(
                this.saverStub.Object,
                this.mapperStub.Object,
                this.userTwitterUserRepositoryStub.Object
                );

            // Act
            var favourites = favouriteUserService
                             .GetUserFavourites("userId")
                             .ToList();

            // Assert
            Assert.AreEqual(
                1,
                favourites.Count()
                );

            Assert.AreEqual(
                "twitterUser",
                favourites[0].Name
                );
        }
Пример #3
0
        public void Throw_InvalidUserIdException_When_UserIdIsEmpty()
        {
            // Arrange
            var favouriteUserService = new global::RTWTR.Service.Data.FavouriteUserService(
                this.saverStub.Object,
                this.mapperStub.Object,
                this.userTwitterUserRepositoryStub.Object
                );

            // Act & Assert
            Assert.ThrowsException <InvalidUserIdException>(() =>
            {
                favouriteUserService.GetUserFavourites(" ");
            });
        }
Пример #4
0
        public void Call_Mapper_MapTo_Once()
        {
            // Arrange
            this.userTwitterUserRepositoryStub
            .Setup(x => x.All)
            .Returns(
                new List <UserTwitterUser>()
            {
                new UserTwitterUser()
                {
                    UserId = "userId"
                }
            }.AsQueryable()
                );

            this.mapperStub
            .Setup(x => x.MapTo <List <TwitterUserDto> >(It.IsAny <IQueryable <TwitterUser> >()))
            .Returns(
                new List <TwitterUserDto>()
            {
                new TwitterUserDto()
                {
                    Name = "twitterUser"
                }
            }
                )
            .Verifiable();

            var favouriteUserService = new global::RTWTR.Service.Data.FavouriteUserService(
                this.saverStub.Object,
                this.mapperStub.Object,
                this.userTwitterUserRepositoryStub.Object
                );

            // Act
            favouriteUserService.GetUserFavourites("userId");

            // Assert
            this.mapperStub.Verify(
                x => x.MapTo <List <TwitterUserDto> >(It.IsAny <IQueryable <TwitterUser> >()),
                Times.Once
                );
        }
Пример #5
0
        public void Return_NoFavourites_When_UserHasNoFavourites()
        {
            // Arrange
            this.mapperStub
            .Setup(x => x.MapTo <List <TwitterUserDto> >(It.IsAny <IQueryable <TwitterUser> >()))
            .Returns(new List <TwitterUserDto>());

            var favouriteUserService = new global::RTWTR.Service.Data.FavouriteUserService(
                this.saverStub.Object,
                this.mapperStub.Object,
                this.userTwitterUserRepositoryStub.Object
                );

            // Act
            var favourites = favouriteUserService
                             .GetUserFavourites("userId");

            // Assert
            Assert.AreEqual(
                0,
                favourites.Count
                );
        }