public void IntersectionWith_InterseccionDeFechasYDias()
        {
            Schedule lInterval1 = new Schedule() { ActiveUntil = new DateTime(2016, 2, 20), ActiveFrom = new DateTime(2016, 2, 2) };
            Schedule lInterval2 = new Schedule() { ActiveUntil = new DateTime(2016, 2, 26), ActiveFrom = new DateTime(2016, 2, 18) };

            Day lDay1 = new Day() { Id = 0, Value = Days.Domingo };
            Day lDay2 = new Day() { Id = 1, Value = Days.Lunes };
            Day lDay3 = new Day() { Id = 2, Value = Days.Martes };

            lInterval1.AddDay(lDay1);
            lInterval1.AddDay(lDay2);
            lInterval2.AddDay(lDay3);
            lInterval2.AddDay(lDay1);

            TimeSpan time1 = new TimeSpan(8, 0, 0);
            TimeSpan time2 = new TimeSpan(12, 0, 0);
            TimeSpan time3 = new TimeSpan(18, 0, 0);
            TimeSpan time4 = new TimeSpan(21, 0, 0);

            ScheduleEntry lTimeInterval1 = new ScheduleEntry() { End = time2, Start = time1 }; //8 a 12
            ScheduleEntry lTimeInterval2 = new ScheduleEntry() { End = time3, Start = time2 };//12 a 18
            ScheduleEntry lTimeInterval3 = new ScheduleEntry() { End = time4, Start = time3 };//18 a 21

            lInterval1.AddTimeInterval(lTimeInterval1);
            lInterval1.AddTimeInterval(lTimeInterval2);
            lInterval2.AddTimeInterval(lTimeInterval3);

            bool lResult = lInterval1.IntersectsWith(lInterval2);

            Assert.IsFalse(lResult);
        }
示例#2
0
        public void ActiveForDate_IsActive()
        {
            Banner lBanner = new Banner() { Name = "Informacion deportiva", Description = "Noticias del ámbito deportivo nacional de distintas fuentes" };

            Schedule lInterval = new Schedule() { Name="Mes de febrero, de lunes a viernes por la mañana",ActiveUntil = new DateTime(2016, 2, 29), ActiveFrom = new DateTime(2016, 2, 1) };

            Day lDay1 = new Day() { Id = 1, Value = Days.Lunes };
            Day lDay2 = new Day() { Id = 2, Value = Days.Martes };
            Day lDay3 = new Day() { Id = 3, Value = Days.Miercoles };
            Day lDay4 = new Day() { Id = 4, Value = Days.Jueves };
            Day lDay5 = new Day() { Id = 5, Value = Days.Viernes };

            lInterval.AddDay(lDay1);
            lInterval.AddDay(lDay2);
            lInterval.AddDay(lDay3);
            lInterval.AddDay(lDay4);
            lInterval.AddDay(lDay5);

            TimeSpan time1 = new TimeSpan(8, 0, 0);
            TimeSpan time2 = new TimeSpan(12, 0, 0);

            ScheduleEntry lTimeInterval = new ScheduleEntry() { End = time2, Start = time1 };

            lInterval.AddTimeInterval(lTimeInterval);

            lBanner.AddSchedule(DomainServiceLocator.Resolve<IScheduleChecker>(), lInterval);

            DateTime lDate = new DateTime(2016, 2, 4,20,0,0);

            bool lResult = lBanner.IsActiveAt(DomainServiceLocator.Resolve<IScheduleChecker>(), lDate);

            Assert.IsFalse(lResult);
        }
示例#3
0
        public virtual void AddSchedule(IScheduleChecker pValidator, Schedule pInterval)
        {
            if (pInterval == null)
            {
                throw new EntidadNulaException("El intervalo de fechas indicado es nulo");
            }
            else if (!pValidator.CanAddSchedule(this, pInterval))
            {
                throw new IntervaloFechaInvalidoException("El intervalo de fechas indicado no puede ser agregado al Banner debido a que se superpone con un intervalo existente");
            }
            else
            {
                this.ActivePeriods.Add(pInterval);

                //TODO excepción si no es valido por interseccion, si es intervalo nulo. irian arriba
            }
        }
