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 }