Пример #1
0
        public void Delete_ShouldDeleteAlbumOfAuthorizedUser()
        {
            // arrange

            string username = "******";
            var    album    = new Album()
            {
                Id      = 2,
                Name    = "customAlbum0",
                Private = false,
                Owner   = new User()
                {
                    UserName = username
                }
            };

            var data = new FakeGalleryData();

            data.Albums.Add(album);
            var service = new AlbumsService(data);

            // act

            service.DeleteAlbumById(2, username);

            // assert

            var actual = data.Albums.All().Count();

            Assert.AreEqual(0, actual);
        }
Пример #2
0
        public void GetAlbumsByUser_ShouldGetOnlyPublicAlbumsOfUserIfOtherAuthenitcatedUser()
        {
            // arrange
            var data = new FakeGalleryData();

            this.PopulateFakeGalleryUsersData(data, 5);
            this.PopulateFakeGalleryAlbumsData(data, 10);

            string username = "******";
            var    album    = new Album()
            {
                Name    = "customAlbum0",
                Private = false
            };

            var service = new AlbumsService(data);

            service.Add(album, username);

            // act
            var actual = service.GetAlbumsByUser(username, "user1").Count();

            // assert
            Assert.AreEqual(1, actual);
        }
Пример #3
0
        public void Delete_ShouldReturnMinusOneIfAlbumWasNotFoundOrAuthorizedUserIsNotOwner()
        {
            // arrange

            string username = "******";
            var    album    = new Album()
            {
                Id      = 2,
                Name    = "customAlbum0",
                Private = false,
                Owner   = new User()
                {
                    UserName = username
                }
            };

            var data = new FakeGalleryData();

            data.Albums.Add(album);
            var service = new AlbumsService(data);

            // act

            var actual = service.DeleteAlbumById(3, username);

            // assert

            Assert.AreEqual(0, actual);
        }
Пример #4
0
        public void Delete_ShouldReturnTheIdOfTheDeletedAlbum()
        {
            // arrange

            string username = "******";
            var    album    = new Album()
            {
                Id      = 2,
                Name    = "customAlbum0",
                Private = false,
                Owner   = new User()
                {
                    UserName = username
                }
            };

            var data = new FakeGalleryData();

            data.Albums.Add(album);
            var service = new AlbumsService(data);

            // act

            var actual = service.DeleteAlbumById(2, username);

            // assert

            Assert.AreEqual(2, actual);
        }
Пример #5
0
        public void Add_ShouldThrowArgumentNullExceptionWhenNullTagProvided()
        {
            var data        = new FakeGalleryData();
            var tagsService = new TagsService(data);

            tagsService.Add(null);
        }
Пример #6
0
        public void Delete_ShouldCallSaveChangesIfOperationIsAuthorizedAndAlbumIsFound()
        {
            // arrange

            string username = "******";
            var    album    = new Album()
            {
                Id      = 2,
                Name    = "customAlbum0",
                Private = false,
                Owner   = new User()
                {
                    UserName = username
                }
            };

            var data = new FakeGalleryData();

            data.Albums.Add(album);
            var service = new AlbumsService(data);

            // act

            service.DeleteAlbumById(2, username);

            // assert

            var actual = data.SaveChangesCallCount;

            Assert.AreEqual(1, actual);
        }
Пример #7
0
        public void GetById_ShouldReturnZeroWhenSuchTagIdIsNotFound()
        {
            var data        = new FakeGalleryData();
            var tagsService = new TagsService(data);

            var foundTags = tagsService.GetById(GlobalConstants.DefaultTagIdForTesting);

            Assert.AreEqual(0, foundTags.Count());
        }
Пример #8
0
        public void Delete_ShouldReturnProperValueWhenTagIdDoesNotExist()
        {
            var data        = new FakeGalleryData();
            var tagsService = new TagsService(data);

            var deletedTagId = tagsService.DeleteTagById(GlobalConstants.DefaultTagIdForTesting);

            Assert.AreEqual(-1, deletedTagId);
        }
