Exemplo n.º 1
0
        public void GroupsModule_RemoveTestData()
        {
            var dataContext = new RockContext();

            // Remove Data Views
            var reportingHelper = new ReportingModuleTestHelper(_SampleDataForeignKey);

            reportingHelper.DeleteDataViewsByRecordTag(dataContext);

            // Remove Categories
            var coreHelper = new CoreModuleTestHelper(_SampleDataForeignKey);

            coreHelper.DeleteCategoriesByRecordTag(dataContext);
        }
Exemplo n.º 2
0
        public void GroupsModule_AddDataViews()
        {
            var dataContext = new RockContext();

            // Add Data View Category "Groups".
            const string categoryDataViewName = "Groups";

            Debug.Print($"Adding Data View Category \"{ categoryDataViewName }\"...");

            var entityTypeId = EntityTypeCache.Get(typeof(global::Rock.Model.DataView)).Id;

            var coreHelper = new CoreModuleTestHelper(_SampleDataForeignKey);

            var locationsCategory = coreHelper.CreateCategory(categoryDataViewName, Constants.CategoryLocationsGuid, entityTypeId);

            coreHelper.AddOrUpdateCategory(dataContext, locationsCategory);

            dataContext.SaveChanges();

            // Get Data View service.
            var service = new DataViewService(dataContext);

            int categoryId = CategoryCache.GetId(Constants.CategoryLocationsGuid) ?? 0;

            DataViewFilter rootFilter;

            // Create Data View: Locations Inside Arizona
            const string dataViewLocationsInsideArizona = "Locations in the state of Arizona";

            Debug.Print($"Adding Data View \"{ dataViewLocationsInsideArizona }\"...");

            var dataViewInside = new DataView();

            dataViewInside.IsSystem = false;

            dataViewInside.Name         = dataViewLocationsInsideArizona;
            dataViewInside.Description  = "Locations that are within the state of Arizona.";
            dataViewInside.EntityTypeId = EntityTypeCache.GetId(typeof(global::Rock.Model.Location));
            dataViewInside.CategoryId   = categoryId;
            dataViewInside.Guid         = Constants.DataViewLocationsInsideArizonaGuid;
            dataViewInside.ForeignKey   = _SampleDataForeignKey;

            rootFilter = new DataViewFilter();

            rootFilter.ExpressionType = FilterExpressionType.GroupAll;

            dataViewInside.DataViewFilter = rootFilter;

            var inStateFilter = new TextPropertyFilterSettings {
                PropertyName = "State", Comparison = ComparisonType.EqualTo, Value = "AZ"
            };

            rootFilter.ChildFilters.Add(inStateFilter.GetFilter());

            service.Add(dataViewInside);

            dataContext.SaveChanges();

            // Create Data View: Locations Outside Arizona
            const string dataViewLocationsOutsideArizona = "Locations outside Arizona";

            Debug.Print($"Adding Data View \"{ dataViewLocationsOutsideArizona }\"...");

            var dataViewOutside = new DataView();

            dataViewOutside.IsSystem = false;

            dataViewOutside.Name         = dataViewLocationsOutsideArizona;
            dataViewOutside.Description  = "Locations that are not within the state of Arizona.";
            dataViewOutside.EntityTypeId = EntityTypeCache.GetId(typeof(global::Rock.Model.Location));
            dataViewOutside.CategoryId   = categoryId;
            dataViewOutside.Guid         = Constants.DataViewLocationsOutsideArizonaGuid;
            dataViewOutside.ForeignKey   = _SampleDataForeignKey;

            rootFilter = new DataViewFilter();

            rootFilter.ExpressionType = FilterExpressionType.GroupAll;

            dataViewOutside.DataViewFilter = rootFilter;

            var notInStateFilter = new TextPropertyFilterSettings {
                PropertyName = "State", Comparison = ComparisonType.NotEqualTo, Value = "AZ"
            };

            rootFilter.ChildFilters.Add(notInStateFilter.GetFilter());

            service.Add(dataViewOutside);

            dataContext.SaveChanges();
        }