示例#1
0
        public static string ListOutKeyProperties(string prefix, ISpecificationModel model)
        {
            string propertiesListed = string.Empty;

            if (model != null && model.Key != null)
            {
                propertiesListed = TestingHelper.ListOutKeyProperties(prefix, model.Key);
            }

            return(propertiesListed);
        }
示例#2
0
        public static string RandomValue(ISpecification specification, ISpecificationProperty specificationProperty, bool usingMocks, bool useNullForDefault)
        {
            if (specificationProperty.Relationship != null && specificationProperty.Relationship.RelatedModel != null)
            {
                ISpecificationModel relatedModel = specificationProperty.Relationship.RelatedModel;

                if (usingMocks)
                {
                    if (specificationProperty.IsList)
                    {
                        return("this." + relatedModel.Variable.ListInstanceName + ".Select(_mock => _mock.Object).ToList()");
                    }
                    else
                    {
                        return("this." + relatedModel.Variable.InstanceName + ".Object");
                    }
                }
                else
                {
                    if (specificationProperty.IsList)
                    {
                        return(TemplatesHelper.NewOf(TemplatesHelper.ListOf(relatedModel.Interface.VariableType)));
                    }
                    else if (useNullForDefault)
                    {
                        return("null");
                    }
                    else
                    {
                        return("this." + relatedModel.Variable.InstanceName);
                    }
                }
            }

            if (specification.Enumerations.Values.Any(_enumeration => _enumeration.Name == specificationProperty.PropertyType.Replace("?", "")))
            {
                ISpecificationEnumeration specificationEnumeration = specification.Enumerations.Values.First(_enumeration => _enumeration.Name == specificationProperty.PropertyType.Replace("?", ""));

                IEnumeration enumeration = new TemplateEnumeration(specification.Settings.FrameworkNamespace, specificationEnumeration.Name);
                foreach (ISpecificationEnumerationItem item in specificationEnumeration.Items)
                {
                    enumeration.Add(new TemplateEnumerationItem(item.Name));
                }

                return(TemplatesHelper.FormatEnumeration(TemplatesHelper.RandomEnumerationItem(enumeration)));
            }

            if (specificationProperty.PropertyType == "bool" || specificationProperty.PropertyType == "bool?")
            {
                return(TemplatesHelper.FormatBool(specificationProperty.Default != null ? (bool)specificationProperty.Default : TemplatesHelper.RandomBool()));
            }
            if (specificationProperty.PropertyType == "DateTime" || specificationProperty.PropertyType == "DateTime?")
            {
                return(TemplatesHelper.FormatDateTime(specificationProperty.Default != null ? (DateTime)specificationProperty.Default : specificationProperty.IsDateOnly?DateTime.Now.Date: DateTime.Now));
            }
            if (specificationProperty.PropertyType == "double" || specificationProperty.PropertyType == "double?")
            {
                return(TemplatesHelper.FormatDouble(specificationProperty.Default != null ? (double)specificationProperty.Default : TestingHelper.RandomDouble(specificationProperty)));
            }
            if (specificationProperty.PropertyType == "Guid" || specificationProperty.PropertyType == "Guid?")
            {
                return("Guid.NewGuid()");
            }
            if (specificationProperty.PropertyType == "int" || specificationProperty.PropertyType == "int?")
            {
                return(TemplatesHelper.FormatInt(specificationProperty.Default != null ? (int)specificationProperty.Default : TestingHelper.RandomInt(specificationProperty)));
            }
            if (specificationProperty.PropertyType == "string")
            {
                return(TemplatesHelper.FormatString(specificationProperty.Default != null ? (string)specificationProperty.Default : TestingHelper.RandomString(specificationProperty)));
            }
            if (specificationProperty.PropertyType == "TimeSpan" || specificationProperty.PropertyType == "TimeSpan?")
            {
                return(TemplatesHelper.FormatTimeSpan(specificationProperty.Default != null ? (TimeSpan)specificationProperty.Default : TemplatesHelper.RandomTimeSpan()));
            }

            return(TemplatesHelper.FormatString("Unsupported type: " + specificationProperty.PropertyType));
        }
示例#3
0
 public static string ListOutKeyProperties(ISpecificationModel model)
 {
     return(TestingHelper.ListOutKeyProperties(null, model));
 }
示例#4
0
 public static string ListOutKeyProperties(ISpecificationKey key)
 {
     return(TestingHelper.ListOutKeyProperties(string.Empty, key));
 }