Ejemplo n.º 1
0
        public void V2ResultMatcher_RemovedAndAdded()
        {
            Run newRun = SampleRun.DeepClone();

            newRun.Results.RemoveAt(2);

            Result newResult = newRun.Results[0].DeepClone();

            newResult.Locations[0].PhysicalLocation.ArtifactLocation.Uri = new Uri("file:///C:/Code/elfie-arriba/XForm/XForm.Web/node_modules/NEW.pem");
            newResult.PartialFingerprints = null;
            newResult.Message.Text        = "Different Message";
            newRun.Results.Add(newResult);

            IEnumerable <MatchedResults> matches = CreateMatchedResults(SampleRun, newRun);

            matches.Where(m => m.PreviousResult != null && m.CurrentResult != null).Should().HaveCount(4);
            matches.Where(m => m.PreviousResult == null || m.CurrentResult == null).Should().HaveCount(2);

            MatchedResults removed = matches.Where(m => m.CurrentResult == null).First();

            SampleRun.Results[2].Should().BeSameAs(removed.PreviousResult.Result);

            MatchedResults added = matches.Where(m => m.PreviousResult == null).First();

            newResult.Should().BeSameAs(added.CurrentResult.Result);
        }
Ejemplo n.º 2
0
        public bool TryMatchResult(Dictionary <int, List <ExtractedResult> > resultDictionary, ExtractedResult currentResult, out MatchedResults result)
        {
            int unmodifiedKey = Comparer.GetHashCode(currentResult);

            if (resultDictionary.ContainsKey(unmodifiedKey))
            {
                List <ExtractedResult> matchingBaselineResult = resultDictionary[unmodifiedKey].Where(b => Comparer.Equals(b, currentResult)).ToList();
                if (matchingBaselineResult.Count == 1)
                {
                    result = new MatchedResults(matchingBaselineResult[0], currentResult);
                    return(true);
                }
                else if (matchingBaselineResult.Count > 1)
                {
                    // TODO--what if multiple results match here?
                    // Right now we grab the first?  It might be better to group them up? ...?
                    // We do want this to be completely deterministic, which is part of the problem--grabbing the first assumes
                    // the input logs have been made deterministic.
                    // This will remain unsolved in the early implementation.
                    // One thought--A discrete difference metric probably makes sense here.
                    result = new MatchedResults(matchingBaselineResult[0], currentResult);
                    return(true);
                }
            }
            result = null;
            return(false);
        }
Ejemplo n.º 3
0
 private void resultslistbox_SelectedIndexChanged(object sender, EventArgs e)
 {
     //just creating this now so i can get to the text form
     MatchedResults match = new MatchedResults();
     //set up the text form
     Text textForm = new Text(match);
     textForm.Show();
     this.Close();
 }
Ejemplo n.º 4
0
        public void V2ResultMatcher_RemoveResult()
        {
            Run newRun = SampleRun.DeepClone();

            newRun.Results.RemoveAt(2);

            IEnumerable <MatchedResults> matches = CreateMatchedResults(SampleRun, newRun);

            matches.Where(m => m.PreviousResult != null && m.CurrentResult != null).Should().HaveCount(4);
            matches.Where(m => m.PreviousResult == null || m.CurrentResult == null).Should().HaveCount(1);

            MatchedResults nonMatch = matches.Where(m => m.PreviousResult == null || m.CurrentResult == null).First();

            SampleRun.Results[2].Should().BeSameAs(nonMatch.PreviousResult.Result);
        }
Ejemplo n.º 5
0
        public void V2ResultMatcher_AddResult()
        {
            Run    newRun    = SampleRun.DeepClone();
            Result newResult = newRun.Results[0].DeepClone();

            newResult.Locations[0].PhysicalLocation.ArtifactLocation.Uri = new Uri("file:///C:/Code/elfie-arriba/XForm/XForm.Web/node_modules/NEW.pem");
            newResult.PartialFingerprints = null;
            newResult.Properties          = null;

            newRun.Results.Add(newResult);

            IEnumerable <MatchedResults> matches = CreateMatchedResults(SampleRun, newRun);

            matches.Where(m => m.PreviousResult != null && m.CurrentResult != null).Should().HaveCount(5);
            matches.Where(m => m.PreviousResult == null || m.CurrentResult == null).Should().HaveCount(1);

            MatchedResults nonMatch = matches.Where(m => m.PreviousResult == null || m.CurrentResult == null).First();

            newResult.Should().BeSameAs(nonMatch.CurrentResult.Result);
        }
