コード例 #1
0
        public void RedirectToCorrectUrl_WhenCreateReviewIsSuccessful()
        {
            var args = MockedEventArgsGenerator.GetBeerReviewInfoEventArgs();
            var view = new Mock <ICreateReviewView>();
            var createReviewResult = new Mock <IDataModifiedResult>();

            createReviewResult.Setup(r => r.Successful)
            .Returns(true);

            var reviewService = new Mock <IBeerReviewService>();

            reviewService.Setup(r => r.CreateReview(It.IsAny <IBeerReview>()))
            .Returns(createReviewResult.Object);
            var imgUpload = new Mock <IImageUploadService>();

            imgUpload.Setup(img => img.UploadImage(It.IsAny <byte[]>(), It.IsAny <int>(), It.IsAny <int>()))
            .Returns((string)null);
            var mockedResponse = new MockedHttpResponse();

            var presenter = new CreateReviewPresenter(reviewService.Object, imgUpload.Object, view.Object)
            {
                HttpContext = new MockedHttpContextBase(mockedResponse)
            };

            view.Raise(v => v.OnCreateReview += null, view.Object, args);

            Assert.AreEqual("/Reviews/My", mockedResponse.RedirectUrl);
        }
コード例 #2
0
        public void Set_ViewErrorMessageText_WhenCreateReviewFails()
        {
            var expectedMessage    = this.Fixture.Create <string>();
            var args               = MockedEventArgsGenerator.GetBeerReviewInfoEventArgs();
            var view               = new Mock <ICreateReviewView>();
            var createReviewResult = new Mock <IDataModifiedResult>();

            createReviewResult.Setup(r => r.Successful)
            .Returns(false);
            createReviewResult.Setup(r => r.Errors)
            .Returns(new[] { expectedMessage });

            var reviewService = new Mock <IBeerReviewService>();

            reviewService.Setup(r => r.CreateReview(It.IsAny <IBeerReview>()))
            .Returns(createReviewResult.Object);
            var imgUpload = new Mock <IImageUploadService>();

            imgUpload.Setup(img => img.UploadImage(It.IsAny <byte[]>(), It.IsAny <int>(), It.IsAny <int>()))
            .Returns((string)null);

            var presenter = new CreateReviewPresenter(reviewService.Object, imgUpload.Object, view.Object);

            view.Raise(v => v.OnCreateReview += null, view.Object, args);

            view.VerifySet(v => v.ErrorMessageText = expectedMessage, Times.Once);
        }
コード例 #3
0
        public void Call_ReviewServiceCreateReviewMethodOnceWithCorrectParams()
        {
            var view = new Mock <ICreateReviewView>();
            var args = MockedEventArgsGenerator.GetBeerReviewInfoEventArgs();
            var createReviewResult = new Mock <IDataModifiedResult>();

            createReviewResult.Setup(r => r.Successful)
            .Returns(false);
            createReviewResult.Setup(r => r.Errors)
            .Returns(new string[0]);
            var reviewService = new Mock <IBeerReviewService>();

            reviewService.Setup(r => r.CreateReview(It.IsAny <IBeerReview>()))
            .Returns(createReviewResult.Object);
            var imgUpload = new Mock <IImageUploadService>();

            imgUpload.Setup(img => img.UploadImage(It.IsAny <byte[]>(), It.IsAny <int>(), It.IsAny <int>()))
            .Returns((string)null);

            var presenter = new CreateReviewPresenter(reviewService.Object, imgUpload.Object, view.Object);

            view.Raise(v => v.OnCreateReview += null, view.Object, args);

            reviewService.Verify(s => s.CreateReview(args.BeerReview), Times.Once);
        }
コード例 #4
0
        public void CatchUpdateExceptionAndSetViewProperties()
        {
            var expectedMessage = this.Fixture.Create <string>();

            var args = MockedEventArgsGenerator.GetBeerReviewInfoEventArgs();

            var view = new Mock <IMyReviewsView>();

            var result = new Mock <IDataModifiedResult>();

            result.Setup(r => r.Successful).Returns(false);
            result.Setup(r => r.Errors).Returns(new[] { expectedMessage });

            var reviewService = new Mock <IBeerReviewService>();

            reviewService.Setup(s => s.UpdateReview(args.BeerReview))
            .Returns(result.Object);

            var httpResponse = new MockedHttpResponse();
            var presenter    = new MyReviewsPresenter(reviewService.Object, view.Object)
            {
                HttpContext = new MockedHttpContextBase(httpResponse)
            };

            view.Raise(v => v.ReviewUpdate += null, view.Object, args);

            view.VerifySet(v => v.SuccessMessageText    = expectedMessage, Times.Once);
            view.VerifySet(v => v.SuccessMessageVisible = true, Times.Once);
        }
コード例 #5
0
        public void SetViewPropertiesCorrectly()
        {
            const string ExpectedMessage = "Review successfully updated!";
            var          args            = MockedEventArgsGenerator.GetBeerReviewInfoEventArgs();

            var view = new Mock <IMyReviewsView>();

            var result = new Mock <IDataModifiedResult>();

            result.Setup(r => r.Successful).Returns(true);

            var reviewService = new Mock <IBeerReviewService>();

            reviewService.Setup(s => s.UpdateReview(args.BeerReview))
            .Returns(result.Object);

            var httpResponse = new MockedHttpResponse();
            var presenter    = new MyReviewsPresenter(reviewService.Object, view.Object)
            {
                HttpContext = new MockedHttpContextBase(httpResponse)
            };

            view.Raise(v => v.ReviewUpdate += null, view.Object, args);

            view.VerifySet(v => v.SuccessMessageText    = ExpectedMessage, Times.Once);
            view.VerifySet(v => v.SuccessMessageVisible = true, Times.Once);
        }
コード例 #6
0
        public void Call_ImgServiceUploadImageMethodOnceWithCorrectParams_WhenImageIsNotNull()
        {
            var args               = MockedEventArgsGenerator.GetBeerReviewInfoEventArgs();
            var view               = new Mock <ICreateReviewView>();
            var imgUpload          = new Mock <IImageUploadService>();
            var createReviewResult = new Mock <IDataModifiedResult>();

            createReviewResult.Setup(r => r.Successful)
            .Returns(false);
            var reviewService = new Mock <IBeerReviewService>();

            reviewService.Setup(r => r.CreateReview(It.IsAny <IBeerReview>()))
            .Returns(createReviewResult.Object);

            var presenter = new CreateReviewPresenter(reviewService.Object, imgUpload.Object, view.Object);

            view.Raise(v => v.OnCreateReview += null, view.Object, args);

            imgUpload.Verify(i => i.UploadImage(args.Image, Constants.DefaultThumbnailSizePx, Constants.DefaultThumbnailSizePx), Times.Once);
        }
コード例 #7
0
        public void CallUpdateReviewMethodOnce()
        {
            var args   = MockedEventArgsGenerator.GetBeerReviewInfoEventArgs();
            var view   = new Mock <IMyReviewsView>();
            var result = new Mock <IDataModifiedResult>();

            result.Setup(r => r.Successful).Returns(false);
            var reviewService = new Mock <IBeerReviewService>();

            reviewService.Setup(s => s.UpdateReview(args.BeerReview))
            .Returns(result.Object);

            var httpResponse = new MockedHttpResponse();
            var presenter    = new MyReviewsPresenter(reviewService.Object, view.Object)
            {
                HttpContext = new MockedHttpContextBase(httpResponse)
            };

            view.Raise(v => v.ReviewUpdate += null, view.Object, args);

            reviewService.Verify(s => s.UpdateReview(args.BeerReview), Times.Once);
        }