コード例 #1
0
        public void SqlScriptRunner_RunWithErrors()
        {
            SqlTestDatabase dbTest;
            SqlConnection   con;

            QueryDisposition[] dispositions;

            using (dbTest = SqlTestDatabase.Create())
            {
                con = new SqlConnection(dbTest.ConnectionInfo);
                con.Open();

                try
                {
                    dispositions = new SqlScriptRunner(CreateSchema).Run(con, true);
                    Assert.AreEqual(3, dispositions.Length);
                    for (int i = 0; i < dispositions.Length; i++)
                    {
                        Assert.IsNull(dispositions[i].Exception);
                        Assert.IsNull(dispositions[i].Message);
                    }

                    dispositions = new SqlScriptRunner("select * from bar\r\ngo\r\nselect * from foo\r\ngo\r\n").Run(con, true);
                    Assert.AreEqual(2, dispositions.Length);
                    Assert.IsNotNull(dispositions[0].Exception);
                    Assert.IsNull(dispositions[1].Exception);

                    dispositions = new SqlScriptRunner("select * from bar\r\ngo\r\nselect * from foo\r\ngo\r\n").Run(con, false);
                    Assert.AreEqual(1, dispositions.Length);
                    Assert.IsNotNull(dispositions[0].Exception);

                    dispositions = new SqlScriptRunner("select * from foo\r\ngo\r\nselect * from bar\r\ngo\r\n").Run(con, true);
                    Assert.AreEqual(2, dispositions.Length);
                    Assert.IsNull(dispositions[0].Exception);
                    Assert.IsNotNull(dispositions[1].Exception);

                    dispositions = new SqlScriptRunner("select * from foo\r\ngo\r\nselect * from bar\r\ngo\r\n").Run(con, false);
                    Assert.AreEqual(2, dispositions.Length);
                    Assert.IsNull(dispositions[0].Exception);
                    Assert.IsNotNull(dispositions[1].Exception);

                    dispositions = new SqlScriptRunner(DeleteSchema).Run(con, true);
                    Assert.AreEqual(2, dispositions.Length);
                    for (int i = 0; i < dispositions.Length; i++)
                    {
                        Assert.IsNull(dispositions[i].Exception);
                        Assert.IsNull(dispositions[i].Message);
                    }
                }
                finally
                {
                    new SqlScriptRunner(DeleteSchema).Run(con, true);
                    con.Close();
                }
            }
        }
コード例 #2
0
        public void CreateDeleteSqlExpress()
        {
            var connectionString = new ConnectionStringBuilder().UseLocalSqlExpress().UseRandomDBName("MyDB").ConnectionString;

            Console.WriteLine(connectionString);
            var db = new SqlTestDatabase(connectionString);

            Assert.False(db.Exist());
            db.Create();
            Assert.True(db.Exist());
            db.Delete();
            Assert.False(db.Exist());
        }
コード例 #3
0
        public virtual void Init(string databaseName)
        {
            try
            {
                AppDomain.CurrentDomain.SetData("DataDirectory", FunctionalTestBase.TempPath);
                TestDatabase = new SqlTestDatabase(databaseName);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);

                throw;
            }
        }
コード例 #4
0
        public static TestDatabase InitializeTestDatabase(DatabaseProvider provider, string databaseName)
        {
            TestDatabase testDatabase;
            switch (provider)
            {
                case DatabaseProvider.SqlClient:
                    testDatabase = new SqlTestDatabase(databaseName);
                    break;
                case DatabaseProvider.SqlServerCe:
                    testDatabase = new SqlCeTestDatabase(databaseName);
                    break;
                default:
                    throw new InvalidOperationException("Unsupported provider");
            }

            testDatabase.EnsureDatabase();
            return testDatabase;
        }
