Ejemplo n.º 1
0
        private CompareBsonDocumentsResult CompareBsonDocuments(TwoBsonDocuments twoBsonDocuments)
        {
            BsonDocument document1 = twoBsonDocuments.Document1;
            BsonDocument document2 = twoBsonDocuments.Document2;

            CompareBsonDocumentsResult result = new CompareBsonDocumentsResult(twoBsonDocuments, _comparatorOptions);
            result.DontSetDocumentReference = _dontSetDocumentReference;
            result.DocumentReferenceElements1 = _documentReferenceElements1;
            result.DocumentReferenceElements2 = _documentReferenceElements2;
            if (document1 == null && document2 == null)
                result.DocumentsType = DocumentsType.Document1AndDocument2AreNull;
            else if (document1 == null)
                result.DocumentsType = DocumentsType.Document1IsNull;
            else if (document2 == null)
                result.DocumentsType = DocumentsType.Document2IsNull;
            else
            {
                result.DocumentsType = DocumentsType.Document1AndDocument2AreNotNull;
                foreach (var twoDocElement in EnumerateTwoBsonDocumentsElements(document1, document2))
                {
                    CompareElementResult compareElements;
                    if (twoDocElement.Value1 != null && twoDocElement.Value2 != null)
                    {
                        //if (twoDocElement.Value1.IsString && twoDocElement.Value2.IsString)
                        //{
                        //    if (_stringComparisonIgnoreWhiteSpace)
                        //    {
                        //    }

                        //}
                        //if (_stringComparisonIgnoreCase && twoDocElement.Value1.IsString && twoDocElement.Value2.IsString)
                        //{
                        //    if (string.Equals(twoDocElement.Value1.AsString, twoDocElement.Value2.AsString, StringComparison.InvariantCultureIgnoreCase))
                        //        compareElements = CompareElementResult.Equal;
                        //    else
                        //        compareElements = CompareElementResult.NotEqual;
                        //}
                        //else if (twoDocElement.Value1 == twoDocElement.Value2)
                        //    compareElements = CompareElementResult.Equal;
                        //else
                        //    compareElements = CompareElementResult.NotEqual;
                        if (Equals(twoDocElement.Value1, twoDocElement.Value2))
                            compareElements = CompareElementResult.Equal;
                        else
                            compareElements = CompareElementResult.NotEqual;
                    }
                    else if (twoDocElement.Value1 != null)
                        compareElements = CompareElementResult.OnlyValue1;
                    else // if (twoDocElement.Value2 != null)
                        compareElements = CompareElementResult.OnlyValue2;
                    result.AddElement(twoDocElement.Name, compareElements, twoDocElement.Value1, twoDocElement.Value2);
                }
            }
            return result;
        }
Ejemplo n.º 2
0
        private IEnumerable<string> _documentReferenceElements2 = null;      // list of reference element from document 2

        public CompareBsonDocumentsResult(TwoBsonDocuments twoBsonDocuments, BsonDocumentComparatorOptions comparatorOptions)
        {
            _twoBsonDocuments = twoBsonDocuments;
            _comparatorOptions = comparatorOptions;
        }