Пример #1
0
 protected override void OnStartup(StartupEventArgs e)
 {
     base.OnStartup(e);
     DiSetup.AdminApp();
     DiHelper.Register<INavigationPresenter, WpfNavigationPresenter>(Lifetime.Singleton);
     DiSetup.Initialize();
 }
        public LEMngIntegrationTests()
        {
            this.Services = DiHelper.GetServiceProvider();
            Settings      = Services.GetService <IOptions <AppSettings> >().Value;

            EnvHelper.SetAzureAccessEnvironment();
        }
Пример #3
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = "adventures/{adventureid}/choices/{choiceid?}")] HttpRequest req,
            string adventureId,
            string choiceId,
            ILogger log)
        {
            log.LogInformation("HTTP trigger function processed a request.");

            try
            {
                using (var servicesProvider = DiHelper.ConfigureServices())
                {
                    //TODO: Select container by adventure Id
                    var itemService = servicesProvider.GetService <IItemService>();

                    string status = req.Query["status"];
                    var    items  = (status?.ToUpper() == "FIRST") ?
                                    await itemService.GetRoot() :
                                    await itemService.Get(choiceId);

                    log.LogInformation("HTTP trigger function has been completed.");

                    return(items != null
                        ? (ActionResult) new OkObjectResult(items)
                        : new NotFoundResult());
                }
            }
            catch (System.Exception ex)
            {
                log.LogError(ex, ex.Message);
                throw ex;
            }
        }
            public void CreateOrUpdateAsyncWithDelegate()
            {
                DiSetup.FileDataServiceTests();
                DiSetup.InitializeFileEndpoints();

                IDataService dataService  = DiHelper.GetService <IDataService>(this.testPath);
                int          numberBefore = dataService.GetAllAsync <ValueObject <string> >("CreateOrUpdateAsyncTest5Action").GetAwaiter().GetResult().Count();

                List <ValueObject <string> > items = new List <ValueObject <string> >();

                items.Add(new ValueObject <string>("TestString1"));
                items.Add(new ValueObject <string>("TestString2"));
                items.Add(new ValueObject <string>("TestString3"));
                items.Add(new ValueObject <string>("TestString4"));

                dataService.CreateOrUpdateAsync <ValueObject <string> >("CreateOrUpdateAsyncTest5Action", items).GetAwaiter().GetResult();

                bool resultAdd    = dataService.CreateOrUpdateAsync <ValueObject <string> >("CreateOrUpdateAsyncTest5Action", new ValueObject <string>("TestString"), x => x.Value.Equals("DunnoYet")).GetAwaiter().GetResult();
                bool resultUpdate = dataService.CreateOrUpdateAsync <ValueObject <string> >("CreateOrUpdateAsyncTest5Action", new ValueObject <string>("TestString"), x => x.Value.Equals("TestString4")).GetAwaiter().GetResult();

                int numberAfterwards = dataService.GetAllAsync <ValueObject <string> >("CreateOrUpdateAsyncTest5Action").GetAwaiter().GetResult().Count();

                Assert.AreEqual(true, resultAdd);
                Assert.AreEqual(true, resultUpdate);
                Assert.AreEqual(5, numberAfterwards - numberBefore);
            }
Пример #5
0
            public void AddPermission(string PermissionName, bool IsExpectedToBeSuccessful)
            {
                DiSetup.Tests();
                IPermissionService permissionService = DiHelper.GetService <IPermissionService>();

                if (PermissionName.Equals("111") && IsExpectedToBeSuccessful.Equals(true))
                {
                    //only clear the first time
                    permissionService.Clear();
                }
                permissionService.CreateTestData();

                int numberBefore = permissionService.GetPermissions().Count();
                var result       = permissionService.AddPermission(new Permission(PermissionName));
                int numberAfter  = permissionService.GetPermissions().Count();

                Assert.IsNotNull(result);
                Assert.IsInstanceOfType(result, typeof(bool));
                if (IsExpectedToBeSuccessful)
                {
                    Assert.AreEqual(true, result);
                    Assert.AreEqual(numberAfter, numberBefore + 1);
                }
                else
                {
                    Assert.AreEqual(false, result);
                    Assert.AreEqual(numberAfter, numberBefore);
                }
            }
