public void WhenCreatingEntityMissingPropertyFailsWithClearException() { Guid fieldId1 = new Guid("{95C7711D-E2B5-42f9-B0DB-4C840BED0C74}"); SPListItem spListItem = Isolate.Fake.Instance <SPListItem>(); Isolate.WhenCalled(() => spListItem[fieldId1]).WithExactArguments().WillReturn("teststring"); Isolate.WhenCalled(() => spListItem.Name).WillReturn("ItemName"); var target = new ListItemFieldMapper <TestEntity>(); target.AddMapping(fieldId1, "NonExistingProperty"); try { target.CreateEntity(spListItem); Assert.Fail(); } catch (ListItemFieldMappingException ex) { Assert.AreEqual( "Type 'Microsoft.Practices.SPG.Common.Tests.ListRepository.TestEntity' does not have a property 'NonExistingProperty' which was mapped to FieldID: '95c7711d-e2b5-42f9-b0db-4c840bed0c74' for SPListItem 'ItemName'." , ex.Message); } catch (Exception) { Assert.Fail(); } }
public void CanFillSPListItemFromEntity() { Guid fieldId1 = Guid.NewGuid(); Guid fieldId2 = Guid.NewGuid(); TestEntity testEntity = new TestEntity() { Property1String = "teststring", Property2Integer = 321 }; SPListItem spListItem = Isolate.Fake.Instance <SPListItem>(); object field1Value = null; object field2Value = null; Isolate.WhenCalled(() => spListItem[fieldId1] = "teststring").DoInstead((context) => field1Value = context.Parameters[1]); Isolate.WhenCalled(() => spListItem[fieldId2] = 321).DoInstead((context) => field2Value = context.Parameters[1]); ListItemFieldMapper <TestEntity> target = new ListItemFieldMapper <TestEntity>(); target.AddMapping(fieldId1, "Property1String"); target.AddMapping(fieldId2, "Property2Integer"); target.FillSPListItemFromEntity(spListItem, testEntity); Assert.AreEqual("teststring", field1Value); Assert.AreEqual(321, field2Value); }
public void CanAddMappingDirectly() { ListItemFieldMapper <TestEntity> target = new ListItemFieldMapper <TestEntity>(); Guid fieldId = Guid.NewGuid(); target.AddMapping(fieldId, "EntityPropertyName"); Assert.AreEqual(1, target.FieldMappings.Count((mapping) => mapping.ListFieldId.Equals(fieldId) && mapping.EntityPropertyName == "EntityPropertyName")); }
public void CanCreateEntityFromSPListItem() { Guid fieldId1 = Guid.NewGuid(); Guid fieldId2 = Guid.NewGuid(); SPListItem spListItem = Isolate.Fake.Instance <SPListItem>(); Isolate.WhenCalled(() => spListItem[fieldId1]).WithExactArguments().WillReturn("teststring"); Isolate.WhenCalled(() => spListItem[fieldId2]).WithExactArguments().WillReturn(123); ListItemFieldMapper <TestEntity> target = new ListItemFieldMapper <TestEntity>(); target.AddMapping(fieldId1, "Property1String"); target.AddMapping(fieldId2, "Property2Integer"); TestEntity testEntity = target.CreateEntity(spListItem); Assert.AreEqual("teststring", testEntity.Property1String); Assert.AreEqual(123, testEntity.Property2Integer); }