コード例 #5
0
        public void Initialize(WebHostContext context)
        {
            ITestDatabase db;
            string        connectionString;
            string        prefix = context.TestType.TestTypeInfo.Type.Name;

            if (context.HostOptions is IISExpressHostOptions)
            {
                connectionString = new ConnectionStringBuilder().UseLocalDB().UseRandomDBName(prefix).ToString();
                db = new SqlTestDatabase(connectionString);
            }
            else if (context.HostOptions is IISHostOptions)
            {
                connectionString = new ConnectionStringBuilder().UseLocalSqlExpress().UseRandomDBName(prefix).ToString();
                db = new SqlTestDatabase(connectionString);
            }
            else if (context.HostOptions is AzureWebsiteHostOptions)
            {
                connectionString = NuwaGlobalConfiguration.SqlAzureConnectionString;
                db = new SqlTestDatabase(connectionString);
            }
            else
            {
                throw new NotSupportedException(context.HostOptions.GetType().Name);
            }

            if (db.Exist())
            {
                db.Delete();
            }

            context.Properties.Add(NuwaDBContextKey, db);

            context.DeploymentOptions.WebConfigTransformers.Add(new WebConfigTransformer(
                                                                    config =>
            {
                config.ClearConnectionStrings();
                config.AddConnectionString(ConnectionStringName, connectionString, "System.Data.SqlClient");
            }));
        }
コード例 #6
0
        public void Cleanup()
        {
            if (this.DB != null)
            {
                this.DB.Dispose();
                this.DB = null;
            }

            if (this.AuthFilePath != null)
            {
                Helper.DeleteFile(this.AuthFilePath);
                this.AuthFilePath = null;
            }

            if (this.RadiusServer != null)
            {
                this.RadiusServer.Stop();
                this.RadiusServer = null;
            }

            Config.SetConfig(null);
        }
コード例 #7
0
        public void SqlScriptRunner_Run()
        {
            SqlTestDatabase dbTest;
            SqlConnection   con;
            SqlCommand      cmd;
            SqlDataReader   reader;
            int             cRows;

            QueryDisposition[] dispositions;

            using (dbTest = SqlTestDatabase.Create())
            {
                con = new SqlConnection(dbTest.ConnectionInfo);
                con.Open();

                try
                {
                    dispositions = new SqlScriptRunner(CreateSchema).Run(con, true);
                    Assert.AreEqual(3, dispositions.Length);
                    for (int i = 0; i < dispositions.Length; i++)
                    {
                        Assert.IsNull(dispositions[i].Exception);
                        Assert.IsNull(dispositions[i].Message);
                    }

                    reader = null;
                    try
                    {
                        cmd             = con.CreateCommand();
                        cmd.CommandType = CommandType.Text;
                        cmd.CommandText = "select * from Foo";

                        reader = cmd.ExecuteReader();

                        cRows = 0;
                        while (reader.Read())
                        {
                            cRows++;
                        }

                        Assert.AreEqual(1, cRows);
                    }
                    finally
                    {
                        if (reader != null)
                        {
                            reader.Close();
                        }
                    }

                    dispositions = new SqlScriptRunner(DeleteSchema).Run(con, true);
                    Assert.AreEqual(2, dispositions.Length);
                    for (int i = 0; i < dispositions.Length; i++)
                    {
                        Assert.IsNull(dispositions[i].Exception);
                        Assert.IsNull(dispositions[i].Message);
                    }
                }
                finally
                {
                    new SqlScriptRunner(DeleteSchema).Run(con, true);
                    con.Close();
                }
            }
        }
