示例#1
0
 private void SetActivePostFromId()
 {
     InitializeRepository();
     activePost = repository.Find(p => p.Id == Id).SingleOrDefault();
 }
        public void Invoke_WithNullInputObjectAndId_DoesNotThrow(
            Mock<Common.IServiceLocator> serviceLocator,
            Mock<IRepository<Post>> repository,
            Post post)
        {
            // Given
            var posts = new[] { post };
            serviceLocator.Setup(s => s.GetInstance<IRepository<Post>>()).Returns(repository.Object);
            repository.Setup(s => s.Find(It.IsAny<Expression<Func<Post, bool>>>())).Returns(posts);
            var sut = new SetPostCommand();
            ServiceLocator.SetCurrentInstance(serviceLocator.Object);

            // When
            sut.InputObject = null;
            sut.Id = post.Id;

            // Then
            Assert.DoesNotThrow(() => sut.Invoke<Post>().Any());
        }
        public void Index_WithSomePosts_ReturnsViewWithPublishedPostInItsModel(
            Mock<IQueryService<Post>> postQueryService,
            Post[] posts)
        {
            // Given
            var publishedPosts = posts.Where(p => !p.IsDraft);
            postQueryService.Setup(s => s.Find()).Returns(posts);
            var sut = new PostController(postQueryService.Object);

            // When
            var view = sut.Index();
            var result = view.ViewData.Model as IEnumerable<Post>;

            // Then
            Assert.Equal(publishedPosts.Count(), result.Count());
        }
        public void Invoke_WithInputObject_ReturnsInputObject(
            Mock<Common.IServiceLocator> serviceLocator,
            Mock<IRepository<Post>> repository,
            Post post)
        {
            // Given
            serviceLocator.Setup(s => s.GetInstance<IRepository<Post>>()).Returns(repository.Object);
            var sut = new SetPostCommand();
            ServiceLocator.SetCurrentInstance(serviceLocator.Object);

            // When
            sut.InputObject = post;
            var result = sut.Invoke<Post>().SingleOrDefault();

            // Then
            Assert.NotNull(result);
        }
        public void Invoke_WithInputObject_SavesInputObject(
            Mock<Common.IServiceLocator> serviceLocator,
            Mock<IRepository<Post>> repository,
            Post post)
        {
            // Given
            serviceLocator.Setup(s => s.GetInstance<IRepository<Post>>()).Returns(repository.Object);
            var sut = new SetPostCommand();
            ServiceLocator.SetCurrentInstance(serviceLocator.Object);

            // When
            sut.InputObject = post;
            sut.Invoke<Post>().Any();

            // Then
            repository.Verify(m => m.Save(post));
        }
示例#6
0
        public void GetPosts_WithNewPost_ReturnsCollectionWithOneElement(
            Post post,
            string databaseName)
        {
            // Given
            var sut = new DataContext(databaseName);

            // When
            sut.RegisterAdded(post);
            sut.SaveChanges();
            var result = sut.Get<Post>();

            // Then
            Assert.Equal(1, result.Count());
            sut.Database.Delete();
            sut.Dispose();
        }
        public void Invoke_WithInputObjectAndTitle_SavesInputObjectWithNewTitle(
            Mock<Common.IServiceLocator> serviceLocator,
            Mock<IRepository<Post>> repository,
            Post post,
            string title)
        {
            // Given
            serviceLocator.Setup(s => s.GetInstance<IRepository<Post>>()).Returns(repository.Object);
            var sut = new SetPostCommand();
            ServiceLocator.SetCurrentInstance(serviceLocator.Object);

            // When
            sut.InputObject = post;
            sut.Title = title;
            sut.Invoke<Post>().Any();

            // Then
            repository.Verify(m => m.Save(It.Is<Post>(
                p => p.Id == post.Id && p.Title == title)));
        }
        public void Invoke_WithId_ReturnsPostWithSameId(
            Mock<Common.IServiceLocator> serviceLocator,
            Mock<IRepository<Post>> repository,
            Post post)
        {
            // Given
            var posts = new[] { post };
            serviceLocator.Setup(s => s.GetInstance<IRepository<Post>>()).Returns(repository.Object);
            repository.Setup(s => s.Find(It.IsAny<Expression<Func<Post, bool>>>())).Returns(posts);
            var sut = new SetPostCommand();
            ServiceLocator.SetCurrentInstance(serviceLocator.Object);

            // When
            sut.Id = post.Id;
            var result = sut.Invoke<Post>().SingleOrDefault();

            // Then
            Assert.Equal(post.Id, result.Id);
        }
        public void Invoke_WithId_SavesPostWithSameId(
            Mock<Common.IServiceLocator> serviceLocator,
            Mock<IRepository<Post>> repository,
            Post post)
        {
            // Given
            var posts = new[] { post };
            serviceLocator.Setup(s => s.GetInstance<IRepository<Post>>()).Returns(repository.Object);
            repository.Setup(s => s.Find(It.IsAny<Expression<Func<Post, bool>>>())).Returns(posts);
            var sut = new SetPostCommand();
            ServiceLocator.SetCurrentInstance(serviceLocator.Object);

            // When
            sut.Id = post.Id;
            sut.Invoke<Post>().Any();

            // Then
            repository.Verify(m => m.Save(post));
        }
