コード例 #1
0
        public void GetBudgetsByCategorySummary_Tests()
        {
            #region Data
            int      channelid = 1, mrmUserId = 25; string fy = "2016", budgettype = "On Air,Off Air,Paid Media", networkLogin = "******";
            string[] total = budgettype.Split(',').ToArray();
            BudgetByCategorySumViewModel summarylist1 = new BudgetByCategorySumViewModel
            {
                Category              = "ABC",
                ActualAmount          = 5256,
                CommittedAmount       = 3000,
                AllocatedBudgetAmount = 2500,
                BudgetAmount          = 4000,
                EstimateToComplete    = 4500,
                EstimatedFinalCost    = 5000,
                OverUnder             = 50
            };
            BudgetByCategorySumViewModel summarylist2 = new BudgetByCategorySumViewModel
            {
                Category              = "Aquired Movies",
                ActualAmount          = 6456,
                CommittedAmount       = 4000,
                AllocatedBudgetAmount = 3500,
                BudgetAmount          = 5000,
                EstimateToComplete    = 5500,
                EstimatedFinalCost    = 4000,
                OverUnder             = 100
            };

            List <BudgetbyCategoryRollup> rollups = new List <BudgetbyCategoryRollup>();
            rollups.Add(new BudgetbyCategoryRollup {
                ActualAmount = 5254, CategoryName = "ABC", CategoryId = 1, BudgetTypeName = "On Air"
            });
            rollups.Add(new BudgetbyCategoryRollup {
                ActualAmount = 4250, CategoryName = "Aquired Movies", CategoryId = 2, BudgetTypeName = "Off Air"
            });
            rollups.Add(new BudgetbyCategoryRollup {
                ActualAmount = 6250, CategoryName = "Aquired Series", CategoryId = 3, BudgetTypeName = "On Air"
            });
            rollups.Add(new BudgetbyCategoryRollup {
                ActualAmount = 7285, CategoryName = "Ad Sales", CategoryId = 4, BudgetTypeName = "Paid Media"
            });
            List <TypeOfWorkBudgetModel> BudgetTypes = new List <TypeOfWorkBudgetModel>();
            BudgetTypes.Add(new TypeOfWorkBudgetModel {
                BudgetTypeId = 1, BudgetTypeName = "On Air"
            });
            BudgetTypes.Add(new TypeOfWorkBudgetModel {
                BudgetTypeId = 2, BudgetTypeName = "Off Air"
            });
            BudgetTypes.Add(new TypeOfWorkBudgetModel {
                BudgetTypeId = 3, BudgetTypeName = "Paid Media"
            });
            BudgetTypes.Add(new TypeOfWorkBudgetModel {
                BudgetTypeId = 4, BudgetTypeName = "Brain Design"
            });
            List <BudgetByCategorySumViewModel> categorysummary = new List <BudgetByCategorySumViewModel>();
            categorysummary.Add(summarylist1);
            categorysummary.Add(summarylist2);
            List <BudgetbyCategoryRollup> Categoryrollup = new List <BudgetbyCategoryRollup>();
            Categoryrollup.Add(new BudgetbyCategoryRollup {
                ActualAmount = 5241, BudgetAmount = 450, BudgetTypeId = 1, BudgetTypeName = "On Air", CategoryId = 1, CategoryName = "ABC"
            });
            Categoryrollup.Add(new BudgetbyCategoryRollup {
                ActualAmount = 3250, BudgetAmount = 350, BudgetTypeId = 1, BudgetTypeName = "On Air", CategoryId = 2, CategoryName = "XYZ"
            });
            Categoryrollup.Add(new BudgetbyCategoryRollup {
                ActualAmount = 4250, BudgetAmount = 300, BudgetTypeId = 2, BudgetTypeName = "Off Air", CategoryId = 3, CategoryName = "PQR"
            });
            Categoryrollup.Add(new BudgetbyCategoryRollup {
                ActualAmount = 3525, BudgetAmount = 200, BudgetTypeId = 3, BudgetTypeName = "Paid Media", CategoryId = 4, CategoryName = "MNO"
            });
            IQueryable <BudgetbyCategoryRollup> rollupslist = Categoryrollup.AsQueryable();
            #endregion
            #region Mock
            mockbudgetService.Setup(x => x.GetBudgetsByCategory(It.IsAny <int>(), It.IsAny <string>())).Returns(rollups);
            mockbudgetService.Setup(x => x.GetTypeOfWorkBudgets()).Returns(BudgetTypes);
            mockBudgetByCategoryRepository.Setup(x => x.GetMany(It.IsAny <Expression <Func <BudgetbyCategoryRollup, bool> > >())).Returns(rollupslist);
            mocktypeOfWorkRepository.Setup(x => x.GetTypeOfWorkBudgets()).Returns(BudgetTypes);

            //Budget Service Mock
            var budgetService    = new BudgetServiceMock(iTypeOfWork: mocktypeOfWorkRepository.Object, budgetByCategory: mockBudgetByCategoryRepository.Object);
            var BudgetController = new BudgetControllerMock(budgetservice: budgetService);

            #endregion
            //Assertions
            #region Assertions
            Assert.IsNotNull(BudgetTypes);
            Assert.IsTrue(BudgetTypes.Count == 4);
            Assert.IsTrue(BudgetTypes.ElementAt(0).BudgetTypeId == 1);
            Assert.IsTrue(BudgetTypes.ElementAt(1).BudgetTypeName == "Off Air");
            Assert.IsTrue(BudgetTypes.ElementAt(2).BudgetTypeId == 3);

            Assert.IsNotNull(categorysummary);
            var rollupsresult = budgetService.GetBudgetsByCategory(channelid, fy);
            Assert.IsNotNull(rollupsresult);

            mockbudgetService.Verify();
            mockBudgetByCategoryRepository.Verify();

            rollupsresult = rollupsresult.Where(p => total.Contains(p.BudgetTypeName)).ToList();
            Assert.IsNotNull(rollupsresult);

            categorysummary = BudgetController.GetBudgetsByCategorySummary(1, budgettype, fy, mrmUserId, networkLogin);
            Assert.IsNotNull(categorysummary);

            categorysummary = BudgetController.GetBudgetsByCategorySummary(1, budgettype, fy, mrmUserId, networkLogin);
            Assert.IsNotNull(categorysummary);


            #endregion
        }