Пример #9
0
        public void Add_ShouldThrowIfAlbumIsNull()
        {
            // arrange
            var    data     = new FakeGalleryData();
            var    service  = new AlbumsService(data);
            string username = "******";

            // act
            service.Add(null, username);
        }
Пример #10
0
        public void Add_ShouldThrow_WhenNoCreatorSpecified()
        {
            // arrange
            var data = new FakeGalleryData();

            this.PopulateFakeGalleryUsersData(data, 5);
            var service = new AlbumsService(data);
            var album   = this.GetAlbum("myalbum", false);

            // act
            service.Add(album, null);
        }
Пример #11
0
        public void Add_ShouldThrowIfUserWithSpecifiedUsernameIsNotFound()
        {
            // arrange
            var data = new FakeGalleryData();

            this.PopulateFakeGalleryUsersData(data, 5);
            var    service  = new AlbumsService(data);
            string username = "******";
            var    album    = this.GetAlbum("myalbum", false);

            // act
            service.Add(album, username);
        }
Пример #12
0
        public void GetAll_ShouldReturnZeroAlbumsCount_WhenNoAlbumsInData()
        {
            // arrange
            var    data     = new FakeGalleryData();
            var    service  = new AlbumsService(data);
            string username = null;

            // act
            var actual = service.GetAll(username).Count();

            // assert
            Assert.AreEqual(0, actual);
        }
Пример #13
0
        public void GetById_ShouldReturnProperAmountOfTags()
        {
            var data        = new FakeGalleryData();
            var tagsService = new TagsService(data);

            var newTag = new Tag();
            var tagId  = newTag.Id;

            tagsService.Add(newTag);
            var foundTags = tagsService.GetById(tagId);

            Assert.AreEqual(1, foundTags.Count());
        }
Пример #14
0
        private void PopulateFakeGalleryUsersData(
            FakeGalleryData data,
            int usersCount)
        {
            for (int i = 0; i < usersCount; i++)
            {
                var user = new User()
                {
                    UserName = "******" + i
                };

                data.Users.Add(user);
            }
        }
Пример #15
0
        public void Delete_ShouldReturnProperDeletedTagId()
        {
            var data        = new FakeGalleryData();
            var tagsService = new TagsService(data);

            var newTag = new Tag();
            var tagId  = newTag.Id;

            tagsService.Add(newTag);
            tagsService.DeleteTagById(tagId);
            var foundTags = tagsService.GetById(tagId);

            Assert.AreEqual(0, foundTags.Count());
        }
Пример #16
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);
        }
Пример #17
0
        public void GetAll_ShouldReturnNonPrivateAndPrivateAlbumsOfTheAuthorizedUser_WhenUserIsAuthorized()
        {
            // arrange
            var data = new FakeGalleryData();

            this.PopulateFakeGalleryAlbumsData(data, 30);
            var    service  = new AlbumsService(data);
            string username = "******";

            // act
            var actual = service.GetAll(username).Count();

            // assert
            Assert.AreEqual(16, actual);
        }
Пример #18
0
        public void Add_ShouldReturnTheAddedAlbumId()
        {
            // arrange
            var data = new FakeGalleryData();

            this.PopulateFakeGalleryUsersData(data, 5);
            var    service  = new AlbumsService(data);
            string username = "******";
            var    album    = this.GetAlbum("myalbum", false);

            // act
            var actual = service.Add(album, username);

            // assert
            Assert.AreEqual(1, actual);
        }
Пример #19
0
        public void Add_ShouldAddAlbumWithCorrectUserWhenUsernameIsValid()
        {
            // arrange
            var data = new FakeGalleryData();
            this.PopulateFakeGalleryUsersData(data, 5);
            var service = new AlbumsService(data);
            string username = "******";
            var album = this.GetAlbum("myalbum", false);

            // act
            service.Add(album, username);
            var actual = service.GetAll(username).First().Owner.UserName;

            // assert
            Assert.AreEqual(username, actual);
        }