示例#4
0
        public void ActiveForDate_IsActive()
        {
            Campaign lCampaign = new Campaign() { Name = "Venta de cactus",Description="Publicidad para la venta de cactus para el vivero XX" };

            Schedule lInterval = new Schedule() {Name="Miércoles y Jueves de la primera quincena de febrero", ActiveUntil = new DateTime(2016, 2, 15), ActiveFrom = new DateTime(2016, 2, 1) };

            Day lDay1 = new Day() { Id = 4, Value = Days.Miercoles };
            Day lDay2 = new Day() { Id = 5, Value = Days.Jueves };

            lInterval.AddDay(lDay1);
            lInterval.AddDay(lDay2);

            TimeSpan time1 = new TimeSpan(18, 0, 0);
            TimeSpan time2 = new TimeSpan(21, 0, 0);

            ScheduleEntry lTimeInterval = new ScheduleEntry() { End = time2, Start = time1 };

            lInterval.AddTimeInterval(lTimeInterval);

            lCampaign.AddSchedule(DomainServiceLocator.Resolve<IScheduleChecker>(), lInterval);

            DateTime lDate = new DateTime(2016, 2, 3,19,0,0);

            bool lResult = lCampaign.IsActiveAt(DomainServiceLocator.Resolve<IScheduleChecker>(), lDate);

            //  Assert.IsTrue(lResult);





        /*    var serv1 = DomainServiceLocator.Resolve<IScheduleChecker>();
            var serv2 = DomainServiceLocator.Resolve<IScheduleChecker>();
            var serv3 = BusinessServiceLocator.Resolve<>();
            var serv4 = BusinessServiceLocator.Resolve<DateIntervalService>();



            Assert.AreSame(serv1, serv2);
            Assert.AreNotSame(serv3, serv4);*/




        }
示例#5
0
 public void RemoveSchedule(Schedule pSchedule)
 {
     this.ActivePeriods.Remove(pSchedule);
 }
示例#6
0
 public void AddSchedule(object p, Schedule schedule)
 {
     throw new NotImplementedException();
 }
示例#7
0
 private bool HasEqualTimeIntervals(Schedule pInterval)
 {
     bool lResult = false;
     int i = this.TimeIntervals.Count - 1;
     while ((lResult == false) && (i >= 0))
     {
         ScheduleEntry pTimeInterval = this.TimeIntervals[i];
         int j = pInterval.ActiveHours.Count() - 1;
         while ((lResult == false) && (j >= 0))
         {
             lResult = pTimeInterval.IntersectsWith(pInterval.ActiveHours.ElementAt(j));
             j--;
         }
         i--;
     }
     return lResult;
 }
示例#8
0
 private bool HasEqualDays(Schedule pInterval)
 {
     bool lResult = false;
     int i = this.Days.Count - 1;
     while ((lResult == false) && (i >= 0))
     {
         Day day = this.Days[i];
         if (pInterval.ActiveDays.Contains(day))
         {
             lResult = true;
         }
         i--;
     }
     return lResult;
 }
示例#9
0
 public bool IntersectsWith(Schedule pInterval)
 {
     bool lResult = false;
     if ((pInterval.ActiveFrom > this.iActiveFrom)
         && (pInterval.ActiveFrom < this.iActiveUntil)) // fecha de inicio de pInterval entre intervalo que llama
     {
         lResult = true;
     }
     else if ((pInterval.ActiveUntil > this.iActiveFrom) //fecha de fin de pInteval entre intervalo que llama
             && (pInterval.ActiveUntil < this.iActiveUntil))
     {
         lResult = true;
     }
     else if ((this.iActiveFrom > pInterval.ActiveFrom) //fecha de inicio de intervalo que llama entre pInterval
             && (this.iActiveFrom < pInterval.ActiveUntil))
     {
         lResult = true;
     }
     else if ((this.iActiveUntil > pInterval.ActiveFrom) //fecha de fin de intervalo que llama entre pInterval
             && (this.iActiveUntil < pInterval.ActiveUntil))
     {
         lResult = true;
     }
     else if ((this.iActiveFrom == pInterval.ActiveFrom)//intervalos iguales
             && (this.iActiveUntil == pInterval.ActiveUntil))
     {
         lResult = true;
     }
     if (lResult)
     {
         lResult = this.HasEqualDays(pInterval);
     }
     if (lResult)
     {
         lResult = this.HasEqualTimeIntervals(pInterval);
     }
     return lResult;
 }