Ejemplo n.º 1
0
        public async Task Throw_When_NoPlaylistsExistToAttachImageTo()
        {
            //Arrange
            var options = Utils.GetOptions(nameof(Throw_When_NoPlaylistsExistToAttachImageTo));

            PlaylistDTO firstPlaylistDTO = new PlaylistDTO
            {
                Id               = 91,
                Title            = "Home",
                PlaylistPlaytime = 5524,
                UserId           = 2,
                Rank             = 552348,
            };

            var dateTimeProviderMock = new Mock <IDateTimeProvider>();
            var mockImageService     = new Mock <IPixaBayImageService>();

            using (var assertContext = new RidePalDbContext(options))
            {
                //Act
                var sut = new PlaylistService(assertContext, dateTimeProviderMock.Object, mockImageService.Object);

                //Assert
                await Assert.ThrowsExceptionAsync <ArgumentNullException>(() => sut.AttachImage(firstPlaylistDTO));
            }
        }
        public async Task SetDeletedStatus_Currectly()
        {
            //Arrange
            var options = Utils.GetOptions(nameof(SetDeletedStatus_Currectly));

            User user = new User
            {
                Id       = 1,
                UserName = "******",
                Email    = "*****@*****.**"
            };

            //Act
            using (var arrangeContext = new RidePalDbContext(options))
            {
                await arrangeContext.Users.AddAsync(user);

                await arrangeContext.SaveChangesAsync();

                var  sut       = new AdminService(arrangeContext);
                bool delResult = await sut.DeleteUser(1);
            }

            //Assert
            using (var assertContext = new RidePalDbContext(options))
            {
                var userFromDb = await assertContext.Users.FirstOrDefaultAsync(u => u.Id == user.Id);

                Assert.IsTrue(userFromDb.IsDeleted);
            }
        }
Ejemplo n.º 3
0
        public async Task SetLockoutStatus_ToFalseCurrectly()
        {
            //Arrange
            var options = Utils.GetOptions(nameof(SetLockoutStatus_ToFalseCurrectly));

            User user = new User
            {
                Id             = 1,
                UserName       = "******",
                Email          = "*****@*****.**",
                LockoutEnabled = true
            };

            //Act
            using (var arrangeContext = new RidePalDbContext(options))
            {
                await arrangeContext.Users.AddAsync(user);

                await arrangeContext.SaveChangesAsync();

                var  sut         = new AdminService(arrangeContext);
                bool unbanResult = await sut.UnbanUserById(1);
            }

            //Assert
            using (var assertContext = new RidePalDbContext(options))
            {
                var userFromDb = await assertContext.Users.FirstOrDefaultAsync(u => u.Id == user.Id);

                Assert.IsFalse(userFromDb.LockoutEnabled);
            }
        }
Ejemplo n.º 4
0
        public async Task ReturnFalse_WhenPlaylistIsAlreadyUndeleted()
        {
            var options = Utils.GetOptions(nameof(ReturnFalse_WhenPlaylistIsAlreadyUndeleted));

            Playlist firstPlaylist = new Playlist
            {
                Id               = 11,
                Title            = "Home",
                PlaylistPlaytime = 5524,
                UserId           = 2,
                Rank             = 552348,
                IsDeleted        = false
            };

            var dateTimeProviderMock = new Mock <IDateTimeProvider>();
            var mockImageService     = new Mock <IPixaBayImageService>();

            using (var arrangeContext = new RidePalDbContext(options))
            {
                arrangeContext.Playlists.Add(firstPlaylist);
                arrangeContext.SaveChanges();
            }

            using (var assertContext = new RidePalDbContext(options))
            {
                //Act
                var sut    = new PlaylistService(assertContext, dateTimeProviderMock.Object, mockImageService.Object);
                var result = await sut.UndoDeletePlaylistAsync(11);

                //Assert
                Assert.IsFalse(result);
            }
        }
