Exemple #1
0
 public void TestUpdate(TestSessionWrapper wrapper) {
     var user = wrapper.Session.Query<User>().First();
     user.HeightInMeters = 1.7m;
     wrapper.Session.Save(user);
     var dbUser = wrapper.Session.Get<User>(user.UserId);
     Assert.Equal(1.7m, dbUser.HeightInMeters);
 }
Exemple #2
0
 public void TestMultipleInsertUpdatesIds(TestSessionWrapper wrapper) {
     var user = new User { Username = "******", EmailAddress = "asd", Password = "******" };
     var user2 = new User { Username = "******", EmailAddress = "asd", Password = "******" };
     wrapper.Session.Insert(user, user2);
     Assert.NotEqual(0, user.UserId);
     Assert.NotEqual(0, user2.UserId);
     Assert.NotEqual(user.UserId, user2.UserId);
 }
 public void TestManyFetches(TestSessionWrapper wrapper) {
     var post =
         wrapper.Session.Query<Post>()
                .FetchMany(p => p.Comments)
                .ThenFetch(c => c.User)
                .Fetch(p => p.Blog)
                .Fetch(p => p.Author)
                .SingleOrDefault(p => p.PostId == 1);
     Assert.True(post != null);
 }
 public void TestManyToManyThing(TestSessionWrapper wrapper) {
     var post =
         wrapper.Session.Query<Post>()
                .FetchMany(p => p.Tags)
                .ThenFetch(t => t.Tag)
                .Fetch(p => p.Blog)
                .Fetch(p => p.Author)
                .SingleOrDefault(p => p.PostId == 1);
     Assert.True(post != null);
 }
Exemple #5
0
 public void MultipleFetchManyWithNonRootAndThenFetchWorks(TestSessionWrapper wrapper) {
     var responses =
         wrapper.Session.Query<QuestionnaireResponse>()
                .Where(qr => qr.Questionnaire.QuestionnaireId == 1)
                .Fetch(qr => qr.Questionnaire)
                .FetchMany(qr => qr.Responses)
                .ThenFetch(qrr => qrr.Question)
                .FetchMany(qr => qr.Booking.Beds)
                .ThenFetch(b => b.RoomSlot.Room)
                .ToArray();
     Assert.Equal(1, responses.Length);
     Assert.Equal(1, responses.First().Booking.Beds.Count);
 }
        public void TestSingleAndFirst(TestSessionWrapper wrapper) {
            // now fetch them
            var t1 = wrapper.Session.Query<User>().First();
            Assert.Equal("User_0", t1.Username);

            var t2 = wrapper.Session.Query<User>().First(u => u.Username == "User_1");
            Assert.Equal("User_1", t2.Username);

            Assert.Throws<InvalidOperationException>(() => wrapper.Session.Query<User>().Single());

            var t3 = wrapper.Session.Query<User>().Single(u => u.Username == "User_2");
            Assert.Equal("User_2", t3.Username);

            var t4 = wrapper.Session.Query<User>().FirstOrDefault();
            Assert.Equal("User_0", t1.Username);

            var t5 = wrapper.Session.Query<User>().FirstOrDefault(u => u.Username == "Boo");
            Assert.Null(t5);

            var t6 = wrapper.Session.Query<User>().SingleOrDefault(u => u.Username == "Boo");
            Assert.Null(t6);
        }
Exemple #7
0
 public void UpdateBulk(TestSessionWrapper wrapper) {
     wrapper.Session.Update<User>(u => u.Password = "******", u => u.Username == "BulkUpdate");
     var user = wrapper.Session.Query<User>().First(u => u.Username == "BulkUpdate");
     Assert.Equal("boo", user.Password);
 }
Exemple #8
0
 public void TestInsertGetsId(TestSessionWrapper wrapper) {
     var user = new User { Username = "******", EmailAddress = Guid.NewGuid().ToString(), Password = "******" };
     wrapper.Session.Insert(user);
     Assert.NotEqual(0, user.UserId);
 }
Exemple #9
0
 public void TestInsert(TestSessionWrapper wrapper) {
     var user = new User { Username = "******", EmailAddress = Guid.NewGuid().ToString(), Password = "******" };
     wrapper.Session.Insert(user);
     var dbUser = wrapper.Session.Query<User>().First(u => u.EmailAddress == user.EmailAddress);
     Assert.NotNull(dbUser);
 }
Exemple #10
0
 public async Task QueryWorks(TestSessionWrapper wrapper) {
     var posts = await wrapper.Session.Query<Post>().ToListAsync();
     Assert.Equal(20, posts.Count());
 }
Exemple #11
0
 public async Task AnyAsyncWhereTrueWorks(TestSessionWrapper wrapper) {
     Assert.True(await wrapper.Session.Query<User>().AnyAsync(u => u.UserId == 8));
 }
Exemple #12
0
 public void TestDelete(TestSessionWrapper wrapper) {
     var user = wrapper.Session.Query<User>().First(u => u.Username == "TestDelete");
     wrapper.Session.Delete(user);
     Assert.Empty(wrapper.Session.Query<User>().Where(u => u.Username == "TestDelete"));
 }
Exemple #13
0
 public void TestChainedCollectionFetch(TestSessionWrapper wrapper) {
     var blog = wrapper.Session.Query<Blog>().FetchMany(p => p.Posts).ThenFetch(p => p.Comments).First();
     Assert.Equal(2, blog.Posts.Count);
     Assert.Equal(3, blog.Posts.First().Comments.Count);
 }
