Ejemplo n.º 1
0
        public void Should_Update_Element()
        {
            using (var con = storm.OpenConnection(PrepMethods.PrepareDB()))
            {
                var task = con.Get("Task").Where(f => f["ID"].EqualTo.Val(1)).Execute().First();

                var r = con.Set("Task", task.ID)
                        .Value(new Task()
                {
                    Completed = task.Completed,
                    Subject   = task.Subject,
                    TaskType  = task.TaskType,
                    UserID    = task.UserID,
                    DateStart = ((DateTime)task.DateStart).AddDays(1),
                    DateEnd   = ((DateTime)task.DateEnd).AddDays(2),
                }).Execute();

                var rows = r.RowsAffected;
                var id   = r.ObjectId;

                Assert.Equal(task.ID, id);
                Assert.Equal(1, rows);


                var task2 = con.Get("Task").Where(f => f["ID"].EqualTo.Val(id)).Execute().First();

                Assert.Equal(task.Completed, task2.Completed);
                Assert.Equal(task.Subject, task2.Subject);
                Assert.Equal(task.TaskType, task2.TaskType);
                Assert.Equal(task.UserID, task2.UserID);
                Assert.Equal(((DateTime)task.DateStart).AddDays(1), task2.DateStart);
                Assert.Equal(((DateTime)task.DateEnd).AddDays(2), task2.DateEnd);
            }
        }
Ejemplo n.º 2
0
        public void Should_Add_NewElement()
        {
            using (var con = storm.OpenConnection(PrepMethods.PrepareDB()))
            {
                var r = con.Set("Task")
                        .Value(new Task()
                {
                    Completed = false,
                    Subject   = "New Task element",
                    TaskType  = "test",
                    UserID    = 1,
                    DateStart = new DateTime(2021, 04, 21, 14, 00, 00),
                    DateEnd   = new DateTime(2021, 04, 21, 15, 00, 00),
                    ID        = 999999 /// should be ignored
                }).Execute();

                var rows = r.RowsAffected;
                var id   = r.ObjectId;

                Assert.NotEqual(999999, id);
                Assert.Equal(1, rows);


                var task = con.Get("Task").Where(f => f["ID"].EqualTo.Val(id)).Execute().First();

                Assert.False(task.Completed);
                Assert.Equal("New Task element", task.Subject);
                Assert.Equal("test", task.TaskType);
                Assert.Equal(1, task.UserID);
                Assert.Equal(new DateTime(2021, 04, 21, 14, 00, 00), task.DateStart);
                Assert.Equal(new DateTime(2021, 04, 21, 15, 00, 00), task.DateEnd);
                Assert.Equal(id.ToString(), task.ID.ToString());
            }
        }
Ejemplo n.º 3
0
        public void Should_Read_Get_Result_3Model_Multiple()
        {
            using (var con = storm.OpenConnection(PrepMethods.PrepareDB()))
            {
                var r = con.Get("Task")
                        .With("User")
                        .With("Info")
                        .Where(x => x["Info.ID"].EqualTo.Val("10") + x["ID"].EqualTo.Val("11"))
                        .Execute();

                Assert.Equal(2, r.Count());

                var res1 = r.First(x => x.ID == 10);

                var task1 = res1.GetModel <Task>();
                var user1 = res1.User[0].GetModel <User>();
                var info1 = res1.GetRelation("Info")[0];

                Assert.Equal("augue a suscipit nulla elit ac nulla sed vel enim", task1.Subject);
                Assert.Equal("*****@*****.**", user1.Email);
                Assert.Equal("cubilia", info1.Field1);

                var res2 = r.First(x => x.ID == 11);

                var task2 = res2.GetModel <Task>();
                var user2 = res2.GetRelation("User")[0].GetModel <User>();
                var info2 = res2.Info[0];

                Assert.Equal("aliquet maecenas leo odio condimentum id luctus nec molestie sed justo", task2.Subject);
                Assert.Equal("*****@*****.**", user2.Email);
                Assert.Equal("nullam porttitor lacus at turpis donec posuere metus vitae", info2.Field1);
            }
        }
Ejemplo n.º 4
0
        public void It_should_have_prefills_db()
        {
            var db = PrepMethods.PrepareDB();

            var cmd = db.CreateCommand();

            cmd.CommandText = "SELECT COUNT(*) FROM Users";
            int cnt = 0;

            using (var r = cmd.ExecuteReader())
            {
                while (r.Read())
                {
                    cnt = r.GetInt32(0);
                }
            }

            Assert.True(cnt > 0);

            cmd             = db.CreateCommand();
            cmd.CommandText = "SELECT COUNT(*) FROM Tasks";
            cnt             = 0;
            using (var r = cmd.ExecuteReader())
            {
                while (r.Read())
                {
                    cnt = r.GetInt32(0);
                }
            }

            Assert.True(cnt > 0);

            cmd             = db.CreateCommand();
            cmd.CommandText = "SELECT COUNT(*) FROM TaskInfos";
            cnt             = 0;
            using (var r = cmd.ExecuteReader())
            {
                while (r.Read())
                {
                    cnt = r.GetInt32(0);
                }
            }

            Assert.True(cnt > 0);

            db.Close();
        }
Ejemplo n.º 5
0
        public void Should_Read_Get_Result_2Model_Single()
        {
            using (var con = storm.OpenConnection(PrepMethods.PrepareDB()))
            {
                var r = con.Get("Task")
                        .With("User")
                        .Where(x => x["ID"].EqualTo.Val("10"))
                        .Execute();

                Assert.Single(r);
                var user = r.First().User[0];
                Assert.Equal(15, user.ID);
                Assert.Equal("Jannelle", user.FirstName);
                Assert.Equal("Lawles", user.LastName);
                Assert.Equal("*****@*****.**", user.Email);
            }
        }
Ejemplo n.º 6
0
        public void Should_Read_Projection_Result()
        {
            using (var con = storm.OpenConnection(PrepMethods.PrepareDB()))
            {
                StormDataSet r = con.Projection("Task")
                                 .Select("User.{FirstName, LastName}")
                                 .Select("TaskType")
                                 .Select("Completed")
                                 .Select("{DateStart, DateEnd}")
                                 .Select("Info.Field2")
                                 .Where(x => x["User.Email"].EqualTo.Val("*****@*****.**"))
                                 .Execute();

                Assert.Equal(8, r.Count());
                Assert.Equal(2, r.Count(x => (bool)x["Completed"] == true));
            }
        }
Ejemplo n.º 7
0
        public void It_should_get_users()
        {
            var          s = PrepMethods.PrepareStorm();
            StormDataSet result;

            using (var stormConnection = s.OpenConnection(PrepMethods.PrepareDB()))
            {
                using (var tran = stormConnection.BeginTransaction())
                {
                    result = tran.Projection("User")
                             .Select("ID")
                             .Select("FirstName")
                             .Select("LastName")
                             .Execute();
                }
            }

            Assert.Equal(20, result.Count());
        }
Ejemplo n.º 8
0
        public void Should_Read_Get_Result_OneModel_Single_TypedModel()
        {
            using (var con = storm.OpenConnection(PrepMethods.PrepareDB()))
            {
                var r = con.Get("Task")
                        .Where(x => x["ID"].EqualTo.Val("10"))
                        .Execute();

                Assert.Single(r);

                var task = r.First().GetModel <Task>();
                Assert.Equal(10, task.ID);
                Assert.Equal(15, task.UserID);
                Assert.Equal("Todo", task.TaskType);
                Assert.Equal("augue a suscipit nulla elit ac nulla sed vel enim", task.Subject);
                Assert.Equal(new DateTime(2021, 6, 22), task.DateStart);
                Assert.Equal(new DateTime(2021, 3, 28), task.DateEnd);
            }
        }
Ejemplo n.º 9
0
        public void Should_Read_Get_Result_3Model_Single()
        {
            using (var con = storm.OpenConnection(PrepMethods.PrepareDB()))
            {
                var r = con.Get("Task")
                        .With("User")
                        .With("Info")
                        .Where(x => x["Info.ID"].EqualTo.Val("10"))
                        .Execute();

                Assert.Single(r);
                var user = r.First().GetRelation("User")[0].GetModel <User>();
                Assert.Equal(15, user.ID);
                Assert.Equal("Jannelle", user.FirstName);
                Assert.Equal("Lawles", user.LastName);
                Assert.Equal("*****@*****.**", user.Email);

                var info = r.First().Info[0];
                Assert.Equal("cubilia", info.Field1);
                Assert.Equal(911, info.Field2);
                Assert.Equal(true, info.Field3);
            }
        }
Ejemplo n.º 10
0
        public void Should_NotUpdate_Element()
        {
            using (var con = storm.OpenConnection(PrepMethods.PrepareDB()))
            {
                var r = con.Set("Task", 99999) // id not exists!!
                        .Value(new Task()
                {
                    Completed = false,
                    Subject   = "New Task element",
                    TaskType  = "test",
                    UserID    = 1,
                    DateStart = new DateTime(2021, 04, 21, 14, 00, 00),
                    DateEnd   = new DateTime(2021, 04, 21, 15, 00, 00)
                }).Execute();

                var rows = r.RowsAffected;
                var id   = r.ObjectId;

                Assert.Equal(0, rows);

                var elements = con.Get("Task").Where(f => f["ID"].EqualTo.Val(99999)).Execute();
                Assert.Empty(elements);
            }
        }