示例#1
0
            public void ModifyPeriodWithNoDateRangesThrowsException()
            {
                // Arrange
                const int existingPeriodId = 5;
                const int existingPeriodDateRangeId = 3;
                IPeriodDateRangeDao periodDateRangeDao = MockRepository.GenerateMock<IPeriodDateRangeDao>();
                IPeriodDao periodDao = MockRepository.GenerateMock<IPeriodDao>();
                IPeriodColorDao periodColorDao = MockRepository.GenerateMock<IPeriodColorDao>();
                IEventTrackingManager eventTrackingMock = MockRepository.GenerateMock<IEventTrackingManager>();

                //set up dummy period with good data other than no date ranges
                Period existingPeriod = CreateValidPeriod(existingPeriodId, periodDateRangeId: existingPeriodDateRangeId);
                existingPeriod.PeriodDateRanges = null;

                periodColorDao.Expect(dao => dao.GetNextPeriodColorForPeriodType(Arg<long>.Is.Anything, Arg<PeriodTypeEnum>.Is.Anything, Arg<string>.Is.Anything)).Repeat.Never();
                periodColorDao.Expect(dao => dao.GetByPeriodId(Arg<int>.Is.Anything, Arg<string>.Is.Anything)).Repeat.Never();
                periodDateRangeDao.Expect(dao => dao.Modify(Arg<PeriodDateRange>.Is.Anything)).Repeat.Never();
                periodDateRangeDao.Expect(dao => dao.IsDateRangeForPeriodTypeOverlapping(Arg<PeriodTypeEnum>.Is.Anything, Arg<long>.Is.Anything, Arg<PeriodDateRange>.Is.Anything)).Repeat.Never();
                periodDao.Expect(dao => dao.Create(Arg<Period>.Is.Anything, Arg<string>.Is.Anything)).Repeat.Never();
                periodDao.Expect(dao => dao.DoesPeriodNameAlreadyExist(Arg<long>.Is.Equal(BUSINESS_ID), Arg<string>.Is.Equal(existingPeriod.Name))).Return(false).Repeat.Never();
                eventTrackingMock.Expect(bedao => bedao.CreateBusinessEventAsync(Arg<long>.Is.Equal(BUSINESS_ID), Arg<BusinessEventTypesEnum>.Is.Equal(BusinessEventTypesEnum.SeasonPeriodAdded), Arg<string>.Is.NotNull, Arg<string>.Is.Anything)).Repeat.Never();
                
                PeriodManager periodManager = new PeriodManager
                {
                    PeriodDao = periodDao,
                    PeriodDateRangeDao = periodDateRangeDao,
                    PeriodColorDao = periodColorDao,
                    EventTrackingManager = eventTrackingMock
                };

                try
                {
                    // Act
                    periodManager.ModifyPeriod(existingPeriod, ENGLISH_CULTURE);

                    // Assert
                    Assert.Fail("Exception was not thrown for invalid period");
                }
                catch (ValidationException vex)
                {
                    periodDateRangeDao.VerifyAllExpectations();
                    periodDao.VerifyAllExpectations();
                    periodColorDao.VerifyAllExpectations();
                    eventTrackingMock.VerifyAllExpectations();
                    Assert.AreEqual("SRVEX30082", vex.Code, "Validation exception thrown was not correct");
                }
            }