Ejemplo n.º 5
0
        public async Task Throw_If_NoTracksExist()
        {
            //Arrange
            var options = Utils.GetOptions(nameof(Throw_If_NoTracksExist));

            Playlist firstPlaylist = new Playlist
            {
                Id               = 27,
                Title            = "Home",
                PlaylistPlaytime = 5524,
                UserId           = 2,
                Rank             = 552348,
                IsDeleted        = false,
            };

            var dateTimeProviderMock = new Mock <IDateTimeProvider>();
            var mockImageService     = new Mock <IPixaBayImageService>();

            using (var arrangeContext = new RidePalDbContext(options))
            {
                arrangeContext.Playlists.Add(firstPlaylist);
                arrangeContext.SaveChanges();
            }

            //Act & Assert
            using (var assertContext = new RidePalDbContext(options))
            {
                var sut = new PlaylistService(assertContext, dateTimeProviderMock.Object, mockImageService.Object);

                await Assert.ThrowsExceptionAsync <ArgumentNullException>(() => sut.GetPlaylistTracksAsync(27));
            }
        }
        public async Task ReturnUserByHisId_Correctly()
        {
            //Arrange
            var options = Utils.GetOptions(nameof(ReturnUserByHisId_Correctly));

            User user = new User
            {
                Id       = 1,
                UserName = "******",
                Email    = "*****@*****.**"
            };

            //Act
            using (var arrangeContext = new RidePalDbContext(options))
            {
                await arrangeContext.Users.AddAsync(user);

                await arrangeContext.SaveChangesAsync();
            }

            //Assert
            using (var assertContext = new RidePalDbContext(options))
            {
                var sut        = new AdminService(assertContext);
                var userResult = await sut.GetUserById(1);

                Assert.AreEqual(userResult.UserName, user.UserName);
                Assert.AreEqual(userResult.Email, user.Email);
            }
        }
        public async Task ReturnTrue_WhenPlaylistFavoriteWasCreatedButDisliked()
        {
            var options = Utils.GetOptions(nameof(ReturnTrue_WhenPlaylistFavoriteWasCreatedButDisliked));

            Playlist firstPlaylist = new Playlist
            {
                Id               = 32,
                Title            = "Home",
                PlaylistPlaytime = 5524,
                UserId           = 2,
                Rank             = 552348,
                IsDeleted        = false
            };

            Playlist secondPlaylist = new Playlist
            {
                Id               = 33,
                Title            = "Metal",
                PlaylistPlaytime = 5024,
                UserId           = 2,
                Rank             = 490258,
                IsDeleted        = false
            };

            User user = new User()
            {
                Id = 4
            };

            PlaylistFavorite favorite = new PlaylistFavorite()
            {
                Id         = 2,
                UserId     = 4,
                PlaylistId = 32,
                IsFavorite = false
            };

            var dateTimeProviderMock = new Mock <IDateTimeProvider>();
            var mockImageService     = new Mock <IPixaBayImageService>();

            using (var arrangeContext = new RidePalDbContext(options))
            {
                arrangeContext.Playlists.Add(firstPlaylist);
                arrangeContext.Playlists.Add(secondPlaylist);
                arrangeContext.Users.Add(user);
                arrangeContext.Favorites.Add(favorite);
                arrangeContext.SaveChanges();
            }

            using (var assertContext = new RidePalDbContext(options))
            {
                //Act
                var sut    = new PlaylistService(assertContext, dateTimeProviderMock.Object, mockImageService.Object);
                var result = await sut.AddPlaylistToFavoritesAsync(32, 4);

                //Assert
                Assert.IsTrue(result);
            }
        }
        public async Task ReturnCorrectPlaylist_WhenParamsAreValid()
        {
            //Arrange
            var options = Utils.GetOptions(nameof(ReturnCorrectPlaylist_WhenParamsAreValid));

            Playlist firstPlaylist = new Playlist
            {
                Id               = 1,
                Title            = "Home",
                PlaylistPlaytime = 5524,
                UserId           = 2,
                Rank             = 552348,
                IsDeleted        = false
            };

            Playlist secondPlaylist = new Playlist
            {
                Id               = 2,
                Title            = "Metal",
                PlaylistPlaytime = 5024,
                UserId           = 2,
                Rank             = 490258,
                IsDeleted        = false
            };

            var playlistDTO = new PlaylistDTO
            {
                Id               = 2,
                Title            = "Metal",
                PlaylistPlaytime = 5024,
                UserId           = 2,
                Rank             = 490258,
            };

            var dateTimeProviderMock = new Mock <IDateTimeProvider>();
            var mockImageService     = new Mock <IPixaBayImageService>();

            using (var arrangeContext = new RidePalDbContext(options))
            {
                arrangeContext.Playlists.Add(firstPlaylist);
                arrangeContext.Playlists.Add(secondPlaylist);
                arrangeContext.SaveChanges();
            }

            using (var assertContext = new RidePalDbContext(options))
            {
                //Act
                var sut    = new PlaylistService(assertContext, dateTimeProviderMock.Object, mockImageService.Object);
                var result = await sut.GetPlaylistByIdAsync(2);

                //Assert
                Assert.AreEqual(playlistDTO.Id, result.Id);
                Assert.AreEqual(playlistDTO.Title, result.Title);
                Assert.AreEqual(playlistDTO.Rank, result.Rank);
                Assert.AreEqual(playlistDTO.UserId, result.UserId);
                Assert.AreEqual(playlistDTO.PlaylistPlaytime, result.PlaylistPlaytime);
            }
        }
        public void ReturnCorrectPlaylists_WhenParamsAreValid()
        {
            //Arrange
            var options = Utils.GetOptions(nameof(ReturnCorrectPlaylists_WhenParamsAreValid));

            Playlist firstPlaylist = new Playlist
            {
                Id               = 60,
                Title            = "Home",
                PlaylistPlaytime = 5524,
                UserId           = 2,
                Rank             = 552348,
                IsDeleted        = false
            };

            Playlist secondPlaylist = new Playlist
            {
                Id               = 61,
                Title            = "Metal",
                PlaylistPlaytime = 5024,
                UserId           = 2,
                Rank             = 490258,
                IsDeleted        = false
            };

            Playlist thirdPlaylist = new Playlist
            {
                Id               = 62,
                Title            = "Jazz",
                PlaylistPlaytime = 5074,
                UserId           = 2,
                Rank             = 580258,
                IsDeleted        = false
            };

            var dateTimeProviderMock = new Mock <IDateTimeProvider>();
            var mockImageService     = new Mock <IPixaBayImageService>();

            using (var arrangeContext = new RidePalDbContext(options))
            {
                arrangeContext.Playlists.Add(firstPlaylist);
                arrangeContext.Playlists.Add(secondPlaylist);
                arrangeContext.Playlists.Add(thirdPlaylist);
                arrangeContext.SaveChanges();
            }

            using (var assertContext = new RidePalDbContext(options))
            {
                //Act
                var sut    = new PlaylistService(assertContext, dateTimeProviderMock.Object, mockImageService.Object);
                var result = sut.GetPageCount();

                //Assert
                Assert.AreEqual(result, 1);
            }
        }
