Пример #1
0
        /// Take all information from model
        /// </summary>
        /// <param name="model">Model to write</param>
        /// <returns>Model view</returns>
        private string GetView(TestReportModel model)
        {
            StringBuilder builder = new StringBuilder();

            Array.ForEach(_properties, (property) => builder.Append(GetFormat(_testItem, property.GetValue(model))));
            return(GetFormat(_row, builder.ToString()).ToString());
        }
 /// <summary>
 /// Set values, which can be received without reflection
 /// </summary>
 /// <param name="context">Test context</param>
 /// <param name="model">Test report model</param>
 protected void SetValuesFromContext(TestContext context, TestReportModel model)
 {
     model.ExecutionStatus = context.Result.Outcome.Status.ToString();
     model.Version         = "1.0";
     model.ExecutionDate   = DateTime.Now.ToLongDateString();
     model.BuildNumber     = Environment.GetEnvironmentVariable("BUILD_BUILDNUMBER");
     model.TestName        = context.Test.Name;
 }
Пример #3
0
 /// <summary>
 /// Write data from model to the output report file
 /// </summary>
 /// <param name="model">Model to write</param>
 private void WriteData(TestReportModel model)
 {
     lock (_writeLocker)
     {
         model.N = ++_testNumber;
         using (StreamWriter writer = new StreamWriter(_path, true))
         {
             writer.Write(GetView(model));
         }
     }
 }
        /// <summary>
        /// Take data from text context and build model
        /// </summary>
        /// <param name="context">Test context</param>
        /// <returns>Model based on current test context</returns>
        public override TestReportModel GetModel(TestContext context)
        {
            var model      = new TestReportModel();
            var attributes = GetMethod(context).CustomAttributes.Where(attribute => attribute.AttributeType == typeof(CategoryAttribute));

            var attributesValues = attributes.Select(attribute => attribute.ConstructorArguments.FirstOrDefault().Value.ToString());
            IEnumerable <string> currentPropertyValuesSequence;

            foreach (var property in properties)
            {
                currentPropertyValuesSequence = attributesValues.Where(attributeValue => attributeValue[0] == property.Name[0]);
                if (currentPropertyValuesSequence.Count() != 0)
                {
                    property.SetValue(model, currentPropertyValuesSequence.Aggregate((current, next) => $"{current} {next}"));
                }
            }
            SetValuesFromContext(context, model);
            return(model);
        }
        /// <summary>
        /// Take data from text context and build model
        /// </summary>
        /// <param name="context">Test context</param>
        /// <returns>Model based on current test context</returns>
        public override TestReportModel GetModel(TestContext context)
        {
            var model      = new TestReportModel();
            var attributes = GetMethod(context).CustomAttributes;

            foreach (var property in properties)
            {
                var currentAttributes = attributes.Where(attribute => attribute.AttributeType.Name.StartsWith(property.Name));
                if (currentAttributes.Count() != 0)
                {
                    property.SetValue(model, currentAttributes
                                      .Select(attribute => attribute.ConstructorArguments.Select(argument => argument.Value.ToString()).Aggregate((first, second) => $"{first} {second}"))
                                      .Distinct().Aggregate((first, second) => $"{first} <br> {second}"));
                }
            }
            SetFeatureInfo(context, model);
            SetValuesFromContext(context, model);
            return(model);
        }
 /// <summary>
 /// Get Feature attribute and set data to the model
 /// </summary>
 /// <param name="context">Test context</param>
 /// <param name="model">Model</param>
 public void SetFeatureInfo(TestContext context, TestReportModel model)
 {
     model.Feature = BaseModelBuilder.AssemblyWithTests.GetType($"{context.Test.ClassName}").CustomAttributes
                     .Where(attribute => attribute.AttributeType.Name == "FeatureAttribute").FirstOrDefault()?.ConstructorArguments.FirstOrDefault().Value.ToString();
 }