/// <summary>
 /// Adds the application.
 /// </summary>
 /// <param name="services">The services.</param>
 /// <param name="startupModuleType">Type of the startup module.</param>
 /// <param name="optionsAction">The options action.</param>
 /// <returns>IApplicationWithExternalServiceProvider.</returns>
 public static IApplicationWithExternalServiceProvider AddApplication(
     [NotNull] this IServiceCollection services,
     [NotNull] Type startupModuleType,
     [CanBeNull] Action <ApplicationCreationOptions> optionsAction = null)
 {
     return(ApplicationFactory.Create(startupModuleType, services, optionsAction));
 }
Exemplo n.º 2
0
        public void WhenInputIsValidTheOutputContainsValidResult()
        {
            var applicationFactory = new ApplicationFactory();
            var input  = new TestInput("15");
            var output = new TestOutput();

            applicationFactory
            .Create(input, output)
            .Execute();

            var          actual   = output.Outputs.Last();
            const string expected =
                @"1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
";

            Assert.That(actual, Is.EqualTo(expected));
        }
 /// <summary>
 /// Adds the application.
 /// </summary>
 /// <typeparam name="TStartupModule">The type of the t startup module.</typeparam>
 /// <param name="services">The services.</param>
 /// <param name="optionsAction">The options action.</param>
 /// <returns>IApplicationWithExternalServiceProvider.</returns>
 public static IApplicationWithExternalServiceProvider AddApplication <TStartupModule>(
     [NotNull] this IServiceCollection services,
     [CanBeNull] Action <ApplicationCreationOptions> optionsAction = null)
     where TStartupModule : IModule
 {
     return(ApplicationFactory.Create <TStartupModule>(services, optionsAction));
 }
        static void Main(string[] args)
        {
            var app = ApplicationFactory.Create();

            app.RegisterType <IArgs, Args>();
            app.RegisterType <IWorker, Worker>();
            app.Run <IWorker>(w => w.DoSomeWork());
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            var applicationFactory = new ApplicationFactory();
            var consoleInput       = new ConsoleInput();
            var consoleOutput      = new ConsoleOutput();
            var application        = applicationFactory.Create(consoleInput, consoleOutput);

            application.Execute();
        }
Exemplo n.º 6
0
        public async Task CreateApplication()
        {
            TestUtils.GetContextWithApplications(nameof(CreateApplication));
            var emailId = Guid.NewGuid();

            using (var assertContext = new SystemDataContext(TestUtils.GetOptions(nameof(CreateApplication))))
            {
                var sut = new ApplicationFactory();

                var application = sut.Create(emailId.ToString(), "userId", "1111", "testName", "+1111");

                Assert.AreEqual(emailId, application.EmailId);
            }
        }
Exemplo n.º 7
0
        public void WhenBadInputIsEnteredThenErrorMessageIsShown(string inputString, string expected)
        {
            var applicationFactory = new ApplicationFactory();
            var input  = new TestInput(inputString);
            var output = new TestOutput();

            applicationFactory
            .Create(input, output)
            .Execute();

            var actual = output.Outputs.Last();

            Assert.That(actual, Is.EqualTo(expected));
        }
Exemplo n.º 8
0
        public async Task <Application> Create(ApplicationCreateRequest dto)
        {
            var application =
                _applicationFactory.Create(dto.CreatorId, dto.Name, dto.Description, dto.WebsiteUrl, dto.RedirectUrl);

            bool anyExistingApps = await _context.Application.AsNoTracking().AnyAsync().ConfigureAwait(false);

            if (!anyExistingApps)
            {
                _applicationFactory.SetFirstPartyApplication(application);
            }

            await _context.Application.AddAsync(application).ConfigureAwait(false);

            await _context.SaveChangesAsync().ConfigureAwait(false);

            return(application);
        }
Exemplo n.º 9
0
        public void PerResolve()
        {
            //arrange
            var maxInstances = 100;
            var app          = ApplicationFactory.Create();

            app.RegisterType <ICommon, Common>(InstanceScope.PerResolve);
            app.RegisterType <IUser1, User1>();
            app.RegisterType <IUser2, User2>();

            //act
            var count = Enumerable.Range(0, maxInstances)
                        .Select(x => app.Resolve <IUser2>())
                        .SelectMany(x => new[] { x.Common.Id, x.User1.Common.Id })
                        .Distinct()
                        .Count();

            //assert

            Assert.AreEqual(maxInstances, count);
        }
Exemplo n.º 10
0
 /// <summary>
 /// 转换为应用程序实体
 /// </summary>
 /// <param name="dto">应用程序数据传输对象</param>
 public static Application ToEntity3(this ApplicationDto dto)
 {
     if (dto == null)
     {
         return(new Application());
     }
     return(ApplicationFactory.Create(
                appId: dto.Id.ToGuid(),
                name: dto.Name,
                clientId: dto.ClientId,
                note: dto.Note,
                isEnabled: dto.IsEnabled,
                versionNo: dto.VersionNo,
                creationTime: dto.CreationTime,
                creatorId: dto.CreatorId,
                lastModificationTime: dto.LastModificationTime,
                lastModifierId: dto.LastModifierId,
                isDeleted: dto.IsDeleted,
                version: dto.Version
                ));
 }
