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 SigleReferenceSuggestionsActionCanNotTest()
        {
            using (WebActionExecutor executor = new WebActionExecutor())
            {
                //we add Adriano in db
                TestContentType  adriano = TestContentType.getARandomTestContentType(enforce_a_reference: true);
                ContentsDatabase db      = this.getGlobalObject <ContentsDatabase>();
                db.Add(adriano);
                //we became not admin
                MysterySession session  = this.getGlobalObject <MysterySession>();
                var            was_adim = session.authenticated_user.account_type == UserType.admin;
                if (was_adim)
                {
                    session.authenticated_user.account_type = UserType.normal;
                }

                var result = executor.executeAction(
                    new SigleReferenceSuggestionsAction(),
                    new PropertyEditSuggestionsActionInput
                {
                    content_reference = new Mystery.Content.ContentReference(adriano),
                    property_name     = nameof(TestContentType.not_ediatable_reference),
                    search_text       = null
                });
                Assert.IsTrue(!result.isSuccessfull && result.UnAuthorized);
                if (was_adim)
                {
                    session.authenticated_user.account_type = UserType.admin;
                }
            }
        }
Esempio n. 3
0
        protected override IContentContainer getContainer()
        {
            var result = new ContentsDatabase()
            {
                can_do_crazy = true
            };

            result.Clear();
            return(result);
        }
Esempio n. 4
0
        public void CreateAContentInDbTest()
        {
            Guid guid = Guid.Empty;

            using (WebActionExecutor e = new WebActionExecutor())
            {
                string json = e.executeAction(new CreateAContentInDb <TestContentType>()).json_output;
                IMysteryJsonConverter converter = this.getGlobalObject <IMysteryJsonConverter>();
                guid = converter.readJson <Guid>(json);
            }

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

            Assert.IsNotNull(db.GetContent <TestContentType>(guid));
            Assert.IsTrue(db.ContainsType <TestContentType>());
        }
Esempio n. 5
0
        public void ContentServiceContentTest()
        {
            var c = TestContentType.getARandomTestContentType(enforce_a_reference: false);

            //let's avoid single reference
            c.single_reference = new ContentReference <TestContentType>();
            ContentsDatabase db = this.getGlobalObject <ContentsDatabase>();

            db.Add(c);
            db.AddContents(c.multi_reference.getAsContentEnum());
            var uid            = c.guid.Tiny();
            var s              = new ContentService();
            var service_result = s.ContentView(nameof(TestContentType), uid);
            var converter      = this.getGlobalObject <IMysteryJsonUiConverter>();

            Assert.IsTrue(converter.readJson <IContent>(service_result.json_output) is TestContentType);
        }
        public void SigleReferenceSuggestionsActionCanTest()
        {
            using (WebActionExecutor executor = new WebActionExecutor())
            {
                TestContentType  adriano = TestContentType.getARandomTestContentType(enforce_a_reference: true);
                ContentsDatabase db      = this.getGlobalObject <ContentsDatabase>();
                db.Add(adriano);

                var result = executor.executeAction(
                    new SigleReferenceSuggestionsAction(),
                    new PropertyEditSuggestionsActionInput {
                    content_reference = new Mystery.Content.ContentReference(adriano),
                    property_name     = nameof(TestContentType.single_reference),
                    search_text       = null
                });
                Assert.IsTrue(result.isSuccessfull);
            }
        }
Esempio n. 7
0
        public void WebContentDispatcherNoExceptionTest()
        {
            IContentDispatcher container = null;
            WebActionExecutor  executor  = null;
            ContentsDatabase   db        = this.getGlobalObject <ContentsDatabase>();
            TestContentType    c         = null;

            ExecuteTest(() => {
                container = WebContentDispatcher.getDispatcher();
                c         = TestContentType.getARandomTestContentType(enforce_a_reference: false);
                container.Add(c);
                Guid guid = c.guid;
                executor  = WebActionExecutor.current;
                return(guid.Tiny());
            });
            Assert.IsTrue(executor.status == WebActionExecutorStatus.done);
            Assert.IsTrue(db.Contains(c));
        }
Esempio n. 8
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)));
        }