public void ThrowArgumentException_WhenInvokedWithInvalidEmptyUserIdParameter()
        {
            //Arrange
            var unitOfWorkMock               = new Mock <IUnitOfWork>();
            var mappingProviderMock          = new Mock <IMappingProvider>();
            var userRepositoryMock           = new Mock <IUserRepository>();
            var twitterAccountRepositoryMock = new Mock <ITwitterAccountRepository>();

            string userId         = string.Empty;
            var    twitterAccount = new TwitterAccount()
            {
                Name = "Marto Stamatov"
            };
            var expectedResult = new TwitterAccountDto()
            {
                Name = "Marto Stamatov"
            };

            twitterAccountRepositoryMock
            .Setup(x => x.Get(userId))
            .ReturnsAsync(twitterAccount);

            mappingProviderMock
            .Setup(x => x.MapTo <TwitterAccountDto>(twitterAccount))
            .Returns(expectedResult);

            var twitterAccountService = new TwitterAccountService(
                unitOfWorkMock.Object,
                mappingProviderMock.Object,
                userRepositoryMock.Object,
                twitterAccountRepositoryMock.Object);

            //Act && Assert
            Assert.ThrowsExceptionAsync <ArgumentException>(async() => await twitterAccountService.GetTwitterAccountById(userId));
        }
Ejemplo n.º 2
0
        public async Task ReturnCollectionOfTwitterAccountDtobjects_WhenInvokedWithValidParameter()
        {
            //Arrange
            var unitOfWorkMock      = new Mock <IUnitOfWork>();
            var mappingProviderMock = new Mock <IMappingProvider>();
            var userRepositoryMock  = new Mock <IUserRepository>();
            var twitterServiceMock  = new Mock <ITwitterService>();
            var userManagerMock     = MockUserManager <User>();

            var userId         = "30";
            var twitterAccount = new TwitterAccount()
            {
                Name = "Grigor", Id = "30"
            };
            var twitterAccounts = new List <TwitterAccount>()
            {
                twitterAccount
            };

            var twitterAccountDto = new TwitterAccountDto()
            {
                Name = "Grigor", Id = "30"
            };
            var expectedResult = new List <TwitterAccountDto>()
            {
                twitterAccountDto
            };

            userRepositoryMock
            .Setup(x => x.GetAllFavoriteTwitterAccounts(userId))
            .ReturnsAsync(twitterAccounts);

            mappingProviderMock
            .Setup(x => x.ProjectTo <TwitterAccount, TwitterAccountDto>(twitterAccounts))
            .Returns(expectedResult);

            var userService = new UserService(
                unitOfWorkMock.Object,
                mappingProviderMock.Object,
                userRepositoryMock.Object,
                twitterServiceMock.Object,
                userManagerMock.Object);

            //Act
            var actualResult = await userService.GetAllFavoriteTwitterAccounts(userId);

            //Assert
            Assert.IsNotNull(actualResult);
        }
Ejemplo n.º 3
0
        public void FindAllTest()
        {
            var mockJsonProvider = new Mock <IJsonProvider>();
            var account1         = new TwitterAccountDto(1, "", "", "");
            var list             = new List <TwitterAccountDto>
            {
                account1
            };

            mockJsonProvider.Setup((jsonProvider) => jsonProvider.Restore(It.IsAny <string>(), It.IsAny <List <TwitterAccountDto> >()))
            .Returns(list);
            var dao = new TwitterAccountDao(() => mockJsonProvider.Object);

            Assert.Equal(list, dao.FindAll());
        }
Ejemplo n.º 4
0
        public void ShouldGetAccount()
        {
            //Arrange
            var socialAccountService = new Mock <ISocialAccountService>();

            socialAccountService.Setup(t => t.FindAccount(1, SocialUserSource.Twitter)).Returns(
                new SocialAccount {
                Id = 1
            });
            TwitterAccountAppService TwitterAccountAppService = new TwitterAccountAppService(socialAccountService.Object, null);
            //Act
            TwitterAccountDto twitterAccountDto = TwitterAccountAppService.GetAccount(1);

            //Assert
            Assert.NotNull(twitterAccountDto);
            Assert.Equal(1, twitterAccountDto.Id);
        }