Пример #20
0
        public void Add_ShouldCallDataSaveChanges()
        {
            // arrange
            var data = new FakeGalleryData();
            this.PopulateFakeGalleryUsersData(data, 5);
            var service = new AlbumsService(data);
            string username = "******";
            var album = this.GetAlbum("myalbum", false);

            // act
            service.Add(album, username);
            var actual = data.SaveChangesCallCount;

            // assert
            Assert.AreEqual(1, actual);
        }
Пример #21
0
        public void Add_ShouldAddAlbumIfAlbumAndUsernameAreValid()
        {
            // arrange
            var data = new FakeGalleryData();
            this.PopulateFakeGalleryUsersData(data, 5);
            var service = new AlbumsService(data);
            string username = "******";
            var album = this.GetAlbum("myalbum", false);

            // act
            service.Add(album, username);
            var actual = service.GetAll(username).Count();

            // assert
            Assert.AreEqual(1, actual);
        }
Пример #22
0
        public void Add_ShouldAddAlbumIfAlbumAndUsernameAreValid()
        {
            // arrange
            var data = new FakeGalleryData();

            this.PopulateFakeGalleryUsersData(data, 5);
            var    service  = new AlbumsService(data);
            string username = "******";
            var    album    = this.GetAlbum("myalbum", false);

            // act
            service.Add(album, username);
            var actual = service.GetAll(username).Count();

            // assert
            Assert.AreEqual(1, actual);
        }
Пример #23
0
        public void Add_ShouldCallDataSaveChanges()
        {
            // arrange
            var data = new FakeGalleryData();

            this.PopulateFakeGalleryUsersData(data, 5);
            var    service  = new AlbumsService(data);
            string username = "******";
            var    album    = this.GetAlbum("myalbum", false);

            // act
            service.Add(album, username);
            var actual = data.SaveChangesCallCount;

            // assert
            Assert.AreEqual(1, actual);
        }
Пример #24
0
        public void Add_ShouldAddAlbumWithCorrectUserWhenUsernameIsValid()
        {
            // arrange
            var data = new FakeGalleryData();

            this.PopulateFakeGalleryUsersData(data, 5);
            var    service  = new AlbumsService(data);
            string username = "******";
            var    album    = this.GetAlbum("myalbum", false);

            // act
            service.Add(album, username);
            var actual = service.GetAll(username).First().Owner.UserName;

            // assert
            Assert.AreEqual(username, actual);
        }
Пример #25
0
        public void Add_ShouldAddAlbumWithCorrectDate()
        {
            // arrange
            var data = new FakeGalleryData();
            this.PopulateFakeGalleryUsersData(data, 5);
            var service = new AlbumsService(data);
            string username = "******";
            var album = this.GetAlbum("myalbum", false);

            // act
            service.Add(album, username);
            var addedAlbum = service.GetAll(username).First();
            var addedAlbumDate = addedAlbum.CreatedOn.Date;
            var addedAlbumHour = addedAlbum.CreatedOn.Hour;

            // assert
            Assert.AreEqual(DateTime.Now.Date, addedAlbumDate);
        }
Пример #26
0
        public void Add_ShouldAddAlbumWithCorrectDate()
        {
            // arrange
            var data = new FakeGalleryData();

            this.PopulateFakeGalleryUsersData(data, 5);
            var    service  = new AlbumsService(data);
            string username = "******";
            var    album    = this.GetAlbum("myalbum", false);

            // act
            service.Add(album, username);
            var addedAlbum     = service.GetAll(username).First();
            var addedAlbumDate = addedAlbum.CreatedOn.Date;
            var addedAlbumHour = addedAlbum.CreatedOn.Hour;

            // assert
            Assert.AreEqual(DateTime.Now.Date, addedAlbumDate);
        }