コード例 #2
0
        public void GetAllWBSElementHistory_Test()
        {
            #region Data
            hWBSElementModel hWBSElementModel1 = new hWBSElementModel()
            {
                FullWBSNumber          = "1234567.001.001",
                BudgetAmount           = 500,
                Comments               = "Test1",
                HistoryInsert          = DateTime.Now,
                LastAction             = "Reflow Audit",
                Q1ForecastAmount       = 0,
                Q2ForecastAmount       = 0,
                Q3ForecastAmount       = 20,
                Q4ForecastAmount       = 60,
                EstimateCompleteAmount = 450,
                TypeOfWorkName         = "Reflow 1"
            };
            hWBSElementModel hWBSElementModel2 = new hWBSElementModel()
            {
                FullWBSNumber          = "1234567.001.002",
                BudgetAmount           = 700,
                Comments               = "Test2",
                HistoryInsert          = DateTime.UtcNow,
                LastAction             = "Edit Type Of Work",
                Q1ForecastAmount       = 0,
                Q2ForecastAmount       = 0,
                Q3ForecastAmount       = 40,
                Q4ForecastAmount       = 900,
                EstimateCompleteAmount = 730,
                TypeOfWorkName         = "TOW 1"
            };
            List <hWBSElementModel> hWBSElementModelList = new List <hWBSElementModel>();
            hWBSElementModelList.Add(hWBSElementModel1);
            hWBSElementModelList.Add(hWBSElementModel2);
            #endregion

            #region  Mock
            mockWBSElementRepository.Setup(x => x.GetAllWBSElementHistory(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>()))
            .Returns(hWBSElementModelList);
            #endregion

            #region Service
            var budgetService = new BudgetServiceMock(iBudgetTypeTOWRepository: mockWBSElementRepository.Object);
            #endregion

            #region Controller
            var budgetController = new BudgetControllerMock(budgetservice: budgetService);
            #endregion

            #region Result
            var result = budgetController.GetAllWBSElementHistory(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>());
            #endregion

            #region Assertions
            Assert.IsFalse(result == null);
            Assert.IsTrue(result.Count() == 2);
            Assert.IsTrue(result.ElementAt(0).BudgetAmount == 500);
            Assert.IsTrue(result.ElementAt(1).TypeOfWorkName == "TOW 1");
            Assert.IsTrue(result.ElementAt(0).Q3ForecastAmount == 20);
            Assert.IsTrue(result.ElementAt(1).Q4ForecastAmount == 900);
            Assert.IsTrue(result.ElementAt(0).EstimateCompleteAmount == 450);
            Assert.IsTrue(result.ElementAt(1).LastAction == "Edit Type Of Work");
            Assert.IsTrue(result.ElementAt(0).LastAction == "Reflow Audit");
            Assert.IsTrue(result.ElementAt(1).FullWBSNumber == "1234567.001.002");
            #endregion
        }
