Exemple #1
0
        public void TryValidate_ShouldValidateAnInt(int value)
        {
            NumericProperty <int> sut = CreateSut <int>();

            sut.Value = value.ToString();

            Assert.IsTrue(sut.TryValidate(Substitute.For <IMessageBoxService>()));
        }
Exemple #2
0
        public void TryValidate_ShouldNotValidateAnInt(long value)
        {
            NumericProperty <int> sut = CreateSut <int>();

            sut.Value = value.ToString();

            IMessageBoxService messageBoxService = Substitute.For <IMessageBoxService>();

            Assert.IsFalse(sut.TryValidate(messageBoxService));
            messageBoxService.Received(1).ShowError("'Num Prop' must be a valid Int32.");
        }
Exemple #3
0
        public void Save_ShouldNotCreateAndAppendElement_WhenValueIsNull()
        {
            NumericProperty <int> sut = CreateSut <int>();

            XmlDocument xmlDoc   = new XmlDocument();
            XmlElement  appender = xmlDoc.CreateElement("appender");

            sut.Save(xmlDoc, appender);

            Assert.IsNull(appender["numProp"]);
        }
Exemple #4
0
        public void Save_ShouldNotCreateAndAppendElement_WhenDefault()
        {
            NumericProperty <int> sut = new NumericProperty <int>("Num Prop:", "numProp", 1234)
            {
                Value = "1234"
            };

            XmlDocument xmlDoc   = new XmlDocument();
            XmlElement  appender = xmlDoc.CreateElement("appender");

            sut.Save(xmlDoc, appender);

            Assert.IsNull(appender["numProp"]);
        }
Exemple #5
0
        public void Save_ShouldCreateAndAppendCorrectElement_WhenNotDefault()
        {
            NumericProperty <int> sut = CreateSut <int>();

            const string value = "10000";

            sut.Value = value;
            XmlDocument xmlDoc   = new XmlDocument();
            XmlElement  appender = xmlDoc.CreateElement("appender");

            sut.Save(xmlDoc, appender);

            XmlElement numProp = appender["numProp"];

            Assert.IsNotNull(numProp);
            Assert.AreEqual(value, numProp.Attributes["value"].Value);
        }
Exemple #6
0
 public void AddPreset(GameEntity gameEntity, ApplicationDbContext db)
 {
     if (!gameEntity.EntityPresets.Select(ep => ep.PresetId).Contains(Id))
     {
         gameEntity.EntityPresets.Add(new EntityPreset {
             PresetId = Id, GameEntityId = gameEntity.Id
         });
         foreach (BaseTextProperty baseProperty in BaseProperties.Where(bp => bp is BaseTextProperty))
         {
             var Property = new TextProperty(baseProperty, gameEntity);
             db.Properties.Add(Property);
         }
         foreach (BaseTextArrayProperty baseProperty in BaseProperties.Where(bp => bp is BaseTextArrayProperty))
         {
             var Property = new TextArrayProperty(baseProperty, gameEntity);
             db.Properties.Add(Property);
         }
         foreach (BaseNumericProperty baseProperty in BaseProperties.Where(bp => bp is BaseNumericProperty))
         {
             var Property = new NumericProperty(baseProperty, gameEntity);
             db.Properties.Add(Property);
         }
     }
 }
        public static ScalarPropertyBuilder CreateScalar(string propertyName, Type propertyType)
        {
            var nullable = System.Nullable.GetUnderlyingType(propertyType);

            var typeInfo = new ClrTypeInfo(propertyType);

            var type    = nullable ?? propertyType;
            var numeric = NumericProperty.GetNumericTypeFromClrType(type);

            if (type == typeof(string))
            {
                return(new TextPropertyBuilder {
                    PropertyType = typeInfo, Name = propertyName, Nullable = true, Unicode = true
                });
            }
            else if (numeric.HasValue)
            {
                return(new NumericPropertyBuilder {
                    PropertyType = typeInfo, Name = propertyName, Nullable = nullable != null, NumericType = numeric.Value
                });
            }
            else if (type == typeof(bool))
            {
                return(new BooleanPropertyBuilder {
                    PropertyType = typeInfo, Name = propertyName, Nullable = nullable != null
                });
            }
            else if (type == typeof(byte[]))
            {
                return(new BlobPropertyBuilder {
                    PropertyType = typeInfo, Name = propertyName, Nullable = true
                });
            }
            else if (type == typeof(DateTime))
            {
                return(new DateTimePropertyBuilder {
                    PropertyType = typeInfo, Name = propertyName, Nullable = nullable != null, DateTimeType = DateTimePropertyType.DateTime
                });
            }
            else if (type == typeof(DateTimeOffset))
            {
                return(new DateTimePropertyBuilder {
                    PropertyType = typeInfo, Name = propertyName, Nullable = nullable != null, DateTimeType = DateTimePropertyType.DateTimeOffset
                });
            }
            else if (type == typeof(Guid))
            {
                return(new GuidPropertyBuilder {
                    PropertyType = typeInfo, Name = propertyName, Nullable = nullable != null
                });
            }
            else if (type.GetTypeInfo().IsEnum)
            {
                return(new EnumPropertyBuilder
                {
                    Name = propertyName,
                    PropertyType = typeInfo,
                    Nullable = nullable != null,
                    EnumTypeInfo = new ClrTypeInfo(type),
                    UnderlyingNumericType = NumericProperty.GetNumericTypeFromClrType(Enum.GetUnderlyingType(type)).GetValueOrDefault()
                });
            }

            throw new InvalidOperationException($"PropertyType {type} not supported.");
        }
Exemple #8
0
        public void Ctor_ShouldNotSetDefaultValue_WhenNull()
        {
            NumericProperty <int> sut = CreateSut <int>();

            Assert.IsNull(sut.Value);
        }
Exemple #9
0
        public void Ctor_ShouldSetDefaultValue()
        {
            NumericProperty <int> sut = new NumericProperty <int>("Num Prop:", "numProp", 1234);

            Assert.AreEqual(sut.Value, 1234.ToString());
        }