Пример #1
0
        public async void Index_ReturnsAViewResult()
        {
            //Arrange
            EventTypesController eventtypescontroller = new EventTypesController(context);

            //Act
            var result = await eventtypescontroller.Index(null, "", "", null);

            //Assert
            Assert.IsType <ViewResult>(result);
        }
Пример #2
0
        public async Task Index_ReturnsAViewResult_WithAListOfEventTypes()
        {
            //Arrange
            var dbContext = await GetDatabaseContext();

            var eventTypesController = new EventTypesController(dbContext);
            //Act
            var result = await eventTypesController.Index("", "", "", null);

            // Assert
            var viewResult = Assert.IsType <ViewResult>(result);
            var model      = Assert.IsAssignableFrom <IEnumerable <EventType> >(
                viewResult.ViewData.Model);

            Assert.Equal(2, model.Count());
        }
Пример #3
0
        public void EventTypesListTest()
        {
            var account             = TestHelper.GetTestAccount();
            var user                = TestHelper.GetAccountAdminUser(account.Id);
            var accountContext      = AccountDbContext.CreateFromAccountId(account.Id);
            var eventTypeRepository = accountContext.GetEventTypeRepository();

            // Создадим три типа событий
            // ComponentEvent, Info
            var eventType1 = new EventType()
            {
                Category            = EventCategory.ComponentEvent,
                DisplayName         = "Тестовый тип события " + DateTime.Now.Ticks + " ComponentEvent, Info",
                ImportanceForNew    = EventImportance.Success,
                JoinIntervalSeconds = 0,
                SystemName          = "EventType.Test " + DateTime.Now.Ticks + " ComponentEvent, Info"
            };

            eventType1 = eventTypeRepository.GetOrCreate(eventType1);

            // ComponentEvent, Alarm
            var eventType2 = new EventType()
            {
                Category            = EventCategory.ComponentEvent,
                DisplayName         = "Тестовый тип события " + DateTime.Now.Ticks + " ComponentEvent, Alarm",
                ImportanceForNew    = EventImportance.Alarm,
                JoinIntervalSeconds = 0,
                SystemName          = "EventType.Test " + DateTime.Now.Ticks + " ComponentEvent, Alarm"
            };

            eventType2 = eventTypeRepository.GetOrCreate(eventType2);

            // ApplicationError, Alarm
            var eventType3 = new EventType()
            {
                Category            = EventCategory.ApplicationError,
                DisplayName         = "Тестовый тип события " + DateTime.Now.Ticks + " ApplicationError, Alarm",
                ImportanceForNew    = EventImportance.Alarm,
                JoinIntervalSeconds = 0,
                SystemName          = "EventType.Test " + DateTime.Now.Ticks + " ApplicationError, Alarm"
            };

            eventType3 = eventTypeRepository.GetOrCreate(eventType3);

            // Проверим, что на странице без фильтров есть только типы с категорией ComponentEvent
            using (var controller = new EventTypesController(account.Id, user.Id))
            {
                var result = (ViewResultBase)controller.Index();
                var model  = (EventTypesListModel)result.Model;
                var types  = model.EventTypes.ToList();
                Assert.True(types.Any(t => t.Id == eventType1.Id));
                Assert.True(types.Any(t => t.Id == eventType2.Id));
                Assert.False(types.Any(t => t.Id == eventType3.Id));
            }

            // Проверим фильтр по категории
            using (var controller = new EventTypesController(account.Id, user.Id))
            {
                var result = (ViewResultBase)controller.Index(category: "ApplicationError");
                var model  = (EventTypesListModel)result.Model;
                Assert.False(model.EventTypes.Any(t => t.Id == eventType1.Id));
                Assert.False(model.EventTypes.Any(t => t.Id == eventType2.Id));
                Assert.True(model.EventTypes.Any(t => t.Id == eventType3.Id));
            }

            // Проверим фильтр по важности
            using (var controller = new EventTypesController(account.Id, user.Id))
            {
                var result = (ViewResultBase)controller.Index(importance: "Alarm");
                var model  = (EventTypesListModel)result.Model;
                Assert.False(model.EventTypes.Any(t => t.Id == eventType1.Id));
                Assert.True(model.EventTypes.Any(t => t.Id == eventType2.Id));
                Assert.False(model.EventTypes.Any(t => t.Id == eventType3.Id));
            }

            // Проверим фильтр по названию
            using (var controller = new EventTypesController(account.Id, user.Id))
            {
                var result = (ViewResultBase)controller.Index(search: eventType1.SystemName);
                var model  = (EventTypesListModel)result.Model;
                Assert.True(model.EventTypes.Any(t => t.Id == eventType1.Id));
                Assert.False(model.EventTypes.Any(t => t.Id == eventType2.Id));
                Assert.False(model.EventTypes.Any(t => t.Id == eventType3.Id));
            }
            using (var controller = new EventTypesController(account.Id, user.Id))
            {
                var result = (ViewResultBase)controller.Index(category: "ApplicationError", search: eventType3.DisplayName);
                var model  = (EventTypesListModel)result.Model;
                Assert.False(model.EventTypes.Any(t => t.Id == eventType1.Id));
                Assert.False(model.EventTypes.Any(t => t.Id == eventType2.Id));
                Assert.True(model.EventTypes.Any(t => t.Id == eventType3.Id));
            }

            //Проверим фильтр по удалённым
            eventTypeRepository.Remove(eventType2);

            using (var controller = new EventTypesController(account.Id, user.Id))
            {
                var result = (ViewResultBase)controller.Index();
                var model  = (EventTypesListModel)result.Model;
                Assert.True(model.EventTypes.Any(t => t.Id == eventType1.Id));
                Assert.False(model.EventTypes.Any(t => t.Id == eventType2.Id));
                Assert.False(model.EventTypes.Any(t => t.Id == eventType3.Id));
            }

            using (var controller = new EventTypesController(account.Id, user.Id))
            {
                var result = (ViewResultBase)controller.Index(showDeleted: 1);
                var model  = (EventTypesListModel)result.Model;
                Assert.True(model.EventTypes.Any(t => t.Id == eventType1.Id));
                Assert.True(model.EventTypes.Any(t => t.Id == eventType2.Id));
                Assert.False(model.EventTypes.Any(t => t.Id == eventType3.Id));
            }
        }