コード例 #3
0
        public void GetExternalTypeofWorks()
        {
            //Set Data
            #region Data

            DeliverableBudgetSummary ds1 = new DeliverableBudgetSummary
            {
                TypeOfWorkId            = 1,
                TypeOfWorkName          = "RDMA",
                TypeOfWorkCategoryId    = 1,
                TypeOfWorkCategoryName  = "External",
                MarketingGroupChannelId = 1,
                FiscalYear             = "2016",
                EstimateCompleteAmount = 11700,
                FullWBSNumber          = "001"
            };

            DeliverableBudgetSummary ds2 = new DeliverableBudgetSummary
            {
                TypeOfWorkId            = 2,
                TypeOfWorkName          = "NBT",
                TypeOfWorkCategoryId    = 1,
                TypeOfWorkCategoryName  = "External",
                MarketingGroupChannelId = 1,
                FiscalYear             = "2016",
                EstimateCompleteAmount = 11323,
                FullWBSNumber          = "002"
            };

            DeliverableBudgetSummary ds3 = new DeliverableBudgetSummary
            {
                TypeOfWorkId            = 3,
                TypeOfWorkName          = "RD Insider",
                TypeOfWorkCategoryId    = 1,
                TypeOfWorkCategoryName  = "External",
                MarketingGroupChannelId = 2,
                FiscalYear             = "2015",
                EstimateCompleteAmount = 12363,
                FullWBSNumber          = "003"
            };
            DeliverableBudgetSummary ds4 = new DeliverableBudgetSummary
            {
                TypeOfWorkId            = 4,
                TypeOfWorkName          = "RD Birthday",
                TypeOfWorkCategoryId    = 1,
                TypeOfWorkCategoryName  = "External",
                MarketingGroupChannelId = 2,
                FiscalYear             = "2015",
                EstimateCompleteAmount = 165789
                ,
                FullWBSNumber = "004"
            };
            List <DeliverableBudgetSummary> dbsList = new List <DeliverableBudgetSummary>();
            dbsList.Add(ds1); dbsList.Add(ds2); dbsList.Add(ds3); dbsList.Add(ds4);
            #endregion

            //Mock
            #region  Mock
            //Type of Service Mock
            mocktypeOfWorkRepository.Setup(x => x.GetExternalTypeofWorks(It.IsAny <int>(), It.IsAny <int>()))
            .Returns <int, int>((ch, fy) =>
                                (ch == 0) ? dbsList.Where(p => p.FiscalYear == fy.ToString()).ToList() :
                                dbsList.Where(p => p.FiscalYear == fy.ToString() && p.MarketingGroupChannelId.Value == ch).ToList()
                                );
            var mockbudgetService = new BudgetServiceMock(iTypeOfWork: mocktypeOfWorkRepository.Object);
            //Budget Controller Mock
            var BudgetController = new BudgetControllerMock(budgetservice: mockbudgetService);

            #endregion

            //Assertions
            #region Assertions

            int    channelId  = 0;
            int    FiscalYear = 2016;
            string LoginUser  = @"swna\TestLogin";

            //Get All Records when channelId=0 and current Year(2016)
            var result = BudgetController.GetExternalTypeofWorks(channelId, FiscalYear, LoginUser);
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(List <TypeOfWorkViewModel>));
            Assert.IsTrue(result.Count == 2);
            Assert.IsTrue(result.All(p => FiscalYear == 2016)); // all records should be fiscal year as 2016

            //filter by ChannelId and Fiscalyear
            channelId = 2; FiscalYear = 2015;
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(List <TypeOfWorkViewModel>));
            Assert.IsTrue(result.Count == 2);
            Assert.IsTrue(result.All(p => FiscalYear == 2015)); // all records should be fiscalyear:2015
            Assert.IsTrue(result.All(p => channelId == 2));     // all records should be with channel=2


            #endregion
        }