Exemple #14
0
 public void TestFetchingEmptyCollection(TestSessionWrapper wrapper) {
     var emptyBlog = wrapper.Session.Query<Blog>().First(b => b.Title == "EmptyBlog");
     Assert.Empty(emptyBlog.Posts);
 }
Exemple #15
0
 public void TestMultiCollectionFetch(TestSessionWrapper wrapper) {
     var posts = wrapper.Session.Query<Post>().Fetch(p => p.Comments).Fetch(p => p.Tags).Where(p => p.PostId == 1).ToList();
     Assert.True(posts.First().Comments.Count == 3);
     Assert.True(posts.First().Tags.Count == 2);
 }
Exemple #16
0
 public void TestCollectionFetch(TestSessionWrapper wrapper) {
     var posts = wrapper.Session.Query<Post>().Fetch(p => p.Comments).ToList();
     Assert.True(
         posts.First(p => p.PostId == 1)
              .Comments.Count(c => c.Content == "Comment_0" || c.Content == "Comment_1" || c.Content == "Nullable User Content") == 3);
 }
Exemple #17
0
 public async Task InsertWorks(TestSessionWrapper wrapper) {
     var comment = new Comment { Content = "Foo" };
     await wrapper.Session.InsertAsync(comment);
     Assert.NotEqual(0, comment.CommentId);
 }
Exemple #18
0
 public async Task CollectionWorks(TestSessionWrapper wrapper) {
     var posts = await wrapper.Session.Query<Post>().Fetch(p => p.Comments).ToListAsync();
     Assert.Equal(20, posts.Count());
 }
Exemple #19
0
 public void DeleteBulk(TestSessionWrapper wrapper) {
     wrapper.Session.Delete<User>(u => u.Username == "BulkDelete");
     var users = wrapper.Session.Query<User>().Where(u => u.Username == "BulkDelete");
     Assert.Empty(users);
 }
Exemple #20
0
 public void AnyWhereTrueWorks(TestSessionWrapper wrapper) {
     Assert.True(wrapper.Session.Query<User>().Any(u => u.UserId == 8));
 }
Exemple #21
0
 public void FetchWithNonFetchedWhere(TestSessionWrapper wrapper) {
     var comment = wrapper.Session.Query<Comment>().Fetch(c => c.Post.Blog).Where(c => c.User.EmailAddress == "foo");
     Assert.Null(comment.FirstOrDefault());
 }
Exemple #22
0
 public void WhereEnumerableWorks(TestSessionWrapper wrapper) {
     var ids = new long[] { 1, 2, 3 };
     var posts = wrapper.Session.Query<Post>().Where(p => ids.Contains(p.PostId)).ToList();
     Assert.Equal(3, posts.Count);
 }
Exemple #23
0
 public void DateTimeInsertedAndSelectedCorrectly(TestSessionWrapper wrapper) {
     var date = new DateTime(2016, 12, 25, 1, 3, 6, DateTimeKind.Utc);
     var comment = new Comment { Content = "Foo", CommentDate = date };
     wrapper.Session.Insert(comment);
     Assert.Equal(date, comment.CommentDate);
     var fetchedComment = wrapper.Session.Get<Comment>(comment.CommentId);
     Assert.Equal(date, fetchedComment.CommentDate);
 }
Exemple #24
0
 public void NullableTripleFetchDoesNotThrow(TestSessionWrapper wrapper) {
     var comment = wrapper.Session.Query<PostTag>().Fetch(c => c.Post.Blog).Where(t => t.Tag.Content == "Null Post Tag");
     Assert.Null(comment.First().Post);
 }
Exemple #25
0
 public async Task AnyAsyncWhereFalseWorks(TestSessionWrapper wrapper) {
     Assert.False(await wrapper.Session.Query<User>().AnyAsync(u => u.UserId == 2000));
 }
Exemple #26
0
 public async Task GetByIdWorks(TestSessionWrapper wrapper) {
     var post = await wrapper.Session.GetAsync<Post, int>(1);
     Assert.Equal(1, post.PostId);
 }
Exemple #27
0
 public void AnyWhereFalseWorks(TestSessionWrapper wrapper) {
     Assert.False(wrapper.Session.Query<User>().Any(u => u.UserId == 2000));
 }
Exemple #28
0
 public async Task InsertAsyncEnablesTracking(TestSessionWrapper wrapper) {
     var user = new User { Username = "******", EmailAddress = Guid.NewGuid().ToString(), Password = "******" };
     await wrapper.Session.InsertAsync(user);
     Assert.True(((ITrackedEntity)user).IsTrackingEnabled());
 }
Exemple #29
0
 public void WhereAnyWorks(TestSessionWrapper wrapper) {
     var posts = wrapper.Session.Query<Post>().Where(p => p.Comments.Any(c => c.Content == "Comment_1")).ToList();
     Assert.Equal(1, posts.Count);
 }
Exemple #30
0
 public void NullableFetchReturnsNull(TestSessionWrapper wrapper) {
     var comment = wrapper.Session.Query<Comment>().Fetch(c => c.User).Where(c => c.Content == "Nullable User Content");
     Assert.Null(comment.First().User);
 }