示例#1
0
        public void EncryptionJournalGetsLatestPropertyValue()
        {
            AutoResetEvent           blocker = new AutoResetEvent(false);
            DataReplicationTestClass value   = GetRandomDataInstance();
            Journal journal        = GetEncryptionJournal <Journal>();
            bool?   checkedJournal = false;

            journal.Enqueue(value, (jes) => jes.Each(je =>
            {
                checkedJournal = true;
                Expect.AreSame(journal, je.Journal);
                blocker.Set();
            }));
            if (!blocker.WaitOne(15000))
            {
                Warn("Inconclusive, blocker was not set");
            }
            Expect.IsTrue(checkedJournal.Value);
            string newAddress = "Updated " + 8.RandomLetters();

            value.Address = newAddress;
            journal.Enqueue(value, (jes) =>
            {
                DataReplicationTestClass check = journal.LoadInstance <DataReplicationTestClass>(value.Id);
                Expect.AreEqual(newAddress, check.Address);
                blocker.Set();
            });

            if (!blocker.WaitOne(15000))
            {
                Warn("Inconclusive, blocker was not set");
            }
        }
示例#2
0
 public void DataTypeGetDataType()
 {
     string[] types = new string[] { "Boolean", "Date", "Number", "Text", "Time", "Url" };
     foreach (string typeName in types)
     {
         object dataType = Dt.DataType.GetDataType(typeName);
         Type   sysType  = Dt.DataType.GetTypeOfDataType(typeName);
         Expect.AreSame(sysType, dataType.GetType());
     }
 }
示例#3
0
        public void ShouldBeAbleToSetApiKeyResolver()
        {
            ProxyFactory   serviceFactory = new ProxyFactory(".\\workspace_".RandomLetters(4), Logger);
            EncryptedEcho  echo           = serviceFactory.GetProxy <EncryptedEcho>();
            ApiKeyResolver resolver       = new ApiKeyResolver();

            echo.Property("ApiKeyResolver", resolver);
            ApiKeyResolver got = echo.Property <ApiKeyResolver>("ApiKeyResolver");

            Expect.AreSame(resolver, got);
        }
示例#4
0
        public void GetShouldReturnSameInstanceThatWasSet()
        {
            Incubator inc  = new Incubator();
            TestBam   test = new TestBam();

            inc.Set(typeof(TestBam), test);
            TestBam check = (TestBam)inc.Get(typeof(TestBam), new object[] { });

            Expect.AreSame(test, check);
            Expect.IsTrue(test == check);
        }
示例#5
0
        public void CoreUsermanagerClientProxyTest()
        {
            Message.PrintLine("This test requires a heart server to be running on port 80 of the localhost", ConsoleColor.Yellow);
            ConsoleLogger logger = new ConsoleLogger() { AddDetails = false };
            logger.StartLoggingThread();
            // get proxies
            ProxyFactory factory = new ProxyFactory();
            CoreClient coreClient = new CoreClient("Bam.Net", "CoreServicesTestApp", "localhost", 80, logger);

            UserRegistryService userService = coreClient.UserRegistryService;
            Expect.IsNotNull(userService);
            Expect.AreSame(coreClient, userService.Property("ApiKeyResolver"));
            Expect.AreSame(coreClient, userService.Property("ClientApplicationNameProvider"));

            bool? initFailed = false;
            coreClient.InitializationFailed += (o, a) =>
            {
                initFailed = true;
            };
            coreClient.Initialized += (o, a) =>
            {
                initFailed = false;
            };
            coreClient.RegisterApplicationProcess();
            Expect.IsTrue(initFailed.Value);
            Expect.AreEqual("You must be logged in to do that", coreClient.Message);

            // sign up
            string email = $"{8.RandomLetters()}@threeheadz.com";
            string userName = 5.RandomLetters();
            string passHash = "password".Sha1();
            SignUpResponse signupResponse = userService.SignUp(email, userName, passHash, false);
            Expect.IsTrue(signupResponse.Success, signupResponse.Message);
            if (!signupResponse.Success)
            {
                Message.PrintLine("Message: {0}", signupResponse.Message);
            }
            else
            {
                OutLine(signupResponse.TryPropertiesToString(), ConsoleColor.Cyan);
            }
            LoginResponse loginResponse = userService.Login(userName, passHash);
            Expect.IsTrue(loginResponse.Success, "Unable to login to userService");

            string youSayIAm = userService.WhoAmI();
            Expect.AreEqual(userName, youSayIAm);

            loginResponse = coreClient.ApplicationRegistryService.Login(userName, passHash);
            Expect.IsTrue(loginResponse.Success, "Unable to login to application registry service");
            Expect.IsTrue(coreClient.RegisterApplicationProcess(), coreClient.Message);
            Expect.IsFalse(initFailed.Value);
            Expect.IsTrue(File.Exists(coreClient.ApiKeyFilePath));
            Pass("No exceptions were thrown and all assertions passed");
        }
