/// <summary>
        /// Creates the group.
        /// </summary>
        /// <param name="itemRequestModel">The item request model containing a valid group to create.</param>
        /// <param name="webUrl">The web URL.</param>
        /// <param name="accessToken">The access token.</param>
        /// <param name="currentUserEmail"></param>
        /// <param name="isUserAdmin">Boolean flag for whether user is an admin</param>
        /// <returns></returns>
        public override Group Create(ItemRequestModel itemRequestModel, string webUrl, string accessToken,
                                     string currentUserEmail, bool isUserAdmin)
        {
            // User cannot create a group in a group they do not own
            //if(groupRequest.Parent != null && !IsOwnerOrDesignee(groupRequest.Parent))
            //    throw new Exception("You cannot create a group in a group you do not own.");

            // Non-admin cannot create a clause in a locked group
            if (itemRequestModel.Parent != null && itemRequestModel.Parent.IsLocked && !isUserAdmin)
            {
                throw new Exception("You cannot modify a locked group.");
            }

            try
            {
                var createdGroup = _groupRepository.Create(webUrl, accessToken, itemRequestModel.Group);

                // need to explicitly retrieve the new group in order to get its full set of properties
                var retrievedNewGroup = _groupRepository.Get(webUrl, createdGroup.Id, accessToken,
                                                             SpApiConstants.Lists.GROUP_EXPAND);
                return
                    (BuildGroups(new List <Group> {
                    retrievedNewGroup
                }, webUrl, accessToken, currentUserEmail, isUserAdmin)
                     .First());
            }
            catch (Exception)
            {
                throw new Exception("Failed to create group");
            }
        }
コード例 #2
0
        public void Get_ShouldReturnThreeListItems()
        {
            IListItemsRepository repo = GetInMemoryListItemRepository();

            Assert.Equal(3, repo.Get().Count());
            Assert.False(repo.Get().Count() > 3);
            Assert.False(repo.Get().Count() < 3);
        }
コード例 #3
0
        public void GetById_ShouldReturnNullIfNoMatch()
        {
            IListItemsRepository repo = GetInMemoryListItemRepository();

            var test1 = repo.Get(-1);
            var test2 = repo.Get(0);
            var test3 = repo.Get(4);


            Assert.Equal(test1, null);
            Assert.Equal(test2, null);
            Assert.Equal(test3, null);
        }
コード例 #4
0
        public void Delete_ShouldKeepAllOtherItemsInTheDatebase()
        {
            IListItemsRepository repo = GetInMemoryListItemRepository();

            var countBeforeDelete = repo.Get().Count();
            var idToDelete        = 1;

            repo.Delete(idToDelete);
            var countAfterDelete = repo.Get().Count();

            Assert.NotEqual(countBeforeDelete, countAfterDelete);
            Assert.True(countAfterDelete == (countBeforeDelete - 1));
        }
コード例 #5
0
        public void Update_ShouldBeAbleToUpdateAllPropertiesExceptIdAndCreated()
        {
            IListItemsRepository repo = GetInMemoryListItemRepository();

            DateTime tomorrow = DateTime.Now;

            ListItem updateItem = new ListItem
            {
                Id          = 3,
                Title       = "Schedule Date Night",
                Description = "Pick a night to have date night",
                Importance  = "High",
                Type        = "Special",
                Created     = tomorrow,
                Updated     = tomorrow,
                Due         = DateTime.Now.AddDays(14),
            };

            repo.Update(updateItem);

            ListItem newlyUpdatedItem = repo.Get(updateItem.Id);

            Assert.Equal(updateItem.Title, newlyUpdatedItem.Title);
            Assert.Equal(updateItem.Description, newlyUpdatedItem.Description);
            Assert.Equal(updateItem.Importance, newlyUpdatedItem.Importance);
            Assert.Equal(updateItem.Type, newlyUpdatedItem.Type);
            Assert.NotEqual(updateItem.Created, newlyUpdatedItem.Created);
            Assert.Equal(updateItem.Updated.Date, newlyUpdatedItem.Updated.Date);
            Assert.Equal(updateItem.Due.Date, newlyUpdatedItem.Due.Date);
        }
        /// <summary>
        /// Get a single ListItem from SharePoint List
        /// </summary>
        /// <param name="webUrl">URL of SharePoint Web which contains the list</param>
        /// <param name="id">Unique Id of ListItem to retrieve</param>
        /// <param name="accessToken">OAuth Access Token to be used as authentication with SharePoint REST API</param>
        /// <returns>List Item with specified Id</returns>
        public virtual T Get(string webUrl, int id, string accessToken = "")
        {
            accessToken = GetAccessToken(accessToken);
            var t = Repository.Get(webUrl, id, accessToken);

            t.ToClient = true;
            return(t);
        }
