public void CreatePeriodWithNoTypeThrowsException() { // 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 no period type Period existingPeriod = CreateValidPeriod(existingPeriodId); existingPeriod.PeriodType = 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.Create(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.CreatePeriod(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 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"); }
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"); }