public void UsersServiceMethodLoadTaskListOwnerShouldLoadOwner()
        {
            // Arrange
            var unitOfWorkMock = new Mock<IUnitOfWork>();
            var repository = new UsersMemoryRepository();
            var taskList = new TaskList { PartitionKey = UsersMemoryRepository.TaskList1PartitionKey, RowKey = repository.Note1RowKey };
            var service = new UsersService(unitOfWorkMock.Object, repository);

            // Act
            service.LoadOwner(taskList);

            // Assert
            Assert.IsNotNull(taskList.Owner);
        }
        public void UsersServiceMethodUpdateShouldUpdateAUser()
        {
            // Arrange
            var unitOfWorkMock = new Mock<IUnitOfWork>();
            var repository = new UsersMemoryRepository();
            var service = new UsersService(unitOfWorkMock.Object, repository);
            var result = service.Get(UsersMemoryRepository.IdentityProvider, UsersMemoryRepository.User1RowKey);

            // Act
            result.Email = "*****@*****.**";
            service.Update(result);
            var updatedResult = service.Get(UsersMemoryRepository.IdentityProvider, UsersMemoryRepository.User1RowKey);

            // Assert
            Assert.IsTrue(updatedResult.Email == "*****@*****.**");
        }
        public void UsersServiceMethodLoadShareShouldLoadTheTaskListShares()
        {
            // Arrange
            var unitOfWorkMock = new Mock<IUnitOfWork>();
            var repository = new UsersMemoryRepository();
            var taskList = new TaskList { PartitionKey = UsersMemoryRepository.TaskList1PartitionKey, RowKey = repository.TaskList1RowKey };
            var service = new UsersService(unitOfWorkMock.Object, repository);

            // Act
            service.LoadShare(taskList);

            // Assert
            Assert.IsTrue(taskList.Share.Count == 2);
        }
        public void UsersServiceMethodLoadShouldReturnAllUsers()
        {
            // Arrange
            var unitOfWorkMock = new Mock<IUnitOfWork>();
            var repository = new UsersMemoryRepository();
            var service = new UsersService(unitOfWorkMock.Object, repository);

            // Act
            var result = service.Load();

            // Assert
            Assert.IsInstanceOfType(result, typeof(IQueryable<User>));
            Assert.IsTrue(result.Count() == 3);
        }
        public void UsersServiceMethodLoadNoteOwnerShouldLoadOwner()
        {
            // Arrange
            var unitOfWorkMock = new Mock<IUnitOfWork>();
            var repository = new UsersMemoryRepository();
            var note = new Note { PartitionKey = UsersMemoryRepository.Note1PartitionKey, RowKey = repository.Note1RowKey };
            var service = new UsersService(unitOfWorkMock.Object, repository);

            // Act
            service.LoadOwner(note);

            // Assert
            Assert.IsNotNull(note.Owner);
        }
        public void UsersServiceMethodLoadShareShouldLoadTheNoteShares()
        {
            // Arrange
            var unitOfWorkMock = new Mock<IUnitOfWork>();
            var repository = new UsersMemoryRepository();
            var note = new Note { PartitionKey = UsersMemoryRepository.Note1PartitionKey, RowKey = repository.Note1RowKey };
            var service = new UsersService(unitOfWorkMock.Object, repository);

            // Act
            service.LoadShare(note);

            // Assert
            Assert.IsTrue(note.Share.Count == 2);
        }
        public void UsersServiceMethodGFillUserAuthenticationInfoShouldFillTheAuthenticationInfo()
        {
            // Arrange
            var claims = new[]
                                     {
                                         new Claim("http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider", "WindowsLiveID") ,
                                         new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier", "user1"),
                                         new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress", "*****@*****.**"),
                                         new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name", "user1"),
                                     };

            IClaimsIdentity identity = new ClaimsIdentity(claims);
            IClaimsPrincipal principal = new ClaimsPrincipal(new[] { identity });
            var user = new User { Name = "user1" };
            var unitOfWorkMock = new Mock<IUnitOfWork>();
            var repository = new UsersMemoryRepository();
            var service = new UsersService(unitOfWorkMock.Object, repository);

            // Act
            service.FillAuthenticationInfo(user, principal);

            // Assert
            Assert.IsTrue(user.PartitionKey == "windowsliveid");
            Assert.IsTrue(user.RowKey == "user1-windowsliveid");
            Assert.IsTrue(user.UniqueIdentifier == "user1");
        }
        public void UsersServiceMethodIsRegisteredReturnsTrueForAnExistingUser()
        {
            // Arrange
            var claims = new[]
                                     {
                                         new Claim("http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider", "WindowsLiveID") ,
                                         new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier", "user1"),
                                         new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress", "*****@*****.**")
                                     };

            IClaimsIdentity identity = new ClaimsIdentity(claims);
            IClaimsPrincipal principal = new ClaimsPrincipal(new[] { identity });
            var unitOfWorkMock = new Mock<IUnitOfWork>();
            var repository = new UsersMemoryRepository();
            var service = new UsersService(unitOfWorkMock.Object, repository);

            // Act
            var result = service.UserIsRegistered(principal);

            // Assert
            Assert.IsTrue(result);
        }
        public void UsersServiceMethodGetShouldReturnNullForANonExistingUser()
        {
            // Arrange
            var unitOfWorkMock = new Mock<IUnitOfWork>();
            var repository = new UsersMemoryRepository();
            var service = new UsersService(unitOfWorkMock.Object, repository);

            // Act
            var result = service.Get(UsersMemoryRepository.IdentityProvider, UsersMemoryRepository.User4RowKey);

            // Assert
            Assert.IsNull(result);
        }
        public void UsersServiceMethodGetUserAuthenticationInfoShouldReturnTheAuthenticationInfoWithoutNameAndEmail()
        {
            // Arrange
            var claims = new[]
                                     {
                                         new Claim("http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider", "WindowsLiveID") ,
                                         new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier", "user1")
                                     };

            IClaimsIdentity identity = new ClaimsIdentity(claims);
            IClaimsPrincipal principal = new ClaimsPrincipal(new[] { identity });
            var unitOfWorkMock = new Mock<IUnitOfWork>();
            var repository = new UsersMemoryRepository();
            var service = new UsersService(unitOfWorkMock.Object, repository);

            // Act
            var result = service.GetUserAuthenticationInfo(principal);

            // Assert
            Assert.IsNotNull(result);
        }
        public void UsersServiceMethodGetShouldReturnAnExistingUser()
        {
            // Arrange
            var unitOfWorkMock = new Mock<IUnitOfWork>();
            var repository = new UsersMemoryRepository();
            var service = new UsersService(unitOfWorkMock.Object, repository);

            // Act
            var result = service.Get(UsersMemoryRepository.IdentityProvider, UsersMemoryRepository.User1RowKey);

            // Assert
            Assert.IsInstanceOfType(result, typeof(User));
            Assert.IsNotNull(result);
        }
        public void UsersServiceMethodGetByIdentifiersShouldReturnAUser()
        {
            // Arrange
            var unitOfWorkMock = new Mock<IUnitOfWork>();
            var repository = new UsersMemoryRepository();
            var service = new UsersService(unitOfWorkMock.Object, repository);

            // Act
            var result = service.GetByIdentifiers("user1", UsersMemoryRepository.IdentityProvider);

            // Assert
            Assert.IsNotNull(result);
        }
        public void UsersServiceMethodDeleteShouldDeleteAUser()
        {
            // Arrange
            var unitOfWorkMock = new Mock<IUnitOfWork>();
            var repository = new UsersMemoryRepository();
            var service = new UsersService(unitOfWorkMock.Object, repository);
            var result = service.Get(UsersMemoryRepository.IdentityProvider, UsersMemoryRepository.User1RowKey);

            // Act
            service.Delete(result);
            result = service.Get(UsersMemoryRepository.IdentityProvider, UsersMemoryRepository.User1RowKey);

            // Assert
            Assert.IsNull(result);
        }
        public void UsersServiceMethodCreateShouldCreateAUser()
        {
            // Arrange
            var user = new User { PartitionKey = UsersMemoryRepository.IdentityProvider, RowKey = UsersMemoryRepository.User4RowKey };
            var unitOfWorkMock = new Mock<IUnitOfWork>();
            var repository = new UsersMemoryRepository();
            var service = new UsersService(unitOfWorkMock.Object, repository);

            // Act
            service.Create(user);
            var result = service.Get(UsersMemoryRepository.IdentityProvider, UsersMemoryRepository.User4RowKey);

            // Assert
            Assert.IsInstanceOfType(result, typeof(User));
            Assert.IsNotNull(result);
        }
        public void UserServiceMethodParseIdentityProviderShouldParseIdentityProviders()
        {
            // Arrange
            var unitOfWorkMock = new Mock<IUnitOfWork>();
            var repository = new UsersMemoryRepository();
            var service = new UsersService(unitOfWorkMock.Object, repository);

            // Act
            var windowsLiveIdProvider = service.ParseIdentityProvider("WindowsLiveID");
            var googleProvider = service.ParseIdentityProvider("Google");
            var yahooProvider = service.ParseIdentityProvider("Yahoo");

            // Assert
            Assert.IsTrue(windowsLiveIdProvider == "windowsliveid");
            Assert.IsTrue(googleProvider == "google");
            Assert.IsTrue(yahooProvider == "yahoo");
        }