public void GetField_FieldContainsInvalidValidInteger_ReturnsInteger() { //Assign string fieldValue = "hello world"; int expected = 3; var fieldId = Guid.NewGuid(); var item = Helpers.CreateFakeItem(fieldId, fieldValue); var field = item.Fields[new ID(fieldId)]; var mapper = new SitecoreFieldIntegerMapper(); //Act var result = (int)mapper.GetField(field, null, null); //Assert }
public void GetField_FieldContainsEmptyString_ReturnsIntegerZero() { //Assign string fieldValue = string.Empty; int expected = 0; var fieldId = Guid.NewGuid(); var item = Helpers.CreateFakeItem(fieldId, fieldValue); var field = item.Fields[new ID(fieldId)]; var mapper = new SitecoreFieldIntegerMapper(); //Act var result = (int)mapper.GetField(field, null, null); //Assert Assert.AreEqual(expected, result); }
public void GetField_FieldContainsEmptyString_ReturnsIntegerZero() { //Assign string fieldValue = string.Empty; int expected = 0; var item = Database.GetItem("/sitecore/content/Tests/DataMappers/SitecoreFieldIntegerMapper/GetField"); var field = item.Fields[FieldName]; var mapper = new SitecoreFieldIntegerMapper(); using (new ItemEditing(item, true)) { field.Value = fieldValue; } //Act var result = (int)mapper.GetField(field, null, null); //Assert Assert.AreEqual(expected, result); }
public void SetField_ObjectisValidInteger_SetsFieldValue() { //Assign string expected = "3"; int objectValue = 3; var fieldId = Guid.NewGuid(); var item = Helpers.CreateFakeItem(fieldId, string.Empty); var field = item.Fields[new ID(fieldId)]; var mapper = new SitecoreFieldIntegerMapper(); item.Editing.BeginEdit(); //Act mapper.SetField(field, objectValue, null, null); //Assert Assert.AreEqual(expected, field.Value); }
public void SetField_ObjectIsDouble_ThrowsException() { //Assign double objectValue = 3; var fieldId = Guid.NewGuid(); var item = Helpers.CreateFakeItem(fieldId, string.Empty); var field = item.Fields[new ID(fieldId)]; var mapper = new SitecoreFieldIntegerMapper(); item.Editing.BeginEdit(); //Act mapper.SetField(field, objectValue, null, null); //Assert }
public void SetField_ObjectIsDouble_ThrowsException() { //Assign double objectValue = 3; var item = Database.GetItem("/sitecore/content/Tests/DataMappers/SitecoreFieldIntegerMapper/SetField"); var field = item.Fields[FieldName]; var mapper = new SitecoreFieldIntegerMapper(); using (new ItemEditing(item, true)) { field.Value = string.Empty; } //Act using (new ItemEditing(item, true)) { mapper.SetField(field, objectValue, null, null); } //Assert }
public void SetField_ObjectisValidInteger_SetsFieldValue() { //Assign string expected = "3"; int objectValue = 3; var item = Database.GetItem("/sitecore/content/Tests/DataMappers/SitecoreFieldIntegerMapper/SetField"); var field = item.Fields[FieldName]; var mapper = new SitecoreFieldIntegerMapper(); using (new ItemEditing(item, true)) { field.Value = string.Empty; } //Act using (new ItemEditing(item, true)) { mapper.SetField(field, objectValue, null, null); } //Assert Assert.AreEqual(expected, field.Value); }