public void Update_IdAndItemIsValid_ItemUpdated()
        {
            SPWeb web = this.RecordWebForUpdate();
            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);

            listItemRepository.Update(web, "Registrations", 1, fields);

            MockManager.Verify();
        }
Ejemplo n.º 2
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
                }
            }
        }