public void Throw_ArgumentException_When_TweetIsNotAFavourite() { // Arrange this.tweetRepositoryStub .Setup(x => x.All) .Returns( new List <Tweet>() { new Tweet { Id = "tweetId", TwitterId = "tweetId" } }.AsQueryable()); var tweetService = new global::RTWTR.Service.Data.TweetService( this.saverStub.Object, this.mapperStub.Object, this.tweetRepositoryStub.Object, this.userTweetsStub.Object ); Assert.ThrowsException <ArgumentException>(() => { tweetService.RemoveTweetFromFavourites("tweetId", "userId"); }); }
public void Throw_NullTweetException_When_TweetIsNotFound() { // Arrange this.tweetRepositoryStub .Setup(x => x.All) .Returns( new List <Tweet>() { }.AsQueryable()); var tweetService = new global::RTWTR.Service.Data.TweetService( this.saverStub.Object, this.mapperStub.Object, this.tweetRepositoryStub.Object, this.userTweetsStub.Object ); Assert.ThrowsException <NullTweetException>(() => { tweetService.RemoveTweetFromFavourites("tweetId", "userId"); }); this.tweetRepositoryStub.Verify( x => x.All, Times.Once ); }
public void Return_One_When_TweetSuccessfullyReRemoved() { // Arrange this.tweetRepositoryStub .Setup(x => x.All) .Returns( new List <Tweet>() { new Tweet { Id = "tweetId", TwitterId = "tweetId" } }.AsQueryable()); this.userTweetsStub .Setup(x => x.All) .Returns( new List <UserTweet>() { new UserTweet { TweetId = "tweetId", UserId = "userId" } }.AsQueryable() ); this.userTweetsStub .Setup(x => x.Delete(It.IsAny <UserTweet>())) .Verifiable(); this.saverStub .Setup(x => x.SaveChanges()) .Returns(1); var tweetService = new global::RTWTR.Service.Data.TweetService( this.saverStub.Object, this.mapperStub.Object, this.tweetRepositoryStub.Object, this.userTweetsStub.Object ); // Act var actual = tweetService.RemoveTweetFromFavourites( "tweetId", "userId" ); // Assert Assert.AreEqual( 1, actual ); this.userTweetsStub.Verify( x => x.Delete(It.IsAny <UserTweet>()), Times.Once ); }
public void Throw_ArgumentException_When_TweetAlreadyFavourite() { // Arrange this.userTweetsStub .Setup(x => x.AllAndDeleted) .Returns( new List<UserTweet>() { new UserTweet { TweetId = "tweetId", UserId = "userId", IsDeleted = false } }.AsQueryable() ) .Verifiable(); this.userTweetsStub .Setup(x => x.Update(It.IsAny<UserTweet>())) .Verifiable(); this.tweetRepositoryStub .Setup(x => x.All) .Returns( new List<Tweet>() { new Tweet { Id = "tweetId", TwitterId = "tweetId", IsDeleted = false } }.AsQueryable()); this.tweetRepositoryStub .Setup(x => x.AllAndDeleted) .Returns( new List<Tweet>() { new Tweet { Id = "tweetId", TwitterId = "tweetId" } }.AsQueryable()); this.mapperStub .Setup(x => x.MapTo<User>(It.IsAny<UserDTO>())) .Returns(new User { Id = "userId" }); this.saverStub .Setup(x => x.SaveChanges()) .Returns(1); var userDtoStub = new UserDTO(); var tweetService = new global::RTWTR.Service.Data.TweetService( this.saverStub.Object, this.mapperStub.Object, this.tweetRepositoryStub.Object, this.userTweetsStub.Object ); Assert.ThrowsException<ArgumentException>(() => { tweetService.AddTweetToFavourites("tweetId", userDtoStub); }); }
public void NotReturnNull_When_InvokedWithCorrectParameters() { // Arrange & Act var tweetService = new global::RTWTR.Service.Data.TweetService( this.saverStub.Object, this.mappingProviderStub.Object, this.tweetRepositoryStub.Object, this.UserTweetStub.Object ); // Assert Assert.IsNotNull(tweetService); }
public void Throw_NullUserException_When_UserDtoIsNull() { // Arrange var tweetService = new global::RTWTR.Service.Data.TweetService( this.saverStub.Object, this.mapperStub.Object, this.tweetRepositoryStub.Object, this.userTweetsStub.Object ); // Act & Assert Assert.ThrowsException<NullUserException>(() => tweetService.AddTweetToFavourites("tweetId", null) ); }
public void Throw_InvalidUserIdException_When_UserIdIsWhitespace() { // Arrange var tweetService = new global::RTWTR.Service.Data.TweetService( this.saverStub.Object, this.mapperStub.Object, this.tweetRepositoryStub.Object, this.userTweetsStub.Object ); // Act & Assert Assert.ThrowsException <InvalidUserIdException>(() => { tweetService.RemoveTweetFromFavourites("tweetId", " "); }); }
public void Return_One_When_TweetSuccessfullyAdded() { // Arrange this.userTweetsStub .Setup(x => x.Add(It.IsAny<UserTweet>())) .Verifiable(); this.tweetRepositoryStub .Setup(x => x.All) .Returns( new List<Tweet>() { new Tweet { TwitterId = "tweetId" } }.AsQueryable()); this.mapperStub .Setup(x => x.MapTo<User>(It.IsAny<UserDTO>())) .Returns(new User { Id = "userId" }); this.saverStub .Setup(x => x.SaveChanges()) .Returns(1); var userDtoStub = new UserDTO(); var tweetService = new global::RTWTR.Service.Data.TweetService( this.saverStub.Object, this.mapperStub.Object, this.tweetRepositoryStub.Object, this.userTweetsStub.Object ); var actual = tweetService.AddTweetToFavourites( "tweetId", userDtoStub ); Assert.AreEqual( 1, actual ); this.userTweetsStub.Verify( x => x.Add(It.IsAny<UserTweet>()), Times.Once ); }
public void Throw_InvalidTweetIdException_When_TweetIdIsWhitespace() { // Arrange var userDtoStub = new UserDTO(); var tweetService = new global::RTWTR.Service.Data.TweetService( this.saverStub.Object, this.mapperStub.Object, this.tweetRepositoryStub.Object, this.userTweetsStub.Object ); // Act & Assert Assert.ThrowsException<InvalidTweetIdException>(() => tweetService.AddTweetToFavourites(" ", userDtoStub) ); }