public void SqlTrace_WithtUriExcluded()
        {
            //Arrange
            var attribDefs    = Mock.Create <IAttributeDefinitions>();
            var attribDefSvc  = new AttributeDefinitionService((f) => attribDefs);
            var sqlTraceMaker = new SqlTraceMaker(_configurationService, attribDefSvc, _databaseService);
            var attribFilter  = Mock.Create <IAttributeFilter>();

            Mock.Arrange(() => attribDefs.RequestUri)
            .Returns(AttributeDefinitionBuilder.CreateString("request.uri", AttributeClassification.AgentAttributes)
                     .AppliesTo(AttributeDestinations.TransactionEvent)
                     .AppliesTo(AttributeDestinations.ErrorEvent)
                     .AppliesTo(AttributeDestinations.ErrorTrace)
                     .AppliesTo(AttributeDestinations.TransactionTrace)
                     .AppliesTo(AttributeDestinations.SqlTrace, false)
                     .WithDefaultOutputValue("/unknown")
                     .Build(attribFilter));

            var uri                   = "sqlTrace/Uri";
            var commandText           = "Select * from Table1";
            var duration              = TimeSpan.FromMilliseconds(500);
            var transaction           = BuildTestTransaction(uri: uri, attribDefs: attribDefs);
            var transactionMetricName = new TransactionMetricName("WebTransaction", "Name");
            var datastoreSegment      = BuildSegment(DatastoreVendor.MSSQL, "Table1", commandText, new TimeSpan(), duration, null, null, null, "myhost", "myport", "mydatabase");

            //Act
            var sqlTrace = sqlTraceMaker.TryGetSqlTrace(transaction, transactionMetricName, datastoreSegment);

            //Assert
            Assert.IsNotNull(sqlTrace);
            Assert.AreEqual("<unknown>", sqlTrace.Uri);
        }
        public void CopyAttributes_Ambiguous()
        {
            var builder = new AttributeDefinitionBuilder(DefinitionObjectMother.CreateMixinDefinition(typeof(MixinWithAmbiguousSource)));
            var method  = typeof(MixinWithAmbiguousSource).GetMethod("ToString", BindingFlags.NonPublic | BindingFlags.Instance);
            var data    = CustomAttributeData.GetCustomAttributes(method).Select(d => (ICustomAttributeData) new CustomAttributeDataAdapter(d));

            builder.Apply(method, data, true);
        }
Ejemplo n.º 3
0
        public void Attributes_with_empty_values_are_valid_attributes()
        {
            var filter = new AttributeFilter(new AttributeFilter.Settings());

            var attribDef = AttributeDefinitionBuilder
                            .CreateCustomAttribute("test", AttributeDestinations.All)
                            .Build(filter);

            var attribVals = new AttributeValueCollection(AttributeValueCollection.AllTargetModelTypes);

            var trySetResult = attribDef.TrySetValue(attribVals, string.Empty);

            var actualAttribVal = attribVals.GetAttributeValues(AttributeClassification.UserAttributes)
                                  .FirstOrDefault(x => x.AttributeDefinition == attribDef);

            NrAssert.Multiple(
                () => Assert.IsTrue(trySetResult),
                () => Assert.AreEqual(string.Empty, actualAttribVal.Value)
                );
        }
Ejemplo n.º 4
0
        private void TestValue(object attributeValue, object expectedResult)
        {
            var filter = new AttributeFilter(new AttributeFilter.Settings());

            var attribDef = AttributeDefinitionBuilder
                            .CreateCustomAttribute("test", AttributeDestinations.All)
                            .Build(filter);

            var attribVals = new AttributeValueCollection(AttributeValueCollection.AllTargetModelTypes);

            attribDef.TrySetValue(attribVals, attributeValue);

            var actualAttribVal = attribVals.GetAttributeValues(AttributeClassification.UserAttributes)
                                  .FirstOrDefault(x => x.AttributeDefinition == attribDef);


            NrAssert.Multiple(
                () => Assert.IsNotNull(actualAttribVal),
                () => Assert.AreEqual(expectedResult, actualAttribVal.Value)
                );
        }
Ejemplo n.º 5
0
        public void Attributes_key_size()
        {
            var filter     = new AttributeFilter(new AttributeFilter.Settings());
            var attribVals = new AttributeValueCollection(AttributeValueCollection.AllTargetModelTypes);

            var testKeys = new string[]
            {
                new string('x', 255),
                new string('a', 256),
                string.Empty,
                " ",
                null as string
            };

            var testResults = new bool[testKeys.Length];


            for (var i = 0; i < testKeys.Length; i++)
            {
                var attribDef = AttributeDefinitionBuilder
                                .CreateCustomAttribute(testKeys[i], AttributeDestinations.All)
                                .Build(filter);

                testResults[i] = attribDef.IsDefinitionValid;

                attribDef.TrySetValue(attribVals, 9);
            }



            NrAssert.Multiple(
                () => Assert.IsTrue(testResults[0]),
                () => Assert.IsFalse(testResults[1]),
                () => Assert.IsFalse(testResults[2]),
                () => Assert.IsFalse(testResults[3]),
                () => Assert.IsFalse(testResults[4]),
                () => Assert.AreEqual(1, attribVals.GetAttributeValues(AttributeClassification.UserAttributes).Count())
                );
        }
        public void when(TestCase testCase)
        {
            // Arrange
            var unfilteredAttribs = new AttributeValueCollection(AttributeValueCollection.AllTargetModelTypes);

            var attributeFilterSettings = testCase.Configuration.ToAttributeFilterSettings();
            var testCaseDestinations    = testCase.AttributeDestinations.ToAttributeDestinations();

            testCaseDestinations = testCaseDestinations.Length > 0
                ? testCaseDestinations
                : new AttributeDestinations[]
            {
                AttributeDestinations.TransactionEvent,
                AttributeDestinations.TransactionTrace,
                AttributeDestinations.JavaScriptAgent,
                AttributeDestinations.ErrorTrace
            };

            var expectedDestinations = testCase.ExpectedDestinations.ToAttributeDestinations();
            var attributeFilter      = new AttributeFilter(attributeFilterSettings);

            var attrib = AttributeDefinitionBuilder.Create <string>(testCase.AttributeKey, AttributeClassification.UserAttributes)
                         .AppliesTo(testCaseDestinations)
                         .Build(attributeFilter);

            attrib.TrySetValue(unfilteredAttribs, "foo");

            foreach (var testDestination in AttributeValueCollection.AllTargetModelTypes)
            {
                var filteredAttribs = new AttributeValueCollection(unfilteredAttribs, testDestination);

                var countMatchAttribValues = filteredAttribs.GetAttributeValues(AttributeClassification.UserAttributes)
                                             .Count(x => x.AttributeDefinition.Name == testCase.AttributeKey);

                var expectedCount = expectedDestinations.Contains(testDestination) ? 1 : 0;

                Assert.AreEqual(expectedCount, countMatchAttribValues, $"{testDestination}");
            }
        }