예제 #1
0
        public void Run_ValidArgs_WritesValidationDescription()
        {
            var mockTextWriter        = Substitute.For <TextWriter>();
            var mockValidationService = Substitute.For <IValidationService>();
            var mockPhotoAlbumService = Substitute.For <IPhotoAlbumService>();

            mockValidationService.GetValidationResult(Arg.Any <string[]>()).Returns(new ValidationResult
            {
                Description = "Valid",
                IsValid     = true,
                Result      = 1
            });

            mockPhotoAlbumService.GetPhotosByAlbumId(1).Returns(new GetPhotosResult
            {
                // saving some space by generating a list of photos with numbers 1-10 as id
                Photos = Enumerable.Range(1, 10).Select(n => new Photo {
                    Id = n, Title = "test"
                }).ToList()
            });

            var testRunner = new PhotoAppRunner(mockTextWriter, mockValidationService, mockPhotoAlbumService);

            testRunner.Run(new[] { "1" });

            mockTextWriter.DidNotReceive().WriteLine("Invalid Album ID provided.");
            // saving space by counting from 1-10
            Enumerable.Range(1, 10).ToList().ForEach((n) => mockTextWriter.Received().WriteLine($"[{n}] test"));
        }
예제 #2
0
        static void Main(string[] args)
        {
            IConfiguration configuration = new ConfigurationBuilder()
                                           .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                                           .Build();
            var validationService     = new ValidationService();
            var jsonSerializerOptions = new JsonSerializerOptions {
                PropertyNameCaseInsensitive = true
            };

            using var httpClientWrapper = new HttpGetService(configuration["PhotosUrl"]);
            var photoService      = new PhotoService(httpClientWrapper, jsonSerializerOptions);
            var photoAlbumService = new PhotoAlbumService(photoService);
            var photoAppRunner    = new PhotoAppRunner(Console.Out, validationService, photoAlbumService);

            photoAppRunner.Run(args);
        }
예제 #3
0
        public void Run_InvalidArgs_WritesValidationDescription()
        {
            var mockTextWriter        = Substitute.For <TextWriter>();
            var mockValidationService = Substitute.For <IValidationService>();
            var mockPhotoAlbumService = Substitute.For <IPhotoAlbumService>();

            mockValidationService.GetValidationResult(Arg.Any <string[]>()).Returns(new ValidationResult
            {
                Description = "Invalid Album ID provided.",
                IsValid     = false
            });

            var testRunner = new PhotoAppRunner(mockTextWriter, mockValidationService, mockPhotoAlbumService);

            testRunner.Run(new[] { "badArg" });

            mockTextWriter.Received(1).WriteLine("Invalid Album ID provided.");
        }