Ejemplo n.º 10
0
        public async Task ReturnCorrectGenreCount_WhenParamsAreValid()
        {
            // Arrange
            var options = Utils.GetOptions(nameof(ReturnCorrectGenreCount_WhenParamsAreValid));

            Genre rock = new Genre
            {
                Id   = 21,
                Name = "rock"
            };

            Genre metal = new Genre
            {
                Id   = 22,
                Name = "metal"
            };

            Genre pop = new Genre
            {
                Id   = 23,
                Name = "pop"
            };

            Genre jazz = new Genre
            {
                Id   = 24,
                Name = "jazz"
            };

            var dateTimeProviderMock = new Mock <IDateTimeProvider>();
            var mockImageService     = new Mock <IPixaBayImageService>();

            using (var arrangeContext = new RidePalDbContext(options))
            {
                arrangeContext.Genres.Add(metal);
                arrangeContext.Genres.Add(rock);
                arrangeContext.Genres.Add(pop);
                arrangeContext.Genres.Add(jazz);
                arrangeContext.SaveChanges();
            }

            using (var assertContext = new RidePalDbContext(options))
            {
                var sut = new PlaylistService(assertContext, dateTimeProviderMock.Object, mockImageService.Object);

                // Act
                var result = await sut.GetAllGenresAsync();

                //Assert
                Assert.AreEqual(result.Count(), 4);
            }
        }
