public void DefaultValues() { var sut = new UnknownReference(); Assert.AreNotEqual(0, sut.GetHashCode()); Assert.AreNotEqual(1, sut.GetHashCode()); }
public void Properties_UnknownReference() { using var tempDir = TempDir.Create(); var dataProvider = new DataProvider(); var dataSource = new DataSource(dataProvider, tempDir, Model.DataSourceType.Custom); var propertyId = "propertyid"; var clsId = "clsid"; var clsDict = CreateClassDictionary(); clsDict["MDC_P001_5"] = clsId; clsDict["MDC_P014"] = propertyId; var cls = new Class(clsDict); var context = new Context(dataSource, new[] { cls }.ToList(), new List <Property>()); var wrapper = context.LoadSubmodels().First() as ClassWrapper; Assert.That(wrapper, Is.Not.Null); if (wrapper == null) { return; } Assert.That(wrapper.Children.Cast <PropertyWrapper>().Select(p => p.Element), Is.Empty); Assert.That(context.UnknownReferences, Is.EquivalentTo(new[] { UnknownReference.Create <Property>(propertyId), })); }
public void Equality() { var a = new UnknownReference(); var b = new UnknownReference(); Assert.AreEqual(a, b); Assert.AreEqual(a.GetHashCode(), b.GetHashCode()); }
public Assignment() { Reference = new UnknownReference(); Expression = new UnknownExpression(); }
public void UnknownReference() { var sst = new UnknownReference(); AssertPrint(sst, "???"); }
public void VisitorWithReturnIsImplemented() { var sut = new UnknownReference(); sut.Accept(23).VerifyWithReturn(v => v.Visit(sut, 23)); }
public EventSubscriptionStatement() { Reference = new UnknownReference(); Expression = new UnknownExpression(); }
public override IAssignableExpression VisitObjectCreationExpression(IObjectCreationExpression expr, IList <IStatement> body) { var r = expr.ConstructorReference.Resolve(); if (r.IsValid() && r.DeclaredElement != null) { var methodName = r.DeclaredElement.GetName <IMethodName>(r.Result.Substitution); Asserts.That(methodName.IsConstructor); var parameters = Lists.NewList <ISimpleExpression>(); foreach (var argument in expr.Arguments) { var parameter = ToSimpleExpression(argument.Value, body); parameters.Add(parameter); } var sstInv = new InvocationExpression { MethodName = methodName, Parameters = parameters }; var oInit = expr.Initializer as IObjectInitializer; var cInit = expr.Initializer as ICollectionInitializer; if (oInit != null || cInit != null) { var varDeclName = GetNameFromDeclaration(expr); IVariableReference newVar; if (varDeclName != null) { newVar = new VariableReference { Identifier = varDeclName }; } else { newVar = new VariableReference { Identifier = _nameGen.GetNextVariableName() }; body.Add( new VariableDeclaration { Reference = newVar, Type = sstInv.MethodName.DeclaringType }); } body.Add( new Assignment { Reference = newVar, Expression = sstInv }); if (oInit != null) { foreach (var mInit in oInit.MemberInitializersEnumerable) { IAssignableReference reference = null; var rr = mInit.Reference.Resolve(); var elem = rr.DeclaredElement; var typeMember = elem as ITypeMember; if (typeMember != null) { reference = ToReference(typeMember, newVar) as IAssignableReference; } if (reference == null) { reference = new UnknownReference(); } // check that operator is "=" if (mInit.Expression != null) { body.Add( new Assignment { Reference = reference, Expression = ToAssignableExpr(mInit.Expression, body) }); } else { var prop = elem as IProperty; var pInit = mInit as IPropertyInitializer; if (prop != null && pInit != null && pInit.Initializer != null) { var nextVar = new VariableReference { Identifier = _nameGen.GetNextVariableName() }; body.Add( new VariableDeclaration { Reference = nextVar, Type = prop.ReturnType.GetName() }); body.Add( new Assignment { Reference = nextVar, Expression = new ReferenceExpression { Reference = reference } }); ISubstitution substitution = EmptySubstitution.INSTANCE; var ctype = pInit.Initializer.ConstructedType as IDeclaredType; if (ctype != null) { var rctype = ctype.Resolve(); substitution = rctype.Substitution; } var addName = FindAdd(prop, substitution); foreach (var eInit in pInit.Initializer.InitializerElements) { var ceInit = eInit as ICollectionElementInitializer; if (ceInit != null) { foreach (var arg in ceInit.Arguments) { body.Add( new ExpressionStatement { Expression = new InvocationExpression { Reference = nextVar, MethodName = addName, Parameters = { ToSimpleExpression(arg.Value, body) } } }); } } } } } } } if (cInit != null) { var m = r.DeclaredElement as IConstructor; var addName = FindAdd(m, r.Result.Substitution) ?? Names.UnknownMethod; foreach (var eInit in cInit.ElementInitializersEnumerable) { foreach (var arg in eInit.Arguments) { body.Add( new ExpressionStatement { Expression = new InvocationExpression { Reference = newVar, MethodName = addName, Parameters = { ToSimpleExpression(arg.Value, body) } } }); } } } return(new ReferenceExpression { Reference = newVar }); } return(sstInv); } return(new InvocationExpression { MethodName = Names.UnknownMethod }); }
public ReferenceExpression() { Reference = new UnknownReference(); }