Пример #27
0
        private void PopulateFakeGalleryAlbumsData(
            FakeGalleryData data,
            int albumsCount)
        {
            for (int i = 0; i < albumsCount; i++)
            {
                var album = new Album()
                {
                    Id        = i,
                    Name      = "Album" + i,
                    Private   = i % 2 == 0,
                    CreatedOn = DateTime.Now.AddDays(i),
                    Owner     = new User()
                    {
                        UserName = "******" + i
                    }
                };

                data.Albums.Add(album);
            }
        }
Пример #28
0
        public void GetAlbumsByUser_ShouldGetAllAlbumsOfUserIfSameIsAuthenticated()
        {
            // arrange
            var data = new FakeGalleryData();

            this.PopulateFakeGalleryUsersData(data, 5);
            this.PopulateFakeGalleryAlbumsData(data, 10);

            string username = "******";
            var    album    = new Album()
            {
                Name = "customAlbum0",
            };
            var service = new AlbumsService(data);

            service.Add(album, username);

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

            // assert
            Assert.AreEqual(2, actual);
        }
Пример #29
0
        public void GetAll_ShouldReturnZeroAlbumsCount_WhenNoAlbumsInData()
        {
            // arrange
            var data = new FakeGalleryData();
            var service = new AlbumsService(data);
            string username = null;

            // act
            var actual = service.GetAll(username).Count();

            // assert
            Assert.AreEqual(0, actual);
        }
Пример #30
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);
        }
Пример #31
0
        public void Add_ShouldThrowIfUserWithSpecifiedUsernameIsNotFound()
        {
            // arrange
            var data = new FakeGalleryData();
            this.PopulateFakeGalleryUsersData(data, 5);
            var service = new AlbumsService(data);
            string username = "******";
            var album = this.GetAlbum("myalbum", false);

            // act
            service.Add(album, username);
        }
Пример #32
0
        public void Add_ShouldThrow_WhenNoCreatorSpecified()
        {
            // arrange
            var data = new FakeGalleryData();
            this.PopulateFakeGalleryUsersData(data, 5);
            var service = new AlbumsService(data);
            var album = this.GetAlbum("myalbum", false);

            // act
            service.Add(album, null);
        }
Пример #33
0
        public void Delete_ShouldCallSaveChangesIfOperationIsAuthorizedAndAlbumIsFound()
        {
            // arrange

            string username = "******";
            var album = new Album()
            {
                Id = 2,
                Name = "customAlbum0",
                Private = false,
                Owner = new User() { UserName = username }
            };

            var data = new FakeGalleryData();
            data.Albums.Add(album);
            var service = new AlbumsService(data);

            // act

            service.DeleteAlbumById(2, username);

            // assert

            var actual = data.SaveChangesCallCount;
            Assert.AreEqual(1, actual);
        }
Пример #34
0
        private void PopulateFakeGalleryUsersData(
            FakeGalleryData data,
            int usersCount)
        {
            for (int i = 0; i < usersCount; i++)
            {
                var user = new User()
                {
                    UserName = "******" + i
                };

                data.Users.Add(user);
            }
        }
Пример #35
0
        public void Delete_ShouldDeleteAlbumOfAuthorizedUser()
        {
            // arrange

            string username = "******";
            var album = new Album()
            {
                Id = 2,
                Name = "customAlbum0",
                Private = false,
                Owner = new User() { UserName = username}
            };

            var data = new FakeGalleryData();
            data.Albums.Add(album);
            var service = new AlbumsService(data);

            // act

            service.DeleteAlbumById(2, username);

            // assert

            var actual = data.Albums.All().Count();
            Assert.AreEqual(0, actual);
        }
