Esempio n. 1
0
        public async Task <IActionResult> GetDashBoardData()
        {
            IOperationResult <DashBoardViewModel> dashBoardDataResult = await _dashBoardManager.GetDashBoarData();

            if (!dashBoardDataResult.Success)
            {
                return(BadRequest(dashBoardDataResult.Message));
            }

            return(Ok(dashBoardDataResult.Entity));
        }
        public async Task GetDashBoarDataWhenActiveUsersQuantityFailShouldReturnOperationResultFail()
        {
            ISystemUserRepository systemUserRepository = Substitute.For <ISystemUserRepository>();

            systemUserRepository.CountAsync(Arg.Any <Expression <Func <SystemUser, bool> > >()).Throws(new Exception());

            DashBoardManager dashBoardManager = new DashBoardManager(systemUserRepository);

            IOperationResult <DashBoardViewModel> actual = await dashBoardManager.GetDashBoarData();

            Assert.IsFalse(actual.Success);
            Assert.AreEqual("Ha ocurrido un error al cargar los datos del tablero", actual.Message);
        }
        public async Task GetDashBoarDataWhenAllSuccessShouldReturnOperationResultSuccess()
        {
            ISystemUserRepository systemUserRepository = Substitute.For <ISystemUserRepository>();

            systemUserRepository.CountAsync().Returns(1);
            systemUserRepository.CountAsync(Arg.Any <Expression <Func <SystemUser, bool> > >()).Returns(2);

            DashBoardManager dashBoardManager = new DashBoardManager(systemUserRepository);

            IOperationResult <DashBoardViewModel> actual = await dashBoardManager.GetDashBoarData();

            Assert.IsTrue(actual.Success);
            Assert.AreEqual(actual.Entity.RegisteredUsersQuantity, 1);
            Assert.AreEqual(actual.Entity.ActiveUsersQuantity, 2);
        }