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"); }
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"); } }
public void ModifyOverlappingClosureSetsOverlapErrorAndReturnsSuccessfully() { // 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 end before start Period existingPeriod = CreateValidPeriod(existingPeriodId, periodType: PeriodTypeEnum.Closure, periodDateRangeId: existingPeriodDateRangeId); 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(); //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(bdao => bdao.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.ModifyPeriod(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"); }