Пример #1
0
            public void NewClosureOverlappingSeasonReturnsOverlapFalse()
            {
                // Arrange
                // data setup queries has seasons from '2013-10-01' to '2013-12-31'
                PeriodDateRange periodDateRangeBeingCreated = new PeriodDateRange
                {
                    StartDate = new DateTime(2013, 10, 15),
                    EndDate = new DateTime(2013, 10, 20)
                };

                // Act
                bool doesItOverlap = periodDateRangeDao.IsDateRangeForPeriodTypeOverlapping(PeriodTypeEnum.Closure, BUSINESS4_ID, periodDateRangeBeingCreated);

                // Assert
                Assert.IsFalse(doesItOverlap, "new closure Date range overlaps with existing season period but should have returned false");
            }
Пример #2
0
            public void NewSeasonWithinExistingSeasonReturnsOverlap()
            {
                // Arrange
                // data setup queries has seasons from 01-01 -> 02-28 and 03-01 -> 03-31
                PeriodDateRange periodDateRangeBeingCreated = new PeriodDateRange
                {
                    StartDate = new DateTime(2013, 01, 05),
                    EndDate = new DateTime(2013, 01, 15)
                };

                // Act
                bool doesItOverlap = periodDateRangeDao.IsDateRangeForPeriodTypeOverlapping(PeriodTypeEnum.Season, BUSINESS4_ID, periodDateRangeBeingCreated);

                // Assert
                Assert.IsTrue(doesItOverlap, "new Date range overlaps with existing period date ranges");
            }
Пример #3
0
            public void NewSeasonOverlappingExistingSeasonReturnsOverlap()
            {
                // Arrange
                // data setup queries has seasons from '2013-10-01' to '2013-12-31'
                PeriodDateRange periodDateRangeBeingCreated = new PeriodDateRange
                {
                    StartDate = new DateTime(2013, 09, 01),
                    EndDate = new DateTime(2014, 02, 01)
                };

                // Act
                bool doesItOverlap = periodDateRangeDao.IsDateRangeForPeriodTypeOverlapping(PeriodTypeEnum.Season, BUSINESS4_ID, periodDateRangeBeingCreated);

                // Assert
                Assert.IsTrue(doesItOverlap, "new Date range overlaps with existing period date ranges");
            }
Пример #4
0
            public void EndDateOverlapCheckForSeasonsReturnsTrue()
            {
                // Arrange
                // data setup queries has seasons from 01-01 -> 02-28 and 03-01 -> 03-31
                PeriodDateRange periodDateRangeBeingCreated = new PeriodDateRange
                {
                    StartDate = new DateTime(2012, 11, 15),
                    EndDate = new DateTime(2013, 01, 15)
                };

                // Act
                bool doesItOverlap = periodDateRangeDao.IsDateRangeForPeriodTypeOverlapping(PeriodTypeEnum.Season, BUSINESS4_ID, periodDateRangeBeingCreated);

                // Assert
                Assert.IsTrue(doesItOverlap, "new Date range should have returned true for overlapping with existing period date ranges");
            }
Пример #5
0
            public void CreatePeriodDateRangeWithValidDataIsSuccessful()
            {
                // Arrange
                //Get a period from the db:
                List<Period> periods = periodDao.GetAllByBusiness(BUSINESS1_ID, ENGLISH_CULTURE);
                Period lowPeriod = periods.Find(p => p.Name.ToLower() == LOW_PERIOD_NAME);

                //set up new period date range
                PeriodDateRange periodDateRange = new PeriodDateRange
                {
                    PeriodId = lowPeriod.Id,
                    StartDate = DateTime.Now,
                    EndDate = DateTime.Now.AddDays(50)
                };

                // Act
                periodDateRangeDao.Create(periodDateRange);

                // Assert
                Assert.AreNotEqual(0, periodDateRange.Id, "Id was not set");
            }  
