Exemplo n.º 1
0
        public async Task Delete_PushNotification(string endPoint)
        {
            using (var factory = new BlogContextFactory())
            {
                using (var context = factory.CreateBlogContext())
                {
                    // Arrange
                    var unitOfWork         = new UnitOfWork(context, mapper);
                    var subscriptionTable1 = GetPushNotificationSubscriptionTableInstance(endPoint: endPoint);
                    context.Add(subscriptionTable1);
                    context.SaveChanges();
                }

                using (var context = factory.CreateBlogContext())
                {
                    // Act
                    var unitOfWork = new UnitOfWork(context, mapper);
                    await unitOfWork.Subscribers.RemovePushNotificationSubscriptionAsync(endPoint);

                    var isDeleted = await unitOfWork.SaveAsync();

                    var subscriber = context.PushNotificationSubscriptions.FirstOrDefault();

                    // Assert
                    Assert.True(isDeleted);
                    Assert.Null(subscriber);
                }
            }
        }
Exemplo n.º 2
0
        public async Task Updating_Blog()
        {
            using (var factory = new BlogContextFactory())
            {
                int blogId = 0;
                using (var context = factory.CreateBlogContext())
                {
                    // Arrange
                    var blogTable = GetBlogTableInstance();
                    context.Add(blogTable);
                    context.SaveChanges();

                    blogId = blogTable.Id;
                }

                using (var context = factory.CreateBlogContext())
                {
                    var unitOfWork         = new UnitOfWork(context, mapper);
                    var blogForUpdatingDto = GetBlogForUpdatingDtoInstance(
                        title: "updated",
                        tags: new List <string> {
                        "test"
                    });
                    // Act
                    await unitOfWork.Blogs.UpdateBlogAsync(blogId, blogForUpdatingDto);

                    var isBlogUpdated = await unitOfWork.SaveAsync();

                    // Assert
                    Assert.True(isBlogUpdated);
                }
            }
        }
Exemplo n.º 3
0
        public async Task Get_All_PushNotificationSubscribers_Should_Not_Be_Null()
        {
            using (var factory = new BlogContextFactory())
            {
                using (var context = factory.CreateBlogContext())
                {
                    // Arrange
                    var unitOfWork         = new UnitOfWork(context, mapper);
                    var subscriptionTable1 = GetPushNotificationSubscriptionTableInstance();
                    var subscriptionTable2 = GetPushNotificationSubscriptionTableInstance();
                    context.Add(subscriptionTable1);
                    context.Add(subscriptionTable2);
                    context.SaveChanges();
                }

                using (var context = factory.CreateBlogContext())
                {
                    // Act
                    var unitOfWork  = new UnitOfWork(context, mapper);
                    var subscribers = await unitOfWork.Subscribers.GetPushNotificationSubscriptionAsync();

                    // Assert
                    Assert.Equal(2, subscribers.Count());
                }
            }
        }
Exemplo n.º 4
0
        public void Get_Blog_Page_Should_Be_In_Descending_Order_By_UpdatedDate()
        {
            using (var factory = new BlogContextFactory())
            {
                using (var context = factory.CreateBlogContext())
                {
                    // Arrange
                    var blogTable1 = GetBlogTableInstance(title: "first", slug: "first", publishDate: "01/01/2019");
                    var blogTable2 = GetBlogTableInstance(title: "second", slug: "second", publishDate: "02/01/2019");

                    context.Add(blogTable1);
                    context.Add(blogTable2);
                    context.SaveChanges();
                }

                using (var context = factory.CreateBlogContext())
                {
                    // Act
                    var unitOfWork = new UnitOfWork(context, mapper);
                    var blog       = unitOfWork.Blogs.GetBlogsPage(new BlogQuery()).TResult.First();
                    // Assert
                    Assert.Equal("second", blog.Title);
                }
            }
        }
Exemplo n.º 5
0
        public async Task Get_Blog_By_Id_Should_Not_Be_Null()
        {
            using (var factory = new BlogContextFactory())
            {
                int blogId = 0;
                using (var context = factory.CreateBlogContext())
                {
                    // Arrange
                    var blogTable = GetBlogTableInstance();
                    context.Add(blogTable);
                    context.SaveChanges();

                    blogId = blogTable.Id;
                }

                using (var context = factory.CreateBlogContext())
                {
                    // Act
                    var unitOfWork = new UnitOfWork(context, mapper);
                    var blog       = await unitOfWork.Blogs.GetBlogAsync(blogId);

                    // Assert
                    Assert.NotNull(blog);
                }
            }
        }
