示例#1
0
        public IActionResult GetDashBoardStyle(string dashboardGUID)
        {
            try
            {
                if (string.IsNullOrEmpty(dashboardGUID))
                {
                    throw new BasicException("Empty GUID!");
                }
                User user = _userRep.GetByEmailAdd(this.User.Claims.SingleOrDefault(x => x.Type == "EmailAddress").Value);

                var dashboardDto = _manager.GetDashBoardStyle(dashboardGUID, user);
                return(Ok(dashboardDto));
            }
            catch (BasicException ex)
            {
                _logger.LogError(ex.Message);
                return(BadRequest(ex.Message));
            }
            catch (NotFoundException ex)
            {
                _logger.LogError(ex.Message);
                return(NotFound(ex.Message));
            }
            catch (PermissionException ex)
            {
                _logger.LogError(ex.Message);
                return(Unauthorized());
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                return(BadRequest());
            }
        }
        public void Test_GetDashBoardStyle_ShouldThrowPermissionException_When_NoRigthToWatch()
        {
            // Arrange
            Mock <IDashboardRepository> dashboardRep = new Mock <IDashboardRepository>();

            dashboardRep.Setup(x => x.Get(It.Is <string>(y => y == "Valid"))).Returns(_dashboards.SingleOrDefault(x => x.DashBoardGUID.Equals("Valid")));
            dashboardRep.Setup(x => x.Get(It.Is <string>(y => y == "InValid"))).Returns(_dashboards.SingleOrDefault(x => x.DashBoardGUID.Equals("InValid")));
            Mock <IUserDashboardRelRepository> userDashRelRep = new Mock <IUserDashboardRelRepository>();

            userDashRelRep.Setup(x => x.Get(It.Is <int>(y => y == 1), It.Is <int>(z => z == 1))).Returns(_dashUserRel.SingleOrDefault(x => x.Dashboard.Id == 1 && x.User.Id == 1));
            // Act
            DashboardManager manager = new DashboardManager(dashboardRep.Object, null, null, userDashRelRep.Object);

            // Assert
            Assert.Throws(typeof(PermissionException), () => manager.GetDashBoardStyle("Valid", _users[2]));
        }
        public void Test_GetDashBoardStyle_Should_GiveBackRigthStyle_When_AddedValidGUID()
        {
            // Arrange
            Mock <IDashboardRepository> dashboardRep = new Mock <IDashboardRepository>();

            dashboardRep.Setup(x => x.Get(It.Is <string>(y => y == "Valid"))).Returns(_dashboards.SingleOrDefault(x => x.DashBoardGUID.Equals("Valid")));
            dashboardRep.Setup(x => x.Get(It.Is <string>(y => y == "InValid"))).Returns(_dashboards.SingleOrDefault(x => x.DashBoardGUID.Equals("InValid")));
            Mock <IUserDashboardRelRepository> userDashRelRep = new Mock <IUserDashboardRelRepository>();

            userDashRelRep.Setup(x => x.Get(It.Is <int>(y => y == 1), It.Is <int>(z => z == 1))).Returns(_dashUserRel.SingleOrDefault(x => x.Dashboard.Id == 1 && x.User.Id == 1));
            // Act
            DashboardManager manager = new DashboardManager(dashboardRep.Object, null, null, userDashRelRep.Object);
            var testStyle            = manager.GetDashBoardStyle("Valid", _users[0]).Style;

            // Assert
            StringAssert.Contains("StyleTest", testStyle);
        }