public void QDeliverablesByTOWAndDepartment_Test() { #region Data Setup int typeOfWorkId = 1; List <DeliverableBudgetSummary> deliverablesByTOWAndDepartment = new List <DeliverableBudgetSummary>(); DeliverableBudgetSummary deliverableOnAir = new DeliverableBudgetSummary { TypeOfWorkId = 1, TypeOfWorkName = "Tow MRM", DeliverableId = 14030212, BudgetTypeName = "On Air" }; DeliverableBudgetSummary deliverableOffAir = new DeliverableBudgetSummary { TypeOfWorkId = 1, TypeOfWorkName = "Tow MRM", DeliverableId = 14030212, BudgetTypeName = "Off Air" }; DeliverableBudgetSummary deliverablePaidMedia = new DeliverableBudgetSummary { TypeOfWorkId = 1, TypeOfWorkName = "Tow MRM", DeliverableId = 14031212, BudgetTypeName = "Paid Media" }; deliverablesByTOWAndDepartment.Add(deliverableOnAir); deliverablesByTOWAndDepartment.Add(deliverableOffAir); deliverablesByTOWAndDepartment.Add(deliverablePaidMedia); #endregion #region Mocking mockdeliverableService.Setup(x => x.QDeliverablesByTOWAndDepartment(It.IsAny <int>())).Returns(deliverablesByTOWAndDepartment.AsQueryable()); //Deliverable Repository Mock mockDeliverableRepository.Setup(x => x.QGetDeliverablesByDepartmentAndTypeOfWork(It.IsAny <int>())).Returns(deliverablesByTOWAndDepartment.AsQueryable()); var deliverableService = new DeliverableServiceMock(deliverableRepository: mockDeliverableRepository.Object); //Budget Controller Mock var controller = new DeliverableControllerMock(deliverableService: deliverableService); #endregion #region Service var deliverablesResult = deliverableService.QDeliverablesByTOWAndDepartment(typeOfWorkId); #endregion #region Assertions Assert.IsFalse(deliverablesResult == null); Assert.IsTrue(deliverablesResult.ElementAt(0).BudgetTypeName == "On Air"); Assert.IsTrue(deliverablesResult.ElementAt(1).BudgetTypeName == "Off Air"); Assert.IsTrue(deliverablesResult.ElementAt(2).BudgetTypeName == "Paid Media"); Assert.IsTrue(deliverablesResult.ElementAt(1).DeliverableId == 14030212); Assert.IsTrue(deliverablesResult.ElementAt(2).DeliverableId == 14031212); Assert.IsTrue(deliverablesResult.ElementAt(0).TypeOfWorkId == 1); #endregion }
public void GetCodeInvoiceDetailsByDbId_Test() { #region Data Setup DeliverableBudgetSummary deliverableBudgetSummary = new DeliverableBudgetSummary() { Id = 122113, DeliverableId = 140000, DeliverableName = "Test for 219", SAPVendorId = 795,//Keep Me Posted WBSElementId = 999, ProductionMethodTypeId = 1100 }; DeliverableBudget deliverableBudgetTest = new DeliverableBudget() { Id = 122113, DeliverableBudgetUniqueID = new Guid(), PHApplyPercent = 45 }; #endregion #region Mocking mockDeliverableRepository.Setup(x => x.GetCodeInvoiceDetails(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>())) .Returns(deliverableBudgetSummary); #endregion #region Service var deliverableServiceMock = new DeliverableServiceMock(deliverableRepository: mockDeliverableRepository.Object); DeliverableBudgetSummary result = deliverableServiceMock.GetCodeInvoiceDetails(deliverableBudgetTest.Id, It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>()); #endregion #region Assert Assert.IsFalse(result == null); Assert.IsTrue(result.DeliverableId == deliverableBudgetSummary.DeliverableId); Assert.IsTrue(result.DeliverableName == "Test for 219"); Assert.IsTrue(result.SAPVendorId == 795); Assert.IsTrue(result.WBSElementId == deliverableBudgetSummary.WBSElementId); Assert.IsTrue(result.ProductionMethodTypeId == deliverableBudgetSummary.ProductionMethodTypeId); #endregion }
public void Get_TypeOfWork_ViewModel_Tests() { #region Data int typeOfWorkId = 1234; int mrmUserId = 25; string networkLogin = "******"; string Company = "Company 1"; string Business = "Business 1"; var flashSnapshot = new List <FlashSnapshotModel>(); flashSnapshot.Add(new FlashSnapshotModel() { ChannelId = 0, SnapshotType = 0, BudgetId = 0, Name = "Snapshot 1", Year = "2016", Quarter = " " }); var forecasts = new List <TypeOfWorkForecastModel>(); forecasts.Add(new TypeOfWorkForecastModel() { Months = new List <ForecastAmountModel>(), Quarters = new List <QuartersAmountModel>() }); var tow = new MRM.DANG.Model.TypeOfWork { Id = typeOfWorkId, Name = "Test Name", FiscalYear = 2015, TypeOfWorkCategoryId = 10 }; WBSFiscalYear_Channel wBSFiscalYear_Channel = new WBSFiscalYear_Channel { WBSNumber = "12345.123.234.001" }; //tow.WBSFiscalYear_Channel = wBSFiscalYear_Channel; TypeOfWorkModel tOfVm = new TypeOfWorkModel(); tOfVm.ExternalWBS = null; tOfVm.Company = Company; tOfVm.Business = Business; tOfVm.Id = typeOfWorkId; tOfVm.TypeOfWorkForecasts = forecasts; #endregion #region Mock mockbudgetService.Setup(x => x.BudgetTypeOfWork(It.IsAny <int>())).Returns(new MRM.DANG.Model.TypeOfWork()); mockbudgetService.Setup(x => x.BudgetsByCategoryRollup(It.IsAny <int>(), It.IsAny <int>())).Returns(new List <BudgetbyCategoryRollup>()); mockbudgetService.Setup(x => x.GetFiscalYearByIdAndChannel(It.IsAny <int>(), It.IsAny <int>())).Returns(""); mockbudgetService.Setup(x => x.BudgetTowFlashSnapshot(It.IsAny <int>())).Returns(new List <FlashSnapshotModel>()); //TypeofService Mock mocktypeOfWorkRepository.Setup(x => x.GetBudgetTypeOfWorkModel(It.IsAny <int>())).Returns(tow); mocktypeOfWorkRepository.Setup(x => x.GetFiscalYearByIdAndChannel(It.IsAny <int>(), It.IsAny <int>())).Returns(new WBSFiscalYear_Channel() { FiscalYear = "2015" }); mocktypeOfWorkRepository.Setup(x => x.GetRatingList()).Returns(new List <Rating>()); mocktypeOfWorkRepository.Setup(x => x.GetTypeOfWorkCategories()).Returns(new List <TypeOfWorkCategory>()); mocktypeOfWorkRepository.Setup(x => x.GetTypeOfWorkStatusList()).Returns(new List <TypeOfWorkStatus>()); mocktypeOfWorkRepository.Setup(x => x.GetAllFiscalYearList()).Returns(new List <WBSFiscalYear_Channel>()); mocktypeOfWorkRepository.Setup(x => x.GetBudgetTowFlashSnapshot(It.IsAny <int>())).Returns(flashSnapshot); //BudgetByCategoryRollupRepository Service Mock mockBudgetByCategoryRollupRepository.Setup(x => x.BudgetByCategoryRollupForTypeOfWork(It.IsAny <int>(), It.IsAny <int>())).Returns(new List <BudgetbyCategoryRollup>()); var userChannels = new List <MRMUser_Channel>(); userChannels.Add(new MRMUser_Channel() { ChannelId = 1, Channel = new Channel() { Name = "Channel 1" } }); userChannels.Add(new MRMUser_Channel() { ChannelId = 2, Channel = new Channel() { Name = "Channel 2" } }); mocktypeOfWorkRepository.Setup(x => x.GetTypeOfWorkModel(It.IsAny <int>())).Returns(tOfVm); mockUserChannelRepository.Setup(x => x.UserChannels(It.IsAny <int>())).Returns(userChannels); var budgetService = new BudgetServiceMock(userChannel: mockUserChannelRepository.Object, iTypeOfWork: mocktypeOfWorkRepository.Object, iBudgetByCategoryRollup: mockBudgetByCategoryRollupRepository.Object); //Product Service Mock mockProductFamilyRepository.Setup(x => x.GetAll()).Returns(new List <ProductFamily>().AsQueryable <ProductFamily>()); mockproductService.Setup(x => x.GetProductFamilies()).Returns(new List <ProductFamily>()); var productService = new ProductServiceMock(productFamilyRepository: mockProductFamilyRepository.Object); //Deliverable Service Mock mockdeliverableCategoryRepository.Setup(x => x.GetAll()).Returns(new List <DeliverableCategory>().AsQueryable <DeliverableCategory>()); mockdeliverableService.Setup(x => x.GetAllDeliverableCategories()).Returns(new List <DeliverableCategory>()); var deliverableService = new DeliverableServiceMock(deliverableCategoryRepository: mockdeliverableCategoryRepository.Object); var BudgetController = new BudgetController(userService: null, loggerService: null, budgetService: budgetService, unitOfWork: null, productService: productService, deliverableService: deliverableService, deliverableServiceV2: null, propertyService: null); #endregion #region Assertions mockbudgetService.Verify(); mockproductService.Verify(); mockdeliverableService.Verify(); //Verify TOW ViewModel var towModel = budgetService.GetTypeOfWork(typeOfWorkId); Assert.IsNotNull(towModel); Assert.AreEqual(Company, towModel.Company); Assert.AreEqual(Business, towModel.Business); var towtOfVm = BudgetController.GetTypeOfWork(typeOfWorkId, mrmUserId, networkLogin); Assert.IsNotNull(towtOfVm); Assert.AreEqual(Company, towtOfVm.Company); Assert.AreEqual(Business, towtOfVm.Business); //Check Channels Assert.AreEqual(towtOfVm.ChannelList.Count(), 2); //Check Channel 1 var channelListArray = towtOfVm.ChannelList.ToArray <SelectListItem>(); Assert.AreEqual("1", channelListArray[0].Value); Assert.AreEqual("Channel 1", channelListArray[0].Text); //Check Channel 2 Assert.AreEqual("2", channelListArray[1].Value); Assert.AreEqual("Channel 2", channelListArray[1].Text); // Check FlashSnapshot Assert.AreEqual(1, towtOfVm.FlashSnapshot.Count()); Assert.AreEqual("Snapshot 1", towtOfVm.FlashSnapshot[0].Name); Assert.AreEqual("2016", towtOfVm.FlashSnapshot[0].Year); Assert.AreEqual(0, towtOfVm.FlashSnapshot[0].SnapshotType); #endregion }