Ejemplo n.º 6
0
        public void MatchedResults_SetsFirstDetectionTime()
        {
            var sb = new StringBuilder();

            foreach (FirstDetectionTimeTestCase testCase in firstDetectionTimeTestCases)
            {
                DateTime expectedFirstDetectionTime = testCase.ExpectedFirstDetectionTime.HasValue
                    ? testCase.ExpectedFirstDetectionTime.Value
                    : fakeNow;

                ExtractedResult previousExtracted = testCase.PreviousResult != null
                    ? new ExtractedResult(testCase.PreviousResult, testCase.PreviousRun)
                    : null;
                ExtractedResult currentExtracted = testCase.CurrentResult != null
                    ? new ExtractedResult(testCase.CurrentResult, testCase.CurrentRun)
                    : null;
                MatchedResults matchedResults = new MatchedResults(previousExtracted, currentExtracted);

                Result result = matchedResults.CalculateBasedlinedResult(DictionaryMergeBehavior.InitializeFromMostRecent /* arbitrary */);

                BaselineState actualBaselineState      = result.BaselineState;
                DateTime?     actualFirstDetectionTime = result?.Provenance?.FirstDetectionTimeUtc;
                if (actualFirstDetectionTime.HasValue && actualFirstDetectionTime.Value >= fakeNow)
                {
                    actualFirstDetectionTime = fakeNow;
                }

                if (actualBaselineState != testCase.ExpectedBaselineState ||
                    actualFirstDetectionTime != expectedFirstDetectionTime)
                {
                    sb.AppendLine($"    Test: {testCase.Name}");
                    sb.AppendLine($"        Expected: {testCase.ExpectedBaselineState}\t{testCase.ExpectedFirstDetectionTime}");
                    sb.AppendLine($"        Actual:   {actualBaselineState}\t{actualFirstDetectionTime}");
                }
            }

            sb.Length.Should().Be(0,
                                  $"all test cases should pass, but the following test cases failed:\n{sb}");
        }
Ejemplo n.º 7
0
        public void V2ResultMatcher_MatchesFirstAndLastInFile()
        {
            // We want to ensure that the first and last Results in a file are compared.
            // To cover this, we need:
            //  - No unique properties in any results in the file.
            //  - The Result file Uri stays the same. (No file rename)
            //  - The Result moves within the file, but is still first/last.
            //  - The Results just before and after (in the file just before and after) change order

            // To do this, we'll change the URIs of /public-encrypt/test/test.pem and test_rsa_privkey_encrypted.pem to /zzz/test
            // and will move the result in /public-encrypt/test/test_rsa_privkey.pem

            Run firstRun  = SampleRun.DeepClone();
            Run secondRun = SampleRun.DeepClone();

            // Change Uris for Result[1] and Result[3]
            string changeFrom = "/public-encrypt/";
            string changeTo   = "/zzz/";

            ReplaceInUri(secondRun.Artifacts[1].Location, changeFrom, changeTo);
            ReplaceInUri(secondRun.Artifacts[3].Location, changeFrom, changeTo);
            ReplaceInUri(secondRun.Results[1].Locations[0].PhysicalLocation.ArtifactLocation, changeFrom, changeTo);
            ReplaceInUri(secondRun.Results[3].Locations[0].PhysicalLocation.ArtifactLocation, changeFrom, changeTo);

            // Move Result[2]
            Result firstInFile = secondRun.Results[2];

            firstInFile.Locations[0].PhysicalLocation.Region.StartLine  += 1;
            firstInFile.Locations[0].PhysicalLocation.Region.CharOffset += 5;

            // Verify the result matched, and matched the copy from the same file
            IEnumerable <MatchedResults> matches = CreateMatchedResults(firstRun, secondRun);
            MatchedResults match = matches.Where(m => Location.ValueComparer.Equals(m.CurrentResult?.Result?.Locations?.FirstOrDefault(), firstInFile.Locations[0])).FirstOrDefault();

            Assert.NotNull(match.PreviousResult);
            Assert.Equal(
                match.PreviousResult.Result.Locations[0].PhysicalLocation.ArtifactLocation.Uri,
                match.CurrentResult.Result.Locations[0].PhysicalLocation.ArtifactLocation.Uri);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Returns the DataTable with users in the specified distance range
        /// </summary>
        /// <param name="longitude"></param>
        /// <param name="latitude"></param>
        /// <returns></returns>
        //public DataTable FindMatches(double longitude, double latitude)
        //{
        //    DataTable dt = new DataTable();
        //    return dt;
        //}
        public List<MatchedResults> FindMatches(string requestedUserName, double longitude, double latitude)
        {
            //setup the list we return
            List<MatchedResults> matchingList = new List<MatchedResults>();

            //find teh matching User for passed username
            double reqLat = -1;
            double reqLong = -1;
            double reqRange = -1;
            int reqPhone = -1;
            //terrible way to do this......
            foreach (User tmpUser in activeUsers)
            {
                if (tmpUser.UserNickName == requestedUserName)
                {
                    reqLat = tmpUser.Latitude;
                    reqLong = tmpUser.Longitude;
                    reqRange = tmpUser.DistanceRange;
                    reqPhone = tmpUser.Phone;
                    break;
                }
            }

            User requestedUser = new User(requestedUserName, reqRange, reqLat, reqLong,reqPhone);

            //init the matchmaker class
            MatchMaker matchMaker = new MatchMaker();

            //loop through the active users and see which ones are within distance
            foreach (User tmpUser in activeUsers)
            {
                //this should give us the actual distance between the 2 users
                //may need to multiple lates by 69.1 and longs by 53 to convert to miles
                //
                if (Math.Sqrt(69.1*Math.Pow((tmpUser.Latitude - requestedUser.Latitude),2) + 53*Math.Pow((tmpUser.Longitude - requestedUser.Longitude),2)) < requestedUser.DistanceRange)
                {
                    //run the match comparision
                    double matchPercentage = matchMaker.matchPercentage(tmpUser.UserNickName, requestedUser.UserNickName);

                    //create the matchedResults object
                    MatchedResults curMatch = new MatchedResults();
                    curMatch.MatchPercentage = matchPercentage;
                    curMatch.Name = tmpUser.UserNickName;
                    curMatch.Phone = tmpUser.Phone;

                    //add that new object to the list (preferably in sorted order)
                    matchingList.Add(curMatch);
                }

            }

            //return a list of matches
            return matchingList;
        }