Example #1
0
        public static TestSuiteInfo GetTestSuiteInfo(Type testerType, IEnumerable<Type> testedTypes, params TestSuiteInfo[] testSuitesForUpdate)
        {
            var testerAttribute = testerType.Attribute<PerfTesterAttribute>();
            var descrGetter = testerType.MethodsWith(Flags.AllMembers, typeof(PerfRunDescriptorAttribute)).FirstOrDefault();

            var suiteInfo = testSuitesForUpdate.FirstOrDefault(x => x.TesterType == testerType) ?? new TestSuiteInfo
                {
                    TesterType = testerType,
                    DefaultTestCount = testerAttribute.TestCount,
                    TestSuiteDescription = testerAttribute.Description,
                    FeatureDescription = testerAttribute.FeatureDescription,
                    TestedAbstraction = testerAttribute.TestedType,
                    GetDescriptoMethodName = descrGetter == null ? string.Empty : descrGetter.Name
                };

            var tests = new List<TestInfo>();
            var ignoredTests = new List<TestInfoIgnored>();

            foreach (var test in from method in testerType.MethodsWith(Flags.AllMembers, typeof(PerfTestAttribute))
                                 from testedType in testedTypes
                                 where suiteInfo.Tests == null || !suiteInfo.Tests.Any(x => x.TestedType == testedType)
                                 select GetTestInfo(Guid.NewGuid(), method, testerAttribute.TestedType, suiteInfo, testedType))
            {
                var ignored = test as TestInfoIgnored;
                if (ignored != null)
                {
                    ignoredTests.Add(ignored);
                    continue;
                }

                if (test != null)
                {
                    tests.Add(test);
                    continue;
                }

                throw new NotImplementedException("Unknown test information type.");
            }

            suiteInfo.Tests = tests.ToArray();

            if (suiteInfo.IgnoredTests != null)
            {
                ignoredTests.AddRange(suiteInfo.IgnoredTests);
            }
            suiteInfo.IgnoredTests = ignoredTests.ToArray();

            return suiteInfo;
        }
Example #2
0
        public ITable Translate(Type entityType)
        {
            Table table;

            if (tables.TryGetValue(entityType, out table))
            {
                return table;
            }

            var dbTable = entityType.Attribute<DbTableAttribute>();

            table = new Table(dbTable != null ? dbTable.TableName : entityType.Name);

            table.EntityType = entityType;

            table.Fields = MakeFields(entityType, table);
            table.Fields = table.Fields
                .Select(f => SetFieldBindMember(this, f.Info, (Field)f))
                .Select(WrapperDateTime).ToList();

            table.Keys = table.Fields
                .Where(f => f.IsKey).ToList();

            table.IdentityField = table.Keys.FirstOrDefault(f => f.IsIdentity);

            Parallel.Invoke(

                () => table.SqlCount = builders[SqlBuilderType.Count].Build(table),
                () => table.SqlCountById = builders[SqlBuilderType.CountById].Build(table),
                () => table.SqlDeleteById = builders[SqlBuilderType.Delete].Build(table),
                () => table.SqlInsert = builders[SqlBuilderType.Insert].Build(table),
                () => table.SqlSelect = builders[SqlBuilderType.Select].Build(table),
                () => table.SqlSelectById = builders[SqlBuilderType.SelectById].Build(table),
                () => table.SqlUpdate = builders[SqlBuilderType.Update].Build(table)

            );

            return tables[entityType] = table;
        }
Example #3
0
        private static bool IsTestableType(Type testerType, Type testedType)
        {
            var testerAttr = testerType.Attribute<PerfTesterAttribute>();
            var commonConditions = testedType.IsPublic && !(testerAttr.TestedType == testedType)
                                   && !testedType.IsAbstract && !testedType.IsInterface;
            var isTestableNonGeneric = !testedType.IsGenericTypeDefinition
                   && testerAttr.TestedType.IsAssignableFrom(testedType);
            var isTestableGeneric = testedType.IsGenericType && testerAttr.TestedType.IsGenericType &&
                testedType.GetInterfaces().Any(x => x.IsGenericType &&
                    x.GetGenericTypeDefinition() == testerAttr.TestedType.GetGenericTypeDefinition());

            return commonConditions && (isTestableGeneric || isTestableNonGeneric);
        }
 public static int SizeOf(Type elementType)
 {
     var elementSize = 0;
     var layoutAttribute = elementType.Attribute(typeof(TagBlockLayoutAttribute)) as TagBlockLayoutAttribute;
     if (layoutAttribute != null)
         elementSize = layoutAttribute.Size;
     else elementSize = Marshal.SizeOf(elementType);
     return elementSize;
 }
