Exemplo n.º 1
0
        public async Task <int> AddTestAssemblyAsync(byte[] rawAssembly)
        {
            if (rawAssembly == null)
            {
                throw new ArgumentNullException(nameof(rawAssembly));
            }

            var assembly        = Assembly.Load(rawAssembly);
            var moduleVersionId = assembly.ManifestModule.ModuleVersionId;

            if (!CheckMetaData(moduleVersionId))
            {
                int    length       = assembly.FullName.IndexOf(",", StringComparison.Ordinal);
                string assemblyName = assembly.FullName.Substring(0, length) + ".dll";

                var testAssemblyInfo = new DemoLab.Data.Access.ExerciseExecutor.TestAssemblyInfo
                {
                    Data            = rawAssembly,
                    AssemblyName    = assemblyName,
                    IsSoftDeleted   = false,
                    ModuleVersionId = moduleVersionId
                };

                _context.TestAssemblyInfo.Add(testAssemblyInfo);

                var testClasses = assembly.TypesWith(typeof(TestFixtureAttribute));
                foreach (var testClass in testClasses)
                {
                    var testClassInfo = new DemoLab.Data.Access.ExerciseExecutor.TestClassInfo
                    {
                        Name         = testClass.FullName,
                        AssemblyInfo = testAssemblyInfo
                    };

                    var methods = testClass.MethodsWith(Flags.InstancePublic, typeof(TestAttribute));
                    foreach (var method in methods)
                    {
                        var testMethodsInfo = new DemoLab.Data.Access.ExerciseExecutor.TestMethodInfo
                        {
                            Name      = method.Name,
                            ClassInfo = testClassInfo
                        };

                        testClassInfo.TestMethods.Add(testMethodsInfo);
                    }

                    _context.TestClassInfo.Add(testClassInfo);
                }

                await _context.SaveChangesAsync();

                return(testAssemblyInfo.Id);
            }

            throw new AssemblyAlreadyExistsException();
        }
Exemplo n.º 2
0
 private void SoftDeleteAssembly(
     DemoLab.Data.Access.ExerciseExecutor.TestAssemblyInfo assemblyInfo)
 {
     assemblyInfo.IsSoftDeleted = true;
 }