Beispiel #1
0
        public void Call_RepositoryAddMethodOnceWithCorrectParams()
        {
            var id         = this.Fixture.Create <string>();
            var review     = new BeerReview();
            var repository = new Mock <IRepository <BeerReview> >();

            repository.Setup(r => r.GetById(id))
            .Returns(review);

            var reviewService = new BeerReviewService(repository.Object);

            reviewService.CreateReview(review);

            repository.Verify(r => r.Add(review), Times.Once);
        }
Beispiel #2
0
        public void Call_RepositorySaveChangesMethodOnceAndReturnItsValue()
        {
            var expected   = new Mock <IDataModifiedResult>();
            var review     = new BeerReview();
            var repository = new Mock <IRepository <BeerReview> >();

            repository.Setup(r => r.SaveChanges())
            .Returns(expected.Object);

            var reviewService = new BeerReviewService(repository.Object);

            var actual = reviewService.CreateReview(review);

            repository.Verify(r => r.SaveChanges(), Times.Once);
            Assert.AreSame(expected.Object, actual);
        }