Example #1
0
 public static EventType GetTestEventType(Guid accountId)
 {
     using (var accountContext = AccountDbContext.CreateFromAccountId(accountId))
     {
         IEventTypeRepository eventTypeRepository = new EventTypeRepository(accountContext);
         var eventType = new EventType()
         {
             Category            = Core.Api.EventCategory.ComponentEvent,
             DisplayName         = "Тестовый тип события " + DateTime.Now.ToString("yyyy-MM-dd HH"),
             ImportanceForNew    = Core.Api.EventImportance.Success,
             JoinIntervalSeconds = 5,
             SystemName          = "EventType.Test " + DateTime.Now.ToString("yyyy-MM-dd HH")
         };
         eventType = eventTypeRepository.GetOrCreate(eventType);
         return(eventType);
     }
 }
        public void EventTypeDeleteTest()
        {
            var account = TestHelper.GetTestAccount();
            var user    = TestHelper.GetAccountAdminUser(account.Id);

            DeleteConfirmationModel model;
            string systemName;

            using (var accountContext = AccountDbContext.CreateFromAccountId(account.Id))
            {
                var eventTypeRepository = new EventTypeRepository(accountContext);
                var eventType           = new EventType()
                {
                    Category            = EventCategory.ComponentEvent,
                    DisplayName         = "Тестовый тип события " + DateTime.Now.Ticks,
                    ImportanceForNew    = EventImportance.Success,
                    JoinIntervalSeconds = 0,
                    SystemName          = "EventType.Test " + DateTime.Now.Ticks
                };
                eventType  = eventTypeRepository.GetOrCreate(eventType);
                systemName = eventType.SystemName;

                using (var controller = new EventTypesController(account.Id, user.Id))
                {
                    var result = (ViewResultBase)controller.Delete(eventType.Id);
                    model = (DeleteConfirmationModel)result.Model;
                }
                using (var controller = new EventTypesController(account.Id, user.Id))
                {
                    controller.Delete(model);
                }
            }

            using (var accountContext = AccountDbContext.CreateFromAccountId(account.Id))
            {
                var eventTypeRepository = new EventTypeRepository(accountContext);
                var eventType           = eventTypeRepository.GetById(Guid.Parse(model.Id));
                Assert.NotNull(eventType);
                Assert.True(eventType.IsDeleted);
                eventType = eventTypeRepository.GetOneOrNullBySystemName(systemName);
                Assert.Null(eventType);
            }
        }