public async void GetPhoto200OKResponse()
        {   //Mocking Setup
            var mockUserRequest = new Mock <IPhotoRequestHandler>();

            mockUserRequest.Setup(req => req.GetPhotos()).ReturnsAsync(GetPhotos());

            var mockIMapper = new Mock <IMapper>();

            mockIMapper.Setup(op => op.Map <List <PhotoDto> >(It.IsAny <List <Photo> >())).Returns(GetPhotosDto());

            //Act
            var controller = new PhotosController(mockUserRequest.Object, mockIMapper.Object);
            var photos     = await controller.GetPhotos();

            //Assert
            Assert.IsType <OkObjectResult>(photos.Result);
        }
        public async void GetPhotosReturnAllItems()
        {   //Mocking Setup
            var mockUserRequest = new Mock <IPhotoRequestHandler>();

            mockUserRequest.Setup(req => req.GetPhotos()).ReturnsAsync(GetPhotos());

            var mockIMapper = new Mock <IMapper>();

            mockIMapper.Setup(op => op.Map <List <PhotoDto> >(It.IsAny <List <Photo> >())).Returns(GetPhotosDto());

            //Act
            var controller = new PhotosController(mockUserRequest.Object, mockIMapper.Object);
            var photos     = await controller.GetPhotos();

            var okResult = photos.Result as OkObjectResult;
            var items    = Assert.IsType <List <PhotoDto> >(okResult.Value);

            //Assert
            Assert.Equal(2, items.Count);
        }
Esempio n. 3
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            while (!stoppingToken.IsCancellationRequested)
            {
                _logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);

                await UsersController.GetUsers();

                UsersController.SaveUsersToDB();
                _logger.LogInformation("Saved Users");

                await PostsController.GetPosts();

                PostsController.SavePostsToDB();
                _logger.LogInformation("Saved Posts");

                await CommentsController.GetComments();

                CommentsController.SaveCommentsToDB();
                _logger.LogInformation("Saved Comments");

                await AlbumsController.GetAlbums();

                AlbumsController.SaveAlbumsToDB();
                _logger.LogInformation("Saved Albums");

                await PhotosController.GetPhotos();

                PhotosController.SavePhotosToDB();
                _logger.LogInformation("Saving Photos");

                await TodosController.GetTodos();

                TodosController.SaveTodosToDB();
                _logger.LogInformation("Saving Todos");

                await Task.Delay(DelayInSeconds * 1000, stoppingToken);
            }
        }
Esempio n. 4
0
        public async Task GetPhotos()
        {
            // Arrange
            var seedPhotos            = SeedPhotos();
            var seedPhotoResources    = this._mapper.Map <IEnumerable <Photo>, IEnumerable <PhotoResource> >(seedPhotos);
            var filterResource        = new PhotoQueryResource();
            var mockPhotoRepository   = new Mock <IPhotoRepository>();
            var mockCommentRepository = new Mock <ICommentRepository>();

            mockPhotoRepository.Setup(m => m.GetPhotos(It.IsAny <PhotoQuery>())).ReturnsAsync(seedPhotos);
            var mockCategoryRepository = new Mock <ICategoryRepository>();
            var mockUserRepository     = new Mock <IUserRepository>();
            var mockAlbumRepository    = new Mock <IAlbumRepository>();
            var mockUnitOfWork         = new Mock <IUnitOfWork>();
            var mockPhotoUploadService = new Mock <IPhotoUploadService>();
            var mockHost = new Mock <IWebHostEnvironment>();

            mockHost.SetupGet(m => m.WebRootPath).Returns(string.Empty);
            var mockObjectDetectionService = new Mock <IObjectDetectionService>();

            PhotosController controller = new PhotosController(this._mapper, mockPhotoRepository.Object,
                                                               mockCategoryRepository.Object, mockUserRepository.Object, mockCommentRepository.Object,
                                                               mockAlbumRepository.Object, mockUnitOfWork.Object, mockPhotoUploadService.Object,
                                                               mockHost.Object, mockObjectDetectionService.Object);

            seedPhotoResources = seedPhotoResources.Select(p => {
                p.BoundingBoxFilePath = string.Format("{0}/{1}", controller.OutputFolderUrl, p.FilePath);
                p.FilePath            = string.Format("{0}/{1}", controller.UploadFolderUrl, p.FilePath);
                return(p);
            });
            // Act
            var photos = await controller.GetPhotos(filterResource);

            // Assert
            Assert.True(seedPhotoResources.SequenceEqual(photos));
        }