Esempio n. 1
0
        [TestMethod] //A value test
        public void GettingTopFiveReviews_WhenFiveExist_ReturnsFiveInDescendingOrder()
        {
            //Arrange
            var mockContext     = Mock.Create <FruitFinderContext>().PrepareMock();
            var reviews         = new List <Review>();
            var builder         = new FruitFinderDalBuilder().WithContext(mockContext);
            var numberToInclude = 5;

            for (int i = 0; i < numberToInclude * 2; i++)
            {
                var review = builder.MakeReview();
                review.VoteTally = i;
                reviews.Add(review);
            }
            mockContext.Reviews.Bind(reviews);
            var dal = builder.Build();

            //Act
            var result = dal.GetTopReviews(numberToInclude);

            //Assert
            result.Count().Should().Be(numberToInclude,
                                       "the list should have " + numberToInclude + " reviews");
            result.Should().BeInDescendingOrder(x => x.VoteTally,
                                                "the reviews should be in descending order by VoteTally");
        }
Esempio n. 2
0
        public void SavingAReview_WhenTheReviewIsNull_RaisesAnArgumentNullException()
        {
            //Arrange
            var    builder = new FruitFinderDalBuilder();
            var    dal     = builder.Build();
            Review review  = null;

            //Act
            dal.SaveReview(review);
        }
Esempio n. 3
0
        public void SavingAReview_WhenNoFruitIncluded_RaisesAnApplicationException()
        {
            //Arrange
            var builder = new FruitFinderDalBuilder();
            var dal     = builder.Build();
            var review  = builder.MakeReview();

            review.FruitId = 0;
            review.Fruit   = null;

            //Act
            dal.SaveReview(review);
        }
Esempio n. 4
0
        public void SavingAReview_WhenSuccessful_CallsContextSaveChanges()
        {
            //Arrange
            var mockContext = EntityFrameworkMock.Create <IFruitFinderContext>();

            Mock.Arrange(() => mockContext.SaveChanges()).OccursOnce();
            var builder = new FruitFinderDalBuilder().WithContext(mockContext);
            var dal     = builder.Build();
            var review  = builder.MakeReview();

            //Act
            dal.SaveReview(review);

            //Assert
            Mock.Assert(mockContext);
        }
Esempio n. 5
0
        public void SavingAReview_WhenItIsNew_SetsTheAddedByAndWhen()
        {
            //Arrange
            var builder     = new FruitFinderDalBuilder();
            var dal         = builder.Build();
            var review      = builder.MakeReview();
            var defaultDate = builder.GetDateTimeService().UtcNow().AddDays(-1);

            review.AddedWhen = defaultDate;

            //Act
            var result = dal.SaveReview(review);

            //Assert
            result.AddedBy.Should().BeGreaterThan(0, "the added by Id should be set.");
            result.AddedWhen.Should().BeAfter(defaultDate, "the added when should be set.");
        }
Esempio n. 6
0
        public void SavingAReview_WhenUpdatingIt_UpdatesTheUpdatedWhenAndBy()
        {
            //Arrange
            var builder         = new FruitFinderDalBuilder();
            var dal             = builder.Build();
            var dateTimeService = builder.GetDateTimeService();
            var review          = builder.MakeReview();

            review.ReviewId    = 1;
            review.UpdatedBy   = FruitFinderDalBuilder.SecurityServiceUserId + 1;
            review.UpdatedWhen = dateTimeService.UtcNow().AddDays(-1);

            //Act
            dal.SaveReview(review);

            //Assert
            review.UpdatedWhen.ShouldBeEquivalentTo(dateTimeService.UtcNow(),
                                                    "the updated date should be set to UtcNow when the review is saved");
            review.UpdatedBy.ShouldBeEquivalentTo(FruitFinderDalBuilder.SecurityServiceUserId,
                                                  "the updated by should be set to the current user when a review is saved");
        }