Пример #6
0
            public void Resolve()
            {
                DiSetup.Tests();

                TypedTestClient client = DiHelper.GetService <TypedTestClient>(new Uri("http://baseUri"));

                Assert.IsNotNull(client);
            }
Пример #7
0
        public IResult <string> Get()
        {
            var s = DiHelper.CreateInstance <SomeoneClass>();

            var x = DiHelper.GetService <IStudentServic>();

            return(this.Success(someone.SomeoneMethod() + s.SomeoneMethod() + x.GetStudent2().Result.StudentName));
        }
Пример #8
0
        public DemoMap()
        {
            InitializeComponent();
            Loaded  += WindowLoaded;
            Closing += WindowClosing;

            _container = DiHelper.GetContainer();
        }
Пример #9
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            DiHelper.AutoRegister(services);

            var connection = Configuration.GetConnectionString("MySql");

            services.AddDbContext <MyDbContext>(options =>
                                                options.UseMySql(connection));

            ////同时使用多个数据库的DEMO
            //var connection2 = Configuration.GetConnectionString("MySq2");
            //services.AddDbContext<TDbContext>(options =>
            //   options.UseMySql(connection2));

            //services.Configure<NetLoggerOption>(Configuration.GetSection("ConfigOptions:NetLoggerOption"));

            //根据需要在这里配置要使用的Option,然后在要使用的地方通过构造器注入IOptions<TOption>得到TOption
            services.Configure <TokenValidateOption>(Configuration.GetSection("SunnyOptions:TokenValidateOption"));
            services.Configure <MailOption>(Configuration.GetSection("SunnyOptions:MailOption"));
            services.Configure <IpInfoQueryOption>(Configuration.GetSection("SunnyOptions:IpInfoQueryOption"));
            //services.Configure<SmsOption>(Configuration.GetSection("SunnyOptions:SmsOption"));

            services.AddMvcCore()
            .AddFluentValidation()
            .AddJsonFormatters(x =>
            {
                x.Converters.Add(new LongConverter());
                x.Converters.Add(new DecimalConverter());
                x.DateFormatString      = "yyyy-MM-dd HH:mm:ss";
                x.ContractResolver      = new CamelCasePropertyNamesContractResolver();
                x.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
            })
            .AddCors()
            .AddFormatterMappings()
            .AddDataAnnotations()
            .AddApiExplorer();

            services.AddAutoMapper();
            services.AddDistributedRedisCache(options =>
            {
                var configOption      = Configuration.GetSection("SunnyOptions:RedisOptions").Get <RedisOption>();
                options.Configuration = configOption.ConnectionString;
                options.InstanceName  = configOption.InstanceName;
                IDistributedCacheExtend.DefaultSlidingExpiration = configOption.DefaultSlidingExpiration;
            });
            services.AddSession();
            services.AddSingleton <ISchedulerFactory, StdSchedulerFactory>();//注册ISchedulerFactory的实例。
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Info {
                    Title = "ApiDemo Project Swagger API", Version = "v1"
                });
                // 为 Swagger JSON and UI设置xml文档注释路径
                var basePath = Path.GetDirectoryName(typeof(Program).Assembly.Location);//获取应用程序所在目录(绝对,不受工作目录影响,建议采用此方法获取路径)
                var xmlPath  = Path.Combine(basePath, "ApiDemo.xml");
                c.IncludeXmlComments(xmlPath);
            });
        }
            public void IsNotNull()
            {
                DiSetup.FileDataServiceTests();

                IDataService dataService = DiHelper.GetService <IDataService>(this.testPath);

                Assert.IsNotNull(dataService);
                Assert.IsInstanceOfType(dataService, typeof(NET.efilnukefesin.Implementations.Services.DataService.FileDataService.FileDataService));
            }
            public void IsNotNull()
            {
                DiSetup.Tests();

                ITimeService timeService = DiHelper.GetService <ITimeService>();

                Assert.IsNotNull(timeService);
                Assert.IsInstanceOfType(timeService, typeof(NET.efilnukefesin.Implementations.Timing.StandardTimeService));
            }
