public async Task AddCode_AccountIdDoesntExists_ReturnTrue(string code,
                                                                   string expirationTime, int accountId, string username, string password, string salt, string emailAddress,
                                                                   string accountType, string accountStatus, string creationDate, string updationDate)
        {
            // Arrange
            IDataGateway               dataGateway               = new SQLServerGateway();
            IConnectionStringData      connectionString          = new ConnectionStringData();
            IUserAccountRepository     userAccountRepository     = new UserAccountRepository(dataGateway, connectionString);
            IUserAccountCodeRepository userAccountCodeRepository = new UserAccountCodeRepository(dataGateway, connectionString);

            var userAccountModel = new UserAccountModel();

            userAccountModel.Id            = accountId;
            userAccountModel.Username      = username;
            userAccountModel.Password      = password;
            userAccountModel.Salt          = salt;
            userAccountModel.EmailAddress  = emailAddress;
            userAccountModel.AccountType   = accountType;
            userAccountModel.AccountStatus = accountStatus;
            userAccountModel.CreationDate  = DateTimeOffset.Parse(creationDate);
            userAccountModel.UpdationDate  = DateTimeOffset.Parse(updationDate);

            await userAccountRepository.CreateAccount(userAccountModel);

            var expectedResult = true;

            IUserAccountCodeService userAccountCodeService = new UserAccountCodeService(userAccountCodeRepository);

            // Act
            var actualResult = await userAccountCodeService.AddCode(code, DateTimeOffset.Parse(expirationTime), accountId);

            // Assert
            Assert.IsTrue(actualResult == expectedResult);
        }
예제 #2
0
        public async Task GetAllUserAccountCodes_AtLeastTwoUserAccountCodesExist_ReturnsCorrectIds()
        {
            // Arrange
            IUserAccountCodeRepository userAccountCodeRepository =
                new UserAccountCodeRepository(new SQLServerGateway(), new ConnectionStringData());

            // Act
            IEnumerable <UserAccountCodeModel> userAccountCodes = await userAccountCodeRepository.GetAllUserAccountCodes();

            // Assert
            int i = 1;

            foreach (UserAccountCodeModel userAccountCode in userAccountCodes)
            {
                if (userAccountCode.Id == i)
                {
                    ++i;
                    continue;
                }

                Assert.IsTrue(false);
                return;
            }

            Assert.IsTrue(true);
        }
        public async Task GetUserAccountCodeByAccountId_AccountIdExists_ReturnBusinessUserAccountCodeModel(int id, string code,
                                                                                                           string expirationTime, int accountId)
        {
            // Arrange
            IDataGateway               dataGateway               = new SQLServerGateway();
            IConnectionStringData      connectionString          = new ConnectionStringData();
            IUserAccountCodeRepository userAccountCodeRepository = new UserAccountCodeRepository(dataGateway, connectionString);

            var expectedResult = new BusinessUserAccountCodeModel();

            expectedResult.Id             = id;
            expectedResult.Code           = code;
            expectedResult.ExpirationTime = DateTimeOffset.Parse(expirationTime);
            expectedResult.UserAccountId  = accountId;

            IUserAccountCodeService userAccountCodeService = new UserAccountCodeService(userAccountCodeRepository);

            // Act
            var actualResult = await userAccountCodeService.GetUserAccountCodeByAccountId(accountId);

            // Assert
            Assert.IsTrue
            (
                actualResult.Id == expectedResult.Id &&
                actualResult.Code == expectedResult.Code &&
                actualResult.ExpirationTime == expectedResult.ExpirationTime &&
                actualResult.UserAccountId == expectedResult.UserAccountId
            );
        }
예제 #4
0
        public async Task DeleteUserAccountCodeByAccountId_UserAccountCodeExists_UserAccountCodeIsNull(int accountId)
        {
            // Arrange
            IUserAccountCodeRepository userAccountCodeRepository =
                new UserAccountCodeRepository(new SQLServerGateway(), new ConnectionStringData());

            // Act
            await userAccountCodeRepository.DeleteUserAccountCodeByAccountId(accountId);

            var retrievedUserAccountCode = await userAccountCodeRepository.GetUserAccountCodeByAccountId(accountId);

            // Assert
            Assert.IsNull(retrievedUserAccountCode);
        }