Exemplo n.º 11
0
 /// <summary>
 /// 初始化种子数据
 /// </summary>
 /// <param name="applicationContext">DbContext上下文</param>
 /// <returns></returns>
 public static async Task InitializeAsync(IExamDbContext applicationContext)
 {
     try
     {
         // 初始化权限
         if (!await applicationContext.Permissions.AnyAsync())
         {
             var lstPerms = new List <PermissionInfo>
             {
                 //module
                 new PermissionInfo {
                     Remarks = "暂无", LevelID = 0, TypeAt = 21, Named = "系统管理", Command = "sys", Enabled = true
                 },
                 new PermissionInfo {
                     Remarks = "暂无", LevelID = 0, TypeAt = 21, Named = "班级管理", Command = "cls", Enabled = true
                 },
                 new PermissionInfo {
                     Remarks = "暂无", LevelID = 0, TypeAt = 21, Named = "教师管理", Command = "thr", Enabled = true
                 },
                 new PermissionInfo {
                     Remarks = "暂无", LevelID = 0, TypeAt = 21, Named = "学生管理", Command = "stu", Enabled = true
                 },
                 new PermissionInfo {
                     Remarks = "暂无", LevelID = 0, TypeAt = 21, Named = "考试管理", Command = "exam", Enabled = true
                 },
                 //module/controllers
                 new PermissionInfo {
                     Remarks = "暂无", LevelID = 1, TypeAt = 22, Named = "站点设置", Command = "settings", Enabled = true
                 },
                 new PermissionInfo {
                     Remarks = "暂无", LevelID = 1, TypeAt = 22, Named = "开发者设置", Command = "developer", Enabled = true
                 },
                 new PermissionInfo {
                     Remarks = "暂无", LevelID = 1, TypeAt = 22, Named = "权限设置", Command = "permission", Enabled = true
                 },
                 new PermissionInfo {
                     Remarks = "暂无", LevelID = 1, TypeAt = 22, Named = "角色设置", Command = "role", Enabled = true
                 },
                 new PermissionInfo {
                     Remarks = "暂无", LevelID = 1, TypeAt = 22, Named = "菜单设置", Command = "menu", Enabled = true
                 },
                 new PermissionInfo {
                     Remarks = "暂无", LevelID = 1, TypeAt = 22, Named = "报表设置", Command = "report", Enabled = true
                 },
                 //module/controller/actions
                 new PermissionInfo {
                     Remarks = "暂无", LevelID = 6, TypeAt = 23, Named = "站点设置1", Command = "action1", Enabled = true
                 },
                 new PermissionInfo {
                     Remarks = "暂无", LevelID = 6, TypeAt = 23, Named = "站点设置2", Command = "action2", Enabled = true
                 },
                 new PermissionInfo {
                     Remarks = "暂无", LevelID = 7, TypeAt = 23, Named = "开发者设置1", Command = "action1", Enabled = true
                 },
                 new PermissionInfo {
                     Remarks = "暂无", LevelID = 7, TypeAt = 23, Named = "开发者设置2", Command = "action2", Enabled = true
                 },
                 new PermissionInfo {
                     Remarks = "暂无", LevelID = 8, TypeAt = 23, Named = "编辑", Command = "edit", Enabled = true
                 },
                 new PermissionInfo {
                     Remarks = "暂无", LevelID = 8, TypeAt = 23, Named = "删除", Command = "remove", Enabled = true
                 },
                 new PermissionInfo {
                     Remarks = "暂无", LevelID = 8, TypeAt = 23, Named = "浏览", Command = "browse", Enabled = true
                 },
                 new PermissionInfo {
                     Remarks = "暂无", LevelID = 9, TypeAt = 23, Named = "新增", Command = "add", Enabled = true
                 },
                 new PermissionInfo {
                     Remarks = "暂无", LevelID = 9, TypeAt = 23, Named = "删除", Command = "remove", Enabled = true
                 },
                 new PermissionInfo {
                     Remarks = "暂无", LevelID = 9, TypeAt = 23, Named = "编辑", Command = "edit", Enabled = true
                 },
                 new PermissionInfo {
                     Remarks = "暂无", LevelID = 9, TypeAt = 23, Named = "浏览", Command = "browse", Enabled = true
                 },
                 new PermissionInfo {
                     Remarks = "暂无", LevelID = 10, TypeAt = 23, Named = "新增", Command = "add", Enabled = true
                 },
                 new PermissionInfo {
                     Remarks = "暂无", LevelID = 10, TypeAt = 23, Named = "删除", Command = "remove", Enabled = true
                 },
                 new PermissionInfo {
                     Remarks = "暂无", LevelID = 10, TypeAt = 23, Named = "编辑", Command = "edit", Enabled = true
                 },
                 new PermissionInfo {
                     Remarks = "暂无", LevelID = 10, TypeAt = 23, Named = "浏览", Command = "browse", Enabled = true
                 },
                 new PermissionInfo {
                     Remarks = "暂无", LevelID = 11, TypeAt = 23, Named = "导出", Command = "export", Enabled = true
                 },
                 new PermissionInfo {
                     Remarks = "暂无", LevelID = 11, TypeAt = 23, Named = "浏览", Command = "browse", Enabled = true
                 },
             };
             await applicationContext.Permissions.AddRangeAsync(lstPerms);
         }
         // 初始化角色
         if (!await applicationContext.Roles.AnyAsync())
         {
             var lstRoles = new List <RoleInfo>
             {
                 ApplicationFactory.Create <RoleInfo>(func: r =>
                 {
                     r.Name    = "管理员";
                     r.Code    = "admin";
                     r.Remarks = "暂无";
                     return(r);
                 }),
                 ApplicationFactory.Create <RoleInfo>(func: r =>
                 {
                     r.Name    = "教师";
                     r.Code    = "teacher";
                     r.Remarks = "暂无";
                     return(r);
                 }),
                 ApplicationFactory.Create <RoleInfo>(func: r =>
                 {
                     r.Name    = "学生";
                     r.Code    = "student";
                     r.Remarks = "暂无";
                     return(r);
                 })
             };
             await applicationContext.Roles.AddRangeAsync(lstRoles);
         }
         // 初始化角色授权
         if (!await applicationContext.RoleAuthorizes.AnyAsync())
         {
             var lstAuthorizes = new List <RoleAuthorize>();
             for (int i = 1; i <= 28; i++)
             {
                 lstAuthorizes.Add(ApplicationFactory.Create <RoleAuthorize>(func: src =>
                 {
                     src.RoleInformation       = applicationContext.Roles.FirstOrDefault(p => p.Code == "admin");
                     src.PermissionInformation = applicationContext.Permissions.FirstOrDefault(p => p.ID == i);
                     return(src);
                 }));
             }
             await applicationContext.RoleAuthorizes.AddRangeAsync(lstAuthorizes);
         }
         // 初始化用户
         if (!await applicationContext.Users.AnyAsync())
         {
             await applicationContext.Users.AddAsync(ApplicationFactory.Create <UserInfo>(func: src =>
             {
                 src.Remarks    = "管理员";
                 src.Account    = "sysadmin";
                 src.Pwd        = "a1234567";
                 src.Name       = "吴嘉";
                 src.Gender     = 0;
                 src.Age        = 39;
                 src.Tel        = "18673968186";
                 src.CreateDate = DateTime.Now;
                 return(src);
             }));
         }
         // 初始化用户角色
         if (!await applicationContext.UserRoles.AnyAsync())
         {
             await applicationContext.UserRoles.AddAsync(ApplicationFactory.Create <UserRole>(func: src =>
             {
                 src.RoleInfomation = applicationContext.Roles.FirstOrDefault(p => p.Code == "admin");
                 src.UserInfomation = applicationContext.Users.FirstOrDefault(p => p.Account == "sysadmin");
                 return(src);
             }));
         }
         // 初始化菜单
         if (!await applicationContext.Menus.AnyAsync())
         {
             var lstMenu = new List <MenuInfo>
             {
                 ApplicationFactory.Create <MenuInfo>(p =>
                 {
                     p.Remarks = "暂无";
                     p.Title   = "首页";
                     p.PathUrl = "/home/index";
                     p.Enabled = true;
                     return(p);
                 }),
                 ApplicationFactory.Create <MenuInfo>(p =>
                 {
                     p.Remarks = "暂无";
                     p.Title   = "关于";
                     p.PathUrl = "/home/about";
                     p.Enabled = true;
                     return(p);
                 })
             };
             await applicationContext.Menus.AddRangeAsync(lstMenu);
         }
         // 保存更改
         await applicationContext.SaveChangesAsync();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 12
0
 public WebApiApplication()
 {
     this.application = ApplicationFactory.Create <HttpApplication>(ApplicationType.WebApi, this);
 }
Exemplo n.º 13
0
 public static IApplication AddApplication(this IServiceCollection services, Type entryModule, Action <ApplicationCreationOptions> optionsAction = null)
 {
     return(ApplicationFactory.Create(entryModule, services, optionsAction));
 }
Exemplo n.º 14
0
 public static IApplication AddApplication <TEntryModule>(this IServiceCollection services, Action <ApplicationCreationOptions> optionsAction = null)
     where TEntryModule : IAppEntryModule
 {
     return(ApplicationFactory.Create <TEntryModule>(services, optionsAction));
 }