Пример #1
0
        public void The_delete_method_with_bson_id_should_delete_entity()
        {
            //arrange
            var persons = new List<Person>();
            var person1 = new Person { Name = "Adrian", Age = 23 };
            var person2 = new Person { Name = "Anna", Age = 33 };
            var person3 = new Person { Name = "Brian", Age = 43 };
            persons.Add(person1);
            persons.Add(person2);
            persons.Add(person3);

            _session.SaveBatch(persons);

            //act
            _session.Delete(person2);
            _session.Delete(person1);

            //assert
            Assert.Equal(1, _session.Count<Person>());
        }
Пример #2
0
        public void The_update_method_with_bson_id_should_update_entity_in_the_database()
        {
            //arrange
            var persons = new List<Person>();
            var person1 = new Person { Name = "Adrian", Age = 23 };
            var person2 = new Person { Name = "Anna", Age = 33 };
            var person3 = new Person { Name = "Brian", Age = 43 };
            persons.Add(person1);
            persons.Add(person2);
            persons.Add(person3);

            _session.SaveBatch(persons);

            //act
            person2.Name = "Dan";
            person2.Age = 50;
            _session.Save(person2);

            //assert
            var person2FromTheDb = _session.Query<Person>().Single(x => x.Id == person2.Id);
            Assert.Equal("Dan", person2FromTheDb.Name);
            Assert.Equal(50, person2FromTheDb.Age);
        }
Пример #3
0
        public void The_save_method_should_insert_one_typed_object_into_the_db()
        {
            //arrange
            var person = new Person { Name = "Adrian", Age = 23 };

            //act
            _session.Save(person);

            //assert
            Assert.Equal(1, _session.Count<Person>());
        }
Пример #4
0
        public void The_save_batch_method_with_bson_id_should_insert_batch_of_multiple_elements_into_the_db()
        {
            //arrange
            var persons = new List<Person>();
            var person1 = new Person { Name = "Adrian", Age = 23 };
            var person2 = new Person { Name = "Anna", Age = 33 };
            persons.Add(person1);
            persons.Add(person2);

            //act
            _session.SaveBatch(persons);

            //assert
            Assert.Equal(persons.Count, _session.Count<Person>());
        }
Пример #5
0
        public void The_query_method_should_return_linq_queryable_list()
        {
            //arrange
            var persons = new List<Person>();
            var person1 = new Person { Name = "Adrian", Age = 23 };
            var person2 = new Person { Name = "Anna", Age = 33 };
            var person3 = new Person { Name = "Brian", Age = 43 };
            persons.Add(person1);
            persons.Add(person2);
            persons.Add(person3);

            _session.SaveBatch(persons);

            //act
            IList<Person> personsOlderThanThirty =
                _session.Query<Person>().Where(x => x.Age > 30).ToList();

            //assert
            Assert.Equal(2, personsOlderThanThirty.Count);
        }
Пример #6
0
        public void The_get_method_with_bson_id_should_return_entity_by_id()
        {
            //arrange
            var persons = new List<Person>();
            var person1 = new Person { Name = "Adrian", Age = 23 };
            var person2 = new Person { Name = "Anna", Age = 33 };
            var person3 = new Person { Name = "Brian", Age = 43 };
            persons.Add(person1);
            persons.Add(person2);
            persons.Add(person3);

            _session.SaveBatch(persons);

            //act
            var personById = _session.Get<Person>(person2.Id);

            //assert
            Assert.Equal("Anna", personById.Name);
            Assert.Equal(33, personById.Age);
        }