Exemple #1
0
 private void EndSpec(string testName, string methodName, SpecLog specLog)
 {
     foreach (var sink in Sinks)
     {
         sink.EndTest(testName, methodName, specLog);
     }
 }
Exemple #2
0
        public void SetModelValueTest()
        {
            SpecLog specLenovo  = new SpecLog();
            SpecLog specDell    = new SpecLog();
            SpecLog specHp      = new SpecLog();
            SpecLog specFujitsu = new SpecLog();
            SpecLog specOther   = new SpecLog();


            specLenovo.Manufacturer  = "LENOVO";
            specLenovo.ModelName     = "ThinkPad W540  ";
            specDell.Manufacturer    = "DELL INC.";
            specDell.ModelName       = "OptiPlex7010 Tower ";
            specHp.Manufacturer      = "HEWLETT-PACKARD";
            specHp.ModelName         = "HP COMPAQ   8300 Pro";
            specFujitsu.Manufacturer = "FUJITSU";
            specFujitsu.ModelName    = "LIFEBOOK S710 ";
            specOther.Manufacturer   = "";
            specOther.ModelName      = "Alienware G25";

            string lenovoModel  = "W540";
            string dellModel    = "7010 TWR";
            string hpModel      = "8300";
            string fujitsuModel = "S710";
            string otherModel   = "Alienware G25";


            Assert.AreEqual(lenovoModel, specLenovo.ModelName);
            Assert.AreEqual(dellModel, specDell.ModelName);
            Assert.AreEqual(hpModel, specHp.ModelName);
            Assert.AreEqual(fujitsuModel, specFujitsu.ModelName);
            Assert.AreEqual(otherModel, specOther.ModelName);
        }
Exemple #3
0
        internal void RegisterAssemblyResolve(IEnumerable <string> paths)
        {
            AppDomain currentDomain = AppDomain.CurrentDomain;

            var searchPath = paths.ToArray();

            currentDomain.AssemblyResolve += (_, e) => {
                var an = new AssemblyName(e.Name);
                if (an.Name == "Carbonfrost.Commons.Spec")
                {
                    return(typeof(Assert).Assembly);
                }

                foreach (var folderPath in searchPath)
                {
                    string assemblyPath = Path.Combine(folderPath, an.Name + ".dll");
                    if (File.Exists(assemblyPath))
                    {
                        SpecLog.AssemblyResolved(assemblyPath);
                        return(LoadAssemblyFromPath(assemblyPath));
                    }
                }

                return(null);
            };
        }
        private void SetupLogger()
        {
            SpecLog.DidSetupLogger(Logger);

            // Message logger must handle events first
            _messageLogger.Initialize(this, this);
            Logger.Initialize(this, this);
        }
Exemple #5
0
        public void AddSelfTests()
        {
            SpecLog.ActivatedSelfTestMode();

            if (!TestClass.HasSelfTests)
            {
                throw SpecFailure.NoSelfTestsAvailable();
            }
            AddAssembly(typeof(TestMatcher).GetTypeInfo().Assembly);
        }
