public void GetField_FieldContainsValidEnumInLowercase_ReturnsEnum() { //Assign string fieldValue = "value1"; StubEnum expected = StubEnum.Value1; var fieldId = Guid.NewGuid(); var item = Helpers.CreateFakeItem(fieldId, fieldValue); var field = item.Fields[new ID(fieldId)]; var config = new SitecoreFieldConfiguration(); config.PropertyInfo = typeof(Stub).GetProperty("Property"); var mapper = new SitecoreFieldNullableEnumMapper(); //Act var result = (StubEnum?)mapper.GetField(field, config, null); //Assert Assert.IsTrue(result.HasValue); Assert.AreEqual(expected, result.Value); }
public void GetField_FieldContainsInvalidValidEnum_ThrowsException() { //Assign string fieldValue = "hello world"; var fieldId = Guid.NewGuid(); var item = Helpers.CreateFakeItem(fieldId, fieldValue); var field = item.Fields[new ID(fieldId)]; var config = new SitecoreFieldConfiguration(); config.PropertyInfo = typeof(Stub).GetProperty("Property"); var mapper = new SitecoreFieldNullableEnumMapper(); //Act Assert.Throws<MapperException>(() => { var result = (StubEnum?) mapper.GetField(field, config, null); }); //Assert }
public void GetField_FieldContainsEmptyString_ReturnsNull() { //Assign string fieldValue = string.Empty; var fieldId = Guid.NewGuid(); var item = Helpers.CreateFakeItem(fieldId, fieldValue); var field = item.Fields[new ID(fieldId)]; var config = new SitecoreFieldConfiguration(); config.PropertyInfo = typeof(Stub).GetProperty("Property"); var mapper = new SitecoreFieldNullableEnumMapper(); //Act var result = (StubEnum?)mapper.GetField(field, config, null); //Assert Assert.IsNull(result); }