Пример #6
0
        /// <summary>
        /// Returns true if the date range in question overlaps any other date ranges for the business
        /// </summary>
        /// <param name="periodType">type of event to look in</param>
        /// <param name="businessId">business Id</param>
        /// <param name="periodDateRange">date range to check</param>
        /// <returns>true if it overlaps, false if it doesn't</returns>
        public bool IsDateRangeForPeriodTypeOverlapping(PeriodTypeEnum periodType, long businessId, PeriodDateRange periodDateRange)
        {
            const string SQL_SELECT = @"
                        SELECT @doesItOverlap =
                            CASE WHEN (COUNT(pdr.id) > 0) 
                                THEN 1
                                ELSE 0
                            END
                        FROM Pricing.PeriodDateRange pdr
                        JOIN Pricing.Period p on p.Id = pdr.PeriodId
                        WHERE p.PeriodTypeCode = @PeriodTypeCode
                        AND p.BusinessId = @BusinessId
                        AND ((@StartDate between pdr.StartDate AND pdr.EndDate) OR
                             (@EndDate between pdr.StartDate AND pdr.EndDate) OR
                             (pdr.StartDate between @StartDate AND @EndDate) OR
                             (pdr.EndDate between @StartDate AND @EndDate))
                        AND (@Id = 0 OR pdr.id <> @Id)
                        ";
            var parameters = new List<SqlParameter>
            {
                DbHelper.CreateParameter(PeriodDateRangeMapper.Parameters.StartDate, periodDateRange.StartDate.Date),
                DbHelper.CreateParameter(PeriodDateRangeMapper.Parameters.EndDate, periodDateRange.EndDate.Date),
                DbHelper.CreateParameter(PeriodDateRangeMapper.Parameters.Id, periodDateRange.Id),
                DbHelper.CreateParameter(PeriodMapper.Parameters.PeriodTypeCode, periodType.GetCode()),
                DbHelper.CreateParameter(PeriodMapper.Parameters.BusinessId, businessId)
            };

            SqlParameter outputKey;
            parameters.Add(outputKey = DbHelper.CreateParameterOut<bool>(PeriodDateRangeMapper.Parameters.DoesItOverlap, SqlDbType.Bit));

            DbHelper.ExecuteNonQueryCommand(SQL_SELECT, CommandType.Text, parameters);
            return DbHelper.ParameterValue<bool>(outputKey);
        }
Пример #7
0
        /// <summary>
        /// Create PeriodDateRange
        /// </summary>
        public void Create(PeriodDateRange periodDateRange)
        {
            var parameters = new List<SqlParameter>
            {
                DbHelper.CreateParameter(PeriodDateRangeMapper.Parameters.PeriodId, periodDateRange.PeriodId),
                DbHelper.CreateParameter(PeriodDateRangeMapper.Parameters.StartDate, periodDateRange.StartDate),
                DbHelper.CreateParameter(PeriodDateRangeMapper.Parameters.EndDate, periodDateRange.EndDate)
            };

            // Add auditing parameters
            AuditFieldsHelper.PopulateAuditFields(parameters);

            SqlParameter outputKey;
            parameters.Add(outputKey = DbHelper.CreateParameterOut<int>(PeriodDateRangeMapper.Parameters.Id, SqlDbType.Int));

            DbHelper.ExecuteNonQueryCommand("Pricing.CreatePeriodDateRange", CommandType.StoredProcedure, parameters);

            periodDateRange.Id = DbHelper.ParameterValue<int>(outputKey);
        }
Пример #8
0
        /// <summary>
        /// Modify PeriodDateRange
        /// </summary>
        public void Modify(PeriodDateRange periodDateRange)
        {
            var parameters = new List<SqlParameter>
            {
                DbHelper.CreateParameter(PeriodDateRangeMapper.Parameters.Id, periodDateRange.Id),
                DbHelper.CreateParameter(PeriodDateRangeMapper.Parameters.StartDate, periodDateRange.StartDate),
                DbHelper.CreateParameter(PeriodDateRangeMapper.Parameters.EndDate, periodDateRange.EndDate)
            };

            // Add auditing parameters
            AuditFieldsHelper.PopulateAuditFields(parameters);

            var rowsAffected = DbHelper.ExecuteNonQueryCommand("Pricing.UpdatePeriodDateRange", CommandType.StoredProcedure, parameters);

            // Check if the update was successful
            if (rowsAffected == 0)
            {
                throw new ExpectedResultException(ErrorFactory.CreateAndLogError(Errors.SRVEX30027,
                                                                             "PeriodDateRangeDao.Modify",
                                                                             additionalDescriptionParameters: (new object[] {typeof(PeriodDateRange).Name, periodDateRange.Id }),
                                                                             arguments: new object[] {typeof(PeriodDateRange).Name, periodDateRange.Id }));
            }
        }