示例#2
0
            public void CreateOverlappingClosureSetsOverlapErrorAndReturnsSuccessfully()
            {
                // Arrange
                const int existingPeriodId = 5;
                IPeriodDateRangeDao periodDateRangeDao = MockRepository.GenerateMock<IPeriodDateRangeDao>();
                IPeriodDao periodDao = MockRepository.GenerateMock<IPeriodDao>();
                IPeriodColorDao periodColorDao = MockRepository.GenerateMock<IPeriodColorDao>();
                IEventTrackingManager eventTrackingMock = MockRepository.GenerateMock<IEventTrackingManager>();

                //set up dummy period with good data other than end before start
                Period existingPeriod = CreateValidPeriod(existingPeriodId, periodType: PeriodTypeEnum.Closure);

                periodColorDao.Expect(dao => dao.GetNextPeriodColorForPeriodType(Arg<long>.Is.Anything, Arg<PeriodTypeEnum>.Is.Anything, Arg<string>.Is.Anything)).Repeat.Never();
                periodColorDao.Expect(dao => dao.GetByPeriodId(Arg<int>.Is.Anything, Arg<string>.Is.Anything)).Repeat.Never();
                periodDateRangeDao.Expect(dao => dao.Create(Arg<PeriodDateRange>.Is.Anything)).Repeat.Never();
                //Make sure it says it overlaps
                periodDateRangeDao.Expect(dao => dao.IsDateRangeForPeriodTypeOverlapping(Arg<PeriodTypeEnum>.Is.Equal(existingPeriod.PeriodType.PeriodTypeEnum), Arg<long>.Is.Equal(existingPeriod.BusinessId), Arg<PeriodDateRange>.Is.Equal(existingPeriod.PeriodDateRanges[0]))).Return(true);
                periodDao.Expect(dao => dao.Create(Arg<Period>.Is.Anything, Arg<string>.Is.Anything)).Repeat.Never();
                periodDao.Expect(dao => dao.DoesPeriodNameAlreadyExist(Arg<long>.Is.Equal(BUSINESS_ID), Arg<string>.Is.Equal(existingPeriod.Name))).Return(false).Repeat.Never();
                eventTrackingMock.Expect(bedao => bedao.CreateBusinessEventAsync(Arg<long>.Is.Equal(BUSINESS_ID), Arg<BusinessEventTypesEnum>.Is.Equal(BusinessEventTypesEnum.SeasonPeriodAdded), Arg<string>.Is.NotNull, Arg<string>.Is.Anything)).Repeat.Never();

                PeriodManager periodManager = new PeriodManager
                {
                    PeriodDao = periodDao,
                    PeriodDateRangeDao = periodDateRangeDao,
                    PeriodColorDao = periodColorDao,
                    EventTrackingManager = eventTrackingMock
                };


                // Act
                Period overlapPeriod = periodManager.CreatePeriod(existingPeriod, ENGLISH_CULTURE);

                // Assert
                periodDateRangeDao.VerifyAllExpectations();
                periodDao.VerifyAllExpectations();
                periodColorDao.VerifyAllExpectations();
                eventTrackingMock.VerifyAllExpectations();
                Assert.AreEqual(PricingPeriodError.ClosureOverClosure, overlapPeriod.PeriodDateRanges[0].PricingPeriodError, "Overlap error was not set correctly");
                Assert.AreEqual(PricingPeriodError.ClosureOverClosure, overlapPeriod.PricingPeriodError, "Overlap error was not set correctly");
            }  
