Ejemplo n.º 1
0
        public static List <TestResult> PushPullCompare(InteropabilityTestSettings settings)
        {
            //Check settings for null
            if (settings == null)
            {
                Base.Compute.RecordError("Null InteropabilityTestSettings provided.");
                return(null);
            }

            //Create the adapter
            IBHoMAdapter adapter = Adapter.Create.BHoMAdapter(settings.AdapterType, settings.AdapterConstructorArguments);

            //Check adapter created properly
            if (adapter == null)
            {
                Base.Compute.RecordError("Failed to construct the adapter");
                return(null);
            }

            //Check types provided properly
            if (settings.TestTypes == null || settings.TestTypes.Count == 0)
            {
                Base.Compute.RecordError("No test types provided.");
                return(null);
            }

            //Check config provided properly
            if (settings.PushPullConfig == null)
            {
                Base.Compute.RecordError("No PushPullComapreConfig provided");
                return(null);
            }

            //Run through the PushPullCompare testing and return all the results
            List <TestResult> results = new List <TestResult>();

            foreach (Type type in settings.TestTypes)
            {
                results.AddRange(PushPullCompare(adapter, type, settings.PushPullConfig, true));
            }

            //Ask the adapter to fully close down any open instance of the software
            adapter.Execute(new Exit {
                SaveBeforeClose = false
            });

            return(results);
        }
Ejemplo n.º 2
0
        public static List <TestResult> PushPullCompare(IBHoMAdapter adapter, List <IBHoMObject> testObjects, string setName = "", Type enforcedType = null, PushPullCompareConfig config = null, bool active = false)
        {
            if (!active)
            {
                return(new List <TestResult>());
            }

            if (enforcedType != null && testObjects.Any(x => !enforcedType.IsAssignableFrom(x.GetType())))
            {
                Base.Compute.RecordError("The testObjects is not matching the enforced type and are not a subtype of the enforced type.");
                return(new List <TestResult>());
            }

            config = config ?? new PushPullCompareConfig();

            IEqualityComparer <IBHoMObject> comparer = config.Comparer(adapter.AdapterIdFragmentType);

            List <TestResult> testResults = new List <TestResult>();

            if (enforcedType == null)
            {
                foreach (var group in testObjects.GroupBy(x => x.GetType()))
                {
                    FilterRequest request = new FilterRequest {
                        Type = group.Key
                    };

                    testResults.Add(RunOneSet(adapter, setName, group.ToList(), request, comparer, config.ResetModelBetweenPushes));
                }
            }
            else
            {
                FilterRequest request = new FilterRequest {
                    Type = enforcedType
                };
                testResults.Add(RunOneSet(adapter, setName, testObjects, request, comparer, config.ResetModelBetweenPushes));
            }
            return(testResults);
        }
Ejemplo n.º 3
0
        public static List <TestResult> PushPullCompare(IBHoMAdapter adapter, Type type, PushPullCompareConfig config = null, bool active = false)
        {
            if (!active)
            {
                return(new List <TestResult>());
            }

            config = config ?? new PushPullCompareConfig();

            //Get testdata
            var testSets = Query.TestDataOfType(type);

            if (testSets == null || testSets.Item1 == null || testSets.Item2 == null)
            {
                Base.Compute.RecordError("Failed to extract testdata");
                return(new List <TestResult>());
            }

            List <string> testSetNames          = testSets.Item1;
            List <List <IBHoMObject> > testData = testSets.Item2;

            //Set up comparer and request
            FilterRequest request = new FilterRequest {
                Type = type
            };
            IEqualityComparer <IBHoMObject> comparer = config.Comparer(adapter.AdapterIdFragmentType);

            //List for storing output

            List <TestResult> results = new List <TestResult>();


            for (int i = 0; i < testSetNames.Count; i++)
            {
                results.Add(RunOneSet(adapter, testSetNames[i], testData[i], request, comparer, config.ResetModelBetweenPushes));
            }

            return(results);
        }