Ejemplo n.º 11
0
        public async Task ReturnTopThreePlaylists_Correctly()
        {
            //Arrange
            var options = Utils.GetOptions(nameof(ReturnTopThreePlaylists_Correctly));
            var plMock  = new Mock <IPlaylistService>();

            var playlists = new List <Playlist>()
            {
                new Playlist()
                {
                    Id    = 1,
                    Title = "Travel music",
                    Rank  = 222
                },
                new Playlist()
                {
                    Id    = 2,
                    Title = "Road Jam",
                    Rank  = 333
                },
                new Playlist()
                {
                    Id    = 3,
                    Title = "Riding Dirty",
                    Rank  = 444
                },
                new Playlist()
                {
                    Id    = 4,
                    Title = "Heavy metal",
                    Rank  = 555
                }
            };

            //Act
            using (var arrangeContext = new RidePalDbContext(options))
            {
                await arrangeContext.Playlists.AddRangeAsync(playlists);

                await arrangeContext.SaveChangesAsync();
            }

            //Assert
            using (var assertContext = new RidePalDbContext(options))
            {
                var sut    = new StatisticsService(assertContext, plMock.Object);
                var result = await sut.TopPlaylists();

                Assert.IsTrue(result.Count == 3);
                Assert.IsTrue(result.FirstOrDefault(r => r.Title == "Travel Music") == null);
            }
        }
        public async Task ThrowsException_OnNoUserFound()
        {
            //Arrange
            var options = Utils.GetOptions(nameof(ThrowsException_OnNoUserFound));

            //Act & Assert
            using (var assertContext = new RidePalDbContext(options))
            {
                var sut = new AdminService(assertContext);

                await Assert.ThrowsExceptionAsync <ArgumentNullException>(() => sut.GetUserById(1));
            }
        }
Ejemplo n.º 13
0
        public async Task ReturnThreeArthistsFromDB_Correctly()
        {
            //Arrange
            var options = Utils.GetOptions(nameof(ReturnThreeArthistsFromDB_Correctly));
            var plMock  = new Mock <IPlaylistService>();

            var artists = new List <Artist>()
            {
                new Artist()
                {
                    Id               = 1,
                    ArtistName       = "The weeknd",
                    ArtistPictureURL = "/images/artist.png"
                },
                new Artist()
                {
                    Id               = 2,
                    ArtistName       = "Bad Wolfs",
                    ArtistPictureURL = "/images/artist.png"
                },
                new Artist()
                {
                    Id               = 3,
                    ArtistName       = "Shakira",
                    ArtistPictureURL = "/images/artist.png"
                },
                new Artist()
                {
                    Id               = 4,
                    ArtistName       = "G-easy",
                    ArtistPictureURL = "/images/artist.png"
                }
            };

            //Act
            using (var arrangeContext = new RidePalDbContext(options))
            {
                await arrangeContext.Artists.AddRangeAsync(artists);

                await arrangeContext.SaveChangesAsync();
            }

            //Assert
            using (var assertContext = new RidePalDbContext(options))
            {
                var sut    = new StatisticsService(assertContext, plMock.Object);
                var result = await sut.FeaturedArtists();

                Assert.IsTrue(result.Count == 3);
            }
        }