コード例 #8
0
        public void SqlTestDatabase_CreateDelete()
        {
            SqlTestDatabase   dbTest;
            SqlConnectionInfo conInfo;
            SqlContext        ctx = null;
            SqlCommand        cmd;
            DataTable         dt;
            bool found;

            // Verify that the test database is created.

            dbTest = SqlTestDatabase.Create();
            try
            {
                conInfo = dbTest.ConnectionInfo;
                ctx     = new SqlContext(conInfo);
                ctx.Open();

                cmd   = ctx.CreateCommand("exec sp_databases");
                dt    = ctx.ExecuteTable(cmd);
                found = false;

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (String.Compare(SqlHelper.AsString(dt.Rows[i]["DATABASE_NAME"]), SqlTestDatabase.DefTestDatabase, true) == 0)
                    {
                        found = true;
                        break;
                    }
                }

                Assert.IsTrue(found);
            }
            finally
            {
                if (ctx != null)
                {
                    ctx.Close();
                    ctx = null;
                }

                dbTest.Dispose();
            }

            // Verify that the test database was deleted

            conInfo.Database = "MASTER";

            ctx = new SqlContext(conInfo);
            ctx.Open();
            try
            {
                cmd   = ctx.CreateCommand("exec sp_databases");
                dt    = ctx.ExecuteTable(cmd);
                found = false;

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (String.Compare(SqlHelper.AsString(dt.Rows[i]["DATABASE_NAME"]), SqlTestDatabase.DefTestDatabase, true) == 0)
                    {
                        found = true;
                        break;
                    }
                }

                Assert.IsFalse(found);
            }
            finally
            {
                if (ctx != null)
                {
                    ctx.Close();
                    ctx = null;
                }
            }
        }
コード例 #9
0
 public void SqlTestDatabase_Basic()
 {
     using (SqlTestDatabase.Create())
     {
     }
 }
コード例 #10
0
        public void SqlTestDatabase_DeleteExisting()
        {
            SqlTestDatabase   dbTest;
            SqlConnectionInfo conInfo;
            string            database;
            SqlContext        ctx = null;
            SqlCommand        cmd;
            DataTable         dt;
            bool found;

            // Create a default test database and create a table within it.

            dbTest   = SqlTestDatabase.Create();
            conInfo  = dbTest.ConnectionInfo;
            database = conInfo.Database;
            dbTest.Dispose();

            conInfo.Database = "MASTER";
            ctx = new SqlContext(conInfo);
            ctx.Open();

            try
            {
                cmd = ctx.CreateCommand("create database [{0}]", database);
                ctx.Execute(cmd);

                ctx.Close();
                ctx = null;

                conInfo.Database = database;
                ctx = new SqlContext(conInfo);
                ctx.Open();

                cmd = ctx.CreateCommand("create table Test (field1 int)");
                ctx.Execute(cmd);
            }
            finally
            {
                if (ctx != null)
                {
                    ctx.Close();
                    ctx = null;
                }
            }

            // OK, now use SqlTestDatabase to create a new database and verify
            // that it actually deleted the old database by checking to see that
            // the table we created above no longer exists.

            dbTest = SqlTestDatabase.Create();

            try
            {
                conInfo = dbTest.ConnectionInfo;
                ctx     = new SqlContext(conInfo);
                ctx.Open();

                cmd   = ctx.CreateCommand("exec sp_tables");
                dt    = ctx.ExecuteTable(cmd);
                found = false;

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (String.Compare(SqlHelper.AsString(dt.Rows[i]["TABLE_NAME"]), "Test", true) == 0)
                    {
                        found = true;
                        break;
                    }
                }

                Assert.IsFalse(found);
            }
            finally
            {
                if (ctx != null)
                {
                    ctx.Close();
                    ctx = null;
                }

                dbTest.Dispose();
            }
        }
