Ejemplo n.º 1
0
        public RenderPipelineTests(IAssert assert, IThreadControl threadControl, ITestAttachment testAttachment)
        {
            _assert         = assert;
            _testAttachment = testAttachment;

            threadControl.RequireTestsToRunOnMainThread();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Updates testcase's field with corresponding value
        /// </summary>
        /// <param name="fieldName"></param>
        /// <param name="value"></param>
        public override void UpdateField(string fieldName, object value)
        {
            // If value is null then just take the default valuea nd return the default value
            if (value == null)
            {
                return;
            }

            List <SourceTestStep> sourceSteps = value as List <SourceTestStep>;

            // If the value is a List of test steps then Update th testcase with test steps
            if (sourceSteps != null)
            {
                m_stepsFieldName = fieldName;

                foreach (SourceTestStep sourceStep in sourceSteps)
                {
                    // Update the Test step's text with correct parameters
                    string title          = sourceStep.title;
                    string expectedResult = sourceStep.expectedResult;

                    if (m_areRichSteps)
                    {
                        // This is temporary. Work around for product issue.
                        title          = title.Replace("\r\n", "<P>").Replace("\n", "<P>").Replace("\r", "<P>");
                        expectedResult = expectedResult.Replace("\r\n", "<P>").Replace("\n", "<P>").Replace("\r", "<P>");
                    }

                    // Creating TCM Test Step and filling testcase with them
                    ITestStep step = m_testCase.CreateTestStep();
                    step.Title = title;

                    // Set the TestStepType properly for validated steps
                    if (!String.IsNullOrEmpty(expectedResult))
                    {
                        step.ExpectedResult = expectedResult;
                        step.TestStepType   = TestStepType.ValidateStep;
                    }

                    if (sourceStep.attachments != null)
                    {
                        foreach (string filePath in sourceStep.attachments)
                        {
                            ITestAttachment attachment = step.CreateAttachment(filePath);
                            step.Attachments.Add(attachment);
                        }
                    }
                    m_testCase.Actions.Add(step);
                }
            }
            // else if it is a normal tfs field then just updates the tfs' testcase field
            else
            {
                base.UpdateField(fieldName, value);
            }
        }
Ejemplo n.º 3
0
            public RenderPipelineWorld(
                IAssetManager assetManager,
                I2DRenderUtilities renderUtilities,
                IGraphicsFactory graphicsFactory,
                IAssert assert,
                ITestAttachment testAttachment,
                IRenderTargetBackBufferUtilities renderTargetBackBufferUtilities,
                IGraphicsBlit graphicsBlit)
            {
                _renderUtilities                 = renderUtilities;
                _assert                          = assert;
                _testAttachment                  = testAttachment;
                _texture                         = assetManager.Get <TextureAsset>("texture.Player");
                _invertPostProcess               = graphicsFactory.CreateInvertPostProcessingRenderPass();
                _blurPostProcess                 = graphicsFactory.CreateBlurPostProcessingRenderPass();
                _customPostProcess               = graphicsFactory.CreateCustomPostProcessingRenderPass("effect.MakeRed");
                _captureInlinePostProcess        = graphicsFactory.CreateCaptureInlinePostProcessingRenderPass();
                _renderTargetBackBufferUtilities = renderTargetBackBufferUtilities;
                _graphicsBlit                    = graphicsBlit;
                _captureInlinePostProcess.RenderPipelineStateAvailable = (gameContext, renderContext, previousPass, d) =>
                {
                    if (!_isValidRun)
                    {
                        return;
                    }

                    _renderTarget = _renderTargetBackBufferUtilities.UpdateCustomRenderTarget(_renderTarget, renderContext, SurfaceFormat.Color, DepthFormat.None, 1);

                    // Blit to the capture target.
                    _graphicsBlit.Blit(renderContext, d, _renderTarget);

#if MANUAL_TEST
#elif RECORDING
                    using (var writer = new StreamWriter("output" + _frame + ".png"))
                    {
                        _renderTarget.SaveAsPng(writer.BaseStream, Width, Height);
                    }
#else
                    var baseStream =
                        typeof(RenderPipelineWorld).Assembly.GetManifestResourceStream(
                            "Protogame.Tests.Expected.RenderPipeline.output" + _frame + ".png");
                    _assert.NotNull(baseStream);
                    var memoryStream = new MemoryStream();
                    _renderTarget.SaveAsPng(memoryStream, Width, Height);
                    // ReSharper disable once AssignNullToNotNullAttribute
                    var expected = new Bitmap(baseStream);
                    var actual   = new Bitmap(memoryStream);

                    _assert.Equal(expected.Height, actual.Height);
                    _assert.Equal(expected.Width, actual.Width);
                    var totalPixelValues     = 0L;
                    var incorrectPixelValues = 0L;
                    for (var x = 0; x < expected.Width; x++)
                    {
                        for (var y = 0; y < expected.Height; y++)
                        {
                            var expectedPixel = expected.GetPixel(x, y);
                            var actualPixel   = actual.GetPixel(x, y);

                            totalPixelValues += 255 * 4;

                            if (expectedPixel != actualPixel)
                            {
                                var diffA = System.Math.Abs((int)actualPixel.A - (int)expectedPixel.A);
                                var diffR = System.Math.Abs((int)actualPixel.R - (int)expectedPixel.R);
                                var diffG = System.Math.Abs((int)actualPixel.G - (int)expectedPixel.G);
                                var diffB = System.Math.Abs((int)actualPixel.B - (int)expectedPixel.B);

                                incorrectPixelValues += (diffA + diffR + diffG + diffB);
                            }
                        }
                    }

                    var percentage = (100 - ((incorrectPixelValues / (double)totalPixelValues) * 100f));

                    var combination = _combinations[_frame % _combinations.Count];
                    _testAttachment.Attach("name-" + combination.Id, combination.Name);
                    _testAttachment.Attach("expected-" + combination.Id, baseStream);
                    _testAttachment.Attach("actual-" + combination.Id, memoryStream);
                    _testAttachment.Attach("threshold-" + combination.Id, 99.9);
                    _testAttachment.Attach("measured-" + combination.Id, percentage);

                    if (percentage <= 99.9f)
                    {
                        combination.FailureMessage = "The actual rendered image did not match the expected image close enough (99.9%).";
                    }

                    //memoryStream.Dispose();
                    //baseStream.Dispose();
#endif

#if MANUAL_TEST
                    _manualTest++;
                    if (_manualTest % 60 == 0)
                    {
                        _frame++;
                    }
#else
                    _frame++;
#endif
                };

                this.Entities = new List <IEntity>();
            }
Ejemplo n.º 4
0
        /// <summary>
        /// This method will upload test results to test lab in visual studio test manager
        /// </summary>
        /// <param name="xmlFileList">
        /// List of all test results xml files, saparate by semicolumn.
        /// All other files are expected to be present in this location
        /// </param>
        /// <param name="testCaseStatus"></param>
        /// Status of executed test case, can be pass, fail or warning
        /// <returns></returns>
        ///
        public static bool UploadTestResults(string xmlFileList, string testCaseStatus)
        {
            Array xmlFiles = xmlFileList.Split(';');
            ITestManagementTeamProject tfsProject = null;

            tfsProject = GetProject(ProjectUrl, ProjectName);

            if (tfsProject == null)
            {
                throw new Exception("Unabled to connect to test project: " + ProjectName);
            }
            //Above section commented as this is not required when InitExecution method is implemented
            ITestCaseResult tfsTestResult = null;

            tfsTestResult = tfsProject.TestResults.Find(Property.RcTestRunId, Property.RcTestResultId);

            if (tfsTestResult == null)
            {
                throw new Exception("Unabled to locate test results in Test Manager");
            }

            //Set status of test case execution
            switch (testCaseStatus.ToLower())
            {
            case "fail":
            case "failed":
                tfsTestResult.Outcome = TestOutcome.Failed;
                break;

            case "pass":
            case "passed":
                tfsTestResult.Outcome = TestOutcome.Passed;
                break;

            case "warning":
                tfsTestResult.Outcome = TestOutcome.Warning;
                break;
            }
            tfsTestResult.Save();
            //Attach files
            foreach (string xmlFileName in xmlFiles)
            {
                DirectoryInfo resultLocation = new DirectoryInfo(xmlFileName).Parent;

                //Generate MHT report
                try
                {
                    string iconLocation = new DirectoryInfo(Property.ApplicationPath).FullName;
                    iconLocation = iconLocation.TrimEnd('\\');
                    Process generateMht = new Process();
                    generateMht.StartInfo.FileName = Property.ApplicationPath + MhtReportGenerationExe;
                    if (resultLocation != null)
                    {
                        generateMht.StartInfo.Arguments = "\"" + resultLocation.FullName + "\"" + " " + "\"" + iconLocation + "\"";
                    }
                    generateMht.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                    generateMht.Start();
                    generateMht.WaitForExit();
                    generateMht.Close();
                }
                catch
                {
                    //No through
                }
                //Traverse through each file
                if (resultLocation != null)
                {
                    foreach (FileInfo resultFile in resultLocation.GetFiles())
                    {
                        if (!(resultFile.Extension.ToLower().Contains("jpeg") ||
                              resultFile.Extension.ToLower().Contains("html") ||
                              resultFile.Extension.ToLower().Contains("jpg")))
                        {
                            ITestAttachment resultAttachment = tfsTestResult.CreateAttachment(resultFile.FullName);
                            tfsTestResult.Attachments.Add(resultAttachment);
                            tfsTestResult.Save();
                        }
                    }
                }
            }

            //Set other details on test execution
            try
            {
                tfsTestResult.RunBy         = tfsTestResult.GetTestRun().Owner;
                tfsTestResult.DateCompleted = DateTime.Now;
                tfsTestResult.Duration      = DateTime.Now - tfsTestResult.DateStarted;
                tfsTestResult.ErrorMessage  = Property.ExecutionFailReason;
                tfsTestResult.State         = TestResultState.Completed;
                tfsTestResult.Save();
            }
            catch
            {
                // ignored
            }
            tfsTestResult.Save();
            return(true);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Copies a test case.
        /// </summary>
        /// <param name="sourceTestCase">The source test case.</param>
        /// <param name="destinationTestSuite">The destination test suite.</param>
        private static string CopyTestCase(ITestCase sourceTestCase, IStaticTestSuite destinationTestSuite)
        {
            string results = string.Empty;

            ITestCase destinationTestCase = destinationTestSuite.Project.TestCases.Create();

            destinationTestCase.Title       = sourceTestCase.Title;
            destinationTestCase.Description = sourceTestCase.Description;
            destinationTestCase.Priority    = sourceTestCase.Priority;


            Debug.WriteLine("Test Case: " + sourceTestCase.Title);
            foreach (Field aField in sourceTestCase.CustomFields)
            {
                Debug.WriteLine(string.Format("Field Name: '{0}', Value: '{1}'", aField.Name, aField.Value));
            }

            List <Field> trueCustomFields = (from aField in destinationTestCase.CustomFields.Cast <Field>()
                                             where !aField.ReferenceName.StartsWith("Microsoft") &&
                                             !aField.ReferenceName.StartsWith("System")
                                             select aField).ToList();

            foreach (Field destField in trueCustomFields)
            {
                Field sourceField = (from aField in sourceTestCase.CustomFields.Cast <Field>()
                                     where aField.ReferenceName == destField.ReferenceName
                                     select aField).FirstOrDefault();

                if (sourceField != null)
                {
                    destField.Value = sourceField.Value;
                }
            }

            // Set Area and Iteration Paths
            string areaPath = sourceTestCase.CustomFields["Area Path"].Value.ToString();

            if (areaPath.Contains("\\"))
            {
                areaPath = areaPath.Replace(sourceTestCase.Project.TeamProjectName, destinationTestSuite.Project.TeamProjectName);  // replace the project name

                int areaId = (from node in _destinationAreaNodes
                              where node.Path == areaPath
                              select node.Id).FirstOrDefault();


                destinationTestCase.CustomFields["Area Path"].Value = areaPath;
                destinationTestCase.CustomFields["Area ID"].Value   = areaId;
            }

            string iterationPath = sourceTestCase.CustomFields["Iteration Path"].Value.ToString();

            if (iterationPath.Contains("\\"))
            {
                iterationPath = iterationPath.Replace(sourceTestCase.Project.TeamProjectName, destinationTestSuite.Project.TeamProjectName);  // replace the project name

                int iterationId = (from node in _destinationIterationNodes
                                   where node.Path == iterationPath
                                   select node.Id).FirstOrDefault();

                destinationTestCase.CustomFields["Iteration Path"].Value = iterationPath;
                destinationTestCase.CustomFields["Iteration ID"].Value   = iterationId;
            }

            #region Attachments

            foreach (ITestAttachment sourceAttachment in sourceTestCase.Attachments)
            {
                string filePath = Path.Combine(Path.GetTempPath(), sourceAttachment.Name);

                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }

                sourceAttachment.DownloadToFile(filePath);

                ITestAttachment destinationAttachment = destinationTestCase.CreateAttachment(filePath);
                destinationAttachment.AttachmentType = sourceAttachment.AttachmentType;
                destinationAttachment.Comment        = sourceAttachment.Comment;

                destinationTestCase.Attachments.Add(destinationAttachment);

                destinationTestCase.Save();

                File.Delete(filePath);
            }

            #endregion

            #region Test Steps/Parameters

            foreach (ITestParameter sourceParameter in sourceTestCase.TestParameters)
            {
                destinationTestCase.ReplaceParameter(sourceParameter.Name, sourceParameter.Value);
            }

            foreach (ITestStep sourceAction in sourceTestCase.Actions)
            {
                ITestStep destinationTestStep = destinationTestCase.CreateTestStep();

                destinationTestStep.Title          = sourceAction.Title;
                destinationTestStep.Description    = sourceAction.Description;
                destinationTestStep.TestStepType   = sourceAction.TestStepType;
                destinationTestStep.ExpectedResult = sourceAction.ExpectedResult;
                destinationTestCase.Actions.Add(destinationTestStep);

                // Test Step Attachments
                foreach (ITestAttachment sourceAttachment in sourceAction.Attachments)
                {
                    string filePath = Path.Combine(Path.GetTempPath(), sourceAttachment.Name);

                    if (File.Exists(filePath))
                    {
                        File.Delete(filePath);
                    }

                    sourceAttachment.DownloadToFile(filePath);

                    ITestAttachment destinationAttachment = destinationTestStep.CreateAttachment(filePath);
                    destinationAttachment.AttachmentType = sourceAttachment.AttachmentType;
                    destinationAttachment.Comment        = sourceAttachment.Comment;

                    destinationTestStep.Attachments.Add(destinationAttachment);

                    try
                    {
                        destinationTestCase.Save();
                    }
                    catch (FileAttachmentException fileException)
                    {
                        destinationTestStep.Attachments.Remove(destinationAttachment);
                        results += string.Format(" - Suite: '{0}', Test Case: '{1}', Could not added attachment '{2}' due to '{3}'" + Environment.NewLine, destinationTestSuite.Title, destinationTestCase.Title, sourceAttachment.Name, fileException.Message);
                    }

                    File.Delete(filePath);
                }
            }

            #endregion

            destinationTestCase.Save();

            destinationTestCase.State = sourceTestCase.State;

            TeamFoundationIdentity sourceIdentity = sourceTestCase.Owner;

            if (sourceIdentity == null)
            {
                results += string.Format(" - Suite: '{0}', Test Case: '{1}', Could not set Assigned To user, not setup as a TFS user." + Environment.NewLine, destinationTestSuite.Title, destinationTestCase.Title);
            }
            else
            {
                TeamFoundationIdentity destinationIdentity = null;
                try
                {
                    destinationIdentity = destinationTestCase.Project.TfsIdentityStore.FindByAccountName(sourceIdentity.UniqueName);
                }
                catch (Exception e) { }

                if (destinationIdentity != null && destinationIdentity.IsActive)
                {
                    destinationTestCase.Owner = destinationIdentity;
                }
                else
                {
                    results += string.Format(" - Suite: '{0}', Test Case: '{1}', Could not set Assigned To user to '{2}'" + Environment.NewLine, destinationTestSuite.Title, destinationTestCase.Title, sourceIdentity.UniqueName);
                }
            }

            destinationTestCase.Save();

            destinationTestSuite.Entries.Add(destinationTestCase);
            destinationTestSuite.Plan.Save();

            return(results);
        }