Exemplo n.º 6
0
        public void Get_Blog_Page_Should_Contain_2_Blogs()
        {
            using (var factory = new BlogContextFactory())
            {
                using (var context = factory.CreateBlogContext())
                {
                    // Arrange
                    var blogTable1 = GetBlogTableInstance(slug: "first");
                    var blogTable2 = GetBlogTableInstance(slug: "second");

                    context.Add(blogTable1);
                    context.Add(blogTable2);
                    context.SaveChanges();
                }

                using (var context = factory.CreateBlogContext())
                {
                    // Act
                    var unitOfWork = new UnitOfWork(context, mapper);
                    var blogsPage  = unitOfWork.Blogs.GetBlogsPage(new BlogQuery());
                    // Assert
                    Assert.Equal(2, blogsPage.TResult.Count());
                    Assert.Equal(2, blogsPage.TotalItems);
                    Assert.Equal(1, blogsPage.TotalPages);
                    Assert.Equal(10, blogsPage.PageSize);
                }
            }
        }
Exemplo n.º 7
0
        public async Task Delete_Blog()
        {
            using (var factory = new BlogContextFactory())
            {
                int blogId = 0;
                using (var context = factory.CreateBlogContext())
                {
                    // Arrange
                    var blogTable = GetBlogTableInstance();
                    context.Add(blogTable);
                    context.SaveChanges();

                    blogId = blogTable.Id;
                }

                using (var context = factory.CreateBlogContext())
                {
                    // Act
                    var unitOfWork = new UnitOfWork(context, mapper);
                    await unitOfWork.Blogs.DeleteBlogAsync(blogId);

                    var isBlogDeleted = await unitOfWork.SaveAsync();

                    // Assert
                    Assert.True(isBlogDeleted);
                    Assert.Null(context.Blogs.FirstOrDefault());
                }
            }
        }
Exemplo n.º 8
0
        public async Task Updating_Blog_Should_Throw_InvalidOperationException()
        {
            using (var factory = new BlogContextFactory())
            {
                using (var context = factory.CreateBlogContext())
                {
                    // Arrange
                    var blogTable = GetBlogTableInstance();
                    context.Add(blogTable);
                    context.SaveChanges();
                }

                using (var context = factory.CreateBlogContext())
                {
                    var unitOfWork         = new UnitOfWork(context, mapper);
                    var blogForUpdatingDto = GetBlogForUpdatingDtoInstance(
                        title: "updated",
                        tags: new List <string> {
                        "test"
                    });

                    // Act & Assert
                    await Assert.ThrowsAsync <InvalidOperationException>(() =>
                                                                         unitOfWork.Blogs.UpdateBlogAsync(999, blogForUpdatingDto));
                }
            }
        }
Exemplo n.º 9
0
        public async Task Is_Blob_Exist_Should_be_True_When_Blob_Exist()
        {
            using (var factory = new BlogContextFactory())
            {
                var blobId = 0;
                using (var context = factory.CreateBlogContext())
                {
                    // Arrange
                    var unitOfWork = new UnitOfWork(context, mapper);
                    var blobTable  = GetBlobTableInstance();
                    context.Add(blobTable);
                    context.SaveChanges();
                    blobId = blobTable.Id;
                }

                using (var context = factory.CreateBlogContext())
                {
                    // Act
                    var unitOfWork = new UnitOfWork(context, mapper);
                    var isExist    = await unitOfWork.Blobs.BlobExistAsync(blobId);

                    // Assert
                    Assert.True(isExist);
                }
            }
        }
Exemplo n.º 10
0
        public async Task Get_Blog_Should_Throw_InvalidOperationException()
        {
            using (var factory = new BlogContextFactory())
            {
                using (var context = factory.CreateBlogContext())
                {
                    // Arrange
                    var blogTable = GetBlogTableInstance();
                    context.Add(blogTable);
                    context.SaveChanges();
                }

                using (var context = factory.CreateBlogContext())
                {
                    var unitOfWork = new UnitOfWork(context, mapper);
                    // Act & Assert
                    await Assert.ThrowsAsync <InvalidOperationException>(() =>
                                                                         unitOfWork.Blogs.GetBlogAsync(999));
                }
            }
        }
