Esempio n. 1
0
 private static void InitTypeInfos()
 {
     lock (s_initTypeInfosLock)
     {
         if (!s_initTypeInfosCalled)
         {
             s_initTypeInfosCalled = true;
             foreach (var assembly in Introspection.AllAssemblies)
             {
                 var typeInfos = Introspection.GetAllTypesWithAttribute <RegisterTypeInfoAttribute>(assembly).ToArray();
                 foreach (var x in typeInfos)
                 {
                     Report.Line(4, "[RegisterTypeInfo] {0}", x.Item1.FullName);
                     try
                     {
                         foreach (var a in x.Item2)
                         {
                             TypeInfo.Add(x.Item1, a.Version);
                         }
                     }
                     catch (Exception e)
                     {
                         Report.Warn("Error registering TypeInfo:\n{0}", e.ToString());
                     }
                 }
             }
         }
     }
 }
Esempio n. 2
0
        public void Introspected_ListType_PropertyCheck()
        {
            var serverBuilder = new TestServerBuilder();
            var server        = serverBuilder.AddGraphType <string>()
                                .Build();

            var schema = new IntrospectedSchema(server.Schema);

            schema.Rebuild();

            var scalar = GraphQLProviders.ScalarProvider.RetrieveScalar(typeof(string));

            var spected = schema.FindIntrospectedType(scalar);

            var wrapped = Introspection.WrapBaseTypeWithModifiers(spected, MetaGraphTypes.IsList);

            Assert.AreEqual(TypeKind.LIST, wrapped.Kind);

            Assert.IsNull(wrapped.Fields);
            Assert.IsNull(wrapped.Interfaces);
            Assert.IsNull(wrapped.PossibleTypes);
            Assert.IsNull(wrapped.EnumValues);
            Assert.IsNull(wrapped.InputFields);
            Assert.IsNull(wrapped.Name);
            Assert.IsNull(wrapped.Description);
            Assert.AreEqual(spected, wrapped.OfType);
        }
Esempio n. 3
0
        public void Introspected_ListType_NotNullType_NotNullList_PropertyCheck()
        {
            var serverBuilder = new TestServerBuilder();
            var server        = serverBuilder.AddGraphType <string>()
                                .Build();

            var schema = new IntrospectedSchema(server.Schema);

            schema.Rebuild();

            var scalar = GraphQLProviders.ScalarProvider.RetrieveScalar(typeof(string));

            var spected = schema.FindIntrospectedType(scalar);

            var wrapped = Introspection.WrapBaseTypeWithModifiers(spected, GraphTypeExpression.RequiredListRequiredItem);

            Assert.AreEqual(TypeKind.NON_NULL, wrapped.Kind);

            var unwrappedList = wrapped.OfType;

            Assert.AreEqual(TypeKind.LIST, unwrappedList.Kind);

            var unwrappedItemType = unwrappedList.OfType;

            Assert.AreEqual(TypeKind.NON_NULL, unwrappedItemType.Kind);

            var itemType = unwrappedItemType.OfType;

            Assert.AreEqual(spected, itemType);
        }
        public void Introspection_SearchForComplexityGt10_ApprovedList()
        {
            var cancellationToken = _cancellationTokenSource.Token;

            IEnumerable <Complexity> methodsWithCyclomaticComplexityGt10 =
                new Introspection()
                .SearchForComplexMethods(
                    solutionFile: _strategy.GetSolutionPath(),
                    maxAllowedCyclomaticComplexity: 10,
                    cancellationToken: cancellationToken);

            methodsWithCyclomaticComplexityGt10.Should()
            .NotBeNull()
            .And.BeOfType <ImmutableList <Complexity> >()
            .And.NotBeEmpty();

            var methodsWithCyclomaticComplexityGt10Results =
                methodsWithCyclomaticComplexityGt10
                .GroupBy(complexity => complexity.TypeIdentifier)
                .OrderByDescending(@group => @group.Sum(complexity => complexity.NStatementSyntax))
                .ThenBy(@group => @group.First().FilePath)
                .Select(@group => @group
                        .OrderByDescending(complexity => complexity.NStatementSyntax)
                        .ThenBy(complexity => complexity.MethodIdentifier))
                .ToArray();

            ApprovalsVerify(methodsWithCyclomaticComplexityGt10Results);
        }
Esempio n. 5
0
        ///<summary>Removes the IntrospectionItems preference from the database.
        ///Manually refreshes the preference cache so that the change instantly takes place.</summary>
        public static void DeletePref()
        {
            string command = "DELETE FROM preference WHERE prefname='" + nameof(PrefName.IntrospectionItems) + "'";

            DataCore.NonQ(command);
            Prefs.RefreshCache();
            Introspection.ClearDictOverrides();
        }
        public void Introspection_Preference_Missing()
        {
            IntrospectionT.DeletePref();
            string retVal = Introspection.GetOverride(Introspection.IntrospectionEntity.DentalXChangeDwsURL, "thisIsADefaultURL");

            //Because there is no preference in the DB we should get back the default value we passed in.
            Assert.AreEqual(retVal, "thisIsADefaultURL");
        }
        public void Introspection_Preference_Present()
        {
            IntrospectionT.UpsertPref(new Dictionary <Introspection.IntrospectionEntity, string>()
            {
                { Introspection.IntrospectionEntity.DentalXChangeDwsURL, "https://prelive2.dentalxchange.com/dws/DwsService" }
            });
            string retVal = Introspection.GetOverride(Introspection.IntrospectionEntity.DentalXChangeDwsURL, "thisIsADefaultURL");

            //The preference is present and valid. retVal should be overridden with the preference value.
            Assert.AreEqual("https://prelive2.dentalxchange.com/dws/DwsService", retVal);
        }
