Skip to content

Instantly share code, notes, and snippets.

@AlexArchive
Last active August 29, 2015 14:05
Show Gist options
  • Save AlexArchive/798feb4ed3b1847ad2b1 to your computer and use it in GitHub Desktop.
Save AlexArchive/798feb4ed3b1847ad2b1 to your computer and use it in GitHub Desktop.
Should I unit test the repository and the controller? I probably only need to verify that the already-tested
repository has been called into.
Should I test All_ReturnsAll and All_OrdersByPublish date or just the former?
@AlexArchive
Copy link
Author

    [Test]
    public void Create()
    {
        var databaseSet = new Mock<DbSet<Post>>();
        var databaseContext = new Mock<DatabaseContext>();
        databaseContext.Setup(context => context.Posts).Returns(databaseSet.Object);

        var actual = new Post { Slug = "AAA" };
        var repository = new PostsRepository(databaseContext.Object);
        repository.Create(actual);
        databaseSet.Verify(set => set.Add(It.IsAny<Post>()), Times.Once);
        Assert.AreNotEqual(DateTime.MinValue, actual.PublishedAt);
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment