예제 #1
0
        private static IDataContext CreateDataContext(Connection currentConnection)
        {
            IDataContext dc = null;

            switch (currentConnection.SourceType)
            {
                case SourceType.File:
                    dc = new FileContext(currentConnection.ConnectionString, "Test");
                    break;

                case SourceType.SqlServer:
                    dc = new SqlServerContext(currentConnection.ConnectionString, "Test");
                    break;

                case SourceType.MySql:
                    dc = new MySqlContext(currentConnection.ConnectionString, "Test");
                    break;
            }

            return dc;
        }
        public void SelectDataInKeyValueFormatTest()
        {
            const string connectionString = @"Data Source=VLADIMIR5D4B\SQLSERVER;Initial Catalog=Crate;Integrated Security=true;";
            var dc = new SqlServerContext(connectionString, "");

            var p = new Person
            {
                Name = "John Doe",
                Age = 24,
                Email = "*****@*****.**"
            };

            var repository = new Repository("ConsoleApp");

            dc.Clear<Person>(repository);

            repository.Add(p);
            dc.SubmitChanges(repository);

            var people = dc.Select(repository.Name, "Person").ToList();

            Assert.AreEqual(4, people[0].Count());
        }
        public void GetAllRepositoriesTest()
        {
            const string connectionString = @"Data Source=VLADIMIR5D4B\SQLSERVER;Initial Catalog=Crate;Integrated Security=true;";
            var dc = new SqlServerContext(connectionString, "");

            var p = new Person
            {
                Name = "John Doe",
                Age = 24,
                Email = "*****@*****.**"
            };

            var repository = new Repository("ConsoleApp");
            repository.Add(p);
            dc.SubmitChanges(repository);

            var repository1 = new Repository("ConsoleApp");
            repository.Add(p);
            dc.SubmitChanges(repository1);

            var repositories = dc.GetRepositories();

            Assert.AreNotEqual(0, repositories.Count());
        }
        public void ClearItemsOfCertainTypeFromRepositoryTest()
        {
            const string connectionString = @"Data Source=VLADIMIR5D4B\SQLSERVER;Initial Catalog=Crate;Integrated Security=true;";
            var dc = new SqlServerContext(connectionString, "");

            var p = new Person
            {
                Name = "John Doe",
                Age = 24,
                Email = "*****@*****.**"
            };

            var repository = new Repository("ConsoleApp");

            repository.Add(p);
            dc.SubmitChanges(repository);

            dc.Clear<Person>(repository);

            var people = dc.Select<Person>(repository);
            Assert.AreEqual(0, people.Count());
        }
        public void UpdateEntryTest()
        {
            const string connectionString = @"Data Source=VLADIMIR5D4B\SQLSERVER;Initial Catalog=Crate;Integrated Security=true;";
            var dc = new SqlServerContext(connectionString, "");

            var p = new Person
            {
                Name = "John Doe",
                Age = 24,
                Email = "*****@*****.**"
            };

            var repository = new Repository("ConsoleApp");

            dc.Clear<Person>(repository);

            repository.Add(p);
            dc.SubmitChanges(repository);

            var man = dc.Select<Person>(repository).First(c => c.Age == 24);
            man.Age = 35;

            repository.Update(man);
            dc.SubmitChanges(repository);

            var actual = dc.Select<Person>(repository).First(c => c.Age == 35);

            Assert.AreEqual(35, actual.Age);
        }