Ejemplo n.º 14
0
        public async Task ReturnFalse_OnUserNotFoundInDB()
        {
            //Arrange
            var options = Utils.GetOptions(nameof(ReturnFalse_OnUserNotFoundInDB));

            //Act & Assert
            using (var assertContext = new RidePalDbContext(options))
            {
                var  sut    = new AdminService(assertContext);
                bool result = await sut.UnbanUserById(1);

                Assert.IsFalse(result);
            }
        }
Ejemplo n.º 15
0
        public async Task ThrowsException_OnNoSearchParamsSubmited()
        {
            //Arrange
            var    options      = Utils.GetOptions(nameof(ThrowsException_OnNoSearchParamsSubmited));
            string searchParams = string.Empty;

            //Act & Assert
            using (var assertContext = new RidePalDbContext(options))
            {
                var sut = new AdminService(assertContext);

                await Assert.ThrowsExceptionAsync <ArgumentNullException>(() => sut.SearchByEmail(searchParams));
            }
        }
Ejemplo n.º 16
0
        public async Task ReturnsEmptyCollection_OnNoUsersFound()
        {
            //Arrange
            var options = Utils.GetOptions(nameof(ReturnsEmptyCollection_OnNoUsersFound));

            //Act & Assert
            using (var assertContext = new RidePalDbContext(options))
            {
                var sut    = new AdminService(assertContext);
                var result = await sut.GetAllUsers();

                Assert.IsTrue(result.Count == 0);
            }
        }
Ejemplo n.º 17
0
        public async Task ReturnFalse_WhenPlaylistFavoriteWasAlreadyRemoved()
        {
            var options = Utils.GetOptions(nameof(ReturnFalse_WhenPlaylistFavoriteWasAlreadyRemoved));

            Playlist firstPlaylist = new Playlist
            {
                Id               = 39,
                Title            = "Home",
                PlaylistPlaytime = 5524,
                UserId           = 2,
                Rank             = 552348,
                IsDeleted        = false
            };

            User user = new User()
            {
                Id = 9
            };

            PlaylistFavorite favorite = new PlaylistFavorite()
            {
                Id         = 6,
                UserId     = 9,
                PlaylistId = 39,
                IsFavorite = false
            };

            var dateTimeProviderMock = new Mock <IDateTimeProvider>();
            var mockImageService     = new Mock <IPixaBayImageService>();

            using (var arrangeContext = new RidePalDbContext(options))
            {
                arrangeContext.Playlists.Add(firstPlaylist);
                arrangeContext.Users.Add(user);
                arrangeContext.Favorites.Add(favorite);
                arrangeContext.SaveChanges();
            }

            using (var assertContext = new RidePalDbContext(options))
            {
                //Act
                var sut    = new PlaylistService(assertContext, dateTimeProviderMock.Object, mockImageService.Object);
                var result = await sut.RemovePlaylistFromFavoritesAsync(39, 9);

                //Assert
                Assert.IsFalse(result);
            }
        }
Ejemplo n.º 18
0
        public async Task Throw_If_NoGenresExist()
        {
            //Arrange
            var options = Utils.GetOptions(nameof(Throw_If_NoGenresExist));

            var dateTimeProviderMock = new Mock <IDateTimeProvider>();
            var mockImageService     = new Mock <IPixaBayImageService>();

            //Act & Assert
            using (var assertContext = new RidePalDbContext(options))
            {
                var sut = new PlaylistService(assertContext, dateTimeProviderMock.Object, mockImageService.Object);

                await Assert.ThrowsExceptionAsync <ArgumentNullException>(() => sut.GetAllGenresAsync());
            }
        }