示例#6
0
        public static void ProxiedDatabasesShouldBeTheSame()
        {
            Dao.ProxyConnection(typeof(Item), "CRUD_SqlClient");
            SqlClientRegistrar.Register <Item>();
            Database db       = Db.For(typeof(Item));     //_.Db[typeof(Item)];
            Database check    = Db.For("CRUD_SqlClient"); //_.Db["CRUD_SqlClient"];
            Database forCheck = Db.For <Item>();

            Expect.AreSame(db, check);
            Expect.AreSame(check, forCheck);
            Expect.AreSame(forCheck, db);
        }
示例#7
0
        public override void Render(object toRender, Stream output)
        {
            Expect.AreSame(ExecutionRequest.Result, toRender, "Attempt to render unexpected value");
            byte[] data = toRender as byte[];
            if (data == null)
            {
                string renderString = toRender as string;
                data = Encoding.UTF8.GetBytes(renderString);
            }

            output.Write(data, 0, data.Length);
        }
示例#8
0
        public static void ParentOfCollectionShouldBeRootDao()
        {
            SqlClientRegistrar.Register(Db.For <DaoReferenceObject>().ServiceProvider);

            DaoReferenceObject d = new DaoReferenceObject();

            d.StringProperty = "".RandomString(8);
            d.Commit();

            DaoReferenceObjectWithForeignKey dfk = d.DaoReferenceObjectWithForeignKeyCollectionByDaoReferenceObjectId.AddNew();

            Expect.AreSame(d, d.DaoReferenceObjectWithForeignKeyCollectionByDaoReferenceObjectId.Parent);
        }
示例#9
0
        public void GetDaoAssemblyShouldGetTheSameOneEachTime()
        {
            TypeDaoGenerator generator = new TypeDaoGenerator();

            generator.AddType(typeof(TestContainer));
            Assembly first    = generator.GetDaoAssembly();
            Assembly again    = generator.GetDaoAssembly();
            Assembly andAgain = generator.GetDaoAssembly();
            Assembly oneMoreForGoodMeasure = generator.GetDaoAssembly();

            Expect.AreSame(first, again);
            Expect.AreSame(first, andAgain);
            Expect.AreSame(first, oneMoreForGoodMeasure);
        }
示例#10
0
        public static void EnablingDropShouldFireDropEnabledEvent()
        {
            SqlClientSqlStringBuilder s = new SqlClientSqlStringBuilder();
            bool?fired = false;

            s.DropEnabled += (sb) =>
            {
                Expect.AreSame(s, sb);
                fired = true;
            };

            s.EnableDrop = true;
            Expect.IsNotNull(fired);
            Expect.IsTrue(fired.HasValue);
            Expect.IsTrue(fired.Value, "Event didn't fire");
        }
