public void UsersRepositoryUserIsRegisteredCallsLoadFromTheUnitOfWorkForAnExistingUser()
        {
            // 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", "nameIdentifier"),
                                         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 UsersRepository(unitOfWorkMock.Object);
            unitOfWorkMock.Setup(uow => uow.Load("Users", It.IsAny<Expression<Func<UserEntity, bool>>>())).Returns(BuildUsersTable());

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

            // Assert
            Assert.IsTrue(result);
            unitOfWorkMock.Verify(uow => uow.Load("Users", It.IsAny<Expression<Func<UserEntity, bool>>>()), Times.Once());
        }
        public void UsersRepositoryLoadTaskListOwnerCallsLoadAndGetFromTheUnitOfWork()
        {
            // Arrange
            var userEntity = new UserEntity(User1PartitionKey, User1RowKey);
            var taskList = new TaskList { PartitionKey = TaskList1PartitionKey, RowKey = _taskList1RowKey };
            var unitOfWorkMock = new Mock<IUnitOfWork>();
            unitOfWorkMock.Setup(u => u.Get<UserEntity>("Users", User1PartitionKey, User1RowKey)).Returns(userEntity);
            var repository = new UsersRepository(unitOfWorkMock.Object);

            // Act
            repository.LoadOwner(taskList);

            // Assert
            Assert.IsNotNull(taskList.Owner);
            unitOfWorkMock.Verify(uow => uow.Get<UserEntity>("Users", User1PartitionKey, User1RowKey), Times.Once());
        }
        public void UsersRepositoryUpdateCallsUpdateFromTheUnitOfWork()
        {
            // Arrange
            var user = new User { PartitionKey = User1PartitionKey, RowKey = User1RowKey };
            var unitOfWorkMock = new Mock<IUnitOfWork>();
            var repository = new UsersRepository(unitOfWorkMock.Object);

            // Act
            repository.Update(user);

            // Assert
            unitOfWorkMock.Verify(uow => uow.Update("Users", It.IsAny<UserEntity>()), Times.Once());
        }
        public void UsersRepositoryLoadCallsLoadFromTheUnitOfWork()
        {
            // Arrange
            var unitOfWorkMock = new Mock<IUnitOfWork>();
            unitOfWorkMock.Setup(u => u.Load<UserEntity>(It.Is<string>(s => s == "Users"))).Returns(BuildUsersTable());
            var repository = new UsersRepository(unitOfWorkMock.Object);

            // Act
            var result = repository.Load().ToList();

            // Assert
            Assert.IsTrue(result.Count() == 2);
            unitOfWorkMock.Verify(uow => uow.Load<UserEntity>("Users"), Times.Once());
        }
        public void UsersRepositoryLoadTaskListAssociatedUsersCallsLoadAndGetFromTheUnitOfWork()
        {
            // Arrange
            var user = new User { PartitionKey = User1PartitionKey, RowKey = User1RowKey };
            var user1Entity = new UserEntity(User1PartitionKey, User1RowKey);
            var user3Entity = new UserEntity(User3PartitionKey, User3RowKey);
            var taskList = new TaskList("Test title", user) { PartitionKey = TaskList1PartitionKey, RowKey = _taskList1RowKey };
            var unitOfWorkMock = new Mock<IUnitOfWork>();
            unitOfWorkMock.Setup(u => u.Load("TaskListShares", It.IsAny<Expression<Func<TaskListShareEntity, bool>>>())).Returns(BuildTaskListSharesTable());
            unitOfWorkMock.Setup(u => u.Get<UserEntity>("Users", User1PartitionKey, User1RowKey)).Returns(user1Entity);
            unitOfWorkMock.Setup(u => u.Get<UserEntity>("Users", User3PartitionKey, User3RowKey)).Returns(user3Entity);
            var repository = new UsersRepository(unitOfWorkMock.Object);

            // Act
            repository.LoadShare(taskList);

            // Assert
            Assert.IsTrue(taskList.Share.Count == 2);
            unitOfWorkMock.Verify(uow => uow.Load("TaskListShares", It.IsAny<Expression<Func<TaskListShareEntity, bool>>>()), Times.Once());
            unitOfWorkMock.Verify(uow => uow.Get<UserEntity>("Users", User1PartitionKey, User1RowKey), Times.Once());
            unitOfWorkMock.Verify(uow => uow.Get<UserEntity>("Users", User3PartitionKey, User3RowKey), Times.Once());
        }
        public void UsersRepositoryGetCallsWithFilterGetFromTheUnitOfWorkAndReturnsAExistingTaskList()
        {
            // Arrange
            var user = new User { PartitionKey = User1PartitionKey, RowKey = User1RowKey };
            var unitOfWorkMock = new Mock<IUnitOfWork>();
            unitOfWorkMock.Setup(u => u.Get("Users", It.IsAny<Expression<Func<User, bool>>>())).Returns(user);
            var repository = new UsersRepository(unitOfWorkMock.Object);

            // Act
            var result = repository.Get(n => n.PartitionKey == User1PartitionKey && n.RowKey == User1RowKey);

            // Assert
            Assert.IsNotNull(result);
            unitOfWorkMock.Verify(uow => uow.Get("Users", It.IsAny<Expression<Func<User, bool>>>()), Times.Once());
        }
        public void UsersRepositoryGetCallsGetFromTheUnitOfWorkAndReturnsNullForANonExistingUser()
        {
            // Arrange
            var unitOfWorkMock = new Mock<IUnitOfWork>();
            var repository = new UsersRepository(unitOfWorkMock.Object);

            // Act
            var result = repository.Get(User3PartitionKey, User3RowKey);

            // Assert
            Assert.IsNull(result);
            unitOfWorkMock.Verify(uow => uow.Get<UserEntity>("Users", User3PartitionKey, User3RowKey), Times.Once());
        }
        public void UsersRepositoryGetCallsGetFromTheUnitOfWorkAndReturnsAExistingUser()
        {
            // Arrange
            var user = new UserEntity { PartitionKey = User1PartitionKey, RowKey = User1RowKey };
            var unitOfWorkMock = new Mock<IUnitOfWork>();
            unitOfWorkMock.Setup(u => u.Get<UserEntity>("Users", User1PartitionKey, User1RowKey)).Returns(user);
            var repository = new UsersRepository(unitOfWorkMock.Object);

            // Act
            var result = repository.Get(User1PartitionKey, User1RowKey);

            // Assert
            Assert.IsNotNull(result);
            unitOfWorkMock.Verify(uow => uow.Get<UserEntity>("Users", User1PartitionKey, User1RowKey), Times.Once());
        }
        public void UsersRepositoryGetByIdentifiersCallsLoadFromTheUnitOfWorkForNonExistingUser()
        {
            // Arrange
            var unitOfWorkMock = new Mock<IUnitOfWork>();
            unitOfWorkMock.Setup(u => u.Load("Users", It.IsAny<Expression<Func<UserEntity, bool>>>())).Returns(new List<UserEntity>().AsQueryable());
            var repository = new UsersRepository(unitOfWorkMock.Object);

            // Act
            var result = repository.GetByIdentifiers(Guid.NewGuid().ToString(), "WindowsLiveID");

            // Assert
            Assert.IsNull(result);
            unitOfWorkMock.Verify(uow => uow.Load("Users", It.IsAny<Expression<Func<UserEntity, bool>>>()), Times.Once());
        }
        public void UsersRepositoryCreateCallsCreateFromTheUnitOfWork()
        {
            // Arrange
            var user = new User { PartitionKey = User1PartitionKey, RowKey = User1RowKey };
            var unitOfWorkMock = new Mock<IUnitOfWork>();
            var repository = new UsersRepository(unitOfWorkMock.Object);

            // Act
            repository.Create(user);

            // Assert
            Assert.IsTrue(user.PartitionKey != string.Empty);
            Assert.IsTrue(user.RowKey != string.Empty);
            unitOfWorkMock.Verify(uow => uow.Create(It.IsAny<UserEntity>(), "Users"), Times.Once());
        }