Example #5
0
        private static void CheckTestability(Type testerType, Type testedType)
        {
            if (testerType == null)
            {
                throw new ArgumentNullException("testerType");
            }

            if (testedType == null)
            {
                throw new ArgumentNullException("testedType");
            }

            var testerAttribute = testerType.Attribute<PerfTesterAttribute>();
            if (testerAttribute == null)
            {
                throw new ArgumentException("Tester type must be marked by PerfTesterAttribute", "testerType");
            }

            if ((!testerAttribute.TestedType.IsAssignableFrom(testedType)) &&
                (!testedType.GetInterfaces().Any(x => x.IsGenericType &&
                    x.GetGenericTypeDefinition() == testerAttribute.TestedType.GetGenericTypeDefinition())))
            {
                throw new ArgumentException(
                    string.Format("Tester type {0} is not assignable from {1}", testerAttribute.TestedType, testedType),
                    "testerType");
            }
        }
		private bool InternalRegister(Type typeToRegister)
		{
			//Ok so here the fun begins.
			//We need a recursive algorithm for walking the graph of the Type to register each
			//serializable type. So, for every member we must look down into that Type recursively and register it.
			//However, we must make sure to check if it's already been registered or we might get circular graphs which
			//would overflow. But that'd be a weird type anyway.

			if (typeToRegister == null)
				throw new ArgumentNullException(nameof(typeToRegister), $"Provided {typeToRegister} is a null arg.");

			//Can't use isDefined exclusively but it'll fail when doing two-way subtypes
			if (registeredTypes.ContainsKey(typeToRegister))
				return true;

			if (typeof(IEnumerable).IsAssignableFrom(typeToRegister) || typeToRegister.IsArray)
				if (typeToRegister.IsArray)
					Register(typeToRegister.GetElementType());
				else
					foreach (var gparam in typeToRegister.GetGenericArguments())
						Register(gparam);

			//if (RuntimeTypeModel.Default.IsDefined(typeToRegister))
			//	return true;


			if (typeToRegister.IsEnum)
			{
				MetaType enumMetaType = RuntimeTypeModel.Default.Add(typeToRegister, false);
				enumMetaType.EnumPassthru = true;
				enumMetaType.AsReferenceDefault = false;

				return true;
			}

			//If it's not defined we need to add it.
			if (typeToRegister.Attribute<GladNetSerializationContractAttribute>() == null)
				return false;

			MetaType typeModel = RuntimeTypeModel.Default.Add(typeToRegister, false);

			//Add each member
			foreach (MemberInfo mi in typeToRegister.MembersWith<GladNetMemberAttribute>(MemberTypes.Field | MemberTypes.Property, Flags.InstanceAnyDeclaredOnly)) //keep this declare only because of Unity3D serialization issues with NetSendable
			{
				typeModel.Add(mi.Attribute<GladNetMemberAttribute>().TagID, mi.Name);

				//Now we might need to register this type aswell.
				//Recur to try to register this type
				Register(mi.Type());
			}

			//If might have a include on it so we should check it to register it with the subtype

			IEnumerable<GladNetSerializationIncludeAttribute> includes = typeToRegister.Attributes<GladNetSerializationIncludeAttribute>();

			foreach (GladNetSerializationIncludeAttribute include in includes)
			{
				//if we don't know about the type register it
				if (!registeredTypes.ContainsKey(include.TypeToWireTo))
					Register(include.TypeToWireTo);

				//this is the simple case; however unlike protobuf we support two-include
				if (include != null && include.IncludeForDerived)
				{
					if (include.TypeToWireTo == typeModel.Type || !typeModel.Type.IsAssignableFrom(include.TypeToWireTo))
						continue;
					else
						typeModel.AddSubType(include.TagID, include.TypeToWireTo);
				}
				else
					if (include != null && !include.IncludeForDerived)
				{
					//this is not for mappping a base type to setup mapping for its child
					//we need to map this child to its base
					//so we need to get the MetaType for it
					RuntimeTypeModel.Default[include.TypeToWireTo]
						.AddSubType(include.TagID, typeToRegister);
				}
			}

			registeredTypes.Add(typeToRegister, null);

			return true;
		}
 private bool TypeIsASingleton(Type type)
 {
     return type.Attribute<SingletonAttribute>() != null;
 }