示例#1
0
        public void Call_CollectionRepository_All_Once()
        {
            // Arrange
            this.collectionRepositoryStub
            .Setup(x => x.All)
            .Returns(
                new List <Collection>()
            {
                new Collection()
                {
                    Id = "collectionId"
                }
            }.AsQueryable()
                )
            .Verifiable();

            var collectionService = new global::RTWTR.Service.Data.CollectionService(
                saverStub.Object,
                mapperStub.Object,
                collectionRepositoryStub.Object,
                tweetRepositoryStub.Object,
                collectionTweetsRepositoryStub.Object
                );

            // Act
            collectionService.RemoveCollection("collectionId");

            // Assert
            this.collectionRepositoryStub.Verify(
                x => x.All,
                Times.Once
                );
        }
示例#2
0
        public void Call_Mapper_ProjectTo_Once()
        {
            // Arrange
            this.collectionRepositoryStub
            .Setup(x => x.All)
            .Returns(new List <Collection>()
            {
                new Collection()
                {
                    UserId = "userId"
                }
            }.AsQueryable());

            this.mapperStub
            .Setup(x => x.ProjectTo <CollectionDTO>(It.IsAny <IQueryable <Collection> >()))
            .Verifiable();

            var collectionService = new global::RTWTR.Service.Data.CollectionService(
                this.saverStub.Object,
                this.mapperStub.Object,
                this.collectionRepositoryStub.Object,
                this.tweetRepositoryStub.Object,
                this.collectionTweetsRepositoryStub.Object
                );

            // Act
            collectionService.GetUserCollections("userId");

            // Assert
            this.mapperStub.Verify(
                x => x.ProjectTo <CollectionDTO>(It.IsAny <IQueryable <Collection> >()),
                Times.Once
                );
        }
示例#3
0
        public void ReturnOne_When_CollectionSuccessfullyRemoved()
        {
            // Arrange
            this.collectionRepositoryStub
            .Setup(x => x.All)
            .Returns(
                new List <Collection>()
            {
                new Collection()
                {
                    Id = "collectionId"
                }
            }.AsQueryable()
                );

            this.saverStub
            .Setup(x => x.SaveChanges())
            .Returns(1);

            var collectionService = new global::RTWTR.Service.Data.CollectionService(
                saverStub.Object,
                mapperStub.Object,
                collectionRepositoryStub.Object,
                tweetRepositoryStub.Object,
                collectionTweetsRepositoryStub.Object
                );

            // Act & Assert
            Assert.AreEqual(
                1,
                collectionService.RemoveCollection("collectionId")
                );
        }
示例#4
0
        public void Throw_NullTweetException_When_TweetIsNotFound()
        {
            // Arrange
            this.collectionsRepositoryStub
            .Setup(x => x.All)
            .Returns(
                new List <Collection>()
            {
                new Collection()
                {
                    Id = "collectionId"
                }
            }.AsQueryable()
                );

            var collectionServie = new global::RTWTR.Service.Data.CollectionService(
                this.saverStub.Object,
                this.mapperStub.Object,
                this.collectionsRepositoryStub.Object,
                this.tweetsRepositoryStub.Object,
                this.collectionTweetsRepositoryStub.Object
                );

            // Act & Assert
            Assert.ThrowsException <NullTweetException>(() =>
            {
                collectionServie.AddTweetToCollection("collectionId", "tweetId");
            });
        }
示例#5
0
        public void NotReturnNull_When_InvokedWithCorrectParameters()
        {
            // Arrange & Act
            var collectionServiceMock = new global::RTWTR.Service.Data.CollectionService(
                this.saverStub.Object,
                this.mapperStub.Object,
                this.collectionRepositoryStub.Object,
                this.tweetRepositoryStub.Object,
                this.collectionTweetsRepositoryStub.Object
                );

            // Assert
            Assert.IsNotNull(collectionServiceMock);
        }
