public void ShouldOnlyBuildBetween7AMAnd7PMOnWeekdays()
        {
            FilterTrigger outerTrigger = new FilterTrigger((DateTimeProvider)mockDateTime.Object);

            outerTrigger.StartTime    = "19:00";
            outerTrigger.EndTime      = "7:00";
            outerTrigger.InnerTrigger = trigger;

            trigger.StartTime = "0:00";
            trigger.EndTime   = "23:59:59";
            trigger.WeekDays  = new DayOfWeek[] { DayOfWeek.Saturday, DayOfWeek.Sunday };
            IntegrationRequest request = ModificationExistRequest();

            mockTrigger.Setup(_trigger => _trigger.Fire()).Returns(request);

            mockDateTime.SetupGet(provider => provider.Now).Returns(new DateTime(2006, 8, 10, 11, 30, 0, 0));             // Thurs midday
            Assert.AreEqual(request, outerTrigger.Fire(), "outerTrigger.Fire()");

            mockDateTime.SetupGet(provider => provider.Now).Returns(new DateTime(2006, 8, 10, 19, 30, 0, 0));             // Thurs evening
            Assert.IsNull(outerTrigger.Fire(), "outerTrigger.Fire()");

            mockDateTime.SetupGet(provider => provider.Now).Returns(new DateTime(2006, 8, 12, 11, 30, 0, 0));             // Sat midday
            Assert.IsNull(outerTrigger.Fire(), "outerTrigger.Fire()");

            mockDateTime.SetupGet(provider => provider.Now).Returns(new DateTime(2006, 8, 12, 19, 30, 0, 0));             // Sat evening
            Assert.IsNull(outerTrigger.Fire(), "outerTrigger.Fire()");
        }
        protected void CreateMocksAndInitialiseObjectUnderTest()
        {
            mockTrigger  = new Mock <ITrigger>();
            mockDateTime = new Mock <DateTimeProvider>();

            trigger = new FilterTrigger((DateTimeProvider)mockDateTime.Object);
            trigger.InnerTrigger   = (ITrigger)mockTrigger.Object;
            trigger.StartTime      = "10:00";
            trigger.EndTime        = "11:00";
            trigger.WeekDays       = new DayOfWeek[] { DayOfWeek.Wednesday };
            trigger.BuildCondition = BuildCondition.NoBuild;
        }
