Exemplo n.º 1
0
        public async Task <OperationResult> Delete(int id)
        {
            try
            {
                CalendarUserModel deleteModel = new CalendarUserModel();
                deleteModel.Id = id;
                await deleteModel.Delete(_dbContext);

                return(new OperationResult(true));

//                CalendarUser calendarUser = _dbContext.CalendarUsers.FirstOrDefault(x => x.Id == id);
//                if (calendarUser == null)
//                {
//                    return new OperationResult(false,
//                        _caseManagementLocalizationService.GetString("CalendarUserNotFound"));
//                }
//
//                _dbContext.CalendarUsers.Remove(calendarUser);
//                _dbContext.SaveChanges();
//                return new OperationResult(true,
//                    _caseManagementLocalizationService.GetString("CalendarUserDeletedSuccessfully"));
            }
            catch (Exception e)
            {
                Trace.TraceError(e.Message);
                _logger.LogError(e.Message);
                return(new OperationResult(false,
                                           _caseManagementLocalizationService.GetString("ErrorWhileDeletingCalendarUser")));
            }
        }
        public async Task CalendarUserModel_Delete_DoesDelete()
        {
            // Arrange
            Random rnd = new Random();

            CalendarUser calendarUser = new CalendarUser();

            calendarUser.Color = Guid.NewGuid().ToString();
            calendarUser.IsVisibleInCalendar = rnd.Next(100) < 50;
            calendarUser.NameInCalendar      = Guid.NewGuid().ToString();
            calendarUser.SiteId        = rnd.Next(1, 255);
            calendarUser.WorkflowState = Constants.WorkflowStates.Created;
            DbContext.CalendarUsers.Add(calendarUser);
            await DbContext.SaveChangesAsync();

            //CalendarUserVersion calendarUserVer = new CalendarUserVersion();


            // Act
            CalendarUserModel calendarUserModel = new CalendarUserModel();

            calendarUserModel.Color = calendarUser.Color;
            calendarUserModel.IsVisibleInCalendar = calendarUser.IsVisibleInCalendar;
            calendarUserModel.NameInCalendar      = calendarUser.NameInCalendar;
            calendarUserModel.SiteId = calendarUser.SiteId;

            calendarUserModel.Id = calendarUser.Id;

            await calendarUserModel.Delete(DbContext);

            CalendarUser        dbCalendarUser = DbContext.CalendarUsers.AsNoTracking().First();
            List <CalendarUser> userList       = DbContext.CalendarUsers.AsNoTracking().ToList();

            //List<CalendarUserVersions> versionList = DbContext.CalendarUsersVersions.AsNoTracking().ToList();

            // Assert
            Assert.NotNull(dbCalendarUser);

            Assert.AreEqual(1, userList.Count());

            Assert.AreEqual(calendarUserModel.Color, dbCalendarUser.Color);
            Assert.AreEqual(calendarUserModel.IsVisibleInCalendar, dbCalendarUser.IsVisibleInCalendar);
            Assert.AreEqual(calendarUserModel.NameInCalendar, dbCalendarUser.NameInCalendar);
            Assert.AreEqual(calendarUserModel.SiteId, dbCalendarUser.SiteId);
            Assert.AreEqual(Constants.WorkflowStates.Removed, dbCalendarUser.WorkflowState);
        }