Exemple #6
0
        public void ViewSpecValuesTest()
        {
            SpecLog       expectedSpec;
            SpecLog       actualSpec;
            DisplayedSpec displayedSpec = new DisplayedSpec();

            expectedSpec = new SpecLog()
            {
                Manufacturer      = "LENOVO",
                ModelName         = "P50",
                ModelSerial       = "S120en0005mbPC0C3D4N",
                MotherboardSerial = "L1HF63Y00TV",
                Cpu           = "i7-6700HQ CPU @ 2.60GHz",
                RamSize       = "16GB (8+8)",
                RamPartNumber = $"M471A1G43DB0-CPB{Environment.NewLine}M471A1G43DB0-CPB",
                RamSerial     = $"9244AF5B{Environment.NewLine}120BAC8E",
                Optical       = "",
                DiskName      = "INTEL SSDPEKKF256G7H",
                DiskSize      = "256SSD",
                DiskSerial    = "0000_0000_0100_0000_E4D2_5C1E_9BE4_4E01.",
                Diagonal      = $@"23""",
                Resolution    = "FHD",
                Gpu           = $"NVIDIA Quadro M1000M{Environment.NewLine}Intel(R) HD Graphics 530",
                InstalledOS   = "Win10 Pro",
                VerOS         = "18362",
                LangOS        = "PL",
                OsKey         = "2NG2R-HRCYB-3J9YB-CG7MP-HH7CP"
            };
            actualSpec = displayedSpec.ViewSpec;


            Assert.AreEqual(expectedSpec.Manufacturer, actualSpec.Manufacturer, "Manufacturer value not equal.");
            Assert.AreEqual(expectedSpec.ModelName, actualSpec.ModelName, "Model value not equal.");
            Assert.AreEqual(expectedSpec.ModelSerial, actualSpec.ModelSerial, "Serial value not equal.");
            Assert.AreEqual(expectedSpec.MotherboardSerial, actualSpec.MotherboardSerial, "MotherboardSerial value not equal.");
            Assert.AreEqual(expectedSpec.Cpu, actualSpec.Cpu, "Processor value not equal.");
            Assert.AreEqual(expectedSpec.RamSize, actualSpec.RamSize, "Ram value not equal.");
            Assert.AreEqual(expectedSpec.RamPartNumber, actualSpec.RamPartNumber, "RamPartNumber value not equal.");
            Assert.AreEqual(expectedSpec.RamSerial, actualSpec.RamSerial, "RamSerial value not equal.");
            Assert.AreEqual(expectedSpec.Optical, actualSpec.Optical, "Optical value not equal.");

            Assert.AreEqual(expectedSpec.DiskName, actualSpec.DiskName, "DiskName value not equal.");
            Assert.AreEqual(expectedSpec.DiskSize, actualSpec.DiskSize, "DiskSize value not equal.");
            Assert.AreEqual(expectedSpec.DiskSerial, actualSpec.DiskSerial, "DiskSerial value not equal.");
            Assert.AreEqual(expectedSpec.Diagonal, actualSpec.Diagonal, "Diagonal value not equal.");
            Assert.AreEqual(expectedSpec.Resolution, actualSpec.Resolution, "Resolution value not equal.");
            Assert.AreEqual(expectedSpec.Gpu, actualSpec.Gpu, "GPU value not equal.");

            Assert.AreEqual(expectedSpec.InstalledOS, actualSpec.InstalledOS, "InstalledOS value not equal.");
            Assert.AreEqual(expectedSpec.VerOS, actualSpec.VerOS, "VerOS value not equal.");
            Assert.AreEqual(expectedSpec.LangOS, actualSpec.LangOS, "LangOS value not equal.");
            Assert.AreEqual(expectedSpec.OsKey, actualSpec.OsKey, "OsKey value not equal.");
        }
Exemple #7
0
        protected virtual TestRun CreateTestRun()
        {
            var run = new TestRun();

            if (Options.SelfTest)
            {
                run.AddSelfTests();
            }

            foreach (var asm in Options.LoadAssembliesAndBindLoader())
            {
                run.AddAssembly(asm);
            }

            SpecLog.DidCreateTestRun();
            return(run);
        }
Exemple #8
0
        public void SetDeviceTypeValueTest()
        {
            SpecLog singleType = new SpecLog();
            SpecLog doubleType = new SpecLog();
            SpecLog multiType  = new SpecLog();

            singleType.DeviceType = "9";
            doubleType.DeviceType = "1/10";
            multiType.DeviceType  = "1/10/24/2/13";

            string singleTypeExpected = "Laptop";
            string doubleTypeExpected = "Other/Notebook";
            string multiTypeExpected  = "Other/Notebook/Sealed-Case PC/Unknown/All in One";

            Assert.AreEqual(singleTypeExpected, singleType.DeviceType);
            Assert.AreEqual(doubleTypeExpected, doubleType.DeviceType);
            Assert.AreEqual(multiTypeExpected, multiType.DeviceType);
        }
