Ejemplo n.º 1
0
        public async Task WhenValidationErrorsDoNotCallWebRepo()
        {
            //arrange
            var errorValidator = new PhotoAlbumValidatorModel()
            {
                Id = 1,
                ValidationResults = new List <ValidationResult>()
                {
                    new ValidationResult("generic error")
                }
            };

            var validatorMock = new Mock <IPhotoAlbumInputValidator>();

            validatorMock.Setup(v => v.ValidateInput(It.IsAny <string>())).Returns(errorValidator);

            var webRepoMock = new Mock <IPhotoAlbumWebRepo>();

            webRepoMock.Setup(w => w.GetPhotoById(It.IsAny <int>())).ReturnsAsync(new List <PhotoModel>());

            var systemUnderTest = new PhotoAlbumComponent(validatorMock.Object, webRepoMock.Object);
            //act
            await systemUnderTest.DoPhotoAlbumWork(It.IsAny <string>());

            //asert
            validatorMock.Verify(v => v.ValidateInput(It.IsAny <string>()), Times.Once);
            webRepoMock.Verify(v => v.GetPhotoById(It.IsAny <int>()), Times.Never);
        }
Ejemplo n.º 2
0
        public async Task HappyPathListWithStuff()
        {
            //arrange
            var passingValidator = new PhotoAlbumValidatorModel()
            {
                Id = 1,
                ValidationResults = new List <ValidationResult>()
            };

            var validatorMock = new Mock <IPhotoAlbumInputValidator>();

            validatorMock.Setup(v => v.ValidateInput(It.IsAny <string>())).Returns(passingValidator);

            var webRepoMock = new Mock <IPhotoAlbumWebRepo>();
            var fakeList    = GetFakeList();

            webRepoMock.Setup(w => w.GetPhotoById(It.IsAny <int>())).ReturnsAsync(fakeList);

            var systemUnderTest = new PhotoAlbumComponent(validatorMock.Object, webRepoMock.Object);
            //act
            await systemUnderTest.DoPhotoAlbumWork(It.IsAny <string>());

            //asert
            validatorMock.Verify(v => v.ValidateInput(It.IsAny <string>()), Times.Once);
            webRepoMock.Verify(v => v.GetPhotoById(It.IsAny <int>()), Times.Once);
        }