Пример #1
0
        public void Test_CreateDashboard_Should_Create_When_ValidDataAdded()
        {
            // Arrange
            Mock <IDashboardRepository> dashboardRep = new Mock <IDashboardRepository>();

            dashboardRep.Setup(x => x.Add(It.IsAny <Dashboard>())).Callback <Dashboard>((x) => _dashboards.Add(x));
            Mock <IUserDashboardRelRepository> userDashRelRep = new Mock <IUserDashboardRelRepository>();

            userDashRelRep.Setup(x => x.Add(It.IsAny <UserDashboardRel>())).Callback <UserDashboardRel>((z) => _dashUserRel.Add(z));
            Mock <IReportRepository> reportRep = new Mock <IReportRepository>();

            reportRep.Setup(x => x.Get(It.IsAny <string>())).Returns <string>((z) => _reports.SingleOrDefault(x => x.ReportGUID.Equals(z)));
            Mock <IReportDashboardRelRepository> repDashRel = new Mock <IReportDashboardRelRepository>();

            repDashRel.Setup(x => x.Add(It.IsAny <ReportDashboardRel>())).Callback <ReportDashboardRel>(z => _reportDashRel.Add(z));
            // Act
            DashboardManager manager  = new DashboardManager(dashboardRep.Object, repDashRel.Object, reportRep.Object, userDashRelRep.Object);
            string           dashGUID = manager.CreateDashboard(new CreateDashboardDto
            {
                Name    = "testing",
                Reports = new List <szakdoga.Models.Dtos.QueryDtos.ReportDashboardRelDto>
                {
                    new szakdoga.Models.Dtos.QueryDtos.ReportDashboardRelDto
                    {
                        Position = "1", ReportGUID = "Valid"
                    }
                }
            },
                                                                _users[0]);

            ReportDashboardRel report = _reportDashRel.FirstOrDefault(x => x.Report.ReportGUID == "Valid" && x.Dashboard.Name == "testing");

            // Assert
            Assert.AreEqual(true, report != null);
        }
Пример #2
0
 public IActionResult CreateDashboard([FromBody] CreateDashboardDto dbDto)
 {
     try
     {
         if (dbDto == null)
         {
             throw new BasicException("Invalid Dto");
         }
         if (!ModelState.IsValid)
         {
             return(BadRequest(ModelState));
         }
         User user = _userRep.GetByEmailAdd(this.User.Claims.SingleOrDefault(x => x.Type == "EmailAddress").Value);
         var  guid = _manager.CreateDashboard(dbDto, user);
         return(Created(string.Empty, guid));
     }
     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());
     }
 }