private void AttachInstrumentation(ArgumentGenerator arguments, object createdObject, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
 {
     InstrumentationConfigurationSection configurationSection = this.GetConfigurationSection(configurationSource);
     if (!configurationSection.InstrumentationIsEntirelyDisabled)
     {
         if (createdObject is IInstrumentationEventProvider)
         {
             createdObject = ((IInstrumentationEventProvider) createdObject).GetInstrumentationEventProvider();
         }
         object[] constructorArgs = arguments.ToArguments(configurationSection);
         this.BindInstrumentationTo(createdObject, constructorArgs, reflectionCache);
     }
 }
Example #2
0
 public DiffTool(string name, string path, ArgumentGenerator argGenerator)
 {
     Name = name;
     _path = Path.IsPathRooted(path) && File.Exists(path) ? path : Discover(path);
     _argGenerator = argGenerator;
 }
 public void AttachInstrumentation(string instanceName, object createdObject, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
 {
     ArgumentGenerator arguments = new ArgumentGenerator(instanceName);
     this.AttachInstrumentation(arguments, createdObject, configurationSource, reflectionCache);
 }
Example #4
0
 public void Create_WhenNotProvidingSingleArgument_ShouldContainArgument()
 {
     Assert.AreEqual("(1)", ArgumentGenerator.Create(new ValueArgument(1)).ToString());
 }
		/// <overloads>
		/// Attaches the instrumentation events in the <paramref name="createdObject"></paramref> to the 
		/// creating instance of the listener object, as defined by the <see cref="InstrumentationListenerAttribute"></see>
		/// on the source class.
		/// </overloads>
		/// <summary>
		/// Attaches the instrumentation events in the <paramref name="createdObject"></paramref> to the 
		/// creating instance of the listener object, as defined by the <see cref="InstrumentationListenerAttribute"></see>
		/// on the source class.
		/// </summary>
		/// <param name="createdObject">Source object used for instrumentation events.</param>
		/// <param name="configurationSource"><see cref="IConfigurationSource"></see> instance used to define whether
		/// instrumentation is enabled or disabled for application.</param>
		/// <param name="reflectionCache">Cache for instrumentation attributes discovered through reflection.</param>
		public void AttachInstrumentation(object createdObject, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
		{
			ArgumentGenerator arguments = new ArgumentGenerator();
			AttachInstrumentation(arguments, createdObject, configurationSource, reflectionCache);
		}
Example #6
0
 public void Create_WhenNotProvidingAnyArguments_ShouldGetEmptyString()
 {
     Assert.AreEqual("()", ArgumentGenerator.Create().ToString());
 }
Example #7
0
 public DiffTool(string name, string path, ArgumentGenerator argGenerator)
 {
     Name          = name;
     _path         = path == null ? null : (Path.IsPathRooted(path) && File.Exists(path) ? path : Discover(path));
     _argGenerator = argGenerator;
 }
        /// <summary>
        /// Attaches the instrumentation events in the <paramref name="createdObject"></paramref> to the
        /// creating instance of the listener object, as defined by the <see cref="InstrumentationListenerAttribute"></see>
        /// on the source class.
        /// </summary>
        /// <param name="instanceName">User-provided instance name given to the instrumenation listener during its instantiation.</param>
        /// <param name="createdObject">Source object used for instrumentation events.</param>
        /// <param name="configurationSource"><see cref="IConfigurationSource"></see> instance used to define whether
        /// instrumentation is enabled or disabled for application.</param>
        /// <param name="reflectionCache">Cache for instrumentation attributes discovered through reflection.</param>
        public void AttachInstrumentation(string instanceName, object createdObject, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
        {
            ArgumentGenerator arguments = new ArgumentGenerator(instanceName);

            AttachInstrumentation(arguments, createdObject, configurationSource, reflectionCache);
        }
        /// <summary>
        /// Generate the assign statements inside a set up
        /// </summary>
        /// <param name="typeUnderTest">Type under tests</param>
        /// <param name="parameters">Parameters that we should create assign statements from</param>
        /// <returns>All generated assign statements</returns>
        public IEnumerable <StatementSyntax> GenerateSetUpStatements(Type typeUnderTest, IEnumerable <Parameter> parameters)
        {
            var statements = new List <StatementSyntax>();
            var arguments  = new List <IArgument>();

            if (typeUnderTest.ContainsGenericParameters)
            {
                return(new List <StatementSyntax>());
            }

            foreach (var parameter in parameters)
            {
                var type = parameter.Type;

                if ((type.IsInterface || type.IsAbstract) && !type.IsICollection())
                {
                    statements.Add(Statement.Declaration.Assign(
                                       $"{parameter.Name}Mock",
                                       CustomType.Create($"Mock<{parameter.Type.FormattedTypeName()}>"),
                                       ArgumentGenerator.Create()));

                    arguments.Add(
                        new ReferenceArgument(new VariableReference($"{parameter.Name}Mock", new MemberReference("Object"))));
                }
                else if (type.IsCollection())
                {
                    statements.Add(Statement.Declaration.Assign(
                                       $"{parameter.Name}",
                                       parameter.Type,
                                       ArgumentGenerator.Create()));

                    arguments.Add(
                        new ReferenceArgument(new VariableReference($"{parameter.Name}")));
                }
                else if (type.IsICollection())
                {
                    statements.Add(Statement.Declaration.Assign(
                                       $"{parameter.Name}",
                                       CustomType.Create($"{parameter.Type.FormattedTypeName().Remove(0, 1)}"),
                                       ArgumentGenerator.Create()));
                    arguments.Add(
                        new ReferenceArgument(new VariableReference($"{parameter.Name}")));
                }
                else if (type.IsNumeric())
                {
                    arguments.Add(new ValueArgument(0));
                }
                else if (type == typeof(bool))
                {
                    arguments.Add(new ValueArgument(true));
                }
                else if (type.Name == "String")
                {
                    arguments.Add(
                        new ReferenceArgument(
                            new VariableReference("string", new MemberReference("Empty"))));
                }
                else if (type.IsArray)
                {
                    arguments.Add(new VariableArgument(parameter.Name));
                }
                else
                {
                    arguments.Add(new ReferenceArgument(new NullReference()));
                }
            }

            statements.Add(Statement.Declaration.Assign(
                               typeUnderTest.FormattedFieldName(),
                               CustomType.Create(typeUnderTest.FormattedTypeName()),
                               ArgumentGenerator.Create(arguments.ToArray())));
            return(statements);
        }
Example #10
0
        protected override ArgumentSyntax CreateArgumentSyntax()
        {
            if (_genericTypes != null && _genericTypes.Any())
            {
                return(SyntaxFactory.Argument(SyntaxFactory.ObjectCreationExpression(GenericGenerator.Create(_type.Name, _genericTypes.ToArray())).WithArgumentList(ArgumentGenerator.Create(_arguments.ToArray()))));
            }

            return(SyntaxFactory.Argument(SyntaxFactory.ObjectCreationExpression(TypeGenerator.Create(_type)).WithArgumentList(ArgumentGenerator.Create(_arguments.ToArray()))));
        }