Ejemplo n.º 5
0
        public void ThrowArgumentNullException_WhenInvokedWithInvalidNullIdParameter()
        {
            //Arrange
            var unitOfWorkMock      = new Mock <IUnitOfWork>();
            var mappingProviderMock = new Mock <IMappingProvider>();
            var userRepositoryMock  = new Mock <IUserRepository>();
            var twitterServiceMock  = new Mock <ITwitterService>();
            var userManagerMock     = MockUserManager <User>();

            var userId         = "30";
            var twitterAccount = new TwitterAccount()
            {
                Name = "Grigor", Id = "30"
            };
            var twitterAccounts = new List <TwitterAccount>()
            {
                twitterAccount
            };

            var twitterAccountDto = new TwitterAccountDto()
            {
                Name = "Grigor", Id = "30"
            };
            var expectedResult = new List <TwitterAccountDto>()
            {
                twitterAccountDto
            };

            userRepositoryMock
            .Setup(x => x.GetAllFavoriteTwitterAccounts(userId))
            .ReturnsAsync(twitterAccounts);

            mappingProviderMock
            .Setup(x => x.ProjectTo <TwitterAccount, TwitterAccountDto>(twitterAccounts))
            .Returns(expectedResult);

            var userService = new UserService(
                unitOfWorkMock.Object,
                mappingProviderMock.Object,
                userRepositoryMock.Object,
                twitterServiceMock.Object,
                userManagerMock.Object);

            //Act && Assert
            Assert.ThrowsExceptionAsync <ArgumentNullException>(async() => await userService.GetAllFavoriteTwitterAccounts(null));
        }
Ejemplo n.º 6
0
        public void AddTest()
        {
            var mockJsonProvider = new Mock <IJsonProvider>();
            var newAccount       = new TwitterAccountDto(0, "", "", "");
            var list             = new List <TwitterAccountDto>
            {
                new TwitterAccountDto(1, "", "", "")
            };

            mockJsonProvider.Setup((jsonProvider) => jsonProvider.Restore(It.IsAny <string>(), It.IsAny <List <TwitterAccountDto> >())).Returns(list);

            var dao = new TwitterAccountDao(() => mockJsonProvider.Object);

            dao.Add(newAccount);

            Assert.Equal(new List <TwitterAccountDto> {
                list[0], newAccount
            }, dao.FindAll());
        }
Ejemplo n.º 7
0
        public void ShouldUpdateAccount()
        {
            //Arrange
            var socialAccountService = new Mock <ISocialAccountService>();

            socialAccountService.Setup(t => t.FindAccount(1, SocialUserSource.Twitter)).Returns(
                new SocialAccount {
                Id = 1
            });
            TwitterAccountAppService TwitterAccountAppService = new TwitterAccountAppService(socialAccountService.Object, null);
            //Act
            TwitterAccountDto twitterAccountDto = TwitterAccountAppService.UpdateAccount(1, new UpdateTwitterAccountDto {
                IfEnable = true
            });

            //Assert
            Assert.NotNull(twitterAccountDto);
            socialAccountService.Verify(t => t.Update(It.Is <SocialAccount>(r => r.Id == 1 && r.IfEnable == true)));
            Assert.Equal(1, twitterAccountDto.Id);
            Assert.Equal(true, twitterAccountDto.IfEnable);
        }
        public async Task ReturnTwitterAccount_WhenInvokedWithValidIdParameter()
        {
            //Arrange
            var unitOfWorkMock               = new Mock <IUnitOfWork>();
            var mappingProviderMock          = new Mock <IMappingProvider>();
            var userRepositoryMock           = new Mock <IUserRepository>();
            var twitterAccountRepositoryMock = new Mock <ITwitterAccountRepository>();

            var userId         = "30";
            var twitterAccount = new TwitterAccount()
            {
                Name = "Marto Stamatov"
            };
            var expectedResult = new TwitterAccountDto()
            {
                Name = "Marto Stamatov"
            };

            twitterAccountRepositoryMock
            .Setup(x => x.Get(userId))
            .ReturnsAsync(twitterAccount);

            mappingProviderMock
            .Setup(x => x.MapTo <TwitterAccountDto>(twitterAccount))
            .Returns(expectedResult);

            var twitterAccountService = new TwitterAccountService(
                unitOfWorkMock.Object,
                mappingProviderMock.Object,
                userRepositoryMock.Object,
                twitterAccountRepositoryMock.Object);

            //Act
            var actualResult = await twitterAccountService.GetTwitterAccountById(userId);

            //Assert
            Assert.IsNotNull(actualResult);
            Assert.AreEqual(actualResult.Name, expectedResult.Name);
        }
