public void Explore() { if (!_assembly.ReferencedAssembliesNames.Any(x => String.Equals(x.AssemblyName.Name, typeof(It).Assembly.GetName().Name, StringComparison.InvariantCultureIgnoreCase))) { return; } _assembly.GetTypes() .Where(type => type.IsContext()) .ForEach(type => { var contextElement = _contextFactory.CreateContext(type); _consumer(contextElement); type.GetSpecifications().ForEach(x => _consumer(_contextSpecificationFactory.CreateContextSpecification(contextElement, x))); type.GetBehaviors().ForEach(x => { BehaviorElement behaviorElement = _behaviorFactory.CreateBehavior(contextElement, x); _consumer(behaviorElement); _behaviorSpecificationFactory.CreateBehaviorSpecificationsFromBehavior(behaviorElement, x).ForEach(y => _consumer(y)); }); }); }
public BehaviorElement GetOrCreateBehavior(ContextElement context, IClrTypeName declaringTypeName, string fieldName, bool isIgnored, string fieldType) { var id = BehaviorElement.CreateId(_elementIdFactory, _provider, context, fieldType, fieldName); var behavior = this._manager.GetElementById(id) as BehaviorElement; if (behavior != null) { behavior.Parent = context; return(behavior); } return(new BehaviorElement(this._provider, id, context, declaringTypeName.GetPersistent(), this._cachingService, this._manager, fieldName, isIgnored, fieldType)); }
public BehaviorElement GetOrCreateBehavior(ContextElement context, IClrTypeName declaringTypeName, string fieldName, bool isIgnored, string fieldType) { var id = BehaviorElement.CreateId(_provider, context, fieldType, fieldName); var behavior = this._manager.GetElementById(id) as BehaviorElement; if (behavior != null) { behavior.Parent = context; behavior.State = UnitTestElementState.Valid; return(behavior); } return(new BehaviorElement(this._provider, this._psiModuleManager, this._cacheManager, context, new ProjectModelElementEnvoy(context.GetProject()), declaringTypeName, fieldName, isIgnored, fieldType)); }
BehaviorSpecificationElement CreateBehaviorSpecification(BehaviorElement behavior, IMetadataField behaviorSpecification) { return(this.GetOrCreateBehaviorSpecification(behavior, new ClrTypeName(behaviorSpecification.DeclaringType.FullyQualifiedName), behaviorSpecification.Name, behaviorSpecification.IsIgnored())); }
internal BehaviorSpecificationElement CreateBehaviorSpecification(BehaviorElement behavior, IDeclaredElement behaviorSpecification) { return(this.GetOrCreateBehaviorSpecification(behavior, ((ITypeMember)behaviorSpecification).GetContainingType().GetClrName(), behaviorSpecification.ShortName, behaviorSpecification.IsIgnored())); }
BehaviorSpecificationElement CreateBehaviorSpecification(BehaviorElement behavior, IMetadataField behaviorSpecification) { return(this.GetOrCreateBehaviorSpecification(behavior, this._reflectionTypeNameCache.GetClrName(behaviorSpecification.DeclaringType), behaviorSpecification.Name, behaviorSpecification.IsIgnored())); }
public UnitTestTask CreateBehaviorTask(ContextElement context, BehaviorElement behavior, bool isExplicit) { return(new UnitTestTask(behavior, new BehaviorTask(_providerId, context.AssemblyLocation, context.GetTypeClrName(), behavior.FieldName, false))); }
BehaviorSpecificationElement CreateBehaviorSpecification(BehaviorElement behavior, IMetadataField behaviorSpecification) { return(new BehaviorSpecificationElement(_provider, behavior, _projectEnvoy, behavior.FullyQualifiedTypeName ?? behaviorSpecification.DeclaringType.FullyQualifiedName, behaviorSpecification.Name, behaviorSpecification.IsIgnored())); }
BehaviorSpecificationElement CreateBehaviorSpecification(BehaviorElement behavior, IDeclaredElement behaviorSpecification) { return(new BehaviorSpecificationElement(_provider, behavior, _projectEnvoy, behavior.FullyQualifiedTypeName ?? behaviorSpecification.GetContainingType().CLRName, behaviorSpecification.ShortName, behaviorSpecification.IsIgnored())); }
public void SetsCorrectAggregateId() { var context = Substitute.For <IContextElement>(); context.TypeName.Returns("Namespace.ContextType"); var element = new BehaviorElement(context, "Namespace.BehaviorType", "a_vehicle_that_is_started", null); Assert.That(element.AggregateId, Is.EqualTo("Namespace.ContextType.Namespace.BehaviorType")); }
public void AddBehavior(IDeclaredElement type, BehaviorElement behavior) { if (!_behaviors.ContainsKey(type)) { _behaviors.Add(type, behavior); } else { _behaviors[type] = behavior; } }
public IEnumerable <BehaviorSpecificationElement> CreateBehaviorSpecificationsFromBehavior( BehaviorElement behavior, IMetadataField behaviorSpecification) { var typeContainingBehaviorSpecifications = behaviorSpecification.GetFirstGenericArgument(); foreach (var specification in typeContainingBehaviorSpecifications.GetSpecifications()) { yield return(this.CreateBehaviorSpecification(behavior, specification)); } }
public void BehaviorPresentationIsValid() { With(() => { var id = CreateId("id"); var element = new BehaviorElement(id, CreateUnitTestElement(), Substitute.For <IClrTypeName>(), ServiceProvider, "field_is_something", false); Assert.That(element.GetPresentation(null, false), Is.EqualTo("behaves like field is something")); }); }
public void CanGetHashCode() { With(() => { var id = CreateId("id"); var element = new BehaviorElement(id, CreateUnitTestElement(), Substitute.For <IClrTypeName>(), ServiceProvider, "field", false); Assert.That(element.GetHashCode(), Is.Not.EqualTo(0)); }); }
BehaviorSpecificationElement CreateBehaviorSpecification(BehaviorElement behavior, IMetadataField behaviorSpecification) { return(GetOrCreateBehaviorSpecification(_provider, #if RESHARPER_61 _manager, _psiModuleManager, _cacheManager, #endif _project, behavior, _projectEnvoy, behavior.FullyQualifiedTypeName ?? behaviorSpecification.DeclaringType.FullyQualifiedName, behaviorSpecification.Name, behaviorSpecification.IsIgnored())); }
BehaviorSpecificationElement CreateBehaviorSpecification(BehaviorElement behavior, IMetadataField behaviorSpecification) { return(GetOrCreateBehaviorSpecification(_provider, _manager, _psiModuleManager, _cacheManager, _project, behavior, _projectEnvoy, _reflectionTypeNameCache.GetClrName(behaviorSpecification.DeclaringType), behaviorSpecification.Name, behaviorSpecification.IsIgnored())); }
internal BehaviorSpecificationElement CreateBehaviorSpecification(BehaviorElement behavior, IDeclaredElement behaviorSpecification) { return(GetOrCreateBehaviorSpecification(_provider, _manager, _psiModuleManager, _cacheManager, _project, behavior, _projectEnvoy, ((ITypeMember)behaviorSpecification).GetContainingType() .GetClrName() .GetPersistent(), behaviorSpecification.ShortName, behaviorSpecification.IsIgnored())); }
public void BehaviorsWithSamePropertiesAreEqual() { With(() => { var id = CreateId("id"); var type = Substitute.For <IClrTypeName>(); var element1 = new BehaviorElement(id, CreateUnitTestElement(), type, ServiceProvider, "field", false); var element2 = new BehaviorElement(id, CreateUnitTestElement(), type, ServiceProvider, "field", false); Assert.That(element1, Is.EqualTo(element2)); }); }
public IUnitTestElement DeserializeElement(XmlElement parent, IUnitTestElement parentElement) { var typeName = parent.GetAttribute("elementType"); if (Equals(typeName, "ContextElement")) { return(ContextElement.ReadFromXml(parent, parentElement, _provider, _solution, _manager, _psiModuleManager, _cacheManager)); } if (Equals(typeName, "BehaviorElement")) { return(BehaviorElement.ReadFromXml(parent, parentElement, _provider, _solution, _manager, _psiModuleManager, _cacheManager)); } if (Equals(typeName, "BehaviorSpecificationElement")) { return(BehaviorSpecificationElement.ReadFromXml(parent, parentElement, _provider, _solution, _manager, _psiModuleManager, _cacheManager)); } if (Equals(typeName, "ContextSpecificationElement")) { return(ContextSpecificationElement.ReadFromXml(parent, parentElement, _provider, _solution, _manager, _psiModuleManager, _cacheManager)); } return(null); }
BehaviorSpecificationElement CreateBehaviorSpecification(BehaviorElement behavior, IDeclaredElement behaviorSpecification) { return(GetOrCreateBehaviorSpecification(_provider, #if RESHARPER_61 _manager, _psiModuleManager, _cacheManager, #endif _project, behavior, _projectEnvoy, #if RESHARPER_6 behavior.FullyQualifiedTypeName ?? ((ITypeMember)behaviorSpecification).GetContainingType().GetClrName().FullName, #else behavior.FullyQualifiedTypeName ?? behaviorSpecification.GetContainingType().CLRName, #endif behaviorSpecification.ShortName, behaviorSpecification.IsIgnored())); }
public void BehaviorSpecsWithSamePropertiesAreEqual() { With(() => { var id = CreateId("id"); var type = Substitute.For <IClrTypeName>(); var context = new ContextElement(id, Substitute.For <IClrTypeName>(), ServiceProvider, "subject", false); var parent = new BehaviorElement(id, context, Substitute.For <IClrTypeName>(), ServiceProvider, "field", false); var element1 = new BehaviorSpecificationElement(id, parent, type, ServiceProvider, "field", false); var element2 = new BehaviorSpecificationElement(id, parent, type, ServiceProvider, "field", false); Assert.That(element1, Is.EqualTo(element2)); }); }
public static BehaviorElement GetOrCreateBehavior(MSpecUnitTestProvider provider, #if RESHARPER_61 IUnitTestElementManager manager, PsiModuleManager psiModuleManager, CacheManager cacheManager, #endif IProject project, ProjectModelElementEnvoy projectEnvoy, ContextElement context, string declaringTypeName, string fieldName, bool isIgnored, string fullyQualifiedTypeName) { #if RESHARPER_6 var id = BehaviorElement.CreateId(context, fieldName); #if RESHARPER_61 var behavior = manager.GetElementById(project, id) as BehaviorElement; #else var behavior = provider.UnitTestManager.GetElementById(project, id) as BehaviorElement; #endif if (behavior != null) { behavior.Parent = context; behavior.State = UnitTestElementState.Valid; return(behavior); } #endif return(new BehaviorElement(provider, #if RESHARPER_6 #if RESHARPER_61 psiModuleManager, cacheManager, #else provider.PsiModuleManager, provider.CacheManager, #endif #endif context, projectEnvoy, declaringTypeName, fieldName, isIgnored, fullyQualifiedTypeName)); }
public static BehaviorSpecificationElement GetOrCreateBehaviorSpecification(MSpecUnitTestProvider provider, #if RESHARPER_61 IUnitTestElementManager manager, PsiModuleManager psiModuleManager, CacheManager cacheManager, #endif IProject project, BehaviorElement behavior, ProjectModelElementEnvoy projectEnvoy, string declaringTypeName, string fieldName, bool isIgnored) { #if RESHARPER_6 var id = BehaviorSpecificationElement.CreateId(behavior, fieldName); #if RESHARPER_61 var behaviorSpecification = manager.GetElementById(project, id) as BehaviorSpecificationElement; #else var behaviorSpecification = provider.UnitTestManager.GetElementById(project, id) as BehaviorSpecificationElement; #endif if (behaviorSpecification != null) { behaviorSpecification.Parent = behavior; behaviorSpecification.State = UnitTestElementState.Valid; return(behaviorSpecification); } #endif return(new BehaviorSpecificationElement(provider, #if RESHARPER_6 #if RESHARPER_61 psiModuleManager, cacheManager, #else provider.PsiModuleManager, provider.CacheManager, #endif #endif behavior, projectEnvoy, declaringTypeName, fieldName, isIgnored)); }
public IEnumerable <UnitTestElementDisposition> AcceptElement(string assemblyPath, IFile file, ITreeNode element) { IDeclaration declaration = (IDeclaration)element; BehaviorElement behavior = this._factory.CreateBehavior(declaration.DeclaredElement); if (behavior == null) { yield break; } var projectFile = file.GetSourceFile().ToProjectFile(); var behaviorTextRange = declaration.GetNameDocumentRange().TextRange; var behaviorContainingRange = declaration.GetDocumentRange().TextRange; yield return(new UnitTestElementDisposition(behavior, projectFile, behaviorTextRange, behaviorContainingRange)); var behaviorContainer = declaration.DeclaredElement.GetFirstGenericArgument(); if (!behaviorContainer.IsBehaviorContainer()) { yield break; } foreach (var field in behaviorContainer.Fields) { if (!field.IsSpecification()) { continue; } BehaviorSpecificationElement behaviorSpecification = this._behaviorSpecifications.CreateBehaviorSpecification(behavior, field); yield return(new UnitTestElementDisposition(behaviorSpecification, projectFile, behaviorTextRange, behaviorContainingRange)); } }
public BehaviorElement CreateBehavior(ContextElement context, IMetadataField behavior) { var typeContainingBehaviorSpecifications = behavior.GetFirstGenericArgument(); var fullyQualifiedTypeName = behavior.FirstGenericArgumentClass().FullyQualifiedName(); var typeName = GetNormalizedTypeName(fullyQualifiedTypeName); var behaviorElement = new BehaviorElement(_provider, context, _projectEnvoy, behavior.DeclaringType.FullyQualifiedName, behavior.Name, behavior.IsIgnored() || typeContainingBehaviorSpecifications.IsIgnored(), fullyQualifiedTypeName); if (!TypeNameCache.ContainsKey(typeName)) { TypeNameCache.Add(typeName, fullyQualifiedTypeName); } return(behaviorElement); }
public async Task AddsSingleBehavior() { var context = new ContextElement("Namespace.ContextType", "subject", null); var behavior = new BehaviorElement(context, "Namespace.ABehavior", "a_vehicle_that_is_started", null); var specification1 = new SpecificationElement(context, "should_be", null, behavior); var specification2 = new SpecificationElement(context, "should_not_be", null, behavior); var sink = new MspecDiscoverySink(CancellationToken.None); sink.OnSpecification(specification1); sink.OnSpecification(specification2); sink.OnDiscoveryCompleted(); var results = await sink.Elements; Assert.That(results.Length, Is.EqualTo(4)); CollectionAssert.Contains(results, context); CollectionAssert.Contains(results, behavior); CollectionAssert.Contains(results, specification1); CollectionAssert.Contains(results, specification2); }
public IUnitTestElement DeserializeElement(XmlElement parent, IUnitTestElement parentElement) { var typeName = parent.GetAttribute("elemenType"); if (Equals(typeName, "ContextElement")) { return(ContextElement.ReadFromXml(parent, parentElement, this, Solution)); } if (Equals(typeName, "BehaviorElement")) { return(BehaviorElement.ReadFromXml(parent, parentElement, this, Solution)); } if (Equals(typeName, "BehaviorSpecificationElement")) { return(BehaviorSpecificationElement.ReadFromXml(parent, parentElement, this, Solution)); } if (Equals(typeName, "ContextSpecificationElement")) { return(ContextSpecificationElement.ReadFromXml(parent, parentElement, this, Solution)); } return(null); }
public BehaviorSpecificationElement GetOrCreateBehaviorSpecification(BehaviorElement behavior, IClrTypeName declaringTypeName, string fieldName, bool isIgnored) { var id = BehaviorSpecificationElement.CreateId(_provider, behavior, fieldName); var behaviorSpecification = this._manager.GetElementById(id) as BehaviorSpecificationElement; if (behaviorSpecification != null) { behaviorSpecification.Parent = behavior; behaviorSpecification.State = UnitTestElementState.Valid; return(behaviorSpecification); } return(new BehaviorSpecificationElement(this._provider, this._psiModuleManager, this._cacheManager, new ProjectModelElementEnvoy(behavior.GetProject()), behavior, declaringTypeName, fieldName, isIgnored)); }
public BehaviorSpecificationElement GetOrCreateBehaviorSpecification(BehaviorElement behavior, IClrTypeName declaringTypeName, string fieldName, bool isIgnored) { var id = BehaviorSpecificationElement.CreateId(_elementIdFactory, _provider, behavior, fieldName); var behaviorSpecification = this._manager.GetElementById(id) as BehaviorSpecificationElement; if (behaviorSpecification != null) { behaviorSpecification.Parent = behavior; return(behaviorSpecification); } return(new BehaviorSpecificationElement(this._provider, id, behavior, declaringTypeName.GetPersistent(), this._cachingService, this._manager, fieldName, isIgnored)); }
public IEnumerable <BehaviorSpecificationElement> CreateBehaviorSpecificationsFromBehavior(BehaviorElement behavior, IDeclaredElement behaviorSpecification) { IClass typeContainingBehaviorSpecifications = behaviorSpecification.GetFirstGenericArgument(); foreach (IField specification in typeContainingBehaviorSpecifications.GetBehaviorSpecifications()) { yield return(CreateBehaviorSpecification(behavior, specification)); } }