示例#6
0
        public void Call_Saver_SaveChanges_Once()
        {
            // Arrange
            this.saverStub
            .Setup(x => x.SaveChanges())
            .Returns(1)
            .Verifiable();

            this.collectionsRepositoryStub
            .Setup(x => x.All)
            .Returns(
                new List <Collection>()
            {
                new Collection()
                {
                    Id = "collectionId"
                }
            }.AsQueryable()
                );

            this.tweetsRepositoryStub
            .Setup(x => x.All)
            .Returns(
                new List <Tweet>()
            {
                new Tweet()
                {
                    Id = "tweetId"
                }
            }.AsQueryable()
                );

            var collectionServie = new global::RTWTR.Service.Data.CollectionService(
                this.saverStub.Object,
                this.mapperStub.Object,
                this.collectionsRepositoryStub.Object,
                this.tweetsRepositoryStub.Object,
                this.collectionTweetsRepositoryStub.Object
                );

            // Act
            collectionServie.AddTweetToCollection("collectionId", "tweetId");

            // Assert
            this.saverStub.Verify(
                x => x.SaveChanges(),
                Times.Once
                );
        }
示例#7
0
        public void Call_CollectionTweetRepository_Delete_Once()
        {
            // Arrange
            this.collectionTweetsRepositoryStub
            .Setup(x => x.Delete(It.IsAny <CollectionTweet>()))
            .Verifiable();

            this.collectionsRepositoryStub
            .Setup(x => x.All)
            .Returns(
                new List <Collection>()
            {
                new Collection()
                {
                    Id = "collectionId"
                }
            }.AsQueryable()
                );

            this.tweetsRepositoryStub
            .Setup(x => x.All)
            .Returns(
                new List <Tweet>()
            {
                new Tweet()
                {
                    Id = "tweetId"
                }
            }.AsQueryable()
                );

            var collectionServie = new global::RTWTR.Service.Data.CollectionService(
                this.saverStub.Object,
                this.mapperStub.Object,
                this.collectionsRepositoryStub.Object,
                this.tweetsRepositoryStub.Object,
                this.collectionTweetsRepositoryStub.Object
                );

            // Act
            collectionServie.RemoveTweetFromCollection("collectionId", "tweetId");

            // Assert
            this.collectionTweetsRepositoryStub.Verify(
                x => x.Delete(It.IsAny <CollectionTweet>()),
                Times.Once
                );
        }
示例#8
0
        public void Throw_NullCollectionException_When_CollectionIsNotFound()
        {
            // Arrange
            var collectionService = new global::RTWTR.Service.Data.CollectionService(
                saverStub.Object,
                mapperStub.Object,
                collectionRepositoryStub.Object,
                tweetRepositoryStub.Object,
                collectionTweetsRepositoryStub.Object
                );

            // Act & Assert
            Assert.ThrowsException <NullCollectionException>(() =>
            {
                collectionService.RemoveCollection("collectionId");
            });
        }
示例#9
0
        public void Throw_InvalidCollectionIdException_When_InvokedWithEmptyCollectionId()
        {
            // Arrange
            var collectionService = new global::RTWTR.Service.Data.CollectionService(
                saverStub.Object,
                mapperStub.Object,
                collectionRepositoryStub.Object,
                tweetRepositoryStub.Object,
                collectionTweetsRepositoryStub.Object
                );

            // Act & Assert
            Assert.ThrowsException <InvalidCollectionIdException>(() =>
            {
                collectionService.RemoveCollection(" ");
            });
        }
示例#10
0
        public void ReturnNull_When_InvokedWithNullUserId()
        {
            // Arrange
            var collectionService = new global::RTWTR.Service.Data.CollectionService(
                this.saverStub.Object,
                this.mapperStub.Object,
                this.collectionRepositoryStub.Object,
                this.tweetRepositoryStub.Object,
                this.collectionTweetsRepositoryStub.Object
                );

            // Act & Assert
            Assert.ThrowsException <InvalidUserIdException>(() =>
            {
                collectionService.GetUserCollections(null);
            });
        }
示例#11
0
        public void Throw_InvalidTweetIdException_When_TweetIdIsEmpty()
        {
            // Arrange
            var collectionServie = new global::RTWTR.Service.Data.CollectionService(
                this.saverStub.Object,
                this.mapperStub.Object,
                this.collectionsRepositoryStub.Object,
                this.tweetsRepositoryStub.Object,
                this.collectionTweetsRepositoryStub.Object
                );

            // Act & Assert
            Assert.ThrowsException <InvalidTweetIdException>(() =>
            {
                collectionServie.AddTweetToCollection("collectionId", " ");
            });
        }