示例#3
0
            public void ModifyPeriodWithGoodDataModifiesDateRangeIsSuccessful()
            {
                // Arrange
                const int existingPeriodId = 5;
                const int existingColorId = 2;
                const int existingPeriodDateRangeId = 3;
                DateTime startDateModify, endDateModify;

                IPeriodDateRangeDao periodDateRangeDao = MockRepository.GenerateMock<IPeriodDateRangeDao>();
                IPeriodDao periodDao = MockRepository.GenerateMock<IPeriodDao>();
                IPeriodColorDao periodColorDao = MockRepository.GenerateMock<IPeriodColorDao>();
                IEventTrackingManager eventTrackingMock = MockRepository.GenerateMock<IEventTrackingManager>();

                //set up dummy period
                Period existingPeriod = CreateValidPeriod(existingPeriodId, periodDateRangeId: existingPeriodDateRangeId);
                startDateModify = existingPeriod.PeriodDateRanges[0].StartDate.AddDays(1);
                endDateModify = existingPeriod.PeriodDateRanges[0].EndDate.AddDays(1);
                existingPeriod.PeriodDateRanges[0].StartDate = startDateModify;
                existingPeriod.PeriodDateRanges[0].EndDate = endDateModify;

                periodColorDao.Expect(dao => dao.GetNextPeriodColorForPeriodType(Arg<long>.Is.Anything, Arg<PeriodTypeEnum>.Is.Anything, Arg<string>.Is.Anything)).Repeat.Never();
                periodColorDao.Expect(dao => dao.GetByPeriodId(existingPeriodId, ENGLISH_CULTURE)).Return(new PeriodColor { Id = existingColorId }).Repeat.AtLeastOnce();
                periodDateRangeDao.Expect(dao => dao.Modify(Arg<PeriodDateRange>.Matches(pdr => pdr.Id == existingPeriodDateRangeId && pdr.StartDate == startDateModify && pdr.EndDate == endDateModify))).Repeat.AtLeastOnce();
                periodDateRangeDao.Expect(dao => dao.IsDateRangeForPeriodTypeOverlapping(Arg<PeriodTypeEnum>.Is.Anything, Arg<long>.Is.Anything, Arg<PeriodDateRange>.Is.Anything)).Return(false).Repeat.AtLeastOnce();
                periodDao.Expect(dao => dao.Create(Arg<Period>.Is.Anything, Arg<string>.Is.Anything)).Repeat.Never();
                periodDao.Expect(dao => dao.DoesPeriodNameAlreadyExist(Arg<long>.Is.Equal(BUSINESS_ID), Arg<string>.Is.Equal(existingPeriod.Name))).Return(false).Repeat.Never();
                eventTrackingMock.Expect(bedao => bedao.CreateBusinessEventAsync(Arg<long>.Is.Equal(BUSINESS_ID), Arg<BusinessEventTypesEnum>.Is.Equal(BusinessEventTypesEnum.SeasonPeriodModified), Arg<string>.Is.NotNull, Arg<string>.Is.Anything)).Repeat.AtLeastOnce();
                periodDateRangeDao.Expect(pdr => pdr.GetAllByPeriodId(Arg<int>.Is.Equal(existingPeriodId))).Return(new List<PeriodDateRange> { new PeriodDateRange() }).Repeat.Once();

                PeriodManager periodManager = new PeriodManager
                {
                    PeriodDao = periodDao,
                    PeriodDateRangeDao = periodDateRangeDao,
                    PeriodColorDao = periodColorDao,
                    EventTrackingManager = eventTrackingMock
                };

                // Act
                Period returnedPeriod = periodManager.ModifyPeriod(existingPeriod, ENGLISH_CULTURE);

                // Assert
                periodDateRangeDao.VerifyAllExpectations();
                periodDao.VerifyAllExpectations();
                periodColorDao.VerifyAllExpectations();
                eventTrackingMock.VerifyAllExpectations();
                // Asserts done by expectations
                Assert.IsNull(returnedPeriod.PricingPeriodError, "Error should be null");
            }
示例#4
0
            public void CreatePeriodWithAllNewDataCreatesPeriodIsSuccessful()
            {
                // Arrange
                IPeriodDateRangeDao periodDateRangeDao = MockRepository.GenerateMock<IPeriodDateRangeDao>();
                IPeriodDao periodDao = MockRepository.GenerateMock<IPeriodDao>();
                IPeriodColorDao periodColorDao = MockRepository.GenerateMock<IPeriodColorDao>();
                IEventTrackingManager eventTrackingMock = MockRepository.GenerateMock<IEventTrackingManager>();
                const int existingColorId = 5;

                //set up dummy period
                Period newPeriod = CreateValidPeriod(default(int));
                newPeriod.PeriodColor = null;
                
                periodDateRangeDao.Expect(dao => dao.Create(Arg<PeriodDateRange>.Matches(pdr => pdr.PeriodId != default(int)))).Repeat.Once();
                periodDateRangeDao.Expect(dao => dao.IsDateRangeForPeriodTypeOverlapping(Arg<PeriodTypeEnum>.Is.Anything, Arg<long>.Is.Anything, Arg<PeriodDateRange>.Is.Anything)).Return(false).Repeat.Once();
                periodColorDao.Expect(dao => dao.GetNextPeriodColorForPeriodType(Arg<long>.Is.Equal(newPeriod.BusinessId), Arg<PeriodTypeEnum>.Is.Equal(PeriodTypeEnum.Season), Arg<string>.Is.Equal(ENGLISH_CULTURE))).Return(new PeriodColor { Id = existingColorId }).Repeat.Once();
                periodColorDao.Expect(dao => dao.GetByPeriodId(Arg<int>.Is.Anything, Arg<string>.Is.Anything)).Repeat.Never();
                periodDao.Expect(dao => dao.Create(Arg<Period>.Is.Equal(newPeriod), Arg<string>.Is.Equal(ENGLISH_CULTURE))).WhenCalled(delegate { newPeriod.Id = 1; }).Repeat.Once();
                periodDao.Expect(dao => dao.DoesPeriodNameAlreadyExist(Arg<long>.Is.Equal(BUSINESS_ID), Arg<string>.Is.Equal(newPeriod.Name))).Return(false).Repeat.Once();
                eventTrackingMock.Expect(bedao => bedao.CreateBusinessEventAsync(Arg<long>.Is.Equal(BUSINESS_ID), Arg<BusinessEventTypesEnum>.Is.Equal(BusinessEventTypesEnum.SeasonPeriodAdded), Arg<string>.Is.NotNull, Arg<string>.Is.Anything)).Repeat.Once();

                PeriodManager periodManager = new PeriodManager
                                                  {
                                                      PeriodDao = periodDao,
                                                      PeriodDateRangeDao = periodDateRangeDao,
                                                      PeriodColorDao = periodColorDao,
                                                      EventTrackingManager = eventTrackingMock
                                                  };

                // Act
                Period returnedPeriod = periodManager.CreatePeriod(newPeriod, ENGLISH_CULTURE);

                // Assert
                periodDateRangeDao.VerifyAllExpectations();
                periodDao.VerifyAllExpectations();
                periodColorDao.VerifyAllExpectations();
                eventTrackingMock.VerifyAllExpectations();

                Assert.AreEqual(returnedPeriod.Id, returnedPeriod.PeriodDateRanges[0].PeriodId, "Date range didn't have period id assigned correctly");
                Assert.IsNotNull(returnedPeriod.PeriodColor, "Period colour wasn't filled in");
                Assert.IsNull(returnedPeriod.PricingPeriodError, "Error should be null");
            }