コード例 #7
0
        public void Get_ShouldBeOrderedByType()
        {
            IListItemsRepository repo = GetInMemoryListItemRepository();

            var actual   = repo.Get();
            var expected = actual.OrderBy(i => i.Type);

            Assert.True(expected.SequenceEqual(actual));
        }
コード例 #8
0
        public void Get_ShouldReturnAnEntityQueryableOfListItems()
        {
            IListItemsRepository repo = GetInMemoryListItemRepository();

            var actual   = repo.Get();
            var expected = typeof(Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable <ListItem>);

            Assert.IsType(expected, actual);
        }
コード例 #9
0
        public void Delete_ShouldRemoveTheItemFromTheDatabase()
        {
            IListItemsRepository repo = GetInMemoryListItemRepository();

            var idToDelete = 1;

            repo.Delete(idToDelete);

            Assert.Null(repo.Get(idToDelete));
        }
コード例 #10
0
        public void Add_ShouldIncrementTheNumberOfItemsByOne()
        {
            IListItemsRepository repo = GetInMemoryListItemRepository();

            var startingCount = repo.Get().Count();

            repo.Add(new ListItem
            {
                Title       = "Test Add",
                Description = "Testing adding an item",
                Importance  = "High",
                Type        = "Special",
                Created     = DateTime.Now,
                Updated     = DateTime.Now,
                Due         = DateTime.Now,
            });

            var endingCount = repo.Get().Count();

            Assert.NotEqual(startingCount, endingCount);
            Assert.True(endingCount == (startingCount + 1));
        }
コード例 #11
0
        /// <summary>
        /// Creates the clause (and optionally a group).
        /// </summary>
        public override Clause Create(ItemRequestModel itemRequestModel, string webUrl, string accessToken,
                                      string currentUserEmail, bool isUserAdmin)
        {
            // User cannot create a clause in a group they do not own
            //if(clauseRequest.Group != null && !IsOwnerOrDesignee(clauseRequest.Group))
            //    throw new Exception("You cannot create a clause in a group you do not own.");

            // Non-admin cannot create a clause in a locked group
            if (itemRequestModel.Group != null && itemRequestModel.Group.IsLocked && !isUserAdmin)
            {
                throw new Exception("You cannot modify a locked group");
            }

            try
            {
                var preparedClause = PrepareClause(itemRequestModel, webUrl, accessToken);

                var createdClause = _clauseRepository.Create(webUrl, accessToken, preparedClause);

                // need to explicitly retrieve the new clause in order to get its full set of properties
                var retrievedNewClause = _clauseRepository.Get(webUrl, createdClause.Id, accessToken,
                                                               SpApiConstants.Lists.CLAUSE_EXPAND);

                // now that the clause has been created, create any new external links; there is a dependency
                // on the clause id (which is not set before the clause is created)
                ProcessExternalLinks(retrievedNewClause, itemRequestModel.ExternalLinks, webUrl, accessToken);

                return
                    (BuildClauses(new List <Clause> {
                    retrievedNewClause
                }, webUrl, accessToken, currentUserEmail,
                                  isUserAdmin).First());
            }
            catch (Exception e)
            {
                throw new Exception("Failed to create clause", e);
            }
        }
コード例 #12
0
        public void GetById_ShouldReturnTheCorrectItem()
        {
            IListItemsRepository repo = GetInMemoryListItemRepository();

            var expectedId          = 2;
            var expectedTitle       = "Project";
            var expectedDescription = "Finish project by end of day on Saturday";
            var expectedImportance  = "High";
            var expectedType        = "Special";

            var actual = repo.Get(2);

            Assert.Equal(actual.Id, expectedId);
            Assert.Equal(actual.Title, expectedTitle);
            Assert.Equal(actual.Description, expectedDescription);
            Assert.Equal(actual.Importance, expectedImportance);
            Assert.Equal(actual.Type, expectedType);
        }