Пример #36
0
        public void Delete_ShouldReturnMinusOneIfAlbumWasNotFoundOrAuthorizedUserIsNotOwner()
        {
            // arrange

            string username = "******";
            var album = new Album()
            {
                Id = 2,
                Name = "customAlbum0",
                Private = false,
                Owner = new User() { UserName = username }
            };

            var data = new FakeGalleryData();
            data.Albums.Add(album);
            var service = new AlbumsService(data);

            // act

            var actual = service.DeleteAlbumById(3, username);

            // assert

            Assert.AreEqual(0, actual);
        }
Пример #37
0
        public void GetAll_ShouldReturnOnlyNonPrivateAlbums_WhenUserIsNotAuthorized()
        {
            // arrange
            var data = new FakeGalleryData();
            this.PopulateFakeGalleryAlbumsData(data, 30);
            var service = new AlbumsService(data);
            string username = null;

            // act
            var actual = service.GetAll(username).Count();

            // assert
            Assert.AreEqual(15, actual);
        }
Пример #38
0
        private void PopulateFakeGalleryAlbumsData(
            FakeGalleryData data,
            int albumsCount)
        {
            for (int i = 0; i < albumsCount; i++)
            {
                var album = new Album()
                {
                    Id = i,
                    Name = "Album" + i,
                    Private = i % 2 == 0,
                    CreatedOn = DateTime.Now.AddDays(i),
                    Owner = new User()
                    {
                        UserName = "******" + i
                    }
                };

                data.Albums.Add(album);
            }
        }
Пример #39
0
        public void Add_ShouldThrowIfAlbumIsNull()
        {
            // arrange
            var data = new FakeGalleryData();
            var service = new AlbumsService(data);
            string username = "******";

            // act
            service.Add(null, username);
        }
Пример #40
0
        public void Add_ShouldReturnTheAddedAlbumId()
        {
            // arrange
            var data = new FakeGalleryData();
            this.PopulateFakeGalleryUsersData(data, 5);
            var service = new AlbumsService(data);
            string username = "******";
            var album = this.GetAlbum("myalbum", false);

            // act
            var actual = service.Add(album, username);

            // assert
            Assert.AreEqual(1, actual);
        }
Пример #41
0
        public void GetAlbumsByUser_ShouldGetOnlyPublicAlbumsOfUserIfOtherAuthenitcatedUser()
        {
            // arrange
            var data = new FakeGalleryData();
            this.PopulateFakeGalleryUsersData(data, 5);
            this.PopulateFakeGalleryAlbumsData(data, 10);

            string username = "******";
            var album = new Album()
            {
                Name = "customAlbum0",
                Private = false
            };

            var service = new AlbumsService(data);
            service.Add(album, username);

            // act
            var actual = service.GetAlbumsByUser(username, "user1").Count();

            // assert
            Assert.AreEqual(1, actual);
        }
Пример #42
0
        public void GetAlbumsByUser_ShouldGetAllAlbumsOfUserIfSameIsAuthenticated()
        {
            // arrange
            var data = new FakeGalleryData();
            this.PopulateFakeGalleryUsersData(data, 5);
            this.PopulateFakeGalleryAlbumsData(data, 10);

            string username = "******";
            var album = new Album()
            {
                Name = "customAlbum0",
            };
            var service = new AlbumsService(data);
            service.Add(album, username);

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

            // assert
            Assert.AreEqual(2, actual);
        }
Пример #43
0
        public void Delete_ShouldReturnTheIdOfTheDeletedAlbum()
        {
            // arrange

            string username = "******";
            var album = new Album()
            {
                Id = 2,
                Name = "customAlbum0",
                Private = false,
                Owner = new User() { UserName = username }
            };

            var data = new FakeGalleryData();
            data.Albums.Add(album);
            var service = new AlbumsService(data);

            // act

            var actual = service.DeleteAlbumById(2, username);

            // assert

            Assert.AreEqual(2, actual);
        }
Пример #44
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);
        }