示例#5
0
            public void GetAllPeriodsCallsCorrectMethodsAndReturnsInCorrectOrder()
            {
                // Arrange
                IPeriodDao periodDao = MockRepository.GenerateMock<IPeriodDao>();
                DateTime FIRST_STARTDATE = new DateTime(2013, 01, 01);
                DateTime SECOND_STARTDATE = FIRST_STARTDATE.AddDays(1);
                DateTime THIRD_STARTDATE = SECOND_STARTDATE.AddDays(1);

                //Set up dummy period
                List<Period> examplePeriods = new List<Period>
                {
                    new Period
                    {
                        PeriodType = new PeriodType { PeriodTypeEnum = PeriodTypeEnum.Closure },
                        PeriodDateRanges = new List<PeriodDateRange>
                        {
                            new PeriodDateRange
                            {
                                StartDate = new DateTime(2014, 01, 01)
                            },
                            new PeriodDateRange
                            {
                                StartDate = THIRD_STARTDATE
                            }
                        }
                    },
                    new Period
                    {
                        PeriodType = new PeriodType { PeriodTypeEnum = PeriodTypeEnum.Season },
                        PeriodDateRanges = new List<PeriodDateRange>
                        {
                            new PeriodDateRange
                            {
                                StartDate = new DateTime(2015, 01, 01)
                            },
                            new PeriodDateRange
                            {
                                StartDate = FIRST_STARTDATE
                            },
                            new PeriodDateRange
                            {
                                StartDate = FIRST_STARTDATE.AddDays(2)
                            }
                        }
                    },
                    new Period
                    {
                        PeriodType = new PeriodType { PeriodTypeEnum = PeriodTypeEnum.Event },
                        PeriodDateRanges = new List<PeriodDateRange>
                        {
                            new PeriodDateRange
                            {
                                StartDate = SECOND_STARTDATE.AddDays(3)
                            },
                            new PeriodDateRange
                            {
                                StartDate = new DateTime(2016, 01, 01)
                            },
                            new PeriodDateRange
                            {
                                StartDate = SECOND_STARTDATE
                            }
                        }
                    }
                };
                periodDao.Expect(p => p.GetAllByBusiness(Arg<long>.Is.Equal(BUSINESS_ID), Arg<string>.Is.Equal(ENGLISH_CULTURE))).Return(examplePeriods).Repeat.Once();
                PeriodManager periodManager = new PeriodManager {PeriodDao = periodDao};

                // Act
                List<Period> periods = periodManager.GetAllPeriodsForBusiness(BUSINESS_ID, ENGLISH_CULTURE);

                // Assert
                periodDao.VerifyAllExpectations();
                Assert.IsNotNull(periods);
                //Check ordering
                Assert.AreEqual(3, periods.Count, "Three periods should have been returned");
                Assert.AreEqual(PeriodTypeEnum.Season, periods[0].PeriodType.PeriodTypeEnum, "Seasons should be first");
                Assert.AreEqual(PeriodTypeEnum.Event, periods[1].PeriodType.PeriodTypeEnum, "Events should be second");
                Assert.AreEqual(PeriodTypeEnum.Closure, periods[2].PeriodType.PeriodTypeEnum, "Closures should be last");
                Assert.AreEqual(FIRST_STARTDATE, periods[0].PeriodDateRanges[0].StartDate, "Date ranges weren't ordered correctly for period 1");
                Assert.AreEqual(SECOND_STARTDATE, periods[1].PeriodDateRanges[0].StartDate, "Date ranges weren't ordered correctly for period 2");
                Assert.AreEqual(THIRD_STARTDATE, periods[2].PeriodDateRanges[0].StartDate, "Date ranges weren't ordered correctly for period 3");
            }   
