Esempio n. 1
0
 public IEnumerable <SpecificationToRun> GetSpecifications()
 {
     foreach (var method in _methods)
     {
         var typename   = GetTypeName(method);
         var methodname = GetMethodName(method);
         var type       = _assembly.GetType(typename);
         if (type == null)
         {
             throw new ArgumentException("Type not found", "method");
         }
         var allMethods  = type.GetMethods(BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance);
         var methodinfos = allMethods.Where(x => x.Name == methodname);
         foreach (var info in methodinfos)
         {
             SpecificationToRun toRun = null;
             if (typeof(Specification).IsAssignableFrom(info.ReturnType))
             {
                 try
                 {
                     var result = info.CallMethod();
                     if (result != null)
                     {
                         toRun = new SpecificationToRun((Specification)result, info);
                     }
                 }
                 catch (Exception ex)
                 {
                     toRun = new SpecificationToRun(null, "Exception when creating specification", ex, info);
                 }
                 yield return(toRun);
             }
             if (typeof(IEnumerable <Specification>).IsAssignableFrom(info.ReturnType))
             {
                 var specsToRun = new List <SpecificationToRun>();
                 var specs      = new List <Specification>();
                 IEnumerable <Specification> obj;
                 bool error = false;
                 try
                 {
                     obj   = (IEnumerable <Specification>)info.CallMethod();
                     specs = obj.ToList();
                 }
                 catch (Exception ex)
                 {
                     specsToRun.Add(new SpecificationToRun(null, "Exception occured creating specification", ex, info));
                     error = true;
                 }
                 if (!error)
                 {
                     foreach (var item in specs)
                     {
                         yield return(new SpecificationToRun(item, info));
                     }
                 }
             }
         }
     }
 }
Esempio n. 2
0
        public RunResult RunSpecifciation(SpecificationToRun spec)
        {
            var method  = typeof(SpecificationRunner).GetMethod("Run", BindingFlags.NonPublic | BindingFlags.Instance);
            var tomake  = spec.Specification.GetType().GetInterfaces().Single(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(TypedSpecification <>));
            var generic = method.MakeGenericMethod(tomake.GetGenericArguments()[0]);
            var result  = (RunResult)generic.Invoke(this, new [] { spec.Specification });

            result.FoundOnMemberInfo = spec.FoundOn;
            return(result);
        }
        public void Verify(SpecificationToRun spec)
        {
            var runner = new SpecificationRunner();

            RunResult result = runner.RunSpecifciation(spec);
            if (result.Passed)
                return;

            Assert.Fail(Format(result));
        }
Esempio n. 4
0
        public void Verify(SpecificationToRun spec)
        {
            var runner = new SpecificationRunner();
            var result = runner.RunSpecifciation(spec);

            if (result.Passed)
            {
                Console.WriteLine(Format(result));
                return;
            }

            Assert.Fail(Format(result));
        }
 public IEnumerable<SpecificationToRun> GetSpecifications()
 {
     foreach(var method in _methods)
     {
         var typename = GetTypeName(method);
         var methodname = GetMethodName(method);
         var type = _assembly.GetType(typename);
         if(type == null) throw new ArgumentException("Type not found", "method");
         var allMethods = type.GetMethods(BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance);
         var methodinfos = allMethods.Where(x => x.Name == methodname);
         foreach(var info in methodinfos)
         {
             SpecificationToRun toRun = null;
             if (typeof(Specification).IsAssignableFrom(info.ReturnType))
             {
                 try
                 {
                     var result = info.CallMethod();
                     if (result != null)  toRun = new SpecificationToRun((Specification) result, info);
                 }
                 catch(Exception ex)
                 {
                     toRun = new SpecificationToRun(null, "Exception when creating specification", ex, info);
                 }
                 yield return toRun;
             }
             if (typeof(IEnumerable<Specification>).IsAssignableFrom(info.ReturnType))
             {
                 var specsToRun = new List<SpecificationToRun>();
                 var specs = new List<Specification>();
                 IEnumerable<Specification> obj;
                 bool error = false;
                 try
                 {
                     obj = (IEnumerable<Specification>) info.CallMethod();
                     specs = obj.ToList();
                 }
                 catch(Exception ex)
                 {
                     specsToRun.Add(new SpecificationToRun(null, "Exception occured creating specification", ex, info));
                     error = true;
                 }
                 if(!error)
                 {
                     foreach (var item in specs)
                         yield return new SpecificationToRun(item, info);
                 }
             }
         }
     }
 }
Esempio n. 6
0
 public void _(SpecificationToRun spec)
 {
     var result = new SpecificationRunner().RunSpecifciation(spec);
     //todo: print detailed output
     //spec.Specification.Document(result);
     if (!result.Passed)
     {
         if (result.Thrown != null)
         {
             throw result.Thrown;
         }
         Assert.Fail(result.Message ?? "<null>");
     }
 }