Ejemplo n.º 19
0
        public async Task ReturnPlaylistWithFilePath_WhenParamsAreValid()
        {
            //Arrange
            var options = Utils.GetOptions(nameof(ReturnPlaylistWithFilePath_WhenParamsAreValid));

            Playlist firstPlaylist = new Playlist
            {
                Id               = 87,
                Title            = "Home",
                PlaylistPlaytime = 5524,
                UserId           = 2,
                Rank             = 552348,
                IsDeleted        = false
            };

            PlaylistDTO firstPlaylistDTO = new PlaylistDTO
            {
                Id               = 87,
                Title            = "Home",
                PlaylistPlaytime = 5524,
                UserId           = 2,
                Rank             = 552348,
            };

            var dateTimeProviderMock = new Mock <IDateTimeProvider>();
            var mockImageService     = new Mock <IPixaBayImageService>();

            mockImageService
            .Setup(x => x.AssignImage(It.IsAny <PlaylistDTO>()))
            .Returns(GetString());

            using (var arrangeContext = new RidePalDbContext(options))
            {
                arrangeContext.Playlists.Add(firstPlaylist);
                arrangeContext.SaveChanges();
            }

            using (var assertContext = new RidePalDbContext(options))
            {
                //Act
                var sut    = new PlaylistService(assertContext, dateTimeProviderMock.Object, mockImageService.Object);
                var result = await sut.AttachImage(firstPlaylistDTO);

                //Assert
                Assert.IsNotNull(result.FilePath);
            }
        }
Ejemplo n.º 20
0
        public async Task ReturnFalse_IfNoPlaylistsExist()
        {
            //Arrange
            var options = Utils.GetOptions(nameof(ReturnFalse_IfNoPlaylistsExist));

            var dateTimeProviderMock = new Mock <IDateTimeProvider>();
            var mockImageService     = new Mock <IPixaBayImageService>();

            //Act & Assert
            using (var assertContext = new RidePalDbContext(options))
            {
                var sut    = new PlaylistService(assertContext, dateTimeProviderMock.Object, mockImageService.Object);
                var result = await sut.UndoDeletePlaylistAsync(10);

                Assert.IsFalse(result);
            }
        }
Ejemplo n.º 21
0
        public void ReturnZeroPlaylistsOnSecondPage()
        {
            //Arrange
            var options = Utils.GetOptions(nameof(ReturnZeroPlaylistsOnSecondPage));

            Playlist firstPlaylist = new Playlist
            {
                Id               = 72,
                Title            = "Home",
                PlaylistPlaytime = 5524,
                UserId           = 2,
                Rank             = 552348,
                IsDeleted        = false
            };

            Playlist secondPlaylist = new Playlist
            {
                Id               = 73,
                Title            = "Metal",
                PlaylistPlaytime = 5024,
                UserId           = 2,
                Rank             = 490258,
                IsDeleted        = false
            };

            var dateTimeProviderMock = new Mock <IDateTimeProvider>();
            var mockImageService     = new Mock <IPixaBayImageService>();

            using (var arrangeContext = new RidePalDbContext(options))
            {
                arrangeContext.Playlists.Add(firstPlaylist);
                arrangeContext.Playlists.Add(secondPlaylist);
                arrangeContext.SaveChanges();
            }

            using (var assertContext = new RidePalDbContext(options))
            {
                //Act
                var sut    = new PlaylistService(assertContext, dateTimeProviderMock.Object, mockImageService.Object);
                var result = sut.GetPlaylistsPerPage(2).ToList();

                //Assert
                Assert.AreEqual(result.Count, 0);
            }
        }
        public async Task ReturnZero_WhenThereAreNoPlaylists()
        {
            //Arrange
            var options = Utils.GetOptions(nameof(ReturnZero_WhenThereAreNoPlaylists));

            var dateTimeProviderMock = new Mock <IDateTimeProvider>();
            var mockImageService     = new Mock <IPixaBayImageService>();

            using (var assertContext = new RidePalDbContext(options))
            {
                //Act
                var sut    = new PlaylistService(assertContext, dateTimeProviderMock.Object, mockImageService.Object);
                var result = await sut.GetHighestPlaytimeAsync();

                //Assert
                Assert.AreEqual(0, result);
            }
        }
        public void ReturnCorrectPlaylists_WhenParamsAreValid()
        {
            //Arrange
            var options = Utils.GetOptions(nameof(ReturnCorrectPlaylists_WhenParamsAreValid));

            var dateTimeProviderMock = new Mock <IDateTimeProvider>();

            using (var assertContext = new RidePalDbContext(options))
            {
                //Act
                var    sut      = new GeneratePlaylistService(assertContext, dateTimeProviderMock.Object);
                var    result   = sut.GetPlaytimeString(4856);
                string expected = "1h 20m 56s";

                //Assert
                Assert.AreEqual(result, expected);
            }
        }
