private static void Verify(TestRun actual, double expectedElapsed, string expectedTestRef, DateTime expectedStamp, TestRun.TestRunState expectedState)
 {
     Assert.AreEqual(expectedTestRef, actual.TestRef, "Test Reference");
     Assert.AreEqual(expectedStamp, actual.Stamp, "Test Stamp");
     Assert.AreEqual(expectedElapsed, actual.Elapsed, "Test Elapsed");
     Assert.AreEqual(expectedState, actual.State, "Test State");
 }
 protected static void Verify(TestRun testRun, TestRun.TestRunState state, string testName, DateTime testtime)
 {
     Assert.IsNotNull(testRun);
     Assert.AreEqual(testtime, testRun.Stamp);
     Assert.AreEqual(state, testRun.State);
     Assert.AreEqual(testName, testRun.TestRef);
 }
        public void CreateDefectClosedAT()
        {
            _svc.Initialize(Config, _mgr, null);
            var testRun = new TestRun(DateTime.Now, "closedTest");
            testRun.State = TestRun.TestRunState.Failed;
            testRun.Elapsed = 10;
            _mgr.Publish(testRun);

            Assert.AreEqual(1, _lastsaved.Count);
            Asset lastSaved = _lastsaved[0].Assets[0];
            Assert.AreEqual("Defect", lastSaved.AssetType.Token);
            AssertMultiValueAttribute(_svc.StubCentral.Services.GetOid("Story:1030"), lastSaved, "Defect.AffectedPrimaryWorkitems");
            AssertSingleValueAttribute("Story \"S-01004\" has failing Acceptance Test(s)", lastSaved, "Defect.Name");
            AssertSingleValueAttribute(
                string.Format("One or more acceptance tests failed at \"{0}\".<BR />Check the external test system for more details.", testRun.Stamp),
                lastSaved,
                "Defect.Description");
            AssertSingleValueAttribute(_svc.StubCentral.Services.GetOid("Scope:0"), lastSaved, "Defect.Scope");
            AssertSingleValueAttribute(_svc.StubCentral.Services.GetOid("Timebox:1009"), lastSaved, "Defect.Timebox");
            AssertNoLogExceptions();
        }
        public void SaveExistingATWithPassedStatus()
        {
            _svc.Initialize(Config, _mgr, null);

            var testRun = new TestRun(DateTime.Now, "passedTest");
            testRun.State = TestRun.TestRunState.Failed;
            testRun.Elapsed = 10;
            _mgr.Publish(testRun);

            Assert.AreEqual(1, _lastsaved.Count);
            Asset lastSaved = _lastsaved[0].Assets[0];
            Assert.AreEqual("Test", lastSaved.AssetType.Token);
            AssertSingleValueAttribute(_svc.StubCentral.Services.GetOid(Config["FailedOid"].InnerText), lastSaved, "Test.Status");

            testRun.State = TestRun.TestRunState.NotRun;
            _mgr.Publish(testRun);
            Assert.AreEqual(2, _lastsaved.Count);
            lastSaved = _lastsaved[1].Assets[0];
            Assert.AreEqual("Test", lastSaved.AssetType.Token);
            AssertSingleValueAttribute(Oid.Null, lastSaved, "Test.Status");
            AssertNoLogExceptions();
        }
        public void NoOpNoStatusChange()
        {
            _svc.Initialize(Config, _mgr, null);
            var testRun = new TestRun(DateTime.Now, "testRef");
            testRun.State = TestRun.TestRunState.NotRun;
            testRun.Elapsed = 10;
            _mgr.Publish(testRun);

            Assert.AreEqual(0, _lastsaved.Count, "Should not save any tests when the status does not change.");

            testRun = new TestRun(DateTime.Now, "passedTest");
            testRun.State = TestRun.TestRunState.Passed;
            testRun.Elapsed = 10;
            _mgr.Publish(testRun);

            Assert.AreEqual(0, _lastsaved.Count, "Should not save any tests when the status does not change.");

            testRun = new TestRun(DateTime.Now, "failedTest");
            testRun.State = TestRun.TestRunState.Failed;
            testRun.Elapsed = 10;
            _mgr.Publish(testRun);

            Assert.AreEqual(0, _lastsaved.Count, "Should not save any tests when the status does not change.");
            AssertNoLogExceptions();
        }
        public void NoOpNonExistentAT()
        {
            _svc.Initialize(Config, _mgr, null);
            var testRun = new TestRun(DateTime.Now, "fooBar");
            testRun.State = TestRun.TestRunState.Failed;
            testRun.Elapsed = 10;
            _mgr.Publish(testRun);

            Assert.AreEqual(0, _lastsaved.Count, "Should not save any tests when the reference is not found in V1.");
            AssertLogMessage("No Tests found by reference");
            AssertNoLogExceptions();
        }
        public void NoOpEmptyReference()
        {
            _svc.Initialize(Config, _mgr, null);
            var testRun = new TestRun(DateTime.Now, null);
            testRun.State = TestRun.TestRunState.Failed;
            testRun.Elapsed = 10;
            _mgr.Publish(testRun);

            Assert.AreEqual(0, _lastsaved.Count, "Should not save any tests when the reference is not found in V1.");
            AssertLogMessage("Test Reference is null or empty. Skipping...");
            AssertNoLogExceptions();
        }
        public void DontCreateExistingDefect()
        {
            _svc.Initialize(Config, _mgr, null);
            var testRun = new TestRun(DateTime.Now, "closedTestHasDefect");
            testRun.State = TestRun.TestRunState.Failed;
            testRun.Elapsed = 10;
            _mgr.Publish(testRun);

            Assert.AreEqual(0, _lastsaved.Count, "Should not create a Defect when one already exists.");
            AssertNoLogExceptions();
        }
        public void CreateDefectNone()
        {
            _svc.Initialize(ConfigNoDefect, _mgr, null);
            var testRun = new TestRun(DateTime.Now, "closedTest");
            testRun.State = TestRun.TestRunState.Failed;
            testRun.Elapsed = 10;
            _mgr.Publish(testRun);

            Assert.AreEqual(0, _lastsaved.Count, "Should not create a Defect when CreateDefect config is \"None\".");
            AssertNoLogExceptions();
        }
        public void CreateDefectCurrentIteration_Closed()
        {
            _svc.Initialize(ConfigCurrentDefect, _mgr, null);
            var testRun = new TestRun(DateTime.Now, "Test5");
            testRun.State = TestRun.TestRunState.Failed;
            testRun.Elapsed = 10;
            _mgr.Publish(testRun);

            Assert.AreEqual(0, _lastsaved.Count, "Should not create a Defect when CreateDefect config is \"CurrentIteration\", and there is NO active iteration in-scope.");
            AssertNoLogExceptions();
        }
        private QueryResult GetRelatedTests(TestRun run) {
            var testQuery = new Query(TestType);
            testQuery.Selection.Add(TestStatusDef);
            testQuery.Selection.Add(TestNameDef);
            testQuery.Selection.Add(TestAssetStateDef);
            testQuery.Selection.Add(TestParentDef);
            testQuery.Selection.Add(TestScopeDef);
            testQuery.Selection.Add(TestParentNumberDef);
            testQuery.Selection.Add(TestScheduleDef);
            testQuery.Selection.Add(TestTimeboxDef);

            var term = new FilterTerm(TestReferenceDef);
            term.Equal(run.TestRef);
            testQuery.Filter = term;

            return Services.Retrieve(testQuery);
        }
        private void DefectForClosedTest(TestRun run, Asset test) {
            var newDescription = string.Format(
                "One or more acceptance tests failed at \"{0}\".<BR />{1}",
                run.Stamp, descriptionsuffix);

            if(ShouldCreateDefect(test)) {
                var defect = CreateRelatedDefect(newDescription, test);
                Services.Save(defect, changeComment);
                Logger.Log(string.Format("Saving defect for test \"{0}\".", run.TestRef));
            }
        }
        private void LoadOid(TestRun.TestRunState state, XmlElement config, Oid def) {
            var configkey = state.ToString() + "Oid";
            var oidconfig = config[configkey];
            var oidtoken = oidconfig != null ? oidconfig.InnerText : null;
            var oid = def;

            try {
                oid = Services.GetOid(oidtoken);
            } catch(OidException) {
            }

            //the oid is null-null or its not oid-null and we can't find it in the V1 system. (Oid.Null is ok!)
            if(oid == null) {
                throw new InvalidOperationException(string.Format("Invalid Oid Token for {0}: {1}", configkey, oidtoken));
            }
 
            if(oid != Oid.Null) {
                if(oid.AssetType != TestStatusType) {
                    throw new InvalidOperationException(string.Format("Oid for {0} is not a TestStatus Type: {1}", configkey, oidtoken));
                }

                var q = new Query(oid.AssetType);
                var term = new FilterTerm(oid.AssetType.GetAttributeDefinition("Key"));
                term.Equal(oid.Key);
                q.Filter = term;
                var assetlist = Services.Retrieve(q).Assets;
                
                if(assetlist.Count == 0) {
                    throw new InvalidOperationException(string.Format("TestStatus for {0} does not exist: {1}", configkey, oidtoken));
                }
            }

            states.Add(state, oid);
        }
 private static void Verify(TestRun testRun, TestRun.TestRunState state, string testName, DateTime? testtime, double elasped)
 {
     Assert.AreEqual(testName, testRun.TestRef, "testRun.TestRef");
     Assert.AreEqual(state, testRun.State, "testRun.State");
     if (testtime != null)
         Assert.AreEqual(testtime, testRun.Stamp, "testRun.Stamp");
     Assert.AreEqual(elasped, testRun.Elapsed, 0.5, "testRun.Elapsed");
 }
 private static void Verify(TestRun testRun, TestRun.TestRunState state, string testName, DateTime testTime, Double elapsed)
 {
     Assert.IsNotNull(testRun);
     Assert.AreEqual(elapsed, testRun.Elapsed);
     Verify(testRun, state, testName, testTime);
 }
        private static TestRun CreateV1TestRun(string externalId, DateTime timestamp, string status) {
            var oneRun = new TestRun(timestamp, externalId);
            
            if (status == "Passed") {
                oneRun.State = TestRun.TestRunState.Passed;
            } else {
                oneRun.State = (status == "Failed")
                                   ? TestRun.TestRunState.Failed
                                   : TestRun.TestRunState.NotRun;
            }

            return oneRun;
        }