示例#1
0
        public AccessEvidenceBenchmarks()
        {
            _flowData = new TestFlowData();
            _flowData.AddEvidence("test", "value");

            _flowDataLargeDict = new TestFlowData();
            for (int i = 0; i < 100; i++)
            {
                _flowDataLargeDict.AddEvidence($"test{i}", $"value{i}");
            }

            _flowDataStringValues = new TestFlowData();
            _flowDataStringValues.AddEvidence("test", new StringValues(new string[] { "value1", "value2", "value3" }));
            for (int i = 0; i < 100; i++)
            {
                _flowDataStringValues.AddEvidence($"test{i}", $"value{i}");
            }
        }
        public void ShareUsageElement_SessionIdAndSequence_Existing()
        {
            // Arrange
            CreateShareUsage(1, 1, 1, new List <string>(), new List <string>(), new List <KeyValuePair <string, string> >());

            Dictionary <string, object> evidenceData = new Dictionary <string, object>()
            {
                { Core.Constants.EVIDENCE_CLIENTIP_KEY, "1.2.3.4" },
                { Constants.EVIDENCE_SESSIONID, "abcdefg-hijklmn-opqrst-uvwyxz" },
                { Constants.EVIDENCE_SEQUENCE, "2" },
            };

            var pipeline = new TestPipeline(_pipeline.Object);
            var data     = new TestFlowData(new Logger <TestFlowData>(new LoggerFactory()), pipeline, new Evidence(new Logger <Evidence>(new LoggerFactory())));

            data.AddEvidence(evidenceData);

            // Act
            _sequenceElement.Process(data);
            _shareUsageElement.Process(data);
            // Wait for the consumer task to finish.
            Assert.IsNotNull(_shareUsageElement.SendDataTask);
            _shareUsageElement.SendDataTask.Wait();

            // Assert
            // Check that one and only one HTTP message was sent
            _httpHandler.Verify(h => h.Send(It.IsAny <HttpRequestMessage>()), Times.Once);
            Assert.AreEqual(1, _xmlContent.Count);

            // Validate that the XML is well formed by passing it through a reader
            using (XmlReader xr = XmlReader.Create(new StringReader(_xmlContent[0])))
            {
                while (xr.Read())
                {
                }
            }

            // Check that the expected values are populated.
            Assert.IsTrue(_xmlContent[0].Contains("<SessionId>abcdefg-hijklmn-opqrst-uvwyxz</SessionId>"));
            Assert.IsTrue(_xmlContent[0].Contains("<Sequence>3</Sequence>"));
            Assert.IsTrue(data.GetEvidence().AsDictionary().ContainsKey(Constants.EVIDENCE_SESSIONID));
            Assert.IsTrue(data.GetEvidence().AsDictionary().ContainsKey(Constants.EVIDENCE_SEQUENCE));
        }