コード例 #11
0
        public void Initialize()
        {
            Helper.InitializeApp(Assembly.GetExecutingAssembly());

            this.ADSettings   = new ADTestSettings();
            this.DB           = SqlTestDatabase.Create();
            this.AuthFilePath = Path.GetTempFileName();

            //-------------------------------------------------------------
            // Initialize file authentication

            Helper.WriteToFile(this.AuthFilePath, @"

file.com;file1;file-password1
file.com;file2;file-password2
");
            this.Accounts.Add(new AuthTestAccount(AuthTestExtensionType.File, "file.com", "file1", "file-password1"));
            this.Accounts.Add(new AuthTestAccount(AuthTestExtensionType.File, "file.com", "file2", "file-password2"));

            //-------------------------------------------------------------
            // Initialize RADIUS authentication

            RadiusServerSettings radiusSettings = new RadiusServerSettings();

            radiusSettings.NetworkBinding = NetworkBinding.Parse("ANY:52111");
            radiusSettings.Devices.Add(new RadiusNasInfo(IPAddress.Loopback, this.RadiusSecret));
            radiusSettings.Devices.Add(new RadiusNasInfo(NetHelper.GetActiveAdapter(), this.RadiusSecret));

            this.RadiusServer = new RadiusServer();
            this.RadiusServer.Start(radiusSettings);
            this.RadiusServer.LoadAccountsFromString(@"

radius.com;radius1;radius-password1
radius.com;radius2;radius-password2
");
            this.Accounts.Add(new AuthTestAccount(AuthTestExtensionType.Radius, "radius.com", "radius1", "radius-password1"));
            this.Accounts.Add(new AuthTestAccount(AuthTestExtensionType.Radius, "radius.com", "radius2", "radius-password2"));

            //-------------------------------------------------------------
            // Initialize config authentication

            Config.SetConfig(@"

Accounts[0] = config.com;config1;config-password1
Accounts[1] = config.com;config2;config-password2
");
            this.Accounts.Add(new AuthTestAccount(AuthTestExtensionType.Config, "config.com", "config1", "config-password1"));
            this.Accounts.Add(new AuthTestAccount(AuthTestExtensionType.Config, "config.com", "config2", "config-password2"));

#if TEST_AD
            //-------------------------------------------------------------
            // Initialize active directory authentication

#if !TEST_AD_LDAP
            if (ADSettings.NasSecret != string.Empty)   // Disable the test if the NAS secret is blank
#endif
            this.Accounts.Add(new AuthTestAccount(AuthTestExtensionType.Ldap, ADSettings.Domain, ADSettings.Account, ADSettings.Password));
#endif

            //-------------------------------------------------------------
            // Initalize ODBC authentication

            SqlConnection   sqlCon = null;
            SqlScriptRunner scriptRunner;
            MacroProcessor  processor;
            string          initScript =
                @"
create table Accounts (

Realm           varchar(64),
Account         varchar(64),
Password        varchar(64),
MD5             varbinary(128),
SHA1            varbinary(128),
SHA256          varbinary(128),
SHA512          varbinary(128)
)
go

insert into Accounts(Realm,Account,Password,MD5,SHA1,SHA256,SHA512)
values ('odbc.com','odbc1','odbc-password1',$(md5-1),$(sha1-1),$(sha256-1),$(sha512-1))

insert into Accounts(Realm,Account,Password,MD5,SHA1,SHA256,SHA512)
values ('odbc.com','odbc2','odbc-password2',$(md5-2),$(sha1-2),$(sha256-2),$(sha512-2))

go
";
            try
            {
                processor = new MacroProcessor();
                processor.Add("md5-1", SqlHelper.Literal(MD5Hasher.Compute("odbc-password1")));
                processor.Add("sha1-1", SqlHelper.Literal(SHA1Hasher.Compute("odbc-password1")));
                processor.Add("sha256-1", SqlHelper.Literal(SHA256Hasher.Compute("odbc-password1")));
                processor.Add("sha512-1", SqlHelper.Literal(SHA512Hasher.Compute("odbc-password1")));

                processor.Add("md5-2", SqlHelper.Literal(MD5Hasher.Compute("odbc-password2")));
                processor.Add("sha1-2", SqlHelper.Literal(SHA1Hasher.Compute("odbc-password2")));
                processor.Add("sha256-2", SqlHelper.Literal(SHA256Hasher.Compute("odbc-password2")));
                processor.Add("sha512-2", SqlHelper.Literal(SHA512Hasher.Compute("odbc-password2")));

                initScript = processor.Expand(initScript);

                sqlCon       = DB.OpenConnection();
                scriptRunner = new SqlScriptRunner(initScript);
                scriptRunner.Run(sqlCon);

                this.Accounts.Add(new AuthTestAccount(AuthTestExtensionType.Odbc, "odbc.com", "odbc1", "odbc-password1"));
                this.Accounts.Add(new AuthTestAccount(AuthTestExtensionType.Odbc, "odbc.com", "odbc2", "odbc-password2"));
            }
            finally
            {
                if (sqlCon != null)
                {
                    sqlCon.Close();
                }
            }
        }
コード例 #12
0
        public void SentinelServiceDB_DeployDB()
        {
            SqlTestDatabase    dbTest;
            Package            dbPackage = null;
            DBPackageInstaller dbInstaller;
            DBInstallParams    dbParams;
            DBInstallResult    result;

            using (dbTest = SqlTestDatabase.Create())
            {
                SqlConnectionInfo conInfo;
                SqlContext        ctx = null;
                SqlCommand        cmd;
                DataTable         dt;

                try
                {
                    // Deploy to a non-existent database

                    dbPackage   = new Package(EnvironmentVars.Expand("$(LT_BUILD)\\LillTek.SentinelService.dbpack"));
                    dbParams    = new DBInstallParams("SentinelService", dbTest.ConnectionInfo.Database);
                    dbInstaller = new DBPackageInstaller(dbPackage);

                    result = dbInstaller.Install(dbParams);
                    Assert.AreEqual(DBInstallResult.Installed, result);

                    conInfo = SqlConnectionInfo.Parse(dbInstaller.ConnectionString);
                    ctx     = new SqlContext(conInfo);
                    ctx.Open();

                    cmd = ctx.CreateSPCall("GetProductInfo");
                    dt  = ctx.ExecuteTable(cmd);
                    Assert.AreEqual(1, dt.Rows.Count);

                    cmd = ctx.CreateSPCall("Ping");
                    dt  = ctx.ExecuteTable(cmd);
                    Assert.AreEqual(1, dt.Rows.Count);
                    Assert.AreEqual("OK", SqlHelper.AsString(dt.Rows[0]["STATUS"]));

                    ctx.Close();
                    ctx = null;

                    // Deploy again and we should see that the database is up-to-date.

                    SqlConnection.ClearAllPools();
                    result = dbInstaller.Install(dbParams);
                    Assert.AreEqual(DBInstallResult.UpToDate, result);
                }
                finally
                {
                    if (dbPackage != null)
                    {
                        dbPackage.Close();
                    }

                    if (ctx != null)
                    {
                        ctx.Close();
                    }
                }
            }
        }
コード例 #13
0
        public void Archivers_SqlArchiver_Blast()
        {
            // Archive 25K fixes in random blocks over an extended period
            // of time with the buffer interval set to 2 seconds to exercise
            // the interaction between archival submissions and the buffer handling
            // background thread.

            const string appConfig =
                @"
&section LillTek.GeoTracker.Server

    GeoFixArchiver = LillTek.GeoTracker.Server.SqlGeoFixArchiver:LillTek.GeoTracker.Server.dll

    // Archiver implementation specific arguments (such as a database connection string)
    // formatted as name=value pairs separated by semicolons.

    GeoFixArchiverArgs = {{

        ConnectionString = {0}
        BufferSize       = 100
        BufferInterval   = 2s

        AddScript        = insert into GeoFixes(TimeUtc,EntityID,GroupID,Technology,Latitude,Longitude,Altitude,Course,Speed,HorizontalAccuracy,VerticalAccurancy,NetworkStatus) values (@(TimeUtc),@(EntityID),@(GroupID),@(Technology),@(Latitude),@(Longitude),@(Altitude),@(Course),@(Speed),@(HorizontalAccuracy),@(VerticalAccurancy),@(NetworkStatus))
    }}

&endsection
";

            const string createTableScript =
                @"create table GeoFixes (

	ID					int			primary key identity,
	TimeUtc				datetime    not null,
	EntityID			varchar(32)	not null,
	GroupID				varchar(32) null,
	Technology			varchar(32) not null,
	Latitude			float(53)   not null,
	Longitude			float(53)   not null,
	Altitude			float(53)   null,
	Course				float(53)   null,
	Speed				float(53)	null,
	HorizontalAccuracy	float(53)   null,
	VerticalAccurancy	float(53)   null,
	NetworkStatus		varchar(32) not null
)
";

            using (var dbTest = SqlTestDatabase.Create())
            {
                DateTime   time = new DateTime(2011, 4, 27, 9, 58, 0);
                SqlContext ctx  = null;
                DataTable  dt;

                try
                {
                    ctx = new SqlContext(dbTest.ConnectionInfo);

                    ctx.Open();
                    ctx.Execute(createTableScript);

                    try
                    {
                        TestInit(appConfig.Replace("{0}", dbTest.ConnectionInfo));

                        const int cTotalFixes = 25000;
                        const int maxBlock    = 300;
                        Random    rand        = new Random(0);
                        int       cSubmitted  = 0;

                        while (cSubmitted < cTotalFixes)
                        {
                            // Blast out a block of between 0...maxBlock-1 fixes.

                            int cBlock = rand.Next(maxBlock);

                            if (cBlock + cSubmitted > cTotalFixes)
                            {
                                cBlock = cTotalFixes - cSubmitted;
                            }

                            for (int i = 0; i < cBlock; i++)
                            {
                                client.SubmitEntityFix((cSubmitted + i).ToString(), "group", new GeoFix()
                                {
                                    TimeUtc = time, Latitude = 10, Longitude = 20
                                });
                            }

                            cSubmitted += cBlock;

                            // Wait a random time between 0 and 100ms

                            Thread.Sleep(rand.Next(101));
                        }

                        // Stop the server so that any buffered fixes will be flushed.

                        server.Stop();

                        // Verify that the fixes are in the database.

                        dt = ctx.ExecuteTable("select * from GeoFixes");
                        Assert.AreEqual(cTotalFixes, dt.Rows.Count);

                        for (int i = 0; i < cTotalFixes; i++)
                        {
                            Assert.AreEqual(time, dt.Rows[i].Field <DateTime>(dt.Columns["TimeUtc"]));
                            Assert.AreEqual(i.ToString(), dt.Rows[i].Field <string>(dt.Columns["EntityID"]));
                            Assert.AreEqual("group", dt.Rows[i].Field <string>(dt.Columns["GroupID"]));
                            Assert.AreEqual(10.0, dt.Rows[i].Field <double>(dt.Columns["Latitude"]));
                            Assert.AreEqual(20.0, dt.Rows[i].Field <double>(dt.Columns["Longitude"]));
                            Assert.IsNull(dt.Rows[i].Field <double?>(dt.Columns["Altitude"]));
                            Assert.IsNull(dt.Rows[i].Field <double?>(dt.Columns["Course"]));
                            Assert.IsNull(dt.Rows[i].Field <double?>(dt.Columns["Speed"]));
                            Assert.IsNull(dt.Rows[i].Field <double?>(dt.Columns["HorizontalAccuracy"]));
                            Assert.IsNull(dt.Rows[i].Field <double?>(dt.Columns["VerticalAccurancy"]));
                            Assert.AreEqual("Unknown", dt.Rows[i].Field <string>(dt.Columns["NetworkStatus"]));
                        }
                    }
                    finally
                    {
                        TestCleanup();
                        Helper.DeleteFile(AppLogFolder, true);
                    }
                }
                finally
                {
                    if (ctx != null)
                    {
                        ctx.Close();
                    }
                }
            }
        }
コード例 #14
0
        public void Archivers_SqlArchiver_FillBuffer()
        {
            // Create a test SQL database with a GeoFixes table where we'll have the
            // SQL archiver write the fixes.  Configure a buffer size of 100 fixes,
            // submit 100 fixes and then verify that they were written immediately
            // to the database (e.g. the buffer was flushed).

            const string appConfig =
                @"
&section LillTek.GeoTracker.Server

    GeoFixArchiver = LillTek.GeoTracker.Server.SqlGeoFixArchiver:LillTek.GeoTracker.Server.dll

    // Archiver implementation specific arguments (such as a database connection string)
    // formatted as name=value pairs separated by semicolons.

    GeoFixArchiverArgs = {{

        ConnectionString = {0}
        BufferSize       = 100
        BufferInterval   = 5m

        AddScript        = insert into GeoFixes(TimeUtc,EntityID,GroupID,Technology,Latitude,Longitude,Altitude,Course,Speed,HorizontalAccuracy,VerticalAccurancy,NetworkStatus) values (@(TimeUtc),@(EntityID),@(GroupID),@(Technology),@(Latitude),@(Longitude),@(Altitude),@(Course),@(Speed),@(HorizontalAccuracy),@(VerticalAccurancy),@(NetworkStatus))
    }}

&endsection
";

            const string createTableScript =
                @"create table GeoFixes (

	ID					int			primary key identity,
	TimeUtc				datetime    not null,
	EntityID			varchar(32)	not null,
	GroupID				varchar(32) null,
	Technology			varchar(32) not null,
	Latitude			float(53)   not null,
	Longitude			float(53)   not null,
	Altitude			float(53)   null,
	Course				float(53)   null,
	Speed				float(53)	null,
	HorizontalAccuracy	float(53)   null,
	VerticalAccurancy	float(53)   null,
	NetworkStatus		varchar(32) not null
)
";

            using (var dbTest = SqlTestDatabase.Create())
            {
                DateTime   time = new DateTime(2011, 4, 27, 9, 58, 0);
                SqlContext ctx  = null;
                DataTable  dt;

                try
                {
                    ctx = new SqlContext(dbTest.ConnectionInfo);

                    ctx.Open();
                    ctx.Execute(createTableScript);

                    try
                    {
                        TestInit(appConfig.Replace("{0}", dbTest.ConnectionInfo));

                        for (int i = 0; i < 100; i++)
                        {
                            client.SubmitEntityFix(i.ToString(), "group", new GeoFix()
                            {
                                TimeUtc = time, Latitude = 10, Longitude = 20
                            });
                        }

                        // Wait 4 times the server's background task scheduling interval to give the
                        // archiver a fair chance to perform the operation.

                        Thread.Sleep(Helper.Multiply(server.Settings.BkInterval, 4));

                        dt = ctx.ExecuteTable("select * from GeoFixes");

                        Assert.AreEqual(100, dt.Rows.Count);

                        for (int i = 0; i < 100; i++)
                        {
                            Assert.AreEqual(time, dt.Rows[i].Field <DateTime>(dt.Columns["TimeUtc"]));
                            Assert.AreEqual(i.ToString(), dt.Rows[i].Field <string>(dt.Columns["EntityID"]));
                            Assert.AreEqual("group", dt.Rows[i].Field <string>(dt.Columns["GroupID"]));
                            Assert.AreEqual(10.0, dt.Rows[i].Field <double>(dt.Columns["Latitude"]));
                            Assert.AreEqual(20.0, dt.Rows[i].Field <double>(dt.Columns["Longitude"]));
                            Assert.IsNull(dt.Rows[i].Field <double?>(dt.Columns["Altitude"]));
                            Assert.IsNull(dt.Rows[i].Field <double?>(dt.Columns["Course"]));
                            Assert.IsNull(dt.Rows[i].Field <double?>(dt.Columns["Speed"]));
                            Assert.IsNull(dt.Rows[i].Field <double?>(dt.Columns["HorizontalAccuracy"]));
                            Assert.IsNull(dt.Rows[i].Field <double?>(dt.Columns["VerticalAccurancy"]));
                            Assert.AreEqual("Unknown", dt.Rows[i].Field <string>(dt.Columns["NetworkStatus"]));
                        }
                    }
                    finally
                    {
                        TestCleanup();
                        Helper.DeleteFile(AppLogFolder, true);
                    }
                }
                finally
                {
                    if (ctx != null)
                    {
                        ctx.Close();
                    }
                }
            }
        }
コード例 #15
0
        public void Archivers_SqlArchiver_Flush()
        {
            // Create a test SQL database with a GeoFixes table where we'll have the
            // SQL archiver write the fixes.  Configure a 1 second archiver buffer interval,
            // start the GeoTracker, submit a single fix to the server and and pause for 5
            // seconds and verify that the buffered fix was persisted to the database.

            const string appConfig =
                @"
&section LillTek.GeoTracker.Server

    GeoFixArchiver = LillTek.GeoTracker.Server.SqlGeoFixArchiver:LillTek.GeoTracker.Server.dll

    // Archiver implementation specific arguments (such as a database connection string)
    // formatted as name=value pairs separated by semicolons.

    GeoFixArchiverArgs = {{

        ConnectionString = {0}
        BufferSize       = 100
        BufferInterval   = 1s

        AddScript        = insert into GeoFixes(TimeUtc,EntityID,GroupID,Technology,Latitude,Longitude,Altitude,Course,Speed,HorizontalAccuracy,VerticalAccurancy,NetworkStatus) values (@(TimeUtc),@(EntityID),@(GroupID),@(Technology),@(Latitude),@(Longitude),@(Altitude),@(Course),@(Speed),@(HorizontalAccuracy),@(VerticalAccurancy),@(NetworkStatus))
    }}

&endsection
";

            const string createTableScript =
                @"create table GeoFixes (

	ID					int			primary key identity,
	TimeUtc				datetime    not null,
	EntityID			varchar(32)	not null,
	GroupID				varchar(32) null,
	Technology			varchar(32) not null,
	Latitude			float(53)   not null,
	Longitude			float(53)   not null,
	Altitude			float(53)   null,
	Course				float(53)   null,
	Speed				float(53)	null,
	HorizontalAccuracy	float(53)   null,
	VerticalAccurancy	float(53)   null,
	NetworkStatus		varchar(32) not null
)
";

            using (var dbTest = SqlTestDatabase.Create())
            {
                DateTime   time = new DateTime(2011, 4, 27, 9, 58, 0);
                SqlContext ctx  = null;
                DataTable  dt;

                try
                {
                    ctx = new SqlContext(dbTest.ConnectionInfo);

                    ctx.Open();
                    ctx.Execute(createTableScript);

                    try
                    {
                        TestInit(appConfig.Replace("{0}", dbTest.ConnectionInfo));

                        client.SubmitEntityFix("jeff", "group", new GeoFix()
                        {
                            TimeUtc = time, Latitude = 10, Longitude = 20
                        });
                        Thread.Sleep(5000);

                        dt = ctx.ExecuteTable("select * from GeoFixes");

                        Assert.AreEqual(1, dt.Rows.Count);
                        Assert.AreEqual(time, dt.Rows[0].Field <DateTime>(dt.Columns["TimeUtc"]));
                        Assert.AreEqual("jeff", dt.Rows[0].Field <string>(dt.Columns["EntityID"]));
                        Assert.AreEqual("group", dt.Rows[0].Field <string>(dt.Columns["GroupID"]));
                        Assert.AreEqual(10.0, dt.Rows[0].Field <double>(dt.Columns["Latitude"]));
                        Assert.AreEqual(20.0, dt.Rows[0].Field <double>(dt.Columns["Longitude"]));
                        Assert.IsNull(dt.Rows[0].Field <double?>(dt.Columns["Altitude"]));
                        Assert.IsNull(dt.Rows[0].Field <double?>(dt.Columns["Course"]));
                        Assert.IsNull(dt.Rows[0].Field <double?>(dt.Columns["Speed"]));
                        Assert.IsNull(dt.Rows[0].Field <double?>(dt.Columns["HorizontalAccuracy"]));
                        Assert.IsNull(dt.Rows[0].Field <double?>(dt.Columns["VerticalAccurancy"]));
                        Assert.AreEqual("Unknown", dt.Rows[0].Field <string>(dt.Columns["NetworkStatus"]));
                    }
                    finally
                    {
                        TestCleanup();
                        Helper.DeleteFile(AppLogFolder, true);
                    }
                }
                finally
                {
                    if (ctx != null)
                    {
                        ctx.Close();
                    }
                }
            }
        }
コード例 #16
0
        public MetadataCachingTestsFixture()
        {
            var database = new SqlTestDatabase("MetadataCachingTests");

            database.EnsureDatabase();
        }