Ejemplo n.º 1
0
        public void GetById_ShouldNotReturnAlbumIfAlbumIsPrivate_WhenUserIsNotAuthorized()
        {
            // arrange
            var data = new FakeGalleryData();

            this.PopulateFakeGalleryAlbumsData(data, 5);
            var    service  = new AlbumsService(data);
            string username = null;

            // act
            var actual = service.GetById(2, username).Count();

            // assert
            Assert.AreEqual(0, actual);
        }
Ejemplo n.º 2
0
        public void GetById_ShouldReturnNullDataWhenAlbumDoesNotExists()
        {
            var user  = UserCreator.Create("test");
            var album = AlbumCreator.Create(false, user);

            var listAlbums      = new List <Album>();
            var listPhotoAlbums = new List <PhotoAlbum>();

            var photoAlbumsRepo = EfRepositoryMock.Get <PhotoAlbum>(listPhotoAlbums);
            var albumsRepo      = DeletableEntityRepositoryMock.Get <Album>(listAlbums);

            var service       = new AlbumsService(albumsRepo.Object, photoAlbumsRepo.Object);
            var returnedAlbum = service.GetById <AlbumViewModel>(album.Id, user.Id);

            Assert.Null(returnedAlbum);
        }
Ejemplo n.º 3
0
        public void GetById_ShouldReturnCorrectData()
        {
            var user  = UserCreator.Create("test");
            var album = AlbumCreator.Create(false, user);

            var listAlbums = new List <Album>()
            {
                album
            };
            var listPhotoAlbums = new List <PhotoAlbum>();

            var photoAlbumsRepo = EfRepositoryMock.Get <PhotoAlbum>(listPhotoAlbums);
            var albumsRepo      = DeletableEntityRepositoryMock.Get <Album>(listAlbums);

            var service       = new AlbumsService(albumsRepo.Object, photoAlbumsRepo.Object);
            var returnedAlbum = service.GetById <AlbumViewModel>(album.Id, user.Id);

            Assert.Equal(album.Id, returnedAlbum.Id);
            Assert.Equal(album.Name, returnedAlbum.Name);
            Assert.Equal(album.Description, returnedAlbum.Description);
        }
Ejemplo n.º 4
0
        public void GetById_ReturnsCorrectItem()
        {
            // Arrange
            var context = this.ServiceProvider.GetRequiredService <WmipDbContext>();
            var album1  = new Album {
                Id = 1, Name = "Abm1"
            };
            var album2 = new Album {
                Id = 2, Name = "Abm2"
            };

            context.Albums.AddRange(album1, album2);
            context.SaveChanges();
            var albumsService = new AlbumsService(context);

            // Act
            var result = albumsService.GetById(1);

            //Assert
            Assert.NotNull(result);
            Assert.Equal(album1.Name, result.Name);
        }
Ejemplo n.º 5
0
        public void GetById_ShouldReturnCorrectAlbumIfNotPrivate_WhenUserIsNotAuthorized()
        {
            // arrange
            var data = new FakeGalleryData();
            this.PopulateFakeGalleryAlbumsData(data, 5);
            var service = new AlbumsService(data);
            string username = null;

            // act
            var actual = service.GetById(1, username).Count();

            // assert
            Assert.AreEqual(1, actual);
        }
Ejemplo n.º 6
0
        public void GetById_ShouldReturnAlbumIfAlbumIsPrivate_AndOwnerIsAuthorized()
        {
            // arrange
            var data = new FakeGalleryData();
            this.PopulateFakeGalleryAlbumsData(data, 5);
            var service = new AlbumsService(data);
            string username = "******";

            // act
            var actual = service.GetById(2, username).Count();

            // assert
            Assert.AreEqual(1, actual);
        }