public void Write(Stream stream, IEnumerable <ExpressionResult> expressions)
        {
            var expressionResults = expressions as ExpressionResult[] ?? expressions.ToArray();
            var testsuite         = new testsuiteType
            {
                name     = "Specifications",
                type     = "Assembly",
                executed = bool.TrueString,
                result   = expressionResults.HasErrors() ? "Failure" : "Success",
                asserts  = "0",
                time     = ConvertToSeconds(expressionResults.ElapsedTime()).ToString(CultureInfo.InvariantCulture),
            };

            var errorCount  = expressionResults.AllErrors().Count();
            var resultType  = CreateResultType(expressionResults, testsuite, errorCount);
            var resultTypes = new Collection <testsuiteType>();

            foreach (var expression in expressionResults)
            {
                var hasResultErrors = expression.Examples.HasErrors();
                var expressionType  = new testsuiteType
                {
                    name     = expression.Name,
                    type     = "Namespace",
                    result   = hasResultErrors ? "Failure" : "Success",
                    executed = bool.TrueString,
                    time     =
                        ConvertToSeconds(expression.Examples.ElapsedTime()).ToString(CultureInfo.InvariantCulture),
                    asserts = "0",
                    success = hasResultErrors ? bool.FalseString : bool.TrueString
                };

                var groupTypes = new Collection <testsuiteType>();

                CreateExamples(expression, groupTypes);

                expressionType.results = groupTypes.ToArray();
                resultTypes.Add(expressionType);
            }

            testsuite.results = resultTypes.ToArray();

            var serializer = new XmlSerializer(typeof(resultType));

            serializer.Serialize(stream, resultType);
        }
        public void Write(Stream stream, IEnumerable<ExpressionResult> expressions)
        {
            var expressionResults = expressions as ExpressionResult[] ?? expressions.ToArray();
            var testsuite = new testsuiteType
                {
                    name = "Specifications",
                    type = "Assembly",
                    executed = bool.TrueString,
                    result = expressionResults.HasErrors() ? "Failure" : "Success",
                    asserts = "0",
                    time = ConvertToSeconds(expressionResults.ElapsedTime()).ToString(CultureInfo.InvariantCulture),
                };
            
            var errorCount = expressionResults.AllErrors().Count();
            var resultType = CreateResultType(expressionResults, testsuite, errorCount);
            var resultTypes = new Collection<testsuiteType>();

            foreach (var expression in expressionResults) {
                var hasResultErrors = expression.Examples.HasErrors();
                var expressionType = new testsuiteType
                    {
                        name = expression.Name,
                        type = "Namespace",
                        result = hasResultErrors ? "Failure" : "Success",
                        executed = bool.TrueString,
                        time =
                            ConvertToSeconds(expression.Examples.ElapsedTime()).ToString(CultureInfo.InvariantCulture),
                        asserts = "0",
                        success = hasResultErrors ? bool.FalseString : bool.TrueString
                    };

                var groupTypes = new Collection<testsuiteType>();

                CreateExamples(expression, groupTypes);

                expressionType.results = groupTypes.ToArray();
                resultTypes.Add(expressionType);
            }
            
            testsuite.results = resultTypes.ToArray();
            
            var serializer = new XmlSerializer(typeof(resultType));
            serializer.Serialize(stream, resultType);
        }
 private static void CreateExamples(ExpressionResult expression, ICollection <testsuiteType> groupTypes)
 {
     foreach (var group in expression.Examples)
     {
         var hasGroupErrors = group.Examples.HasErrors();
         var groupType      = new testsuiteType
         {
             name     = group.Reason,
             type     = "TestFixture",
             result   = hasGroupErrors ? "Failure" : "Success",
             executed = bool.TrueString,
             time     = ConvertToSeconds(group.Examples.ElapsedTime()).ToString(CultureInfo.InvariantCulture),
             asserts  = "0",
             success  = hasGroupErrors ? bool.FalseString : bool.TrueString
         };
         var cases = new Collection <testcaseType>();
         CreateErrors(group, cases);
         CreateSuccesses(group, cases);
         groupType.results = cases.ToArray();
         groupTypes.Add(groupType);
     }
 }
 private static resultType CreateResultType(IEnumerable<ExpressionResult> expressions, testsuiteType testsuite,
                                            int errorCount)
 {
     var resultType = new resultType {
         environment = new environmentType {
             nunitversion = typeof(TestAttribute).Assembly.GetName().Version.ToString(),
             clrversion = Environment.Version.ToString(),
             osversion = Environment.OSVersion.VersionString,
             machinename = Environment.MachineName,
             platform = Enum.GetName(typeof(PlatformID), Environment.OSVersion.Platform),
             user = Environment.UserName,
             userdomain = Environment.UserDomainName
         },
         cultureinfo = new cultureinfoType {
             currentculture = CultureInfo.CurrentCulture.ToString(),
             currentuiculture = CultureInfo.CurrentUICulture.ToString()
         },
         testsuite = testsuite,
         errors = errorCount,
         total = expressions.AllSuccesses().Count() + errorCount,
         name = "Results",
         date = DateTime.Now.ToString("yyyy-MM-dd"),
         time = DateTime.Now.ToString("H:mm:ss")
     };
     
     return resultType;
 }
 private static void CreateExamples(ExpressionResult expression, ICollection<testsuiteType> groupTypes)
 {
     foreach (var group in expression.Examples) {
         var hasGroupErrors = group.Examples.HasErrors();
         var groupType = new testsuiteType
             {
                 name = group.Reason,
                 type = "TestFixture",
                 result = hasGroupErrors ? "Failure" : "Success",
                 executed = bool.TrueString,
                 time = ConvertToSeconds(group.Examples.ElapsedTime()).ToString(CultureInfo.InvariantCulture),
                 asserts = "0",
                 success = hasGroupErrors ? bool.FalseString : bool.TrueString
             };
         var cases = new Collection<testcaseType>();
         CreateErrors(group, cases);
         CreateSuccesses(group, cases);
         groupType.results = cases.ToArray();
         groupTypes.Add(groupType);
     }
 }
        private static resultType CreateResultType(IEnumerable <ExpressionResult> expressions, testsuiteType testsuite,
                                                   int errorCount)
        {
            var resultType = new resultType {
                environment = new environmentType {
                    nunitversion = typeof(TestAttribute).Assembly.GetName().Version.ToString(),
                    clrversion   = Environment.Version.ToString(),
                    osversion    = Environment.OSVersion.VersionString,
                    machinename  = Environment.MachineName,
                    platform     = Enum.GetName(typeof(PlatformID), Environment.OSVersion.Platform),
                    user         = Environment.UserName,
                    userdomain   = Environment.UserDomainName
                },
                cultureinfo = new cultureinfoType {
                    currentculture   = CultureInfo.CurrentCulture.ToString(),
                    currentuiculture = CultureInfo.CurrentUICulture.ToString()
                },
                testsuite = testsuite,
                errors    = errorCount,
                total     = expressions.AllSuccesses().Count() + errorCount,
                name      = "Results",
                date      = DateTime.Now.ToString("yyyy-MM-dd"),
                time      = DateTime.Now.ToString("H:mm:ss")
            };

            return(resultType);
        }