Ejemplo n.º 24
0
        public async Task ReturnTrue_WhenParamsAreValid()
        {
            var options = Utils.GetOptions(nameof(ReturnTrue_WhenParamsAreValid));

            Playlist firstPlaylist = new Playlist
            {
                Id               = 12,
                Title            = "Home",
                PlaylistPlaytime = 5524,
                UserId           = 2,
                Rank             = 552348,
                IsDeleted        = true
            };

            Playlist secondPlaylist = new Playlist
            {
                Id               = 13,
                Title            = "Metal",
                PlaylistPlaytime = 5024,
                UserId           = 2,
                Rank             = 490258,
                IsDeleted        = false
            };

            var dateTimeProviderMock = new Mock <IDateTimeProvider>();
            var mockImageService     = new Mock <IPixaBayImageService>();

            using (var arrangeContext = new RidePalDbContext(options))
            {
                arrangeContext.Playlists.Add(firstPlaylist);
                arrangeContext.Playlists.Add(secondPlaylist);
                arrangeContext.SaveChanges();
            }

            using (var assertContext = new RidePalDbContext(options))
            {
                //Act
                var sut    = new PlaylistService(assertContext, dateTimeProviderMock.Object, mockImageService.Object);
                var result = await sut.UndoDeletePlaylistAsync(12);

                //Assert
                Assert.IsTrue(result);
            }
        }
Ejemplo n.º 25
0
        public async Task ReturnUserCollection_MatchingTheEmailString()
        {
            //Arrange
            var options     = Utils.GetOptions(nameof(ReturnUserCollection_MatchingTheEmailString));
            int expected    = 2;
            var userEntries = new List <User>()
            {
                new User()
                {
                    Id       = 1,
                    UserName = "******",
                    Email    = "*****@*****.**",
                },
                new User()
                {
                    Id       = 2,
                    UserName = "******",
                    Email    = "*****@*****.**",
                },
                new User()
                {
                    Id       = 3,
                    UserName = "******",
                    Email    = "*****@*****.**",
                }
            };

            //Act
            using (var arrangeContext = new RidePalDbContext(options))
            {
                await arrangeContext.Users.AddRangeAsync(userEntries);

                await arrangeContext.SaveChangesAsync();
            }

            //Assert
            using (var assertContext = new RidePalDbContext(options))
            {
                var sut        = new AdminService(assertContext);
                var userResult = await sut.SearchByEmail("*****@*****.**");

                Assert.AreEqual(userResult.Count, expected);
            }
        }
        public async Task ThrowException_OnUserNotFound()
        {
            //Arrange
            var options = Utils.GetOptions(nameof(ThrowException_OnUserNotFound));

            UserDTO inputDTO = new UserDTO()
            {
                Id       = 2,
                UserName = "******"
            };

            //Act & Assert
            using (var assertContext = new RidePalDbContext(options))
            {
                var sut = new AdminService(assertContext);

                await Assert.ThrowsExceptionAsync <ArgumentNullException>(() => sut.EditUser(inputDTO));
            }
        }
        public async Task EditUserOn_OnlyPasswordSubmited()
        {
            //Arrange
            var options = Utils.GetOptions(nameof(EditUserOn_OnlyPasswordSubmited));
            var hasher  = new PasswordHasher <User>();

            User user = new User()
            {
                Id       = 2,
                UserName = "******",
                Email    = "*****@*****.**",
            };

            user.PasswordHash = hasher.HashPassword(user, "unbreakablepass");

            UserDTO inputDTO = new UserDTO()
            {
                Id       = 2,
                Password = "******"
            };

            //Act
            using (var arrangeContext = new RidePalDbContext(options))
            {
                await arrangeContext.Users.AddAsync(user);

                await arrangeContext.SaveChangesAsync();

                var sut     = new AdminService(arrangeContext);
                var editDTO = await sut.EditUser(inputDTO);
            }

            //Assert
            using (var assertContext = new RidePalDbContext(options))
            {
                var sut    = new AdminService(assertContext);
                var result = assertContext.Users.FirstOrDefaultAsync(u => u.UserName == inputDTO.UserName);

                var expected = hasher.VerifyHashedPassword(user, user.PasswordHash, inputDTO.Password);

                Assert.IsTrue(expected == PasswordVerificationResult.Success);
            }
        }
        public async Task ReturnUserCountOfDb_Correctly()
        {
            //Arrange
            var options = Utils.GetOptions(nameof(ReturnUserCountOfDb_Correctly));
            var plMock  = new Mock <IPlaylistService>();

            var users = new List <User>()
            {
                new User()
                {
                    Id       = 1,
                    UserName = "******",
                    Email    = "*****@*****.**"
                },
                new User()
                {
                    Id       = 2,
                    UserName = "******",
                    Email    = "*****@*****.**"
                }
            };

            //Act
            using (var arrangeContext = new RidePalDbContext(options))
            {
                await arrangeContext.Users.AddRangeAsync(users);

                await arrangeContext.SaveChangesAsync();
            }

            //Assert
            using (var assertContext = new RidePalDbContext(options))
            {
                var sut    = new StatisticsService(assertContext, plMock.Object);
                int result = await sut.UserCount();

                Assert.IsTrue(result == 2);
            }
        }
