コード例 #1
0
        public async Task <CommandResult> ExecuteAsync(SaveDeliveryIntervalContext commandContext)
        {
            var templateByIdCriterion = new DeliveryIntervalTemplateByIdCriterion(commandContext.DeliveryIntervalTemplate.Id);
            var template = await _queryBuilder.For <DeliveryIntervalTemplate>().WithAsync(templateByIdCriterion);

            if (template == null)
            {
                throw new Exception("Delivery Problem!");
            }

            var cronDaysString           = BuildCronDaysString(commandContext.MonthDays);
            var cronFormatMonthFrequency = template.CronFormatMonthFrequency;
            var cronMonthString          = cronFormatMonthFrequency.Substring(1, cronFormatMonthFrequency.Length - 1);

            cronMonthString = $"{DateTime.Today.Month}{cronMonthString}";
            var delivery = new DeliveryInterval
            {
                DeliveryIntervalTemplateId = commandContext.DeliveryIntervalTemplate.Id,
                CronString = $"0 0 0 {cronDaysString} {cronMonthString} *"
            };

            var repositoryContext = new SaveDeliveryIntervalRepositoryContext(delivery);

            return(await _commandBuilder.ExecuteAsync(repositoryContext));
        }
コード例 #2
0
        public async Task ShouldReturnSpentSumOfSubscriptedProductsBetweenDates_WhenSubscrsiptionIntervalIsEveryMonthAt5And8DaysOfMonth()
        {
            var today = DateTime.Today;
            var sumOfProductsInSubscription = 10;
            var subscriptionDates           = new List <SubscriptionDate>
            {
                new SubscriptionDate
                {
                    Date = today.AddYears(-1),
                    Type = SubscriptionDateType.Start
                },
                new SubscriptionDate
                {
                    Date = today,
                    Type = SubscriptionDateType.Suspend
                }
            };
            var countOfMonths    = 12;
            var frequencyInMonth = 2;
            var deliveryInterval = new DeliveryInterval
            {
                CronString = "0 0 0 8,5 12/1 *"
            };

            SetupMocks(subscriptionDates, deliveryInterval);
            var criterion = new CalculateSpentAmountCriterion(today, sumOfProductsInSubscription);
            var query     = new CalculateSpentAmountQuery(_queryBuilderMock.Object);

            var queryResult = await query.AskAsync(criterion);

            Assert.AreEqual(queryResult, sumOfProductsInSubscription * countOfMonths * frequencyInMonth);
        }
コード例 #3
0
        public async Task ShouldReturnDeliveryDatesForInterval_WhenSubscrsiptionIntervalIsEveryMonthAt5And8DaysOfMonth(int suspendDateMonthValueAdd)
        {
            var monthsAhead       = 3;
            var today             = DateTime.Today;
            var showUntil         = DateTime.Today.AddMonths(monthsAhead);
            var subscriptionDates = new List <SubscriptionDate>
            {
                new SubscriptionDate
                {
                    Date = today.AddYears(-1),
                    Type = SubscriptionDateType.Start
                },
                new SubscriptionDate
                {
                    Date = today.AddMonths(suspendDateMonthValueAdd),
                    Type = SubscriptionDateType.Suspend
                }
            };
            var frequencyInMonth = 2;
            var deliveryInterval = new DeliveryInterval
            {
                CronString = "0 0 0 8,5 12/1 *"
            };

            SetupMocks(subscriptionDates, deliveryInterval);
            var criterion = new DeliveryDatesCriterion(today, showUntil);
            var query     = new DeliveryDatesQuery(_queryBuilderMock.Object);

            var queryResult = await query.AskAsync(criterion);

            Assert.AreEqual(queryResult.Count, frequencyInMonth * suspendDateMonthValueAdd);
        }
コード例 #4
0
        private void SetupMocks(List <SubscriptionDate> subscriptionDates, DeliveryInterval deliveryInterval = null)
        {
            _queryBuilderMock.Setup(x => x.For <List <SubscriptionDate> >()
                                    .WithAsync(It.IsAny <SubscriptionDatesForSubscriptionCriterion>()))
            .ReturnsAsync(subscriptionDates);

            _queryBuilderMock.Setup(x => x.For <DeliveryInterval>()
                                    .WithAsync(It.IsAny <DeliveryIntervalWithTemplateForSubscriptionCriterion>()))
            .ReturnsAsync(deliveryInterval);
        }
コード例 #5
0
 public Parcel(
     DeliveryInterval deliveryInterval,
     TrackingCode trackingCode,
     Carrier carrier,
     Customer customer,
     string code
     )
 {
     DeliveryInterval = deliveryInterval;
     TrackingCode     = trackingCode;
     Carrier          = carrier;
     Customer         = customer;
     Code             = code;
 }
コード例 #6
0
        private static bool IsTimeAvailable(DeliveryInterval interval, DateTime startDate, DayOfWeek currentDayOfWeek, uint?delta, int weekNumber)
        {
            // urgent delivery is available only for today
            if (interval.Type == DeliveryIntervalType.Urgent)
            {
                return(CheckTime(interval, startDate, currentDayOfWeek));
            }

            var result = CheckTime(interval, startDate, currentDayOfWeek);

            if (result)
            {
                return(true);
            }

            if (!delta.HasValue)
            {
                return(false);
            }

            var intervalDate = GetIntervalDate(startDate, currentDayOfWeek, weekNumber, interval);

            return(startDate >= intervalDate.AddHours((int)delta * -1));
        }
コード例 #7
0
        private static DateTime GetIntervalDate(DateTime startDate, DayOfWeek currentDayOfWeek, int weekNumber, DeliveryInterval interval)
        {
            // calculate how much days pass from startDate
            var currentDaysPass = (int)currentDayOfWeek - (int)startDate.DayOfWeek + (weekNumber - 1) * 7;
            var date            = startDate.AddDays(currentDaysPass);

            return(new DateTime(date.Year, date.Month, date.Day, interval.AvailableFrom.Hours, interval.AvailableFrom.Minutes, 0));
        }
コード例 #8
0
 private static bool CheckTime(DeliveryInterval interval, DateTime startDate, DayOfWeek currentDayOfWeek)
 {
     return(startDate.DayOfWeek == currentDayOfWeek && startDate.TimeOfDay >= interval.AvailableFrom && startDate.TimeOfDay <= interval.AvailableTo);
 }
コード例 #9
0
 public SaveDeliveryIntervalRepositoryContext(DeliveryInterval deliveryInterval)
 {
     DeliveryInterval = deliveryInterval;
 }