Ejemplo n.º 1
0
        public override IUnitTestElement Map(Test test)
        {
            using (ReadLockCookie.Create())
            {
                var assemblyPath  = _project?.GetOutputFilePath(_targetFrameworkId);
                var typeName      = GetType(test);
                var fieldName     = GetField(test);
                var subject       = GetTraits(test, "Subject").FirstOrDefault();
                var tags          = GetTraits(test, "Tag");
                var behaviorField = GetTraits(test, "BehaviorField").FirstOrDefault();
                var behaviorType  = GetTraits(test, "BehaviorType").FirstOrDefault();

                var type = new ClrTypeName(typeName);

                var context = _factory.GetOrCreateContext(_project, type, assemblyPath, subject, tags.ToArray(), false);

                if (!string.IsNullOrEmpty(behaviorField) && !string.IsNullOrEmpty(behaviorType))
                {
                    var behavior = _factory.GetOrCreateBehavior(_project, context, type, behaviorField, false);

                    return(_factory.GetOrCreateBehaviorSpecification(_project, behavior, new ClrTypeName(behaviorType), fieldName, false));
                }

                return(_factory.GetOrCreateContextSpecification(_project, context, type, fieldName, false));
            }
        }
Ejemplo n.º 2
0
        private void ProcessBehaviorField(IProject project, IFieldInfo field, IDeclaration declaration = null)
        {
            var behaviorType   = field.FieldType.GetGenericArguments().FirstOrDefault();
            var containingType = new ClrTypeName(field.DeclaringType);

            if (_contexts.TryGetValue(containingType, out var context))
            {
                var behavior = _factory.GetOrCreateBehavior(
                    project,
                    context,
                    containingType,
                    field.ShortName,
                    field.IsIgnored());

                OnUnitTestElement(behavior, declaration);

                if (behaviorType != null && behaviorType.IsBehaviorContainer())
                {
                    var specFields = behaviorType.GetFields()
                                     .Where(x => x.IsSpecification());

                    foreach (var specField in specFields)
                    {
                        var specification = _factory.GetOrCreateBehaviorSpecification(
                            project,
                            behavior,
                            new ClrTypeName(specField.DeclaringType),
                            specField.ShortName,
                            specField.IsIgnored());

                        OnUnitTestElement(specification, declaration);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private void ExploreBehaviorSpecification(IProject project, IUnitTestElement behaviorElement, IFieldInfo field)
        {
            var specificationElement = _factory.GetOrCreateBehaviorSpecification(
                project,
                behaviorElement,
                new ClrTypeName(field.DeclaringType),
                field.ShortName,
                field.IsIgnored());

            _observer.OnUnitTestElement(specificationElement);
        }