Beispiel #1
0
        public static IEnumerable <Argument> ToArguments(WiremockProperties wiremockProperties)
        {
            var props = wiremockProperties.GetType().GetProperties();

            foreach (var prop in props)
            {
                var value = prop.GetValue(wiremockProperties);
                if (value != null && value.ToString() != "")
                {
                    var arg = new Argument()
                    {
                        Name  = prop.Name,
                        Value = value.ToString(),
                        Type  = prop.PropertyType.Name
                    };

                    var attrs = prop.GetCustomAttributes(true).Where(f => f is WiremockProperties.ArgumentAttribute).FirstOrDefault();
                    if (attrs is WiremockProperties.ArgumentAttribute argAttr)
                    {
                        arg.ArgName = argAttr.ArgName;
                    }

                    yield return(arg);
                }
            }
        }
Beispiel #2
0
        public void Save(WiremockProperties properties = null)
        {
            var db = new UnitOfWork();

            if (properties != null)
            {
                Arguments = ToArguments(properties);
            }

            if (Id == Guid.Empty)
            {
                AddScenario(new Scenario()
                {
                    IsDefault = true,
                    Name      = Resource.defaultScenarioName
                });
                db.Servers.Insert(this);
            }
            else
            {
                db.Servers.Update(this);
            }

            db.Servers.Update(this);
            db.Save();
        }
Beispiel #3
0
        public WiremockProperties GetWiremockProperties()
        {
            var properties = new WiremockProperties();

            if (Arguments != null)
            {
                var type = properties.GetType();
                foreach (var arg in Arguments)
                {
                    var property = type.GetProperty(arg.Name);
                    if (property == null)
                    {
                        continue;
                    }
                    var convertedValue = Convert.ChangeType(arg.Value, property.PropertyType);
                    property.SetValue(properties, convertedValue);
                }
            }
            return(properties);
        }