Ejemplo n.º 1
0
        public void Delete_IdIsValid_ItemDeleted()
        {
            using (SPSite site = new SPSite(siteUrl))
            {
                using (SPWeb web = site.AllWebs[webId])
                {
                    #region Arrange

                    ListItemRepository        listItemRepository = new ListItemRepository();
                    Dictionary <Guid, object> fields             = new Dictionary <Guid, object>();
                    fields.Add(new Guid(Fields.CourseId), 1);
                    fields.Add(new Guid(Fields.UserId), 1);
                    SPListItem targetItem = listItemRepository.Add(web, Lists.Registrations, fields);

                    #endregion

                    #region Act

                    listItemRepository.Delete(web, Lists.Registrations, (int)targetItem[new Guid(Fields.Id)]);

                    #endregion

                    #region Assert

                    SPListItemCollection items = listItemRepository.Get(web, Lists.Registrations);
                    Assert.AreEqual(0, items.Count);

                    #endregion
                }
            }
        }
Ejemplo n.º 2
0
        public void Get_ValidListName_ItemFound()
        {
            using (SPSite site = new SPSite(siteUrl))
            {
                using (SPWeb web = site.AllWebs[webId])
                {
                    #region Arrange

                    ListItemRepository        listItemRepository = new ListItemRepository();
                    Dictionary <Guid, object> fields             = new Dictionary <Guid, object>();
                    fields.Add(new Guid(Fields.CourseId), 999);
                    fields.Add(new Guid(Fields.UserId), 999);
                    SPListItem targetItem1 = listItemRepository.Add(web, Lists.Registrations, fields);

                    fields.Clear();
                    fields.Add(new Guid(Fields.CourseId), 998);
                    fields.Add(new Guid(Fields.UserId), 998);
                    SPListItem targetItem2 = listItemRepository.Add(web, Lists.Registrations, fields);

                    List <SPListItem> targetItems = new List <SPListItem>()
                    {
                        targetItem1, targetItem2
                    };

                    #endregion

                    #region Act

                    SPListItemCollection foundItems = listItemRepository.Get(web, Lists.Registrations);

                    #endregion

                    #region Assert

                    Assert.IsNotNull(foundItems);
                    Assert.AreEqual(2, foundItems.Count);
                    for (int i = 0; i < foundItems.Count; i++)
                    {
                        Assert.AreEqual(targetItems[i][new Guid(Fields.Id)], foundItems[i][new Guid(Fields.Id)]);
                        Assert.AreEqual(targetItems[i][new Guid(Fields.CourseId)], foundItems[i][new Guid(Fields.CourseId)]);
                        Assert.AreEqual(targetItems[i][new Guid(Fields.UserId)], foundItems[i][new Guid(Fields.UserId)]);
                    }

                    #endregion

                    #region Cleanup

                    foreach (SPListItem item in targetItems)
                    {
                        listItemRepository.Delete(web, Lists.Registrations, (int)item[new Guid(Fields.Id)]);
                    }

                    #endregion
                }
            }
        }
        public void Get_QueryIsValid_ItemFound()
        {
            SPWeb web = this.RecordWebForGet();
            ListItemRepository listItemRepository = new ListItemRepository();
            SPQuery            query = new SPQuery();
            SPListItem         item  = null;

            item = listItemRepository.Get(web, "Registrations", query);

            Assert.IsNotNull(item);
            MockManager.Verify();
        }
        public void Get_ValidListName_ItemsFound()
        {
            SPWeb web = this.RecordWebForGetAll();
            ListItemRepository   listItemRepository = new ListItemRepository();
            SPQuery              query = new SPQuery();
            SPListItemCollection items = null;

            items = listItemRepository.Get(web, "Registrations");

            Assert.IsNotNull(items);
            Assert.AreEqual(2, items.Count);
            MockManager.Verify();
        }
Ejemplo n.º 5
0
        public void Update_IdAndItemIsValid_ItemUpdated()
        {
            using (SPSite site = new SPSite(siteUrl))
            {
                using (SPWeb web = site.AllWebs[webId])
                {
                    #region Arrange

                    ListItemRepository        listItemRepository = new ListItemRepository();
                    Dictionary <Guid, object> fields             = new Dictionary <Guid, object>();
                    fields.Add(new Guid(Fields.CourseId), 1);
                    fields.Add(new Guid(Fields.UserId), 1);
                    SPListItem targetItem = listItemRepository.Add(web, Lists.Registrations, fields);

                    #endregion

                    #region Act

                    fields.Clear();
                    fields.Add(new Guid(Fields.CourseId), 999);
                    fields.Add(new Guid(Fields.UserId), 999);
                    listItemRepository.Update(web, Lists.Registrations, (int)targetItem[new Guid(Fields.Id)], fields);

                    #endregion

                    #region Assert

                    StringBuilder queryBuilder = new StringBuilder("<Where>");
                    queryBuilder.Append(string.Format("<Eq><FieldRef Name='ID'/>"));
                    queryBuilder.Append(string.Format("<Value Type='Integer'>{0}</Value></Eq>", targetItem[new Guid(Fields.Id)]));
                    queryBuilder.Append("</Where>");
                    SPQuery query = new SPQuery();
                    query.Query = queryBuilder.ToString();
                    SPListItem foundItem = listItemRepository.Get(web, Lists.Registrations, query);

                    Assert.AreEqual(999, foundItem[new Guid(Fields.CourseId)]);
                    Assert.AreEqual(999, foundItem[new Guid(Fields.UserId)]);

                    #endregion

                    #region Cleanup

                    listItemRepository.Delete(web, Lists.Registrations, (int)targetItem[new Guid(Fields.Id)]);

                    #endregion
                }
            }
        }