コード例 #1
0
        public void TestControllerView()
        {
            var controller = new AccountantController();
            var result     = controller.Index("Hi") as ViewResult;

            Assert.AreEqual("Index", result.ViewName);
        }
コード例 #2
0
        public void ListOfUsersTest()
        {
            var mockUserHelper = new Mock <IUsersHelper>();

            mockUserHelper.Setup(i => i.ListOfUsers()).Returns(GetUser());
            var MockAccountantController = new AccountantController(mockUserHelper.Object);
            var result = MockAccountantController.ListOfUsers() as ViewResult;

            Assert.AreEqual(2, result.ViewEngineCollection.Count);
            Assert.IsInstanceOfType(result.ViewData.Model, typeof(IList <UserViewModel>));
        }
コード例 #3
0
        public void SetUp()
        {
            IMSDBLayer.Models.User db_accountant = new IMSDBLayer.Models.User()
            {
                Id              = new Guid(),
                Name            = "John Smith",
                Type            = 1,
                AuthorisedCosts = 40,
                AuthorisedHours = 40,
                IdentityId      = "",
                DistrictId      = new Guid()
            };
            IMSDBLayer.Models.User db_user = new IMSDBLayer.Models.User()
            {
                Id              = new Guid(),
                Name            = "Mr. Engineer",
                Type            = 1,
                AuthorisedCosts = 20,
                AuthorisedHours = 20,
                IdentityId      = "",
                DistrictId      = new Guid()
            };
            IMSDBLayer.Models.District db_district = new IMSDBLayer.Models.District()
            {
                Id   = new Guid(),
                Name = "NSW"
            };
            IMSLogicLayer.Models.User accountant = new IMSLogicLayer.Models.User(db_accountant);
            user = new IMSLogicLayer.Models.User(db_user);
            IMSLogicLayer.Models.District district = new IMSLogicLayer.Models.District(db_district);

            accountantService = new Mock <IAccountantService>();
            accountantService.Setup(a => a.getDetail()).Returns(accountant);
            accountantService.Setup(a => a.getAllManger()).Returns(new List <IMSLogicLayer.Models.User>());
            accountantService.Setup(a => a.getAllSiteEngineer()).Returns(new List <IMSLogicLayer.Models.User>());
            accountantService.Setup(a => a.getUserById(It.IsAny <Guid>())).Returns(user);
            accountantService.Setup(a => a.getDistrictForUser(It.IsAny <Guid>())).Returns(district);
            accountantService.Setup(a => a.getDistricts()).Returns(new List <IMSLogicLayer.Models.District>());
            accountantService.Setup(a => a.printAverageCostByEngineer()).Returns(new List <IMSLogicLayer.Models.ReportRow>());
            accountantService.Setup(a => a.printMonthlyCostByDistrict(It.IsAny <Guid>())).Returns(new List <IMSLogicLayer.Models.ReportRow>());
            accountantService.Setup(a => a.printTotalCostByDistrict()).Returns(new List <IMSLogicLayer.Models.ReportRow>());
            accountantService.Setup(a => a.printTotalCostByEngineer()).Returns(new List <IMSLogicLayer.Models.ReportRow>());

            controller = new AccountantController(accountantService.Object);
        }
コード例 #4
0
        public void Accountant_EditDistrictViewPostFailed()
        {
            Mock <IAccountantService> accountantService = new Mock <IAccountantService>();

            accountantService.Setup(a => a.changeDistrict(It.IsAny <Guid>(), It.IsAny <Guid>())).Returns(false);
            accountantService.Setup(a => a.getUserById(It.IsAny <Guid>())).Returns(user);

            AccountantController controller = new AccountantController(accountantService.Object);

            EditDistrictViewModel district = new EditDistrictViewModel()
            {
                Id = "9D2B0228-4444-4C23-8B49-01A698857709",
                SelectedDistrict = "9D2B0228-5555-4C23-8B49-01A698857709"
            };
            var view = controller.EditDistrict(district) as ViewResult;

            Assert.IsNotNull(view);
            Assert.AreEqual("Error", view.ViewName);
        }
コード例 #5
0
        public void Accountant_EditDistrictViewPostSuccess()
        {
            Mock <IAccountantService> accountantService = new Mock <IAccountantService>();

            accountantService.Setup(a => a.changeDistrict(It.IsAny <Guid>(), It.IsAny <Guid>())).Returns(true);
            accountantService.Setup(a => a.getUserById(It.IsAny <Guid>())).Returns(user);

            AccountantController controller = new AccountantController(accountantService.Object);

            EditDistrictViewModel district = new EditDistrictViewModel()
            {
                Id = user.Id.ToString(),
                SelectedDistrict = user.DistrictId.ToString()
            };
            var result = controller.EditDistrict(district) as RedirectToRouteResult;

            Assert.IsNotNull(result);
            Assert.AreEqual("EditDistrict", result.RouteValues["Action"]);
            Assert.AreEqual("Accountant", result.RouteValues["Controller"]);
        }