Exemplo n.º 11
0
        public async Task Get_Blog_By_Slug_Should_Return_Null_If_Slug_Not_Exist()
        {
            using (var factory = new BlogContextFactory())
            {
                using (var context = factory.CreateBlogContext())
                {
                    // Arrange
                    var blogTable = GetBlogTableInstance();
                    context.Add(blogTable);
                    context.SaveChanges();
                }

                using (var context = factory.CreateBlogContext())
                {
                    var unitOfWork = new UnitOfWork(context, mapper);
                    // Act & Assert
                    var blog = await unitOfWork.Blogs.GetBlogAsync("un existing slug");

                    Assert.Null(blog);
                }
            }
        }
Exemplo n.º 12
0
        public async Task Is_Blog_Slug_Unipque_Should_be_False()
        {
            using (var factory = new BlogContextFactory())
            {
                using (var context = factory.CreateBlogContext())
                {
                    // Arrange
                    var blogTable = GetBlogTableInstance(slug: "new-blog");
                    context.Add(blogTable);
                    context.SaveChanges();
                }

                using (var context = factory.CreateBlogContext())
                {
                    // Act
                    var unitOfWork   = new UnitOfWork(context, mapper);
                    var isSlugUnique = await unitOfWork.Blogs.IsBlogSlugUniqueAsync("new-blog");

                    // Assert
                    Assert.False(isSlugUnique);
                }
            }
        }
Exemplo n.º 13
0
        public async Task Add_PushNotificationSubscriber()
        {
            using (var factory = new BlogContextFactory())
            {
                bool isSaved = false;
                using (var context = factory.CreateBlogContext())
                {
                    // Arrange
                    var unitOfWork      = new UnitOfWork(context, mapper);
                    var subscriptionDto = GetPushNotificationSubscriptionDtoInstance();
                    // Act
                    await unitOfWork.Subscribers.AddPushNotificationSubscriptionAsync(subscriptionDto);

                    isSaved = await unitOfWork.SaveAsync();
                }

                using (var context = factory.CreateBlogContext())
                {
                    // Assert
                    Assert.NotNull(context.PushNotificationSubscriptions.First());
                    Assert.True(isSaved);
                }
            }
        }
Exemplo n.º 14
0
        public async Task Get_PushNotification_Should_Not_Be_Null(string endPoint)
        {
            using (var factory = new BlogContextFactory())
            {
                using (var context = factory.CreateBlogContext())
                {
                    // Arrange
                    var unitOfWork         = new UnitOfWork(context, mapper);
                    var subscriptionTable1 = GetPushNotificationSubscriptionTableInstance(endPoint: endPoint);
                    context.Add(subscriptionTable1);
                    context.SaveChanges();
                }

                using (var context = factory.CreateBlogContext())
                {
                    // Act
                    var unitOfWork = new UnitOfWork(context, mapper);
                    var subscriber = await unitOfWork.Subscribers.GetPushNotificationSubscriptionAsync(endPoint);

                    // Assert
                    Assert.NotNull(subscriber);
                }
            }
        }
Exemplo n.º 15
0
        public async Task Blog_Should_Have_Unique_Slug()
        {
            using (var factory = new BlogContextFactory())
            {
                using (var context = factory.CreateBlogContext())
                {
                    // Arrange
                    var unitOfWork = new UnitOfWork(context, mapper);
                    var blogTable  = GetBlogTableInstance(slug: "new-blog", title: "new blog");
                    context.Blogs.Add(blogTable);
                    await unitOfWork.SaveAsync();

                    try
                    {
                        // Act
                        var blogForCreatingDto = GetBlogForCreatingDtoInstance(title: "new blog");
                        await unitOfWork.Blogs.AddBlog(blogForCreatingDto);

                        // Should Throw SQLite Exception
                        // becourse it's a test related exception we don't care about it
                        // only the result of this action that matter
                        await unitOfWork.SaveAsync();
                    }
                    catch
                    {
                        Assert.Single(context.Blogs);
                    }
                }

                using (var context = factory.CreateBlogContext())
                {
                    // Assert
                    var blogs = context.Blogs.ToList();
                }
            }
        }
Exemplo n.º 16
0
        public async Task Adding_Blog()
        {
            using (var factory = new BlogContextFactory())
            {
                bool isSaved = false;
                using (var context = factory.CreateBlogContext())
                {
                    // Arrange
                    var unitOfWork      = new UnitOfWork(context, mapper);
                    var blogForCreating = GetBlogForCreatingDtoInstance();
                    // Act
                    await unitOfWork.Blogs.AddBlog(blogForCreating);

                    isSaved = await unitOfWork.SaveAsync();
                }

                using (var context = factory.CreateBlogContext())
                {
                    // Assert
                    Assert.NotNull(context.Blogs.First());
                    Assert.True(isSaved);
                }
            }
        }