示例#12
0
        public void Throw_NullCollectionException_When_CollectionIsNotFound()
        {
            // Arrange
            var collectionServie = new global::RTWTR.Service.Data.CollectionService(
                this.saverStub.Object,
                this.mapperStub.Object,
                this.collectionsRepositoryStub.Object,
                this.tweetsRepositoryStub.Object,
                this.collectionTweetsRepositoryStub.Object
                );

            // Act & Assert
            Assert.ThrowsException <NullCollectionException>(() =>
            {
                collectionServie.AddTweetToCollection("collectionId", "tweetId");
            });
        }
示例#13
0
        public void Throw_InvalidCollectionIdException_When_CollectionIdIsNull()
        {
            // Arrange
            var collectionServie = new global::RTWTR.Service.Data.CollectionService(
                this.saverStub.Object,
                this.mapperStub.Object,
                this.collectionsRepositoryStub.Object,
                this.tweetsRepositoryStub.Object,
                this.collectionTweetsRepositoryStub.Object
                );

            // Act & Assert
            Assert.ThrowsException <InvalidCollectionIdException>(() =>
            {
                collectionServie.RemoveTweetFromCollection(null, "tweetId");
            });
        }
示例#14
0
        public void Return_One_When_SuccessfullyAddedUserToFavourites()
        {
            // Arrange
            this.saverStub
            .Setup(x => x.SaveChanges())
            .Returns(1);

            this.collectionsRepositoryStub
            .Setup(x => x.All)
            .Returns(
                new List <Collection>()
            {
                new Collection()
                {
                    Id = "collectionId"
                }
            }.AsQueryable()
                );

            this.tweetsRepositoryStub
            .Setup(x => x.All)
            .Returns(
                new List <Tweet>()
            {
                new Tweet()
                {
                    Id = "tweetId"
                }
            }.AsQueryable()
                );

            var collectionServie = new global::RTWTR.Service.Data.CollectionService(
                this.saverStub.Object,
                this.mapperStub.Object,
                this.collectionsRepositoryStub.Object,
                this.tweetsRepositoryStub.Object,
                this.collectionTweetsRepositoryStub.Object
                );

            // Act & Assert
            Assert.AreEqual(
                1,
                collectionServie.AddTweetToCollection("collectionId", "tweetId")
                );
        }
示例#15
0
        public void ReturnZeroCollections_When_UserHasNoCollections()
        {
            // Arrange
            this.mapperStub
            .Setup(x => x.ProjectTo <CollectionDTO>(It.IsAny <IQueryable <object> >()))
            .Returns(new List <CollectionDTO>().AsQueryable());

            var collectionService = new global::RTWTR.Service.Data.CollectionService(
                this.saverStub.Object,
                this.mapperStub.Object,
                this.collectionRepositoryStub.Object,
                this.tweetRepositoryStub.Object,
                this.collectionTweetsRepositoryStub.Object
                );

            // Act & Assert
            Assert.AreEqual(
                0,
                collectionService.GetUserCollections("userId").Count()
                );
        }
示例#16
0
        public void ReturnCorrectCollections_When_UserIsValid()
        {
            // Arrange
            this.collectionRepositoryStub
            .Setup(x => x.All)
            .Returns(
                new List <Collection>()
            {
                new Collection()
                {
                    Name = "nope", UserId = "notThisOne"
                },
                new Collection()
                {
                    Name = "test1", UserId = "userId"
                },
                new Collection()
                {
                    Name = "test2", UserId = "userId"
                }
            }.AsQueryable());

            this.mapperStub
            .Setup(x => x.ProjectTo <CollectionDTO>(It.IsAny <IQueryable <object> >()))
            .Returns(
                new List <CollectionDTO>()
            {
                new CollectionDTO()
                {
                    Name = "test1"
                },
                new CollectionDTO()
                {
                    Name = "test2"
                }
            }.AsQueryable());

            var collectionService = new global::RTWTR.Service.Data.CollectionService(
                this.saverStub.Object,
                this.mapperStub.Object,
                this.collectionRepositoryStub.Object,
                this.tweetRepositoryStub.Object,
                this.collectionTweetsRepositoryStub.Object
                );

            // Act
            var collections = collectionService.GetUserCollections("userId").ToList();

            // Assert
            Assert.AreEqual(
                2,
                collections.Count()
                );

            Assert.AreEqual(
                "test1",
                collections[0].Name
                );

            Assert.AreEqual(
                "test2",
                collections[1].Name
                );
        }