Esempio n. 1
0
        public void FahClientUnitRunData_CopyConstructor_Test()
        {
            // Arrange
            var data = new FahClientUnitRunData
            {
                FramesObserved = 50,
                CoreVersion    = "1.23",
                ProjectID      = 1,
                ProjectRun     = 2,
                ProjectClone   = 3,
                ProjectGen     = 4,
                WorkUnitResult = WorkUnitResult.FINISHED_UNIT,
                Frames         = new Dictionary <int, LogLineFrameData> {
                    { 1, new LogLineFrameData {
                          ID = 1
                      } }
                }
            };
            // Act
            var copy = new FahClientUnitRunData(data);

            // Assert
            Assert.AreEqual(data.FramesObserved, copy.FramesObserved);
            Assert.AreEqual(data.CoreVersion, copy.CoreVersion);
            Assert.AreEqual(data.ProjectID, copy.ProjectID);
            Assert.AreEqual(data.ProjectRun, copy.ProjectRun);
            Assert.AreEqual(data.ProjectClone, copy.ProjectClone);
            Assert.AreEqual(data.ProjectGen, copy.ProjectGen);
            Assert.AreEqual(data.WorkUnitResult, copy.WorkUnitResult);
            Assert.AreNotSame(data.Frames, copy.Frames);
            Assert.AreNotSame(data.Frames[1], copy.Frames[1]);
            Assert.AreEqual(data.Frames[1].ID, copy.Frames[1].ID);
        }
Esempio n. 2
0
        public void FahClientUnitRunData_CopyConstructor_OtherIsNull_Test()
        {
            // Act
            var copy = new FahClientUnitRunData(null);

            // Assert
            Assert.AreEqual(0, copy.FramesObserved);
            Assert.AreEqual(null, copy.CoreVersion);
            Assert.AreEqual(0, copy.ProjectID);
            Assert.AreEqual(0, copy.ProjectRun);
            Assert.AreEqual(0, copy.ProjectClone);
            Assert.AreEqual(0, copy.ProjectGen);
            Assert.AreEqual(null, copy.WorkUnitResult);
            Assert.AreEqual(null, copy.Frames);
        }
        /// <summary>
        /// Creates a new <see cref="UnitRunData"/> object from the information contained in the <see cref="UnitRun"/> object.
        /// </summary>
        protected override UnitRunData OnGetUnitRunData(UnitRun unitRun)
        {
            var unitRunData = new FahClientUnitRunData();
            var frames      = new Dictionary <int, LogLineFrameData>();

            int count = unitRun.LogLines.Count;

            for (int i = 0; i < count; i++)
            {
                var line = unitRun.LogLines[i];
                switch (line.LineType)
                {
                case LogLineType.WorkUnitWorking:
                    unitRunData.UnitStartTimeStamp = line.TimeStamp;
                    unitRunData.WorkUnitResult     = Internal.WorkUnitResult.None;
                    break;

                case LogLineType.WorkUnitFrame:
                    if (unitRunData.UnitStartTimeStamp == null)
                    {
                        unitRunData.UnitStartTimeStamp = line.TimeStamp;
                    }
                    if (line.Data != null && !(line.Data is LogLineDataParserError))
                    {
                        if (line.Data is LogLineFrameData frameData)
                        {
                            // Make a copy so UnitRunData is not holding a reference to the same
                            // WorkUnitFrameData instance as the LogLine it was sourced from.
                            var frameDataCopy = new LogLineFrameData(frameData);
                            frames.TryAdd(frameData.ID, frameDataCopy);

                            if (unitRunData.FramesObserved > 0)
                            {
                                Internal.CommonRunDataAggregator.CalculateFrameDataDuration(frameDataCopy, frames);
                            }
                        }
                        unitRunData.FramesObserved++;
                    }
                    break;

                case LogLineType.WorkUnitCoreVersion:
                    if (line.Data != null && !(line.Data is LogLineDataParserError))
                    {
                        unitRunData.CoreVersion = (string)line.Data;
                    }
                    break;

                case LogLineType.WorkUnitProject:
                    var projectData = (LogLineProjectData)line.Data;
                    unitRunData.ProjectID    = projectData.ProjectID;
                    unitRunData.ProjectRun   = projectData.ProjectRun;
                    unitRunData.ProjectClone = projectData.ProjectClone;
                    unitRunData.ProjectGen   = projectData.ProjectGen;
                    break;

                case LogLineType.WorkUnitPlatform:
                    if (line.Data != null)
                    {
                        unitRunData.Platform = (string)line.Data;
                    }
                    break;

                case LogLineType.WorkUnitCoreReturn:
                    unitRunData.WorkUnitResult = (string)line.Data;
                    switch (unitRunData.WorkUnitResult)
                    {
                    case Internal.WorkUnitResult.INTERRUPTED:
                    case Internal.WorkUnitResult.UNKNOWN_ENUM:
                        unitRunData.FramesObserved = 0;
                        break;

                    case Internal.WorkUnitResult.CORE_RESTART:
                        unitRunData.FramesObserved = 0;
                        frames.Clear();
                        break;
                    }
                    break;
                }
            }

            unitRunData.Frames = frames;
            return(unitRunData);
        }