public void CreateFunctionWithParamsCreatesCorrectObject() { int integerParam = 7; string textParam = "TEST_STRING"; ITestClassWithParams etalon_object = new TestClassWithParams(integerParam, textParam); ITestClassWithParams created_object = classFactory.Create <ITestClassWithParams>(integerParam, textParam); Assert.ReferenceEquals(etalon_object, created_object); }
/// <summary> /// Resolves the specified container name. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="containerName">Name of the container.</param> /// <returns></returns> static public T Resolve <T>(string containerName) { T results = default(T); UnityContainerElement container = UnityHelper.GetContainer(containerName); Type theTypeImInterestedIn = typeof(T); UnityTypeElement matchedType = null; Boolean bMatchFound = false; foreach (UnityTypeElement typeElement in container.Types) { string[] typeParts = typeElement.TypeName.Split(','); string typeNameDef = string.Format("{0},{1}", typeParts[0], typeParts[1]); string typeMapDef = string.Format("{0}.{1},{2}", theTypeImInterestedIn.Namespace, theTypeImInterestedIn.Name, theTypeImInterestedIn.Assembly.GetName().Name); typeNameDef = typeNameDef.Replace(" ", string.Empty); typeMapDef = typeMapDef.Replace(" ", string.Empty); if (string.Compare(typeNameDef, typeMapDef, true) == 0) { bMatchFound = true; matchedType = typeElement; break; } } if (bMatchFound) { string[] typeParts = matchedType.MapToName.Split(','); results = ClassFactory <T> .Create(typeParts[1], typeParts[0]); } return(results); }
public void TestCrash() { var args = new object[1]; var constructedType = typeof(int); var classFactory = new ClassFactory(delegate { throw new MockException(); }, constructedType); injectionContextMock.Setup(c => c.BeginConstruct(constructedType)); injectionContextMock.Setup(c => c.Crash()); injectionContextMock.Setup(c => c.EndConstruct(constructedType)); RunMethodWithException <MockException>(() => classFactory.Create(injectionContextMock.Object, args)); }
///<summary> ///</summary> ///<param name="termCurve"></param> ///<returns></returns> public static IInterpolation Create(TermCurve termCurve) { string interpolationName = "LinearInterpolation"; if (null != termCurve.interpolationMethod) { interpolationName = termCurve.interpolationMethod.Value; } //WTF??? - hardcoded string literal for the assembly name ???? // return(ClassFactory <IInterpolation> .Create(DefaultAssembly, interpolationName)); }
/// <summary> /// Used to create the interpolation. /// </summary> /// <param name="interpolationMethod"></param> /// <returns></returns> public static IInterpolation Create(InterpolationMethod interpolationMethod) { var interpolationName = "LogLinearInterpolation"; if (null != interpolationMethod) { interpolationName = interpolationMethod.Value; } //WTF??? - hardcoded string literal for the assembly name ???? // return(ClassFactory <IInterpolation> .Create("Analytics", interpolationName)); }
public void ClassWithBaseClass_CreateFromSymbol_ClassAndBaseClassCreated() { // arrange // 1. load source files and get class and mixin declarations var sourceCode = new SourceCode(Files.Person); var personClass = sourceCode.Class(nameof(ThirdPersonClass)); var classFactory = new ClassFactory(sourceCode.Semantic); var @class = classFactory.Create(personClass); Assert.IsFalse(@class.Properties.Any()); Assert.AreEqual("Name", @class.BaseClass.BaseClass.Properties.Single().Name); }
public void ClassFactory_CreateFromCode_ClassCreated() { // arrange // 1. load source files and get class and mixin declarations var sourceCode = new SourceCode(Files.Person); var personClass = sourceCode.Class(nameof(WorkingPerson)); var classFactory = new ClassFactory(sourceCode.Semantic); var @class = classFactory.Create(personClass); Assert.AreEqual("Name", @class.Properties.Single().Name); Assert.AreEqual("void Work(int toolNumber)", @class.Methods.Single().ToString()); }
public void TestWork() { var args = new object[1]; Type constructedType = typeof(int); var q = new Queue <int>(); var classFactory = new ClassFactory(delegate(IInternalContainer aContainer, IInjectionContext aContext, object[] arg3) { Assert.AreSame(internalContainer, aContainer); Assert.AreSame(injectionContext, aContext); Assert.AreSame(args, arg3); return(q.Dequeue()); }, constructedType); injectionContext.Expect(c => c.BeginConstruct(constructedType)); injectionContext.Expect(c => c.EndConstruct(constructedType)); q.Enqueue(100); Assert.AreEqual(100, classFactory.Create(injectionContext, args)); injectionContext.Expect(c => c.BeginConstruct(constructedType)); injectionContext.Expect(c => c.EndConstruct(constructedType)); q.Enqueue(200); Assert.AreEqual(200, classFactory.Create(injectionContext, args)); }
/// <summary> /// Create an instance of the IScenario interface /// </summary> /// <param name="name">The class name to create</param> /// <returns></returns> public static IInterpolation Create(string name) { return(ClassFactory <IInterpolation> .Create(DefaultAssembly, name)); }
public void Init(SuperOffice.CRM.Security.Sentry sentry) { _sentry = sentry; _rightsManager = ClassFactory.Create <SentryRightsManager>(); }
private SentryRightsDispatcher GetDispatcher() { return(ClassFactory.Create <SentryRightsDispatcher>()); }
/// <summary> /// Return the current sentry rights manager instance. /// </summary> /// <returns>The one and only sentry rights manager.</returns> public static SentryRightsManager GetCurrent() { return(ClassFactory.Create <SentryRightsManager>()); }