public IHttpActionResult Post(DashboardModel dashboardModel)
 {
     if (ModelState.IsValid)
     {
         var dashboard = new Dashboard
         {
             Title = dashboardModel.Title,
             Config = dashboardModel.Config,
             Id = Guid.NewGuid().ToString("n"),
             Description = dashboardModel.Description,
             DataSource = dashboardModel.DataSource
         };
         try
         {
             dashboard.UserId = (dashboardModel.UserName == null) ? GetCurrentUserId() : GetIdByUsername(dashboardModel.UserName);
             _dashboardService.Add(dashboard);
             return Ok(new { Message = (string)null });
         }
         catch (Exception e)
         {
             return Ok(new { Message = e.Message });
         }
     }
     return BadRequest();
 }
示例#2
0
 public void Update(Dashboard dashboard)
 {
     using (var unitOfWork = _factory.CreateUnitOfWork())
     {
         unitOfWork.DashboardRepository.Update(dashboard);
         unitOfWork.Save();
     }
 }
 public void Update_CallsInternalMethods()
 {
     A.CallTo(() => _fakeUnitOfWorkFaktory.CreateUnitOfWork()).Returns(_fakeUnitOfWork);
     var testDashboardService = Factory.CreateDashboardService(_fakeUnitOfWorkFaktory);
     var testDashboardToUpdate = new Dashboard();
     testDashboardService.Update(testDashboardToUpdate);
     A.CallTo(() => _fakeUnitOfWork.DashboardRepository.Update(testDashboardToUpdate)).MustHaveHappened();
     A.CallTo(() => _fakeUnitOfWork.Save()).MustHaveHappened();
 }
 public void GetById_CorrectDashboard()
 {
     A.CallTo(() => _fakeUnitOfWorkFaktory.CreateUnitOfWork()).Returns(_fakeUnitOfWork);
     var testDashboardService = Factory.CreateDashboardService(_fakeUnitOfWorkFaktory);
     var testIdToGet = "212";
     var testDashboardToGet = new Dashboard();
     A.CallTo(() => _fakeUnitOfWork.DashboardRepository.GetById(testIdToGet)).Returns(testDashboardToGet);
     var result = testDashboardService.GetById(testIdToGet);
     A.CallTo(() => _fakeUnitOfWork.DashboardRepository.GetById(testIdToGet)).MustHaveHappened();
     Assert.AreEqual(testDashboardToGet, result);
 }
 public void Add_CorrectDashboard()
 {
     A.CallTo(() => _fakeUnitOfWorkFaktory.CreateUnitOfWork()).Returns(_fakeUnitOfWork);
     var testDashboardService = Factory.CreateDashboardService(_fakeUnitOfWorkFaktory);
     var testDashboardToAdd = new Dashboard();
     A.CallTo(() => _fakeUnitOfWork.DashboardRepository.Insert(testDashboardToAdd)).Returns(testDashboardToAdd);
     var result = testDashboardService.Add(testDashboardToAdd);
     A.CallTo(() => _fakeUnitOfWork.DashboardRepository.Insert(testDashboardToAdd)).MustHaveHappened();
     A.CallTo(() => _fakeUnitOfWork.Save()).MustHaveHappened();
     Assert.AreEqual(testDashboardToAdd, result);
 }
        public void GetById_Null()
        {
            var myController = new DashboardController(_fakeDashboardService);
            var dashboard = new Dashboard();
            string id = null;

            A.CallTo(() => _fakeDashboardService.GetById(id)).Returns(dashboard);
            var result = myController.Get(id);
            A.CallTo(() => _fakeDashboardService.GetById(id)).MustHaveHappened();
            Assert.AreEqual(dashboard, result);
        }
示例#7
0
 public Dashboard Add(Dashboard dashboard)
 {
     using (var unitOfWork = _factory.CreateUnitOfWork())
     {
         if (dashboard != null)
         {
             var result = unitOfWork.DashboardRepository.Insert(dashboard);
             unitOfWork.Save();
             return result;
         }
         return null;
     }
 }