示例#6
0
            public void DoBookingsExistForPeriodDateRangeCallsDaoCorrectly()
            {
                // Arrange
                var bookingDao = MockRepository.GenerateMock<IBookingDao>();

                var periodManager = new PeriodManager { BookingDao = bookingDao };
                
                bookingDao.Expect(b => b.DoBookingsExistForPeriodDateRange(Arg<long>.Is.Equal(BUSINESS_ID), Arg<DateTime>.Is.Anything, Arg<DateTime>.Is.Anything)).Return(true).Repeat.Once();

                // Act
                periodManager.DoBookingsExistForPeriodDateRange(BUSINESS_ID, DateTime.Now, DateTime.Now);

                // Assert
                bookingDao.VerifyAllExpectations();
            }
示例#7
0
            public void DoRatesExistForValidPeriodCallsDaoCorrectly()
            {
                // Arrange
                IRatePlanDao ratePlanDaoMock = MockRepository.GenerateMock<IRatePlanDao>();
                ratePlanDaoMock.Expect(rp => rp.DoRatesExistForPeriod(Arg<int>.Is.Equal(PERIOD_WITHRATES_ID))).Return(true).Repeat.Once();

                IPeriodManager periodManager = new PeriodManager
                {
                    RatePlanDao = ratePlanDaoMock
                };

                // Act
                bool result = periodManager.DoRatesExistForPeriod(PERIOD_WITHRATES_ID);

                // Assert
                ratePlanDaoMock.VerifyAllExpectations();
                Assert.IsTrue(result, "Verify mock returned true correctly");
            }  
示例#8
0
            public void DeletePeriodWithRatesExpectDeletionOfRatesToBeExecuted()
            {
                // Arrange
                IVariantRatePlanDao variantRatePlanDaoMock = MockRepository.GenerateMock<IVariantRatePlanDao>();
                IRatePlanDao ratePlanMock = MockRepository.GenerateMock<IRatePlanDao>();
                IEventTrackingManager eventTrackingMock = MockRepository.GenerateMock<IEventTrackingManager>();
                IPeriodDao periodMock = MockRepository.GenerateMock<IPeriodDao>();
                IPeriodDateRangeDao periodDateRangeMock = MockRepository.GenerateMock<IPeriodDateRangeDao>();
                PeriodTypeEnum seasonType = PeriodTypeEnum.Season;

                eventTrackingMock.Expect(bedao => bedao.CreateBusinessEventAsync(Arg<long>.Is.Equal(BUSINESS_ID), Arg<BusinessEventTypesEnum>.Is.Equal(BusinessEventTypesEnum.SeasonPeriodDeleted), Arg<string>.Is.Anything, Arg<string>.Is.Anything));
                variantRatePlanDaoMock.Expect(vrp => vrp.DeleteRatePlanRatesAssociatedWithPeriod(Arg<int>.Is.Equal(PERIOD_WITHRATES_ID))).Return(true);
                periodMock.Expect(pedao => pedao.Remove(Arg<int>.Is.Anything));
                periodDateRangeMock.Expect(pdr => pdr.Remove(Arg<int>.Is.Equal(PERIOD_DATERANGE_ID)));
                periodDateRangeMock.Expect(pdr => pdr.GetAllByPeriodId(Arg<int>.Is.Equal(PERIOD_WITHRATES_ID))).Return(new List<PeriodDateRange> { new PeriodDateRange() }).Repeat.Once();
                

               // set up manager with the mocks
                PeriodManager periodManager = new PeriodManager
                {
                    EventTrackingManager = eventTrackingMock,
                    RatePlanDao = ratePlanMock,
                    PeriodDao = periodMock,
                    PeriodDateRangeDao = periodDateRangeMock,
                    VariantRatePlanDao = variantRatePlanDaoMock
                    
                };

                //Act
                periodManager.DeletePeriod(BUSINESS_ID, seasonType, PERIOD_WITHRATES_ID, PERIOD_DATERANGE_ID);

                // Assert
                eventTrackingMock.VerifyAllExpectations();
                periodMock.VerifyAllExpectations();
                periodDateRangeMock.VerifyAllExpectations();
                variantRatePlanDaoMock.VerifyAllExpectations();
            }  