Esempio n. 7
0
        private static IEnumerable <SpecificationToRun> AllMethodSpecifications(Type t)
        {
            foreach (var s in t.GetMethods(BindingFlags.Public | BindingFlags.Instance))
            {
                SpecificationToRun toRun = null;
                if (typeof(Specification).IsAssignableFrom(s.ReturnType))
                {
                    try
                    {
                        var result = s.CallMethod();

                        if (result != null)
                        {
                            toRun = new SpecificationToRun((Specification)result, s);
                        }
                    }
                    catch (Exception ex)
                    {
                        toRun = new SpecificationToRun(null, "Exception when creating specification", ex, s);
                    }
                    yield return(toRun);
                }
                if (typeof(IEnumerable <Specification>).IsAssignableFrom(s.ReturnType))
                {
                    var specsToRun = new List <SpecificationToRun>();
                    var specs      = new List <Specification>();
                    IEnumerable <Specification> obj;
                    bool error = false;
                    try
                    {
                        obj   = (IEnumerable <Specification>)s.CallMethod();
                        specs = obj.ToList();
                    }
                    catch (Exception ex)
                    {
                        specsToRun.Add(new SpecificationToRun(null, "Exception occured creating specification", ex, s));
                        error = true;
                    }
                    if (!error)
                    {
                        foreach (var item in specs)
                        {
                            yield return(new SpecificationToRun(item, s));
                        }
                    }
                }
            }
        }
Esempio n. 8
0
 private static IEnumerable<SpecificationToRun> AllMethodSpecifications(Type t)
 {
     foreach (var s in t.GetMethods(BindingFlags.Public | BindingFlags.Instance))
     {
         SpecificationToRun toRun = null;
         if (typeof(Specification).IsAssignableFrom(s.ReturnType))
         {
             try
             {
                 var result = s.CallMethod();
                 
                 if (result != null) toRun = new SpecificationToRun((Specification)result, s);
             }
             catch (Exception ex)
             {
                 toRun = new SpecificationToRun(null, "Exception when creating specification", ex, s);
             }
             yield return toRun;
         }
         if (typeof(IEnumerable<Specification>).IsAssignableFrom(s.ReturnType))
         {
             var specsToRun = new List<SpecificationToRun>();
             var specs = new List<Specification>();
             IEnumerable<Specification> obj;
             bool error = false;
             try
             {
                 obj = (IEnumerable<Specification>)s.CallMethod();
                 specs = obj.ToList();
             }
             catch (Exception ex)
             {
                 specsToRun.Add(new SpecificationToRun(null, "Exception occured creating specification", ex, s));
                 error = true;
             }
             if (!error)
             {
                 foreach (var item in specs)
                     yield return new SpecificationToRun(item, s);
             }
         }
     }
 }
        public override TaskResult Start(TaskExecutionNode node)
        {
            var specificationTask = node.RemoteTask as SpecificationTask;
            if (specificationTask == null)
                return TaskResult.Error;

            var assembly = Assembly.LoadFrom(specificationTask.AssemblyLocation);
            if (assembly == null)
            {
                Server.TaskError(specificationTask, string.Format("Could not load context assembly: {0}", specificationTask.AssemblyLocation));
                return TaskResult.Error;
            }

            var specificationContainer = assembly.GetTypes().FirstOrDefault(t => t.FullName == specificationTask.SpecificationContainerName);
            if (specificationContainer == null)
            {
                Server.TaskError(specificationTask, string.Format("Could not load type '{0}' from assembly {1}", specificationTask.SpecificationContainerName, specificationTask.AssemblyLocation));
                return TaskResult.Error;
            }

            var fieldInfo = specificationContainer.GetField(specificationTask.SpecificationName);
            if (fieldInfo == null)
            {
                Server.TaskError(specificationTask, string.Format("Could not find field '{0}' on type {1}", specificationTask.SpecificationName, specificationTask.SpecificationContainerName));
                return TaskResult.Error;
            }

            if (!typeof(Specification).IsAssignableFrom(fieldInfo.FieldType))
            {
                Server.TaskError(specificationTask, string.Format("'{0}' is not a specification", specificationTask.SpecificationName));
                return TaskResult.Error;
            }

            var specification = (Specification)fieldInfo.GetValue(Activator.CreateInstance(specificationContainer));
            var specificationToRun = new SpecificationToRun(specification, fieldInfo);

            var runner = new SpecificationRunner();
            var runResult = runner.RunSpecification(specificationToRun);

            Server.TaskOutput(specificationTask, RunResultFormatter.FormatRunResult(runResult), TaskOutputType.STDOUT);

            return runResult.Passed ? TaskResult.Success : TaskResult.Error;
        }
        public RunResult RunSpecifciation(SpecificationToRun spec)
        {
            if (!spec.IsRunnable)
            {
                return(new RunResult
                {
                    FoundOnMemberInfo = spec.FoundOn,
                    Message = spec.Reason,
                    Thrown = spec.Exception,
                    Passed = false
                });
            }
            var method  = typeof(SpecificationRunner).GetMethod("Run", BindingFlags.NonPublic | BindingFlags.Instance);
            var tomake  = spec.Specification.GetType().GetInterfaces().Single(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(TypedSpecification <>));
            var generic = method.MakeGenericMethod(tomake.GetGenericArguments()[0]);
            var result  = (RunResult)generic.Invoke(this, new object[] { spec.Specification, spec.FoundOn });

            result.FoundOnMemberInfo = spec.FoundOn;
            return(result);
        }
Esempio n. 11
0
 static TestCaseData AsTestCaseData(SpecificationToRun spec)
 {
     var data = new TestCaseData(spec);
     data.SetName(spec.Specification.GetName());
     return data;
 }
Esempio n. 12
0
 static string Name(SpecificationToRun r)
 {
     return (r.Specification.GetName() ?? r.FoundOn.Name).CleanupName() + " ";
 }