Beispiel #1
0
        ///<summary>
        /// Add Persistent Store with Sqlite. Connection string is current dir or otherwise specified if not null
        ///</summary>
        public static IServiceCollection AddPersistent(this IServiceCollection services, string sqliteConnection = null)
        {
            var store = new EfStore(sqliteConnection);

            services.AddSingleton <IStorageModel>(store);
            services.AddSingleton <IAuthStorageModel>(store);

            return(services);
        }
Beispiel #2
0
        private static async Task <(IStorageModel, IAuthStorageModel)> StorageFromConfig(Configuration configuration)
        {
            if (configuration.StorageModel.Equals("persistent", StringComparison.InvariantCultureIgnoreCase))
            {
                Log("using ef store with sqlite and location:  " + configuration.StorageLocation);
                var persist = new EfStore(configuration.StorageLocation);
                await persist.InitAsync();

                return(persist, persist);
            }

            Log("using in memory store!");
            // default
            var store = new InMemoryStore
                        (
                configuration.AdminName,
                configuration.AdminPassword,
                configuration.InitialAppName
                        );

            return(store, store);
        }
Beispiel #3
0
        public static async Task Run(Action <object> log)
        {
            // run migrate async
            // use efstore
            // run different tests  by using in memory service
            var persistent     = new EfStore("Data Source=./config.db");
            var memoryInteract = new MemoryInteract(persistent, persistent);

            var authModel = new AuthModel {
                Name = "timoh", Password = "******"
            };
            var appClaims = new AppClaimModel[]
            {
                new AppClaimModel()
                {
                    ApplicationName  = "test-app-1",
                    ConfigEntitiyKey = "ConnectionString",
                    CanRead          = true,
                    CanWrite         = true
                }
            };
            // add user
            var             createUser = persistent.CreateUserContext(authModel, persistent, appClaims);
            OperationResult result     = await memoryInteract.Run(new ContextModel
            {
                Type      = ContextType.AddUser,
                AppClaims = appClaims,
                User      = authModel,
                Value     = "",
                Key       = "",
            });

            Debug.Assert(result.IsSuccess);

            // create
            var changeRequest = new ConfigChangeRequest
            {
                Name  = "ConnectionString",
                Value = "/Users/timoheiten/my-db.db"
            };
            var context = new CommandContext(CommandTypes.Create, changeRequest, persistent);

            result = await Factory.RunOperationAsync(context);

            Debug.Assert(result.IsSuccess);
            // read
            result = await Factory.RunOperationAsync(persistent.QueryOne(changeRequest.Name));

            Debug.Assert(result.IsSuccess);
            Debug.Assert(result.Result.Value == changeRequest.Value);

            // delete
            result = await Factory.RunOperationAsync(persistent.DeleteContext(changeRequest.Name));

            Debug.Assert(result.IsSuccess);

            // read after delete
            result = await Factory.RunOperationAsync(persistent.QueryOne(changeRequest.Name));

            Debug.Assert(result.IsSuccess == false);
            Debug.Assert(result.ResultType == ResultType.NotFound);

            string padding = "-".PadRight(50, '-');

            System.Console.WriteLine(padding);
            System.Console.WriteLine($"if no assertion error occured, everything is working fine with EF store and Sqlite");
            System.Console.WriteLine(padding);
        }