示例#9
0
            public void DeleteClosurePeriodWithMoreThanOneDateRangeOnlyDeletesPeriodDateRangeIsSuccessful()
            {
                // Arrange
                IRatePlanDao ratePlanMock = MockRepository.GenerateMock<IRatePlanDao>();
                IEventTrackingManager eventTrackingMock = MockRepository.GenerateMock<IEventTrackingManager>();
                IPeriodDao periodMock = MockRepository.GenerateMock<IPeriodDao>();
                IPeriodDateRangeDao periodDateRangeMock = MockRepository.GenerateMock<IPeriodDateRangeDao>();
                PeriodTypeEnum closureType = PeriodTypeEnum.Closure;

                ratePlanMock.Expect(rpdao => rpdao.DoRatesExistForPeriod(Arg<int>.Is.Equal(PERIOD_WITHOUTRATES_ID))).Return(false).Repeat.Never();
                eventTrackingMock.Expect(bedao => bedao.CreateBusinessEventAsync(Arg<long>.Is.Equal(BUSINESS_ID), Arg<BusinessEventTypesEnum>.Is.Equal(BusinessEventTypesEnum.ClosurePeriodDeleted), Arg<string>.Is.Anything, Arg<string>.Is.Anything)).Repeat.Once();
                periodMock.Expect(pedao => pedao.Remove(Arg<int>.Is.Anything)).Repeat.Never();
                periodDateRangeMock.Expect(pdr => pdr.Remove(Arg<int>.Is.Equal(PERIOD_DATERANGE_ID))).Repeat.Once();
                periodDateRangeMock.Expect(pdr => pdr.GetAllByPeriodId(Arg<int>.Is.Equal(PERIOD_WITHOUTRATES_ID))).Return(new List<PeriodDateRange> { new PeriodDateRange(), new PeriodDateRange() }).Repeat.Once();

                // set up manager with the mocks
                PeriodManager periodManager = new PeriodManager
                {
                    EventTrackingManager = eventTrackingMock,
                    RatePlanDao = ratePlanMock,
                    PeriodDao = periodMock,
                    PeriodDateRangeDao = periodDateRangeMock
                };

                // Act
                periodManager.DeletePeriod(BUSINESS_ID, closureType, PERIOD_WITHOUTRATES_ID, PERIOD_DATERANGE_ID);

                // Assert
                eventTrackingMock.VerifyAllExpectations();
                ratePlanMock.VerifyAllExpectations();
                periodMock.VerifyAllExpectations();
                periodDateRangeMock.VerifyAllExpectations();
            }
示例#10
0
            public void GetAllPeriodTypesIsSuccessful()
            {
                // Arrange
                IPeriodTypeDao periodTypeDao = MockRepository.GenerateMock<IPeriodTypeDao>();
                periodTypeDao.Expect(pt => pt.GetAll(Arg<string>.Is.Equal(ENGLISH_CULTURE))).Return(new List<PeriodType>());

                PeriodManager periodManager = new PeriodManager { PeriodTypeDao = periodTypeDao };

                // ACT
                List<PeriodType> periodTypes = periodManager.GetAllPeriodTypes(ENGLISH_CULTURE);

                // Assert
                Assert.IsNotNull(periodTypes, "Period types were not returned");
                periodTypeDao.VerifyAllExpectations();
            }