예제 #5
0
        public async Task GetUserAccountCodeByAccountId_UserAccountCodeExists_UserAccountIdIsCorrect(int expectedAccountId)
        {
            // Arrange
            IUserAccountCodeRepository userAccountCodeRepository =
                new UserAccountCodeRepository(new SQLServerGateway(), new ConnectionStringData());

            // Act
            var userAccountCodeModel = await userAccountCodeRepository.GetUserAccountCodeByAccountId(expectedAccountId);

            var actualAccountId = userAccountCodeModel.UserAccountId;

            // Assert
            Assert.IsTrue(actualAccountId == expectedAccountId);
        }
        public async Task GetUserAccountCodeByAccountId_AccountIdDoesntExists_ReturnNull(int accountId)
        {
            // Arrange
            IDataGateway               dataGateway               = new SQLServerGateway();
            IConnectionStringData      connectionString          = new ConnectionStringData();
            IUserAccountCodeRepository userAccountCodeRepository = new UserAccountCodeRepository(dataGateway, connectionString);

            IUserAccountCodeService userAccountCodeService = new UserAccountCodeService(userAccountCodeRepository);

            // Act
            var actualResult = await userAccountCodeService.GetUserAccountCodeByAccountId(accountId);

            // Assert
            Assert.IsNull(actualResult);
        }
예제 #7
0
        public async Task UpdateAccountCodeByAccountId_UserAccountCodeExists_DataIsAccurate
            (int accountId, string code, string expirationTime, long expectedMaxExecutionTime)
        {
            // Arrange
            IUserAccountCodeRepository userAccountCodeRepository =
                new UserAccountCodeRepository(new SQLServerGateway(), new ConnectionStringData());

            // Act
            await userAccountCodeRepository.UpdateUserAccountCodeById(code, DateTimeOffset.Parse(expirationTime), accountId);

            var newUserAccountCode = await userAccountCodeRepository.GetUserAccountCodeByAccountId(accountId);

            // Assert
            Assert.IsTrue(newUserAccountCode.UserAccountId == accountId);
            Assert.IsTrue(newUserAccountCode.Code == code);
            Assert.IsTrue(newUserAccountCode.ExpirationTime == DateTimeOffset.Parse(expirationTime));
        }
예제 #8
0
        public async Task CreateUserAccountCode_UserAccountIdDoesntExist_DataIsAccurate
            (int expectedId, string expectedCode, string expectedExpirationTime, int expectedAccountId,
            string username, string password, string salt, string emailAddress, string accountType, string accountStatus,
            string creationDate, string updationDate)
        {
            // Arrange
            IUserAccountRepository userAccountRepository =
                new UserAccountRepository(new SQLServerGateway(), new ConnectionStringData());
            IUserAccountCodeRepository userAccountCodeRepository =
                new UserAccountCodeRepository(new SQLServerGateway(), new ConnectionStringData());

            UserAccountModel userAccountModel = new UserAccountModel();

            userAccountModel.Id            = expectedAccountId;
            userAccountModel.Username      = username;
            userAccountModel.Password      = password;
            userAccountModel.Salt          = salt;
            userAccountModel.EmailAddress  = emailAddress;
            userAccountModel.AccountType   = accountType;
            userAccountModel.AccountStatus = accountStatus;
            userAccountModel.CreationDate  = DateTimeOffset.Parse(creationDate);
            userAccountModel.UpdationDate  = DateTimeOffset.Parse(updationDate);

            UserAccountCodeModel userAccountCodeModel = new UserAccountCodeModel();

            userAccountCodeModel.Id             = expectedId;
            userAccountCodeModel.Code           = expectedCode;
            userAccountCodeModel.ExpirationTime = DateTimeOffset.Parse(expectedExpirationTime);
            userAccountCodeModel.UserAccountId  = expectedAccountId;

            // Act
            await userAccountRepository.CreateAccount(userAccountModel);

            await userAccountCodeRepository.CreateUserAccountCode(userAccountCodeModel);

            var actualUserAccountCode = await userAccountCodeRepository.GetUserAccountCodeById(expectedId);

            // Assert
            Assert.IsTrue
            (
                actualUserAccountCode.Id == expectedId &&
                actualUserAccountCode.Code == expectedCode &&
                actualUserAccountCode.ExpirationTime == DateTimeOffset.Parse(expectedExpirationTime) &&
                actualUserAccountCode.UserAccountId == expectedAccountId
            );
        }
        public async Task DeleteCodeByAccountId_AccountIdExists_ReturnTrue(int accountId)
        {
            // Arrange
            IDataGateway               dataGateway               = new SQLServerGateway();
            IConnectionStringData      connectionString          = new ConnectionStringData();
            IUserAccountCodeRepository userAccountCodeRepository = new UserAccountCodeRepository(dataGateway, connectionString);

            var expectedResult = true;

            IUserAccountCodeService userAccountCodeService = new UserAccountCodeService(userAccountCodeRepository);

            // Act
            var actualResult = await userAccountCodeService.DeleteCodeByAccountId(accountId);

            // Assert
            Assert.IsTrue(actualResult == expectedResult);
        }
