示例#1
0
        public async Task CanDownloadInCertainQuality_NotRegisteredUsers_ShouldNotBeAbleTo()
        {
            //Arrange
            Mock <IUserRepository>   mock   = new Mock <IUserRepository>();
            AccountPermissionChecker target = new AccountPermissionChecker(mock.Object);
            bool isAuthenticated            = false;

            foreach (string quality in StandardUsersQualities.Concat(GoldUsersQualities))
            {
                //Act
                var result = await target.CanDownloadInCertainQualityAsync(quality, isAuthenticated);

                bool   canDownload  = result.isAllowed;
                string errorMessage = result.errorMessageIfNotAllowed;

                //Assert
                Assert.False(canDownload);
                Assert.True(errorMessage == "You need to be logged in !");
            }
        }
示例#2
0
        public async Task CanDownloadInCertainQuality_StandardUsers_ShouldBeAbleTo()
        {
            //Arrange
            Mock <IUserRepository> mock = new Mock <IUserRepository>();

            mock.Setup(x => x.GetUserAccountLevelAsync(It.IsAny <string>())).ReturnsAsync(AccountLevel.Standard);
            AccountPermissionChecker target = new AccountPermissionChecker(mock.Object);
            bool isAuthenticated            = true;

            foreach (string quality in NotRegisteredUsersQualities.Concat(StandardUsersQualities))
            {
                //Act
                var result = await target.CanDownloadInCertainQualityAsync(quality, isAuthenticated);

                bool   canDownload  = result.isAllowed;
                string errorMessage = result.errorMessageIfNotAllowed;

                //Assert
                Assert.True(canDownload);
                Assert.True(errorMessage == "");
            }
        }