Ejemplo n.º 4
0
        /***************************************************/
        /**** Private Methods                           ****/
        /***************************************************/

        private static TestResult RunOneSet(IBHoMAdapter adapter, string setName, List <IBHoMObject> objects, IRequest request, IEqualityComparer <IBHoMObject> comparer, bool resetModelBetweenRuns)
        {
            if (adapter == null)
            {
                return(new TestResult {
                    Description = "PushPullCompare", Message = "Adapter is null, could not preform test", Status = oM.Test.TestStatus.Error
                });
            }

            TestResult setResult = new TestResult {
                Description = $"PushPullCompare: Adapter: {adapter.GetType().Name}, test set: {setName}.", ID = adapter.GetType().Name + ":" + setName
            };

            bool success = true;

            //CalculateObjectHashes
            objects = objects.SetHashFragment();

            //Start up an empty model
            if (resetModelBetweenRuns)
            {
                adapter.Execute(new NewModel());
            }

            List <IBHoMObject> pushedObjects = new List <IBHoMObject>();
            List <IBHoMObject> pulledObjects = new List <IBHoMObject>();

            BH.oM.Base.ComparisonConfig config = Engine.Test.Create.DefaultTestComparisonConfig();
            config.PropertyExceptions.Add("CustomData");
            config.TypeExceptions.Add(typeof(HashFragment));

            //Push objects
            try
            {
                Engine.Base.Compute.ClearCurrentEvents();
                pushedObjects = adapter.Push(objects).Cast <IBHoMObject>().ToList();
                success      &= pushedObjects.Count == objects.Count;
            }
            catch (Exception e)
            {
                Engine.Base.Compute.RecordError(e.Message);
                setResult.Message = "The adapter crashed trying to push the objects.";
                setResult.Status  = oM.Test.TestStatus.Error;
                return(setResult);
            }
            finally
            {
                setResult.Information.AddRange(Engine.Base.Query.CurrentEvents().Select(x => x.ToEventMessage()));
            }

            if (pushedObjects.Count != objects.Count)
            {
                setResult.Information.AddRange(objects.Where(x => !pushedObjects.Any(y => x.Name == y.Name)).Select(x => TestFailedResult(x, "Object could not be pushed.")));
            }

            //Pull objects
            try
            {
                Engine.Base.Compute.ClearCurrentEvents();
                pulledObjects = adapter.Pull(request).Cast <IBHoMObject>().ToList();
                success      &= pulledObjects.Count == pushedObjects.Count;
            }
            catch (Exception e)
            {
                Engine.Base.Compute.RecordError(e.Message);
                setResult.Message = "The adapter crashed trying to pull the objects.";
                setResult.Status  = oM.Test.TestStatus.Error;
                return(setResult);
            }
            finally
            {
                setResult.Information.AddRange(Engine.Base.Query.CurrentEvents().Select(x => x.ToEventMessage()));
            }

            //Compare pushed and pulled objects
            VennDiagram <IBHoMObject> diagram = Engine.Data.Create.VennDiagram(pushedObjects, pulledObjects, comparer);


            foreach (Tuple <IBHoMObject, IBHoMObject> pair in diagram.Intersection)
            {
                setResult.Information.Add(ComparePushedAndPulledObject(pair.Item1, pair.Item2, config));
            }

            setResult.Information.AddRange(diagram.OnlySet1.Select(x => TestFailedResult(x, "Unable to compare the object.")));

            //Close the model
            if (resetModelBetweenRuns)
            {
                adapter.Execute(new Close {
                    SaveBeforeClose = false
                });
            }

            //Clear events
            Engine.Base.Compute.ClearCurrentEvents();

            setResult.Status = setResult.Information.OfType <TestResult>().MostSevereStatus();

            if (setResult.Status == oM.Test.TestStatus.Error)
            {
                setResult.Message = "Errors where raised trying to run the test";
            }
            else if (setResult.Status == oM.Test.TestStatus.Pass)
            {
                setResult.Message = "All objects were successfully pushed, pulled and compared without any differences.";
            }
            else
            {
                setResult.Message = "All objects were successfully pushed and pulled, but some differences were found.";
            }

            return(setResult);
        }