Ejemplo n.º 29
0
        public void ReturnCorrectRank_WhenParamsAreValid()
        {
            //Arrange
            var options = Utils.GetOptions(nameof(ReturnCorrectRank_WhenParamsAreValid));

            Track firstTrack = new Track()
            {
                Id            = 7,
                ArtistId      = 1,
                TrackDuration = 218,
                TrackRank     = 587931
            };

            Track secondTrack = new Track()
            {
                Id            = 8,
                ArtistId      = 1,
                TrackDuration = 257,
                TrackRank     = 637965
            };

            var playlist = new List <Track>()
            {
                firstTrack, secondTrack
            };

            var dateTimeProviderMock = new Mock <IDateTimeProvider>();

            using (var assertContext = new RidePalDbContext(options))
            {
                //Act
                var sut      = new GeneratePlaylistService(assertContext, dateTimeProviderMock.Object);
                var result   = sut.CalculateRank(playlist);
                var expected = 612948;

                //Assert
                Assert.AreEqual(result, expected);
            }
        }
        public async Task EditUserOn_OnlyEmailSubmited()
        {
            //Arrange
            var  options = Utils.GetOptions(nameof(EditUserOn_OnlyEmailSubmited));
            User user    = new User()
            {
                Id       = 2,
                LastName = "Topchiev",
                UserName = "******",
                Email    = "*****@*****.**"
            };

            UserDTO inputDTO = new UserDTO()
            {
                Id    = 2,
                Email = "*****@*****.**"
            };

            //Act
            using (var arrangeContext = new RidePalDbContext(options))
            {
                await arrangeContext.Users.AddAsync(user);

                await arrangeContext.SaveChangesAsync();

                var sut     = new AdminService(arrangeContext);
                var editDTO = await sut.EditUser(inputDTO);
            }

            //Assert
            using (var assertContext = new RidePalDbContext(options))
            {
                var sut    = new AdminService(assertContext);
                var result = assertContext.Users.FirstOrDefaultAsync(u => u.Email == inputDTO.Email);

                Assert.IsNotNull(result);
            }
        }