示例#11
0
        public void CompressionJournalGetsLatestPropertyValue()
        {
            Log.DebugOut = true;
            AutoResetEvent           blocker = new AutoResetEvent(false);
            DataReplicationTestClass value   = GetRandomDataInstance();
            Journal journal = GetCompressionJournal <Journal>();

            journal.Logger = new ConsoleLogger();
            bool?checkedJournal = false;

            journal.Enqueue(value, (jes) => jes.Each(je =>
            {
                Message.PrintLine("Fully flushed called", ConsoleColor.DarkBlue);
                checkedJournal = true;
                Expect.AreSame(journal, je.Journal);
                blocker.Set();
            }));
            for (int i = 0; i < 100; i++)
            {
                Thread.Sleep(30);
                Message.PrintLine("QueueLength={0}", ConsoleColor.Cyan, journal.QueueLength.ToString());
                Message.PrintLine("Flushed status: {0}", ConsoleColor.Yellow, journal.QueueFlusher.ThreadState.ToString());
            }
            if (!blocker.WaitOne(15000))
            {
                Warn("Inconclusive, blocker was not set");
            }
            checkedJournal.Value.IsTrue();
            string newAddress = "Updated " + 8.RandomLetters();

            value.Address = newAddress;
            journal.Enqueue(value, (jes) =>
            {
                DataReplicationTestClass check = journal.LoadInstance <DataReplicationTestClass>(value.Id);
                Expect.AreEqual(newAddress, check.Address);
                OutLine(check.Address);
                blocker.Set();
            });

            if (!blocker.WaitOne(15000))
            {
                Warn("Inconclusive, blocker was not set");
            }
        }
示例#12
0
        public void SavingParentFiresChildCommitEvent()
        {
            SQLiteDatabase database = new SQLiteDatabase(nameof(SavingParentFiresChildCommitEvent));

            database.TryEnsureSchema <Parent>();

            Parent parent = new Parent(database);

            parent.Name = 8.RandomLetters();
            parent.Save();
            Son addedSon = new Son();

            addedSon.Name = 7.RandomLetters();
            parent.SonsByParentId.Add(addedSon);

            bool?addedSonEventFired = false;

            addedSon.AfterCommit += (db, dao) =>
            {
                Son cast = dao as Son;
                Expect.IsNotNull(cast);
                Expect.AreSame(addedSon, dao);
                Expect.AreEqual(addedSon.Name, cast.Name);
                Expect.AreSame(database, db);
                addedSonEventFired = true;
            };

            bool?parentEventFired = false;

            parent.AfterCommit += (db, dao) =>
            {
                parentEventFired = true;
                Parent cast = dao as Parent;
                Expect.IsNotNull(cast);
                Expect.AreSame(parent, cast);
                //Expect.IsFalse(cast.IsNew, "Son was still new after commit event fired");
                Expect.AreSame(database, db);
            };

            parent.Save(database);
            Expect.IsTrue(parentEventFired.Value, "Parent didn't fire AfterCommit event");
            Expect.IsTrue(addedSonEventFired.Value, "Son added using SonsById.Add didn't fire AfterCommit event");
        }
示例#13
0
        public void ShouldBeAbleToCopyDaoAsGeneratedDtoType()
        {
            SQLiteDatabase saveTo = GetTestDatabase(false);
            MainObject     toAdd  = new MainObject();

            toAdd.Name = 4.RandomLetters().Plus(":: The Name");
            toAdd.Save(saveTo);

            object dtoInstance = Dto.Copy(toAdd);

            OutLine("Dto info", ConsoleColor.Cyan);
            OutLineFormat("Type: {0}.{1}", dtoInstance.GetType().Namespace, dtoInstance.GetType().Name);
            OutLine(dtoInstance.TryPropertiesToString());

            MainObject daoInstance = MainObject.FirstOneWhere(c => c.Name == dtoInstance.Property("Name"), saveTo);

            Expect.IsNotNull(daoInstance);
            Expect.AreSame(saveTo, daoInstance.Database);
            OutLine("Dao info", ConsoleColor.Cyan);
            OutLineFormat("Type: {0}.{1}", daoInstance.GetType().Namespace, daoInstance.GetType().Name);
            OutLine(daoInstance.TryPropertiesToString());
        }
示例#14
0
        public void CoreApplicationRegistryServiceNotLoggedInIsAnonymous()
        {
            CoreApplicationRegistrationService svc = GetTestService();

            Expect.AreSame(UserAccounts.Data.User.Anonymous, svc.CurrentUser);
        }