public static void initIntegrationTest(TestContext context)
        {
            var cfp = new MongoDbConfigurationProvider()
            {
                env_name = nameof(IntegrationTests)
            };

            context.setGlobalObject <IConfigurationProvider>(cfp);

            //context.getMystery().AssemblyRegister.Register(typeof(MysteryTests.BaseMysteryTest).Assembly);
            context.getMystery().AssemblyRegister.Register(typeof(MysteryDMS.Model.DMSFolder).Assembly);
            context.getMystery().AssemblyRegister.Register(typeof(WebContentDispatcher).Assembly);

            MysterySession        session = context.getGlobalObject <MysterySession>();
            IGlobalContentCreator cc      = context.getGlobalObject <IGlobalContentCreator>();

            session.authenticated_user = cc.getNewContent <User>();
            session.authenticated_user.account_type = UserType.admin;

            context.setGlobalObject <IContentDispatcher>(new ContentMemory());
            context.setGlobalObject <INotifier>(new MongoMockNotifier());

            ContentsDatabase db = context.getGlobalObject <ContentsDatabase>();

            db.can_do_crazy = true;
            db.Clear();
            db.Add(session.authenticated_user);
        }
        public void Load_should_set_data()
        {
            var reader = new MongoDbReaderBuilder()
                         .AddSetting("setting1", "value1")
                         .AddSetting("setting2", "value2")
                         .Build();

            var provider = new MongoDbConfigurationProvider(reader, "settings");

            provider.Load();

            Assert.True(provider.TryGet("setting1", out var value1));
            Assert.True(provider.TryGet("setting2", out var value2));
            Assert.False(provider.TryGet("setting3", out var value3));
            Assert.Equal("value1", value1);
            Assert.Equal("value2", value2);
            Assert.True(provider.TryGet("SeTTing1", out value1));
            Assert.Equal("value1", value1);
        }
Example #3
0
        public static void initIntegrationTest(TestContext context)
        {
            var cfp = new MongoDbConfigurationProvider()
            {
                env_name = nameof(IntegrationTests)
            };

            context.setGlobalObject <IConfigurationProvider>(cfp);

            context.getMystery().AssemblyRegister.Register(typeof(MysteryTests.BaseMysteryTest).Assembly);
            context.getMystery().AssemblyRegister.Register(typeof(DatabaseTest).Assembly);
            context.getMystery().AssemblyRegister.Register(typeof(WebContentDispatcher).Assembly);

            MysterySession        session = context.getGlobalObject <MysterySession>();
            IGlobalContentCreator cc      = context.getGlobalObject <IGlobalContentCreator>();

            session.authenticated_user = cc.getNewContent <User>();
            session.authenticated_user.account_type = UserType.admin;

            context.setGlobalObject <IContentDispatcher>(new ContentMemory());
            context.setGlobalObject <INotifier>(new MongoMockNotifier());

            ContentsDatabase db = context.getGlobalObject <ContentsDatabase>();

            db.can_do_crazy = true;
            db.Add(session.authenticated_user);
            IContent c = cc.getNewContent <TestContentType>();

            db.Add(c);
            db.Clear();

            //cleaning for tests
            var test_folder_files = context.getGlobalObject <IConfigurationProvider>()
                                    .getConfiguration <MongoFsFileRepositoryConfiguration>()
                                    .files_root_folder;

            if (test_folder_files.Exists)
            {
                foreach (var sub_folder in test_folder_files.GetDirectories())
                {
                    sub_folder.Delete(true);
                }
            }

            var content_db = context.getGlobalObject <MysteryMongoDb>().content_db;

            content_db.DropCollection(nameof(MongoFsSingleCopyFileRepository));

            content_db.DropCollection(MongoDBHistoryRepository.collectionName);


            var client = new MongoClient();

            client.DropDatabase("testDb");
            var mongo_db = client.GetDatabase("testDb");

            collection = mongo_db.GetCollection <BsonDocument>(nameof(TestContentType));
            var converter = context.getGlobalObject <IMysteryJsonConverter>();

            collection.InsertOne(BsonDocument.Parse(converter.getJson(c)));
        }