Ejemplo n.º 9
0
        public async Task ReturnEmptyCollectionOfTweets_WhenThereIsNotTwitterAccounts()
        {
            //Arrange
            var unitOfWorkMock      = new Mock <IUnitOfWork>();
            var mappingProviderMock = new Mock <IMappingProvider>();
            var userRepositoryMock  = new Mock <IUserRepository>();
            var twitterServiceMock  = new Mock <ITwitterService>();
            var userManagerMock     = MockUserManager <User>();

            var userId         = "30";
            var twitterAccount = new TwitterAccount()
            {
                Name = "Grigor", Id = "30"
            };
            var twitterAccountSecond = new TwitterAccount()
            {
                Name = "Grigor", Id = "40"
            };
            var twitterAccounts = new List <TwitterAccount>()
            {
                twitterAccount,
                twitterAccountSecond
            };

            var twitterAccountDto = new TwitterAccountDto()
            {
                Name = "Grigor", Id = "30"
            };
            var twitterAccountDtoSecond = new TwitterAccountDto()
            {
                Name = "Grigor", Id = "40"
            };
            var twitterAccountsDto = new List <TwitterAccountDto>();

            var tweet = new TweetApiDto()
            {
                Id = "1905"
            };
            var expectedResult = new List <TweetApiDto>();

            userRepositoryMock
            .Setup(x => x.GetAllFavoriteTwitterAccounts(userId))
            .ReturnsAsync(twitterAccounts);

            mappingProviderMock
            .Setup(x => x.ProjectTo <TwitterAccount, TwitterAccountDto>(twitterAccounts))
            .Returns(twitterAccountsDto);

            twitterServiceMock
            .Setup(x => x.GetTimeline("30,40"))
            .ReturnsAsync(expectedResult);

            var userService = new UserService(
                unitOfWorkMock.Object,
                mappingProviderMock.Object,
                userRepositoryMock.Object,
                twitterServiceMock.Object,
                userManagerMock.Object);

            //Act
            var actualResult = await userService.GetTimeline(userId);

            //Assert
            Assert.IsNotNull(actualResult);
        }
Ejemplo n.º 10
0
        public void ThrowArgumentNullException_WhenTwitterServiceGetTimelineMethodReturnsNull()
        {
            //Arrange
            var unitOfWorkMock      = new Mock <IUnitOfWork>();
            var mappingProviderMock = new Mock <IMappingProvider>();
            var userRepositoryMock  = new Mock <IUserRepository>();
            var twitterServiceMock  = new Mock <ITwitterService>();
            var userManagerMock     = MockUserManager <User>();

            var userId         = "30";
            var twitterAccount = new TwitterAccount()
            {
                Name = "Grigor", Id = "30"
            };
            var twitterAccountSecond = new TwitterAccount()
            {
                Name = "Grigor", Id = "40"
            };
            var twitterAccounts = new List <TwitterAccount>()
            {
                twitterAccount,
                twitterAccountSecond
            };

            var twitterAccountDto = new TwitterAccountDto()
            {
                Name = "Grigor", Id = "30"
            };
            var twitterAccountDtoSecond = new TwitterAccountDto()
            {
                Name = "Grigor", Id = "40"
            };
            var twitterAccountsDto = new List <TwitterAccountDto>()
            {
                twitterAccountDto,
                twitterAccountDtoSecond
            };

            var tweet = new TweetApiDto()
            {
                Id = "1905"
            };
            var expectedResult = new List <TweetApiDto>()
            {
                tweet
            };

            userRepositoryMock
            .Setup(x => x.GetAllFavoriteTwitterAccounts(userId))
            .ReturnsAsync(twitterAccounts);

            mappingProviderMock
            .Setup(x => x.ProjectTo <TwitterAccount, TwitterAccountDto>(twitterAccounts))
            .Returns(twitterAccountsDto);

            twitterServiceMock
            .Setup(x => x.GetTimeline("30,40"))
            .ReturnsAsync((ICollection <TweetApiDto>)null);

            var userService = new UserService(
                unitOfWorkMock.Object,
                mappingProviderMock.Object,
                userRepositoryMock.Object,
                twitterServiceMock.Object,
                userManagerMock.Object);

            //Act
            Assert.ThrowsExceptionAsync <ArgumentNullException>(async() => await userService.GetTimeline(userId));
        }