Beispiel #1
0
        public async void Publish_BlogPost_does_not_allow_empty_title(string title, EPostStatus status, int numberOfErrors, string[] expectedMessages)
        {
            // Given a blog post to publish
            var blogPost = new BlogPost {
                Title = title, Status = status
            };

            // When validate it throws FanException
            var ex = await Assert.ThrowsAsync <FanException>(() => blogPost.ValidateTitleAsync());

            Assert.Equal(numberOfErrors, ex.ValidationErrors.Count);
            Assert.Equal(expectedMessages[0], ex.ValidationErrors[0].ErrorMessage);
        }
Beispiel #2
0
        public async void BlogPost_title_cannot_exceed_250_chars_regardless_status(EPostStatus status, string[] expectedMessages)
        {
            // Arrange: a blog post with a title of 251 chars
            var title    = string.Join("", Enumerable.Repeat <char>('a', 251));
            var blogPost = new BlogPost {
                Title = title, Status = status
            };

            // Act: validate
            var ex = await Assert.ThrowsAsync <FanException>(() => blogPost.ValidateTitleAsync());

            // Assert: 1 error
            Assert.Equal(1, ex.ValidationErrors.Count);
            Assert.Equal(expectedMessages[0], ex.ValidationErrors[0].ErrorMessage);
        }
        public async void Create_post_throws_FanException_if_post_status_is_published_and_title_is_empty(string title, EPostStatus status, string expectedMessages)
        {
            // Arrange: a blog post with an invalid title
            var blogPost = new BlogPost {
                Title = title, UserId = Actor.AUTHOR_ID, Status = status
            };

            // Act: validate
            await Assert.ThrowsAsync <FanException>(() => _blogPostSvc.CreateAsync(blogPost));

            try
            {
                await _blogPostSvc.CreateAsync(blogPost);
            }
            catch (FanException ex)
            {
                Assert.Equal(expectedMessages, ex.Message);
            }
        }