예제 #10
0
        public async Task CreateUserAccountCode_ExecutionTimeLessThan400Milliseconds
            (int id, string code, string expirationTime, int accountId, string username, string password, string salt,
            string emailAddress, string accountType, string accountStatus, string creationDate, string updationDate,
            long expectedMaxExecutionTime)
        {
            // Arrange
            IUserAccountCodeRepository userAccountCodeRepository =
                new UserAccountCodeRepository(new SQLServerGateway(), new ConnectionStringData());
            IUserAccountRepository userAccountRepository =
                new UserAccountRepository(new SQLServerGateway(), new ConnectionStringData());

            UserAccountModel userAccountModel = new UserAccountModel();

            userAccountModel.Id            = accountId;
            userAccountModel.Username      = username;
            userAccountModel.Password      = password;
            userAccountModel.Salt          = salt;
            userAccountModel.EmailAddress  = emailAddress;
            userAccountModel.AccountType   = accountType;
            userAccountModel.AccountStatus = accountStatus;
            userAccountModel.CreationDate  = DateTimeOffset.Parse(creationDate);
            userAccountModel.UpdationDate  = DateTimeOffset.Parse(updationDate);

            UserAccountCodeModel userAccountCodeModel = new UserAccountCodeModel();

            await userAccountRepository.CreateAccount(userAccountModel);

            userAccountCodeModel.Id             = id;
            userAccountCodeModel.Code           = code;
            userAccountCodeModel.ExpirationTime = DateTimeOffset.Parse(expirationTime);
            userAccountCodeModel.UserAccountId  = accountId;

            // Act
            var timer = Stopwatch.StartNew();
            await userAccountCodeRepository.CreateUserAccountCode(userAccountCodeModel);

            timer.Stop();

            var actualExecutionTime = timer.ElapsedMilliseconds;

            Debug.WriteLine("Actual Execution Time: " + actualExecutionTime);

            // Assert
            Assert.IsTrue(actualExecutionTime <= expectedMaxExecutionTime);
        }
        public async Task UpdateCode_AccountIdExists_ReturnTrue(string code, string expirationTime, int accountId)
        {
            // Arrange
            IDataGateway               dataGateway               = new SQLServerGateway();
            IConnectionStringData      connectionString          = new ConnectionStringData();
            IUserAccountCodeRepository userAccountCodeRepository = new UserAccountCodeRepository(dataGateway, connectionString);

            var expectedResult = true;

            IUserAccountCodeService userAccountCodeService = new UserAccountCodeService(userAccountCodeRepository);

            // Act
            var actualResult = await userAccountCodeService.UpdateCodeByAccountId(code, DateTimeOffset.Parse(expirationTime),
                                                                                  accountId);

            // Assert
            Assert.IsTrue(actualResult == expectedResult);
        }
예제 #12
0
        public async Task UpdateAccountCodeById_ExecutionTimeLessThan400Milliseconds
            (int id, string code, string expirationTime, long expectedMaxExecutionTime)
        {
            // Arrange
            IUserAccountCodeRepository userAccountCodeRepository =
                new UserAccountCodeRepository(new SQLServerGateway(), new ConnectionStringData());

            // Act
            var timer = Stopwatch.StartNew();
            await userAccountCodeRepository.UpdateUserAccountCodeById(code, DateTimeOffset.Parse(expirationTime), id);

            timer.Stop();

            var actualExecutionTime = timer.ElapsedMilliseconds;

            Debug.WriteLine("Actual Execution Time: " + actualExecutionTime);

            // Assert
            Assert.IsTrue(actualExecutionTime <= expectedMaxExecutionTime);
        }
예제 #13
0
        public async Task GetAllUserAccountCodes_AtLeastTwoUserAccountCodesExist_ExecutionTimeLessThan400Milliseconds
            (long expectedMaxExecutionTime)
        {
            // Arrange
            IUserAccountCodeRepository userAccountCodeRepository =
                new UserAccountCodeRepository(new SQLServerGateway(), new ConnectionStringData());

            // Act
            var timer = Stopwatch.StartNew();
            await userAccountCodeRepository.GetAllUserAccountCodes();

            timer.Stop();

            var actualExecutionTime = timer.ElapsedMilliseconds;

            Debug.WriteLine("Actual Execution Time: " + actualExecutionTime);

            // Assert
            Assert.IsTrue(actualExecutionTime <= expectedMaxExecutionTime);
        }