Пример #12
0
            public void Resolve()
            {
                DiSetup.Tests();
                DiManager.GetInstance().RegisterInstance <INavigationPresenter>(new DummyNavigationPresenter());

                var navigationService = DiHelper.GetService <INavigationService>();

                Assert.IsNotNull(navigationService);
            }
            public void IsNotNull()
            {
                DiSetup.RestDataServiceTests();
                DiSetup.InitializeRestEndpoints();

                IDataService dataService = DiHelper.GetService <IDataService>(new Uri("http://baseUri"), "someToken");

                Assert.IsNotNull(dataService);
                Assert.IsInstanceOfType(dataService, typeof(NET.efilnukefesin.Implementations.Services.DataService.RestDataService.RestDataService));
            }
            public void CreateTestUsers()
            {
                DiSetup.Tests();
                IUserService userService = DiHelper.GetService <IUserService>();

                userService.CreateTestData();

                Assert.AreEqual("88421113", userService.GetUserBySubject("88421113").Logins.ToList()[0].SubjectId);
                Assert.AreEqual("Bob", userService.GetUserBySubject("88421113").Name);
            }
            public void DeleteAsync()
            {
                DiSetup.FileDataServiceTests();
                DiSetup.InitializeFileEndpoints();

                IDataService dataService = DiHelper.GetService <IDataService>(this.testPath);

                bool result = dataService.DeleteAsync <ValueObject <string> >("DeleteAsyncTest1Action", "Opel").GetAwaiter().GetResult();

                Assert.AreEqual(true, result);
            }
            public void CreateOrUpdateAsyncAppend()
            {
                DiSetup.FileDataServiceTests();
                DiSetup.InitializeFileEndpoints();

                IDataService dataService = DiHelper.GetService <IDataService>(this.testPath);

                bool result = dataService.CreateOrUpdateAsync <ValueObject <string> >("CreateOrUpdateAsyncTest1Action", new ValueObject <string>("TestString")).GetAwaiter().GetResult();

                Assert.AreEqual(true, result);
            }
            public void Exists()
            {
                DiSetup.Tests();

                IFeatureToggleManager featureToggleManager = DiHelper.GetService <IFeatureToggleManager>();

                featureToggleManager.Clear();
                featureToggleManager.Add(new StaticFeatureToggle("TestFeature", true));

                Assert.AreEqual(true, featureToggleManager.Exists("TestFeature"));
                Assert.AreEqual(false, featureToggleManager.Exists("TestFeature2"));
            }
            public void GetEndpoint()
            {
                DiSetup.RestDataServiceTests();
                IEndpointRegister endpointRegister = DiHelper.GetService <IEndpointRegister>();
                bool wasSuccessfullyAdded          = endpointRegister.AddEndpoint("SomeEndpointTest", "TestString");

                string result = endpointRegister.GetEndpoint("SomeEndpointTest");

                Assert.AreEqual(true, wasSuccessfullyAdded);
                Assert.IsNotNull(result);
                Assert.AreEqual("TestString", result);
            }
            public void JumpTo()
            {
                DiSetup.Tests();

                ITimeService timeService = DiHelper.GetService <ITimeService>();

                TimeSpan target = new TimeSpan(3, 2, 1, 59, 999);

                timeService.JumpTo(target);

                Assert.IsTrue(StandardTimeServiceTests.timeEquals(target, timeService.ElapsedTimeRelative, new TimeSpan(0, 0, 1)));
            }
            public void GetAllAsyncInt()
            {
                DiSetup.FileDataServiceTests();
                DiSetup.InitializeFileEndpoints();

                IDataService dataService = DiHelper.GetService <IDataService>(this.testPath);

                var result = dataService.GetAllAsync <ValueObject <int> >("GetAsyncTest4Action").GetAwaiter().GetResult();

                Assert.IsNotNull(result);
                Assert.AreEqual(123, result.ToList()[0].Value);
            }
Пример #21
0
            public void GetRoles()
            {
                DiSetup.Tests();
                IRoleService roleService = DiHelper.GetService <IRoleService>();

                roleService.CreateTestData();

                var result = roleService.GetRoles();

                Assert.IsNotNull(result);
                Assert.IsInstanceOfType(result, typeof(IEnumerable <Role>));
            }