Esempio n. 8
0
        public void ComposeNewRxDoseSpot()
        {
            string additionalHeaders = "Content-Type: application/x-www-form-urlencoded\r\n";
            string doseSpotUrl       = Introspection.GetOverride(Introspection.IntrospectionEntity.DoseSpotSingleSignOnURL, "https://my.dosespot.com/LoginSingleSignOn.aspx");

#if DEBUG
            doseSpotUrl = "https://my.staging.dosespot.com/LoginSingleSignOn.aspx?b=2";
#endif
            OIDExternal oidPatID = DoseSpot.GetDoseSpotPatID(PatCur.PatNum);
            if (oidPatID == null)
            {
                browser.DocumentCompleted += new System.Windows.Forms.WebBrowserDocumentCompletedEventHandler(this.GetPatientIdFromWebBrowser);
            }
            browser.Navigate(doseSpotUrl, "", PostDataBytes, additionalHeaders);
        }
        public void Introspection_Preference_Malformed()
        {
            IntrospectionT.UpsertPref("INVALID JSON ValueString");
            string retVal = "";

            try {
                retVal = Introspection.GetOverride(Introspection.IntrospectionEntity.DentalXChangeDwsURL, "thisIsADefaultURL");
            }
            catch (ApplicationException) {
                //GetOverride() should throw an application exception if the json is malformed and retVal should never be set.
                Assert.IsTrue(retVal == "");
                return;
            }
            Assert.Fail();
        }
Esempio n. 10
0
        ///<summary>Inserts the IntrospectionItems preference into the database if it is missing.  Runs an update statement if the pref already exists.
        ///Always sets ValueString to the value passed in.  Manually refreshes the preference cache so that the change instantly takes place.</summary>
        public static void UpsertPref(string valueString = "")
        {
            string command = "SELECT COUNT(*) FROM preference WHERE PrefName='IntrospectionItems'";

            if (DataCore.GetScalar(command) == "0")
            {
                command = "INSERT INTO preference (PrefName,ValueString) VALUES('IntrospectionItems','" + POut.String(valueString) + "')";
                DataCore.NonQ(command);
            }
            else
            {
                command = "UPDATE preference SET ValueString='" + POut.String(valueString) + "' WHERE PrefName='IntrospectionItems'";
                DataCore.NonQ(command);
            }
            Prefs.RefreshCache();
            Introspection.ClearDictOverrides();
        }
Esempio n. 11
0
        private AccessModifier[] getAccessModifiers(IBCLUserType bclUserType, bool isInterface)
        {
            List <AccessModifier> list = new List <AccessModifier>();
            Type type = Type.GetType(bclUserType.Name);

            MemberInfo[] members = type.GetMembers(BindingFlags.Instance | BindingFlags.Public);
            foreach (MemberInfo member in members)
            {
                // * Duck typing :-)
                IMemberType    memberType     = (IMemberType)bclUserType.GetType().GetMethod("FindMember").Invoke(bclUserType, new object[] { member.Name });
                AccessModifier accessModifier = new AccessModifier(Introspection.getMethodModifierList(member),
                                                                   member.Name, memberType, isInterface);
                list.Add(accessModifier);
            }
            AccessModifier[] result = new AccessModifier[list.Count];
            list.CopyTo(result);
            return(result);
        }
Esempio n. 12
0
        static PointCloudFileFormat()
        {
            var xs = Introspection.GetAllTypesWithAttribute <PointCloudFileFormatAttributeAttribute>().ToArray();

            foreach (var x in xs)
            {
                try
                {
                    var t = x.Item1;
                    RuntimeHelpers.RunClassConstructor(t.TypeHandle);
                    Console.WriteLine($"[PointCloudFileFormat] registered {x.Item1.FullName}");
                }
                catch (Exception e)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine($"[PointCloudFileFormat] registered {x.Item1.FullName} [failed]");
                    Console.WriteLine(e.Message);
                    Console.ResetColor();
                }
            }
        }
Esempio n. 13
0
        public void Introspected_NotNullType_WhenSuppliedANotNullType_ThrowsException()
        {
            var serverBuilder = new TestServerBuilder();
            var server        = serverBuilder.AddGraphType <string>()
                                .Build();

            var schema = new IntrospectedSchema(server.Schema);

            schema.Rebuild();

            var scalar = GraphQLProviders.ScalarProvider.RetrieveScalar(typeof(string));

            var spected = schema.FindIntrospectedType(scalar);

            var wrapped = Introspection.WrapBaseTypeWithModifiers(spected, MetaGraphTypes.IsNotNull);

            Assert.Throws <GraphTypeDeclarationException>(() =>
            {
                var _ = new IntrospectedType(wrapped, TypeKind.NON_NULL);
            });
        }
        public void Introspection_SearchForReturnNullStatements_ApprovedList()
        {
            var cancellationToken = _cancellationTokenSource.Token;

            IEnumerable <ReturnNull> returnNullStatements =
                new Introspection()
                .SearchForReturnNullStatements(
                    solutionFile: _strategy.GetSolutionPath(),
                    cancellationToken: cancellationToken);

            returnNullStatements.Should()
            .NotBeNull()
            .And.BeOfType <ImmutableList <ReturnNull> >()
            .And.NotBeEmpty();

            var orderedReturnNullStatements =
                returnNullStatements
                .OrderBy(returnNull => returnNull.FilePath)
                .ThenBy(returnNull => returnNull.SourceLine)
                .ToArray();

            ApprovalsVerify(orderedReturnNullStatements);
        }