示例#1
0
        public async Task Create_Update_Delete_Module_Test()
        {
            var list = new List <ModuleCreateDto>
            {
                new ModuleCreateDto
                {
                    AppUrl             = "~/Admin/Dashboard/Index",
                    ClassName          = "fa fa-dashboard",
                    Description        = "Dashboard",
                    DisplayAsFrontMenu = false,
                    DisplayAsMenu      = true,
                    DisplayName        = "Dashboard",
                    FrontUrl           = "#",
                    IsActive           = true,
                    ModuleCode         = "CMS.Admin.Dashboard",
                    Order    = 1,
                    ParentId = null
                }, new ModuleCreateDto
                {
                    AppUrl             = "#",
                    ClassName          = "fa fa-cog",
                    Description        = "Setup",
                    DisplayAsFrontMenu = false,
                    DisplayAsMenu      = true,
                    DisplayName        = "Setup",
                    FrontUrl           = "#",
                    IsActive           = true,
                    ModuleCode         = "CMS.Admin.Setup",
                    Order    = 2,
                    ParentId = null
                }
            };

            foreach (var item in list)
            {
                await _moduleAppService.Create(item);
            }

            var setupModule = await _moduleAppService.GetModule("CMS.Admin.Setup");

            setupModule.ShouldNotBe(null);
            setupModule.ModuleCode.ShouldBe("CMS.Admin.Setup");

            Guid parentid = setupModule.Id;
            var  setups   = new List <ModuleCreateDto>
            {
                new ModuleCreateDto
                {
                    AppUrl             = "~/Admin/Users/Index",
                    ClassName          = "",
                    Description        = "Users",
                    DisplayAsFrontMenu = false,
                    DisplayAsMenu      = true,
                    DisplayName        = "Users",
                    FrontUrl           = "#",
                    IsActive           = true,
                    ModuleCode         = "CMS.Admin.Users",
                    Order    = 1,
                    ParentId = parentid
                }, new ModuleCreateDto
                {
                    AppUrl             = "~/Admin/Roles/Index",
                    ClassName          = "",
                    Description        = "Roles",
                    DisplayAsFrontMenu = false,
                    DisplayAsMenu      = true,
                    DisplayName        = "Roles",
                    FrontUrl           = "#",
                    IsActive           = true,
                    ModuleCode         = "CMS.Admin.Roles",
                    Order    = 2,
                    ParentId = parentid
                }, new ModuleCreateDto
                {
                    AppUrl             = "~/Admin/Actions/Index",
                    ClassName          = "",
                    Description        = "Actions",
                    DisplayAsFrontMenu = false,
                    DisplayAsMenu      = true,
                    DisplayName        = "Actions",
                    FrontUrl           = "#",
                    IsActive           = true,
                    ModuleCode         = "CMS.Admin.Actions",
                    Order    = 3,
                    ParentId = parentid
                }, new ModuleCreateDto
                {
                    AppUrl             = "~/Admin/Modules/Index",
                    ClassName          = "",
                    Description        = "Modules",
                    DisplayAsFrontMenu = false,
                    DisplayAsMenu      = true,
                    DisplayName        = "Modules",
                    FrontUrl           = "#",
                    IsActive           = true,
                    ModuleCode         = "CMS.Admin.Modules",
                    Order    = 4,
                    ParentId = parentid
                }, new ModuleCreateDto
                {
                    AppUrl             = "~/Admin/RoleRights/Index",
                    ClassName          = "",
                    Description        = "Role Rights",
                    DisplayAsFrontMenu = false,
                    DisplayAsMenu      = true,
                    DisplayName        = "Role Rights",
                    FrontUrl           = "#",
                    IsActive           = true,
                    ModuleCode         = "CMS.Admin.RoleRights",
                    Order    = 5,
                    ParentId = parentid
                }, new ModuleCreateDto
                {
                    AppUrl             = "~/Admin/Tests/Index",
                    ClassName          = "",
                    Description        = "Tests",
                    DisplayAsFrontMenu = false,
                    DisplayAsMenu      = true,
                    DisplayName        = "Tests",
                    FrontUrl           = "#",
                    IsActive           = true,
                    ModuleCode         = "CMS.Admin.Tests",
                    Order    = 6,
                    ParentId = parentid
                }
            };

            foreach (var item in setups)
            {
                await _moduleAppService.Create(item);
            }

            var module = await _moduleAppService.GetModule("CMS.Admin.Tests");

            module.ShouldNotBe(null);
            module.ModuleCode.ShouldBe("CMS.Admin.Tests");

            module.DisplayName = "Tests : just a test";

            await _moduleAppService.Update(module);

            module = await _moduleAppService.GetModule("CMS.Admin.Tests");

            module.DisplayName.ShouldBe("Tests : just a test");

            await _moduleAppService.Delete(new Abp.Application.Services.Dto.IdInput <Guid> {
                Id = module.Id
            });

            var rs = await _moduleAppService.GetModule(new Abp.Application.Services.Dto.IdInput <Guid> {
                Id = module.Id
            });

            rs.ShouldBe(null);
        }