Beispiel #3
0
        protected void CreateMocksAndInitialiseObjectUnderTest()
        {
            mockTrigger  = new DynamicMock(typeof(ITrigger));
            mockDateTime = new DynamicMock(typeof(DateTimeProvider));

            trigger = new FilterTrigger((DateTimeProvider)mockDateTime.MockInstance);
            trigger.InnerTrigger   = (ITrigger)mockTrigger.MockInstance;
            trigger.StartTime      = "10:00";
            trigger.EndTime        = "11:00";
            trigger.WeekDays       = new DayOfWeek[] { DayOfWeek.Wednesday };
            trigger.BuildCondition = BuildCondition.NoBuild;
        }
        public void TestCacheTriggerListener()
        {
            INamedCache cache = CacheFactory.GetCache(CacheName);

            cache.Clear();

            FilterTrigger ftRollback = new FilterTrigger(NeverFilter.Instance, FilterTrigger.ActionCode.Rollback);
            FilterTrigger ftIgnore   = new FilterTrigger(NeverFilter.Instance, FilterTrigger.ActionCode.Ignore);
            FilterTrigger ftRemove   = new FilterTrigger(NeverFilter.Instance, FilterTrigger.ActionCode.Remove);

            IDictionary dict = new Hashtable();

            for (int i = 0; i < 10; i++)
            {
                dict.Add(GetKeyObject("key" + i), "value" + i);
            }
            cache.InsertAll(dict);

            CacheTriggerListener listener = new CacheTriggerListener(ftIgnore);

            cache.AddCacheListener(listener);
            Assert.AreEqual(cache[GetKeyObject("key1")], "value1");
            cache[GetKeyObject("key1")] = "newvalue";
            Assert.AreEqual(cache[GetKeyObject("key1")], "value1");
            cache.RemoveCacheListener(listener);

            listener = new CacheTriggerListener(ftRemove);
            cache.AddCacheListener(listener);
            Assert.IsTrue(cache.Contains(GetKeyObject("key1")));
            cache[GetKeyObject("key1")] = "newvalue";
            Assert.IsFalse(cache.Contains(GetKeyObject("key1")));
            cache.RemoveCacheListener(listener);

            listener = new CacheTriggerListener(ftRollback);
            cache.AddCacheListener(listener);
            Assert.AreEqual(cache[GetKeyObject("key3")], "value3");
            Exception e = null;

            try
            {
                cache[GetKeyObject("key3")] = "newvalue";
            }
            catch (Exception ex)
            {
                e = ex;
            }
            Assert.IsNotNull(e);
            Assert.AreEqual(cache[GetKeyObject("key3")], "value3");
            cache.RemoveCacheListener(listener);

            CacheFactory.Shutdown();
        }
        public void ShouldMinimallyPopulateFromReflector()
        {
            string xml =
                string.Format(
                    @"<filterTrigger>
											<trigger type=""scheduleTrigger"" time=""12:00:00"" />
										</filterTrigger>"                                        );

            trigger = (FilterTrigger)NetReflector.Read(xml);
            Assert.AreEqual("00:00:00", trigger.StartTime, "trigger.StartTime");
            Assert.AreEqual("23:59:59", trigger.EndTime, "trigger.EndTime");
            Assert.AreEqual(typeof(ScheduleTrigger), trigger.InnerTrigger.GetType(), "trigger.InnerTrigger type");
            Assert.AreEqual(7, trigger.WeekDays.Length, "trigger.WeekDays.Length");
            Assert.AreEqual(BuildCondition.NoBuild, trigger.BuildCondition, "trigger.BuildCondition");
        }
        public void ShouldHandleNestedFilterTriggers()
        {
            string xml =
                @"<filterTrigger startTime=""19:00"" endTime=""07:00"">
                    <trigger type=""filterTrigger"" startTime=""0:00"" endTime=""23:59:59"">
                        <trigger type=""intervalTrigger"" name=""continuous"" seconds=""900"" buildCondition=""ForceBuild""/>
                        <weekDays>
                            <weekDay>Saturday</weekDay>
                            <weekDay>Sunday</weekDay>
                        </weekDays>
                    </trigger>
				  </filterTrigger>"                ;

            trigger = (FilterTrigger)NetReflector.Read(xml);
            Assert.AreEqual(typeof(FilterTrigger), trigger.InnerTrigger.GetType(), "trigger.InnerTrigger type");
            Assert.AreEqual(typeof(IntervalTrigger), ((FilterTrigger)trigger.InnerTrigger).InnerTrigger.GetType(), "trigger.InnerTrigger.InnerTrigger type");
        }
        public void ShouldFullyPopulateFromReflector()
        {
            string xml =
                string.Format(
                    @"<filterTrigger startTime=""8:30:30"" endTime=""22:30:30"" buildCondition=""ForceBuild"">
											<trigger type=""scheduleTrigger"" time=""12:00:00""/>
											<weekDays>
												<weekDay>Monday</weekDay>
												<weekDay>Tuesday</weekDay>
											</weekDays>
										</filterTrigger>"                                        );

            trigger = (FilterTrigger)NetReflector.Read(xml);
            Assert.AreEqual("08:30:30", trigger.StartTime, "trigger.StartTime");
            Assert.AreEqual("22:30:30", trigger.EndTime, "trigger.EndTime");
            Assert.AreEqual(typeof(ScheduleTrigger), trigger.InnerTrigger.GetType(), "trigger.InnerTrigger type");
            Assert.AreEqual(DayOfWeek.Monday, trigger.WeekDays[0], "trigger.WeekDays[0]");
            Assert.AreEqual(DayOfWeek.Tuesday, trigger.WeekDays[1], "trigger.WeekDays[1]");
            Assert.AreEqual(BuildCondition.ForceBuild, trigger.BuildCondition, "trigger.BuildCondition");
        }