示例#10
0
 private void CreateNewPostFromParameters()
 {
     newPost = new Post { Title = Title, MarkdownContent = Content };
     AddTagsFromParameters();
 }
示例#11
0
        public void Invoke_WithIdAndSingleTag_SavesPostWithSameIdAndTag(
            Mock<Common.IServiceLocator> serviceLocator,
            Mock<IRepository<Post>> repository,
            Post post,
            string tag)
        {
            // Given
            var posts = new[] { post };
            serviceLocator.Setup(s => s.GetInstance<IRepository<Post>>()).Returns(repository.Object);
            repository.Setup(s => s.Find(It.IsAny<Expression<Func<Post, bool>>>())).Returns(posts);
            var sut = new SetPostCommand();
            ServiceLocator.SetCurrentInstance(serviceLocator.Object);

            // When
            sut.Id = post.Id;
            sut.Tags = new[] { tag };
            sut.Invoke<Post>().Any();

            // Then
            repository.Verify(m => m.Save(It.Is<Post>(
                p => p.Id == post.Id &&
                     p.Tags.Select(t => t.Name).FirstOrDefault() == tag)));
        }
示例#12
0
        public void GetPosts_WithNewPostAndEagerLoadedTag_ReturnsPostWithTheSameTag(
            Post post,
            Tag tag,
            string databaseName)
        {
            // Given
            post.Tags.Add(tag);
            var sut = new DataContext(databaseName);

            // When
            sut.RegisterAdded(post);
            sut.SaveChanges();
            var result = sut.Get<Post>("Tags").SingleOrDefault();

            // Then
            Assert.True(post.Tags.SequenceEqual(result.Tags));
            sut.Database.Delete();
            sut.Dispose();
        }
示例#13
0
        public void RegisterModified_WithModifiedPost_PersistsPost(
            string databaseName,
            Post post,
            string modifiedValue)
        {
            // Given
            var sut = new DataContext(databaseName);
            sut.RegisterAdded(post);
            sut.Commit();

            // When
            post.Title = modifiedValue;
            sut.RegisterModified(post);
            sut.Commit();
            var result = sut.Get<Post>().FirstOrDefault();

            // Then
            Assert.Equal(post, result);
            sut.Database.Delete();
            sut.Dispose();
        }
示例#14
0
        public void RegisterDeleted_WithPost_RemovesPost(
            string databaseName,
            Post post)
        {
            // Given
            var sut = new DataContext(databaseName);
            sut.RegisterAdded(post);
            sut.Commit();

            // When
            sut.RegisterDeleted(post);
            sut.Commit();
            var result = sut.Get<Post>().Any();

            // Then
            Assert.False(result);
            sut.Database.Delete();
            sut.Dispose();
        }
示例#15
0
 private void SetActivePostFromInputObject()
 {
     activePost = InputObject;
 }
示例#16
0
        public void Invoke_WithInputObjectAndNullContent_SavesInputObjectWithNotNullContent(
            Mock<Common.IServiceLocator> serviceLocator,
            Mock<IRepository<Post>> repository,
            Post post)
        {
            // Given
            serviceLocator.Setup(s => s.GetInstance<IRepository<Post>>()).Returns(repository.Object);
            var sut = new SetPostCommand();
            ServiceLocator.SetCurrentInstance(serviceLocator.Object);

            // When
            sut.InputObject = post;
            sut.Content = null;
            sut.Invoke<Post>().Any();

            // Then
            repository.Verify(m => m.Save(It.Is<Post>(
                p => p.Id == post.Id && p.MarkdownContent != null)));
        }
示例#17
0
        public void Invoke_WithSomePosts_ReturnsSameNumberOfPosts(
            Mock<Common.IServiceLocator> serviceLocator,
            Mock<IRepository<Post>> repository,
            Post[] posts)
        {
            // Given
            serviceLocator.Setup(s => s.GetInstance<IRepository<Post>>()).Returns(repository.Object);
            repository.Setup(s => s.Find(It.IsAny<string[]>())).Returns(posts);
            var sut = new GetPostCommand();
            ServiceLocator.SetCurrentInstance(serviceLocator.Object);

            // When
            var result = sut.Invoke<Post>();

            // Then
            Assert.Equal(posts.Count(), result.Count());
        }
示例#18
0
        public void GetPosts_WithNewPostAndNonExistentEagerLoadedProperty_Throws(
            Post post,
            string propertyName,
            string databaseName)
        {
            // Given
            var sut = new DataContext(databaseName);

            // When
            sut.RegisterAdded(post);
            sut.SaveChanges();

            // Then
            Assert.Throws<InvalidOperationException>(() => sut.Get<Post>(propertyName).Any());
            sut.Database.Delete();
            sut.Dispose();
        }