Exemple #9
0
        internal Assembly LoadAssembly(string asmPath)
        {
            string fullPath = Path.GetFullPath(asmPath);

            if (!File.Exists(fullPath))
            {
                throw SpecFailure.FailedToLoadAssemblyPath(asmPath);
            }
            try {
                SpecLog.LoadAssembly(fullPath);

                return(LoadAssemblyFromPath(fullPath));
            } catch (BadImageFormatException) {
                throw SpecFailure.FailedToLoadAssembly(asmPath);
            } catch (FileNotFoundException ex) {
                throw SpecFailure.FailedToLoadAssemblyPath(asmPath + " -> " + ex.FileName);
            } catch (IOException ex) {
                throw SpecFailure.FailedToLoadAssemblyGeneralIO(asmPath, ex.Message);
            }
        }
Exemple #10
0
        protected override void Initialize(TestContext testContext)
        {
            Metadata.Apply(testContext);

            foreach (var nsGroup in GetTestTypes().GroupBy(t => t.Namespace))
            {
                var tests = nsGroup.Select(t => TestUnitFromType(t));
                var unit  = TestNamespace.Create(nsGroup.Key, tests);
                SpecLog.DiscoveredTests(unit.Children);
                if (unit.Children.Count == 0)
                {
                    // if the ns has no tests, we don't even report it exists
                    continue;
                }

                Children.Add(unit);
            }

            Metadata.ApplyDescendants(testContext, Descendants);
        }
Exemple #11
0
 public void EndTest(string className, string methodName, SpecLog log)
 {
     //end the current spec
     MessageSinkActorRef.Tell(new EndSpec(className, methodName, log));
 }
Exemple #12
0
        private static void ReportTestMessages(SpecSession session, Dictionary <int, UnitTestResult> nodeResults, UnitTestResult specResult, SpecLog log)
        {
            foreach (var(_, message) in session.Messages)
            {
                var textMessage = $"[{message.When:G}] {message.Message}";

                Output output;
                if (nodeResults.TryGetValue(message.NodeIndex, out var result))
                {
                    if (result.Output == null)
                    {
                        result.Output = new Output();
                    }

                    output = result.Output;
                }
                else
                {
                    if (specResult.Output == null)
                    {
                        specResult.Output = new Output();
                    }

                    output = specResult.Output;
                }

                output.StdOut.Add(textMessage);
                output.DebugTrace.Add(textMessage);
            }

            specResult.Output = specResult.Output ?? new Output();
            specResult.Output.StdErr.AddRange(log.AggregatedTimelineLog);
        }
Exemple #13
0
        private static void ReportFailure(SpecSession session, Dictionary <int, UnitTestResult> nodeResults, SpecLog log)
        {
            foreach (var(time, message) in session.Fails)
            {
                var result = nodeResults[message.NodeIndex];
                result.Outcome = TestOutcome.Failed;
                result.EndTime = time;

                result.Output = new Output();
                result.Output.StdErr.Add(message.Message);

                var nodeLog = log.NodeLogs.Find(n => n.NodeIndex == message.NodeIndex);
                if (nodeLog.Log != null)
                {
                    result.Output.StdErr.AddRange(nodeLog.Log);
                }

                result.Output.DebugTrace.Add(message.Message);
                result.Output.ErrorInfo = new ErrorInfo()
                {
                    Message = message.Message
                };
            }
        }
Exemple #14
0
        private static void ReportSpec(SpecSession session, TestRun testRun, string computerName, SpecLog log)
        {
            var begin     = session.Begin.Value;
            var beginTime = session.Begin.Time;

            var test       = testRun.AddUnitTest(begin.ClassName, begin.MethodName, $"{begin.ClassName}.{begin.MethodName}");
            var specResult = test.AddResult(begin.MethodName, computerName);

            var nodeResults = new Dictionary <int, UnitTestResult>();

            ReportNodes(begin, specResult, beginTime, nodeResults);
            ReportSuccess(session, nodeResults);
            ReportFailure(session, nodeResults, log);

            specResult.Outcome   = GetCombinedTestOutcome(nodeResults.Values);
            specResult.StartTime = beginTime;
            specResult.EndTime   = session.End.Time;

            ReportTestMessages(session, nodeResults, specResult, log);
        }
 public DisplayedSpec()
 {
     SpecReader specReader = new SpecReader();
     ViewSpec = specReader.CurrentSpec;
 }
Exemple #16
0
 public EndSpec(string className, string methodName, SpecLog log)
 {
     ClassName  = className;
     MethodName = methodName;
     Log        = log;
 }