예제 #14
0
        public async Task Init()
        {
            await TestCleaner.CleanDatabase();

            var numTestRows = 20;

            IDataGateway               dataGateway               = new SQLServerGateway();
            IConnectionStringData      connectionString          = new ConnectionStringData();
            IUserAccountRepository     userAccountRepository     = new UserAccountRepository(dataGateway, connectionString);
            IUserAccountCodeRepository userAccountCodeRepository = new UserAccountCodeRepository(dataGateway, connectionString);

            for (int i = 1; i <= numTestRows; ++i)
            {
                UserAccountModel userAccountModel = new UserAccountModel();

                userAccountModel.Id            = i;
                userAccountModel.Username      = "******" + i;
                userAccountModel.Password      = "******" + i;
                userAccountModel.Salt          = "TestSalt" + i;
                userAccountModel.EmailAddress  = "TestEmailAddress" + i;
                userAccountModel.AccountType   = "TestAccountType" + i;
                userAccountModel.AccountStatus = "TestAccountStatus" + i;
                userAccountModel.CreationDate  = DateTimeOffset.UtcNow;
                userAccountModel.UpdationDate  = DateTimeOffset.UtcNow;

                await userAccountRepository.CreateAccount(userAccountModel);

                UserAccountCodeModel userAccountCodeModel = new UserAccountCodeModel();

                userAccountCodeModel.Id             = i;
                userAccountCodeModel.Code           = "ABC" + i;
                userAccountCodeModel.ExpirationTime = DateTimeOffset.Parse("3/28/2007 7:13:50 PM +00:00");
                userAccountCodeModel.UserAccountId  = i;

                await userAccountCodeRepository.CreateUserAccountCode(userAccountCodeModel);
            }
        }
        public static async Task CleanDatabase()
        {
            IDataGateway                        dataGateway                        = new SQLServerGateway();
            IConnectionStringData               connectionString                   = new ConnectionStringData();
            IUserAccountRepository              userAccountRepository              = new UserAccountRepository(dataGateway, connectionString);
            IUserProfileRepository              userProfileRepository              = new UserProfileRepository(dataGateway, connectionString);
            IUserAccountCodeRepository          userAccountCodeRepository          = new UserAccountCodeRepository(dataGateway, connectionString);
            IUserAccountSettingsRepository      userAccountSettingsRepository      = new UserAccountSettingRepository(dataGateway, connectionString);
            ILoginAttemptsRepository            loginAttemptsRepository            = new LoginAttemptsRepository(dataGateway, connectionString);
            IResourceRepository                 resourceRepository                 = new ResourceRepository(dataGateway, connectionString);
            IClaimRepository                    claimRepository                    = new ClaimRepository(dataGateway, connectionString);
            IScopeRepository                    scopeRepository                    = new ScopeRepository(dataGateway, connectionString);
            IScopeClaimRepository               scopeClaimRepository               = new ScopeClaimRepository(dataGateway, connectionString);
            IUserScopeRepository                userScopeRepository                = new UserScopeRepository(dataGateway, connectionString);
            IUserClaimRepository                userClaimRepository                = new UserClaimRepository(dataGateway, connectionString);
            IAssignmentPolicyRepository         assignmentPolicyRepository         = new AssignmentPolicyRepository(dataGateway, connectionString);
            IAssignmentPolicyPairingRepository  assignmentPolicyPairingRepository  = new AssignmentPolicyPairingRepository(dataGateway, connectionString);
            IUserScopeClaimRepository           userScopeClaimRepository           = new UserScopeClaimRepository(dataGateway, connectionString);
            IAccessPolicyRepository             accessPolicyRepository             = new AccessPolicyRepository(dataGateway, connectionString);
            IAccessPolicyPairingRepository      accessPolicyPairingRepository      = new AccessPolicyPairingRepository(dataGateway, connectionString);
            ITraditionalListingSearchRepository traditionalListingSearchRepository = new TraditionalListingSearchRepository(dataGateway, connectionString);


            var accounts = await userAccountRepository.GetAllAccounts();

            var profiles = await userProfileRepository.GetAllUserProfiles();

            var accountCodes = await userAccountCodeRepository.GetAllUserAccountCodes();

            var accountSettings = await userAccountSettingsRepository.GetAllSettings();

            var loginAttempts = await loginAttemptsRepository.GetAllLoginAttempts();

            var resources = await resourceRepository.GetAllResources();

            var claims = await claimRepository.GetAllClaims();

            var scopes = await scopeRepository.GetAllScopes();

            var scopeClaims = await scopeClaimRepository.GetAllScopeClaims();

            var userClaims = await userClaimRepository.GetAllUserClaims();

            var userScopes = await userScopeRepository.GetAllUserScopes();

            var assignmentPolicies = await assignmentPolicyRepository.GetAllAssignmentPolicies();

            var assignmentPolicyPairings = await assignmentPolicyPairingRepository.GetAllAssignmentPolicyPairings();

            var userScopeClaims = await userScopeClaimRepository.GetAllUserScopeClaims();

            var accessPolicies = await accessPolicyRepository.GetAllAccessPolicies();

            var accesssPolicyPairings = await accessPolicyPairingRepository.GetAllAccessPoliciesPairings();

            var listings = await traditionalListingSearchRepository.GetAllListings();

            var collaborationListings = await traditionalListingSearchRepository.GetAllCollaborationListings();

            var relationshipListings = await traditionalListingSearchRepository.GetAllRelationshipListings();

            var teamListings = await traditionalListingSearchRepository.GetAllTeamListings();

            if (resources != null)
            {
                await DeleteAllFromTable("Resource");
                await ReseedAsync("Resource", 0, connectionString, dataGateway);
            }

            if (claimRepository != null)
            {
                await DeleteAllFromTable("Claim");
                await ReseedAsync("Claim", 0, connectionString, dataGateway);
            }

            if (scopeRepository != null)
            {
                await DeleteAllFromTable("Scope");
                await ReseedAsync("Scope", 0, connectionString, dataGateway);
            }

            if (scopeClaims != null)
            {
                await DeleteAllFromTable("ScopeClaim");
                await ReseedAsync("ScopeClaim", 0, connectionString, dataGateway);
            }
            if (assignmentPolicies != null)
            {
                await DeleteAllFromTable("AssignmentPolicy");
                await ReseedAsync("AssignmentPolicy", 0, connectionString, dataGateway);
            }

            if (assignmentPolicyPairings != null)
            {
                await DeleteAllFromTable("AssignmentPolicyPairing");
            }

            if (userScopeClaims != null)
            {
                await DeleteAllFromTable("UserScopeClaim");
                await ReseedAsync("UserScopeClaim", 0, connectionString, dataGateway);
            }

            if (userScopes != null)
            {
                await DeleteAllFromTable("UserScope");
                await ReseedAsync("UserScope", 0, connectionString, dataGateway);
            }

            if (userClaims != null)
            {
                await DeleteAllFromTable("UserClaim");
                await ReseedAsync("UserClaim", 0, connectionString, dataGateway);
            }

            if (accessPolicies != null)
            {
                await DeleteAllFromTable("AccessPolicy");
                await ReseedAsync("AccessPolicy", 0, connectionString, dataGateway);
            }

            if (accesssPolicyPairings != null)
            {
                await DeleteAllFromTable("AccessPolicyPairing");
                await ReseedAsync("AssignmentPolicyPairing", 0, connectionString, dataGateway);
                await ReseedAsync("AccessPolicyPairing", 0, connectionString, dataGateway);
            }

            if (loginAttempts != null)
            {
                await DeleteAllFromTable("LoginAttempts");
                await ReseedAsync("LoginAttempts", 0, connectionString, dataGateway);
            }

            if (accounts != null)
            {
                await DeleteAllFromTable("UserProfile");
                await DeleteAllFromTable("UserAccountSettings");
                await DeleteAllFromTable("UserAccountCode");
                await DeleteAllFromTable("UserAccount");

                await ReseedAsync("UserAccount", 0, connectionString, dataGateway);
                await ReseedAsync("UserProfile", 0, connectionString, dataGateway);
                await ReseedAsync("UserAccountCode", 0, connectionString, dataGateway);
                await ReseedAsync("UserAccountSettings", 0, connectionString, dataGateway);
            }
            if (listings != null)
            {
                await DeleteAllFromTable("Listing");
                await ReseedAsync("Listing", 0, connectionString, dataGateway);
            }
            if (collaborationListings != null)
            {
                await DeleteAllFromTable("Collaboration");
                await ReseedAsync("Collaboration", 0, connectionString, dataGateway);
            }
            if (relationshipListings != null)
            {
                await DeleteAllFromTable("Relationship");
                await ReseedAsync("Relationship", 0, connectionString, dataGateway);
            }
            if (teamListings != null)
            {
                await DeleteAllFromTable("TeamModel");
                await ReseedAsync("TeamModel", 0, connectionString, dataGateway);
            }
        }