public void StepStorageTest() { var storage = new StepStorage(); var step1 = new step(); var step2 = new step(); var step3 = new step(); storage.Put(step1); Assert.AreEqual(2, storage.Get().Count); Assert.AreEqual(step1, storage.Last); new Thread(() => { storage.Put(step2); Thread.Sleep(100); Assert.AreEqual(2, storage.Get().Count); Assert.AreEqual(step2, storage.Last); }).Start(); new Thread(() => { storage.Put(step3); Assert.AreEqual(2, storage.Get().Count); Assert.AreEqual(step3, storage.Last); }).Start(); }
/// <summary> /// Processes all testcase events. /// <see cref="AllureCSharpCommons.Events.TestCaseStartedEvent"/> /// <see cref="AllureCSharpCommons.Events.TestCasePendingEvent"/> /// <see cref="AllureCSharpCommons.Events.TestCaseCanceledEvent"/> /// <see cref="AllureCSharpCommons.Events.TestCaseFinishedEvent"/> /// </summary> /// <param name="evt">event to process</param> public void Fire(ITestCaseEvent evt) { if (typeof(TestCaseStartedEvent).IsAssignableFrom(evt.GetType())) { StepStorage.Get(); var testcaseresult = TestCaseStorage.Get(); evt.Process(testcaseresult); lock (TestSuiteAddChildLock) { TestSuiteStorage.Put(evt.SuiteUid); TestSuiteStorage.Get(evt.SuiteUid).testcases = ArraysUtils.Add(TestSuiteStorage.Get(evt.SuiteUid).testcases, testcaseresult); } } else if (typeof(TestCaseFinishedEvent).IsAssignableFrom(evt.GetType())) { var testcaseresult = TestCaseStorage.Get(); evt.Process(testcaseresult); var root = StepStorage.PollLast(); testcaseresult.steps = ArraysUtils.AddAll(testcaseresult.steps, root.steps); testcaseresult.attachments = ArraysUtils.AddAll(testcaseresult.attachments, root.attachments); StepStorage.Remove(); TestCaseStorage.Remove(); } else { var testcaseresult = TestCaseStorage.Get(); evt.Process(testcaseresult); } }
protected Allure() { Logger.Setup(); StepStorage = new StepStorage(); TestCaseStorage = new TestCaseStorage(); TestSuiteStorage = new TestSuiteStorage(); }
/// <summary> /// Processes all step events. /// <see cref="AllureCSharpCommons.Events.StepStartedEvent"/> /// <see cref="AllureCSharpCommons.Events.StepCanceledEvent"/> /// <see cref="AllureCSharpCommons.Events.StepFinishedEvent"/> /// </summary> /// <param name="evt">event to process</param> public void Fire(IStepEvent evt) { if (typeof(StepStartedEvent).IsAssignableFrom(evt.GetType())) { var step = new step(); evt.Process(step); StepStorage.Put(step); } else if (typeof(StepFinishedEvent).IsAssignableFrom(evt.GetType())) { var step = StepStorage.PollLast(); evt.Process(step); StepStorage.Last.steps = ArraysUtils.Add(StepStorage.Last.steps, step); } else { var step = StepStorage.Last; evt.Process(step); } }
/// <summary> /// Step through a Range of Numerics. /// </summary> private static object StepNumeric(StepStorage /*!*/ storage, BlockParam /*!*/ block, Range /*!*/ self, object begin, object end, object step) { Assert.NotNull(storage, block, self); CheckStep(storage, step); object item = begin; object result; var site = self.ExcludeEnd ? storage.LessThanSite : storage.LessThanEqualsSite; while (RubyOps.IsTrue(site.Target(site, item, end))) { if (block.Yield(item, out result)) { return(result); } var add = storage.AddSite; item = add.Target(add, item, step); } return(self); }
public static object Step(StepStorage /*!*/ storage, [NotNull] BlockParam /*!*/ block, Range /*!*/ self, [Optional] object step) { if (step == Missing.Value) { step = ClrInteger.One; } // We attempt to cast step to Fixnum here even though if we were iterating over Floats, for instance, we use step as is. // This prevents cases such as (1.0..2.0).step(0x800000000000000) {|x| x } from working but that is what MRI does. if (self.Begin is int && self.End is int) { // self.begin is Fixnum; directly call item = item + 1 instead of succ var site = storage.FixnumCastSite; int intStep = site.Target(site, step); return(StepFixnum(block, self, (int)self.Begin, (int)self.End, intStep)); } else if (self.Begin is MutableString) { // self.begin is String; use item.succ and item <=> self.end but make sure you check the length of the strings var site = storage.FixnumCastSite; int intStep = site.Target(site, step); return(StepString(storage, block, self, (MutableString)self.Begin, (MutableString)self.End, intStep)); } else if (storage.Context.IsInstanceOf(self.Begin, storage.Context.GetClass(typeof(Numeric)))) { // self.begin is Numeric; invoke item = item + 1 instead of succ and invoke < or <= for compare return(StepNumeric(storage, block, self, self.Begin, self.End, step)); } else { // self.begin is not Numeric or String; just invoke item.succ and item <=> self.end var site = storage.FixnumCastSite; int intStep = site.Target(site, step); return(StepObject(storage, block, self, self.Begin, self.End, intStep)); } }
/// <summary> /// Step through a Range of Numerics. /// </summary> private static object StepNumeric(StepStorage/*!*/ storage, BlockParam/*!*/ block, Range/*!*/ self, object begin, object end, object step) { Assert.NotNull(storage, block, self); CheckStep(storage, step); object item = begin; object result; var site = self.ExcludeEnd ? storage.LessThanSite : storage.LessThanEqualsSite; while (RubyOps.IsTrue(site.Target(site, item, end))) { if (block.Yield(item, out result)) { return result; } var add = storage.AddSite; item = add.Target(add, item, step); } return self; }
public static object Step(StepStorage/*!*/ storage, [NotNull]BlockParam/*!*/ block, Range/*!*/ self, [Optional]object step) { if (step == Missing.Value) { step = ClrInteger.One; } // We attempt to cast step to Fixnum here even though if we were iterating over Floats, for instance, we use step as is. // This prevents cases such as (1.0..2.0).step(0x800000000000000) {|x| x } from working but that is what MRI does. if (self.Begin is int && self.End is int) { // self.begin is Fixnum; directly call item = item + 1 instead of succ var site = storage.FixnumCastSite; int intStep = site.Target(site, step); return StepFixnum(block, self, (int)self.Begin, (int)self.End, intStep); } else if (self.Begin is MutableString) { // self.begin is String; use item.succ and item <=> self.end but make sure you check the length of the strings var site = storage.FixnumCastSite; int intStep = site.Target(site, step); return StepString(storage, block, self, (MutableString)self.Begin, (MutableString)self.End, intStep); } else if (storage.Context.IsInstanceOf(self.Begin, storage.Context.GetClass(typeof(Numeric)))) { // self.begin is Numeric; invoke item = item + 1 instead of succ and invoke < or <= for compare return StepNumeric(storage, block, self, self.Begin, self.End, step); } else { // self.begin is not Numeric or String; just invoke item.succ and item <=> self.end var site = storage.FixnumCastSite; int intStep = site.Target(site, step); return StepObject(storage, block, self, self.Begin, self.End, intStep); } }
public static Enumerator/*!*/ GetStepEnumerator(StepStorage/*!*/ storage, Range/*!*/ self, [Optional]object step) { return new Enumerator((_, block) => Step(storage, block, self, step)); }
public static Enumerator /*!*/ GetStepEnumerator(StepStorage /*!*/ storage, Range /*!*/ self, [Optional] object step) { return(new Enumerator((_, block) => Step(storage, block, self, step))); }
/// <summary> /// Clear current step context /// </summary> /// <param name="evt"></param> public void Fire(ClearStepStorageEvent evt) { StepStorage.Remove(); }