Пример #22
0
            public void GetPermissions()
            {
                DiSetup.Tests();
                IPermissionService permissionService = DiHelper.GetService <IPermissionService>();

                permissionService.Clear();
                permissionService.CreateTestData();

                var result = permissionService.GetPermissions();

                Assert.IsNotNull(result);
                Assert.IsInstanceOfType(result, typeof(IEnumerable <Permission>));
            }
        public async Task KeyVaultKeyCache_Success()
        {
            var services = DiHelper.GetServiceProviderKeyCache <AcmeKeyVaultCache>();

            var key           = KeyFactory.NewKey(KeyAlgorithm.ES256);
            var cacheProvider = services.GetService <IAcmeKeyCache>();

            await cacheProvider.SaveAccountKey(key);

            var key2 = await cacheProvider.GetAccountKey();

            Assert.Equal(key.ToPem(), key2.ToPem());
        }
            public void AddVersionbasedFeatureToggle()
            {
                DiSetup.Tests();

                IFeatureToggleManager featureToggleManager = DiHelper.GetService <IFeatureToggleManager>();

                featureToggleManager.Clear();
                featureToggleManager.Add(new VersionbasedFeatureToggle("TestFeature", new Version(0, 8), this.GetType()));
                featureToggleManager.Add(new VersionbasedFeatureToggle("TestFeature2", new Version(1, 0), this.GetType()));

                //Assert.AreEqual(true, featureToggleManager.GetValue("TestFeature"));
                //Assert.AreEqual(false, featureToggleManager.GetValue("TestFeature2"));
            }
        //[TestMethod]
        public async Task AskSpecialEndpoint()
        {
            DiSetup.RestDataServiceTests();
            DiSetup.InitializeRestEndpoints();

            this.startLocalServer();

            IDataService dataService = DiHelper.GetService <IDataService>(this.localServerUri, this.getHttpClientHandler());

            var result = await dataService.GetAsync <ValueObject <bool> >("SpecialValueStore", "1", "Hello World");

            Assert.IsNotNull(result);
            Assert.AreEqual(true, result.Value);
        }
Пример #26
0
            public void GetPermissions()
            {
                DiSetup.Tests();
                IUserService userService = DiHelper.GetService <IUserService>();

                userService.Clear();
                userService.CreateTestData();
                AuthenticationService authenticationService = DiHelper.GetService <AuthenticationService>();

                var result = authenticationService.GetPermissions();

                Assert.IsNotNull(result);
                Assert.IsTrue(result.Count() > 0);
            }
        //[TestMethod]
        public async Task SimpleCallWithDataService()
        {
            DiSetup.RestDataServiceTests();
            DiSetup.InitializeRestEndpoints();

            this.startLocalServer();

            IDataService dataService = DiHelper.GetService <IDataService>(this.localServerUri, this.getHttpClientHandler());

            var result = await dataService.GetAllAsync <ValueObject <string> >("ValueStore");

            Assert.IsNotNull(result);
            Assert.AreEqual(3, result.Count());
        }
Пример #28
0
            public void GetPermissionByName()
            {
                DiSetup.Tests();
                IPermissionService permissionService = DiHelper.GetService <IPermissionService>();

                permissionService.Clear();
                permissionService.CreateTestData();

                var result = permissionService.GetPermissionByName("User");

                Assert.IsNotNull(result);
                Assert.IsInstanceOfType(result, typeof(Permission));
                Assert.AreEqual("User", result.Name);
            }
            public void CreateOrUpdateAsyncCreateNewWithLists()
            {
                DiSetup.FileDataServiceTests();
                DiSetup.InitializeFileEndpoints();

                IDataService dataService = DiHelper.GetService <IDataService>(this.testPath);
                List <ValueObject <string> > stringList = new List <ValueObject <string> >()
                {
                    new ValueObject <string>("a"), new ValueObject <string>("b"), new ValueObject <string>("c")
                };

                bool result = dataService.CreateOrUpdateAsync <ValueObject <string> >("CreateOrUpdateAsyncTest4Action", stringList).GetAwaiter().GetResult();

                Assert.AreEqual(true, result);
            }
Пример #30
0
            public void DeleteAsyncNotFound()
            {
                DiSetup.Tests();

                var handlerMock = this.messageHandlerMockFaker(new HttpResponseMessage()
                {
                    StatusCode = HttpStatusCode.NotFound
                });

                TypedTestClient client = DiHelper.GetService <TypedTestClient>(new Uri("http://baseUri"), handlerMock.Object);
                bool            result = client.DeleteAsync(1).GetAwaiter().GetResult();

                Assert.IsNotNull(result);
                Assert.AreEqual(false, result);
            }