Exemple #1
0
        async Task AndGivenCreatedArticlesInDatabase()
        {
            var fakerGenerator = new FakerGenerator();

            var user = fakerGenerator.GetUserAccountDataFakerGenerator()
                       .RuleFor(x => x.Id, _userId)
                       .RuleFor(x => x.FirstName, "John")
                       .RuleFor(x => x.LastName, "Doo")
                       .Generate();

            var otherUser = fakerGenerator.GetUserAccountDataFakerGenerator().Generate();

            _context.UserAccountsData.Add(user);
            _context.UserAccountsData.Add(otherUser);

            var standardArticles = fakerGenerator.GetArticleFakerGenerator()
                                   .RuleFor(x => x.CreatorId, _userId)
                                   .RuleFor(x => x.ArticleType, ArticleType.Standard)
                                   .Generate(5);

            var cryptoBlogArticles = fakerGenerator.GetArticleFakerGenerator()
                                     .RuleFor(x => x.CreatorId, otherUser.Id)
                                     .RuleFor(x => x.ArticleType, ArticleType.CryptoBlog)
                                     .Generate(3);

            _context.Articles.AddRange(standardArticles);
            _context.Articles.AddRange(cryptoBlogArticles);
            await _context.SaveChangesAsync();
        }
        private async Task CreateExistingUsersInDatabase()
        {
            var fakerGenerator = new FakerGenerator();

            var existingUserAccountData = fakerGenerator.GetUserAccountDataFakerGenerator().Generate();

            _context.UserAccountsData.Add(existingUserAccountData);
            await _context.SaveChangesAsync();

            var multiAccount1 = fakerGenerator.GetUserMultiAccountFakerGenerator()
                                .RuleFor(x => x.UserAccountDataId, existingUserAccountData.Id)
                                .Generate();

            var multiAccount2 = fakerGenerator.GetUserMultiAccountFakerGenerator()
                                .RuleFor(x => x.UserAccountDataId, existingUserAccountData.Id)
                                .RuleFor(x => x.MultiAccountName, "222")
                                .Generate();

            var multiAccount3 = fakerGenerator.GetUserMultiAccountFakerGenerator()
                                .RuleFor(x => x.UserAccountDataId, existingUserAccountData.Id)
                                .RuleFor(x => x.MultiAccountName, "333")
                                .RuleFor(x => x.RefLink, "reflink333")
                                .Generate();

            _context.UserMultiAccounts.AddRange(multiAccount1, multiAccount2, multiAccount3);
            await _context.SaveChangesAsync();
        }
        async Task AndGivenCreatedDefaultAccountsInDatabase()
        {
            var fakerGenerator = new FakerGenerator();

            var hashSalt = PasswordEncryptionUtilities.GenerateSaltedHash("Password12345");

            var myUserAccountData = fakerGenerator.GetUserAccountDataFakerGenerator()
                                    .RuleFor(x => x.Id, Guid.Parse("042d748c-9cef-4a5a-92bd-3fd9a4a0e499"))
                                    .RuleFor(x => x.Salt, hashSalt.Salt)
                                    .RuleFor(x => x.Hash, hashSalt.Hash)
                                    .Generate();

            var otherUser = fakerGenerator.GetUserAccountDataFakerGenerator().Generate();

            _context.UserAccountsData.AddRange(myUserAccountData, otherUser);
            await _context.SaveChangesAsync();

            // Multi accounts
            var otherMultiAccount = new UserMultiAccount
                                    (
                id: Guid.NewGuid(),
                userAccountDataId: otherUser.Id,
                sponsorId: null,
                multiAccountName: "otherMultiAccountName"
                                    );

            otherMultiAccount.SetReflink("FIRST_REFLINK");
            otherMultiAccount.SetAsMainAccount();

            var myMultiAccount1 = new UserMultiAccount
                                  (
                id: Guid.NewGuid(),
                userAccountDataId: myUserAccountData.Id,
                sponsorId: null,
                multiAccountName: "myMultiAccount1"
                                  );

            var myMultiAccount2 = new UserMultiAccount
                                  (
                id: Guid.NewGuid(),
                userAccountDataId: myUserAccountData.Id,
                sponsorId: null,
                multiAccountName: "myMultiAccount2"
                                  );

            var myMultiAccount3 = new UserMultiAccount
                                  (
                id: Guid.NewGuid(),
                userAccountDataId: myUserAccountData.Id,
                sponsorId: null,
                multiAccountName: "myMultiAccount3"
                                  );

            _context.UserMultiAccounts.AddRange(otherMultiAccount, myMultiAccount1, myMultiAccount2, myMultiAccount3);
            await _context.SaveChangesAsync();
        }
Exemple #4
0
        async Task AndGivenCreatedTicketsInDatabase()
        {
            var fakerGenerator = new FakerGenerator();

            var tickets = fakerGenerator.GetTicketsFakerGenerator()
                          .Generate(5);

            _context.Tickets.AddRange(tickets);
            await _context.SaveChangesAsync();
        }
        async Task AndGivenCreatedRootUserInDatabase()
        {
            var fakerGenerator = new FakerGenerator();

            var user = fakerGenerator.GetUserAccountDataFakerGenerator()
                       .RuleFor(x => x.Id, _userId)
                       .RuleFor(x => x.Role, UserRolesHelper.Root)
                       .Generate();

            _context.UserAccountsData.Add(user);
            await _context.SaveChangesAsync();
        }
        async Task AndGivenCreatedUserAccountInDatabase()
        {
            var fakerGenerator = new FakerGenerator();

            var user = fakerGenerator.GetUserAccountDataFakerGenerator()
                       .RuleFor(x => x.Id, _updatedUserId)
                       .RuleFor(x => x.Email, _updatedUserEmail)
                       .RuleFor(x => x.Role, _updatedUserRole)
                       .Generate();

            _context.UserAccountsData.Add(user);
            await _context.SaveChangesAsync();
        }
Exemple #7
0
        async Task AndGivenCreatedUserAccountInDatabase()
        {
            var fakerGenerator = new FakerGenerator();

            var userAccountData = fakerGenerator.GetUserAccountDataFakerGenerator()
                                  .RuleFor(x => x.Id, _testUserId)
                                  .RuleFor(x => x.Login, _testLogin)
                                  .RuleFor(x => x.FirstName, _testFirstName)
                                  .Generate();

            _context.UserAccountsData.Add(userAccountData);
            await _context.SaveChangesAsync();
        }
Exemple #8
0
        async Task AndGivenCreatedUserAccountInDatabase()
        {
            var fakerGenerator = new FakerGenerator();
            var hashSalt       = PasswordEncryptionUtilities.GenerateSaltedHash(TestPassword);

            var myUserAccountData = fakerGenerator.GetUserAccountDataFakerGenerator()
                                    .RuleFor(x => x.Id, f => Guid.Parse("042d748c-9cef-4a5a-92bd-3fd9a4a0e499"))
                                    .RuleFor(x => x.Login, f => TestLogin)
                                    .RuleFor(x => x.Hash, hashSalt.Hash)
                                    .RuleFor(x => x.Salt, hashSalt.Salt)
                                    .Generate();

            _context.UserAccountsData.Add(myUserAccountData);
            await _context.SaveChangesAsync();
        }
        async Task AndGivenCreatedArticleInDatabase()
        {
            var fakerGenerator = new FakerGenerator();

            var user = fakerGenerator.GetUserAccountDataFakerGenerator().Generate();

            _context.UserAccountsData.Add(user);

            var article = fakerGenerator.GetArticleFakerGenerator()
                          .RuleFor(x => x.Id, _articleId)
                          .RuleFor(x => x.CreatorId, user.Id)
                          .Generate();

            _context.Articles.Add(article);
            await _context.SaveChangesAsync();
        }
Exemple #10
0
        async Task AndGivenCreatedTicketsInDatabase()
        {
            var fakerGenerator = new FakerGenerator();

            var testedTicket = fakerGenerator.GetTicketsFakerGenerator()
                               .RuleFor(x => x.Id, _ticketId)
                               .RuleFor(x => x.FullTicketNumber, "ticket-000005")
                               .Generate();

            var tickets = fakerGenerator.GetTicketsFakerGenerator()
                          .Generate(5);

            tickets.Add(testedTicket);

            _context.Tickets.AddRange(tickets);
            await _context.SaveChangesAsync();
        }
Exemple #11
0
        async Task AndGivenPaymentAndUserAccountInDatabase()
        {
            var fakerGenerator = new FakerGenerator();

            var payment = fakerGenerator.GetPaymentHistoryFakerGenerator()
                          .RuleFor(x => x.PaymentId, f => Guid.Parse("ab1a5483-fd98-4fe0-b859-240b718c3ac3"))
                          .RuleFor(x => x.AmountToPay, f => 0.008M)
                          .RuleFor(x => x.PaymentFor, f => PaymentForHelper.MembershipsFee)
                          .Generate();

            _context.PaymentHistories.Add(payment);

            var user = fakerGenerator.GetUserAccountDataFakerGenerator()
                       .RuleFor(x => x.Id, f => Guid.Parse("590565b0-df3e-49f0-866c-ececbe696611"))
                       .Generate();

            _context.UserAccountsData.Add(user);
            await _context.SaveChangesAsync();
        }
 public UserMultiAccountHelperTests()
 {
     _fakeGenerator = new FakerGenerator();
     _contextMock   = new Mock <IBitClub7Context>(MockBehavior.Strict);
     _userAccountDataRepositoryMock = new Mock <IUserAccountDataRepository>(MockBehavior.Strict);
 }
        async Task AndGivenCreatedDefaultAccountsAndMatricesInDatabase()
        {
            var fakerGenerator = new FakerGenerator();

            var myUserAccountData = fakerGenerator.GetUserAccountDataFakerGenerator()
                                    .RuleFor(x => x.Id, Guid.Parse("042d748c-9cef-4a5a-92bd-3fd9a4a0e499"))
                                    .RuleFor(x => x.IsMembershipFeePaid, true)
                                    .Generate();

            var otherUser = fakerGenerator.GetUserAccountDataFakerGenerator()
                            .RuleFor(x => x.IsMembershipFeePaid, true)
                            .Generate();

            _context.UserAccountsData.AddRange(myUserAccountData, otherUser);
            await _context.SaveChangesAsync();

            // Multi accounts
            var otherMultiAccount = new UserMultiAccount
                                    (
                id: Guid.NewGuid(),
                userAccountDataId: otherUser.Id,
                sponsorId: null,
                multiAccountName: "otherMultiAccountName"
                                    );

            otherMultiAccount.SetReflink("FIRST_REFLINK");
            otherMultiAccount.SetAsMainAccount();

            var otherMultiAccount2 = new UserMultiAccount
                                     (
                id: Guid.NewGuid(),
                userAccountDataId: otherUser.Id,
                sponsorId: null,
                multiAccountName: "otherMultiAccountName2"
                                     );

            otherMultiAccount2.SetReflink("SECOND_REFLINK");

            var otherMultiAccount3 = new UserMultiAccount
                                     (
                id: Guid.NewGuid(),
                userAccountDataId: otherUser.Id,
                sponsorId: null,
                multiAccountName: "otherMultiAccountName3"
                                     );

            otherMultiAccount3.SetReflink("THIRD_REFLINK");

            var otherMultiAccount4 = new UserMultiAccount
                                     (
                id: Guid.NewGuid(),
                userAccountDataId: otherUser.Id,
                sponsorId: null,
                multiAccountName: "otherMultiAccountName4"
                                     );

            otherMultiAccount4.SetReflink("FOURTH_REFLINK");

            var otherMultiAccount5 = new UserMultiAccount
                                     (
                id: Guid.NewGuid(),
                userAccountDataId: otherUser.Id,
                sponsorId: null,
                multiAccountName: "otherMultiAccountName5"
                                     );

            otherMultiAccount5.SetReflink("FIFTH_REFLINK");

            var otherMultiAccount6 = new UserMultiAccount
                                     (
                id: Guid.NewGuid(),
                userAccountDataId: otherUser.Id,
                sponsorId: null,
                multiAccountName: "otherMultiAccountName6"
                                     );

            otherMultiAccount6.SetReflink("SIXTH_REFLINK");

            var otherMultiAccount7 = new UserMultiAccount
                                     (
                id: Guid.NewGuid(),
                userAccountDataId: otherUser.Id,
                sponsorId: null,
                multiAccountName: "otherMultiAccountName7"
                                     );

            otherMultiAccount7.SetReflink("SEVENTH_REFLINK");

            var myMultiAccount = new UserMultiAccount
                                 (
                id: Guid.NewGuid(),
                userAccountDataId: myUserAccountData.Id,
                sponsorId: otherMultiAccount.Id,
                multiAccountName: "myMultiAccountName"
                                 );

            myMultiAccount.SetReflink("myReflink12345");
            myMultiAccount.SetAsMainAccount();

            _context.UserMultiAccounts.AddRange(otherMultiAccount, otherMultiAccount2, otherMultiAccount3, otherMultiAccount4, otherMultiAccount5, otherMultiAccount6, otherMultiAccount7, myMultiAccount);
            await _context.SaveChangesAsync();

            // Matrices
            var rootMatrixPosition = new MatrixPosition
                                     (
                id: Guid.NewGuid(),
                userMultiAccountId: otherMultiAccount.Id,
                parentId: null,
                matrixLevel: 0,
                depthLevel: 0,
                left: 1,
                right: 20
                                     );

            _context.MatrixPositions.Add(rootMatrixPosition);
            await _context.SaveChangesAsync();

            var otherMatrixPosition = new MatrixPosition
                                      (
                id: Guid.NewGuid(),
                userMultiAccountId: otherMultiAccount2.Id,
                parentId: rootMatrixPosition.Id,
                matrixLevel: 0,
                depthLevel: 1,
                left: 2,
                right: 11
                                      );

            _context.MatrixPositions.Add(otherMatrixPosition);
            await _context.SaveChangesAsync();

            var otherMatrixPosition2 = new MatrixPosition
                                       (
                id: Guid.NewGuid(),
                userMultiAccountId: otherMultiAccount4.Id,
                parentId: otherMatrixPosition.Id,
                matrixLevel: 0,
                depthLevel: 2,
                left: 3,
                right: 8
                                       );

            _context.MatrixPositions.Add(otherMatrixPosition2);
            await _context.SaveChangesAsync();

            var otherMatrixPosition3 = new MatrixPosition
                                       (
                id: Guid.NewGuid(),
                userMultiAccountId: null,
                parentId: otherMatrixPosition2.Id,
                matrixLevel: 0,
                depthLevel: 3,
                left: 4,
                right: 5
                                       );

            _context.MatrixPositions.Add(otherMatrixPosition3);
            await _context.SaveChangesAsync();

            var otherMatrixPosition4 = new MatrixPosition
                                       (
                id: Guid.NewGuid(),
                userMultiAccountId: myMultiAccount.Id,
                parentId: otherMatrixPosition2.Id,
                matrixLevel: 0,
                depthLevel: 3,
                left: 6,
                right: 7
                                       );

            _context.MatrixPositions.Add(otherMatrixPosition4);
            await _context.SaveChangesAsync();

            var otherMatrixPosition5 = new MatrixPosition
                                       (
                id: Guid.NewGuid(),
                userMultiAccountId: otherMultiAccount5.Id,
                parentId: otherMatrixPosition.Id,
                matrixLevel: 0,
                depthLevel: 2,
                left: 9,
                right: 10
                                       );

            _context.MatrixPositions.Add(otherMatrixPosition5);
            await _context.SaveChangesAsync();

            var otherMatrixPosition6 = new MatrixPosition
                                       (
                id: Guid.NewGuid(),
                userMultiAccountId: otherMultiAccount3.Id,
                parentId: rootMatrixPosition.Id,
                matrixLevel: 0,
                depthLevel: 1,
                left: 12,
                right: 19
                                       );

            _context.MatrixPositions.Add(otherMatrixPosition6);
            await _context.SaveChangesAsync();

            var otherMatrixPosition7 = new MatrixPosition
                                       (
                id: Guid.NewGuid(),
                userMultiAccountId: otherMultiAccount6.Id,
                parentId: otherMatrixPosition6.Id,
                matrixLevel: 0,
                depthLevel: 2,
                left: 13,
                right: 14
                                       );

            _context.MatrixPositions.Add(otherMatrixPosition7);
            await _context.SaveChangesAsync();

            var otherMatrixPosition8 = new MatrixPosition
                                       (
                id: Guid.NewGuid(),
                userMultiAccountId: otherMultiAccount7.Id,
                parentId: otherMatrixPosition6.Id,
                matrixLevel: 0,
                depthLevel: 2,
                left: 15,
                right: 18
                                       );

            _context.MatrixPositions.Add(otherMatrixPosition8);
            await _context.SaveChangesAsync();

            var otherMatrixPosition9 = new MatrixPosition
                                       (
                id: Guid.NewGuid(),
                userMultiAccountId: null,
                parentId: otherMatrixPosition8.Id,
                matrixLevel: 0,
                depthLevel: 3,
                left: 16,
                right: 17
                                       );

            _context.MatrixPositions.Add(otherMatrixPosition9);
            await _context.SaveChangesAsync();
        }
Exemple #14
0
        private async Task CreateUserAndMultiAccountAndMatrixPositionsInDatabase()
        {
            var fakerGenerator = new FakerGenerator();

            var existingUserAccountData = fakerGenerator.GetUserAccountDataFakerGenerator()
                                          .RuleFor(x => x.Id, f => Guid.Parse("042d748c-9cef-4a5a-92bd-3fd9a4a0e499"))
                                          .RuleFor(x => x.IsMembershipFeePaid, true)
                                          .Generate();

            var otherUser = fakerGenerator.GetUserAccountDataFakerGenerator()
                            .RuleFor(x => x.IsMembershipFeePaid, true)
                            .Generate();

            _context.UserAccountsData.AddRange(existingUserAccountData, otherUser);
            await _context.SaveChangesAsync();

            var myMultiAccount = new UserMultiAccount
                                 (
                id: Guid.NewGuid(),
                userAccountDataId: existingUserAccountData.Id,
                sponsorId: null,
                multiAccountName: "myMultiAccountName"
                                 );

            myMultiAccount.SetReflink("myReflink12345");
            myMultiAccount.SetAsMainAccount();

            var otherMultiAccount = new UserMultiAccount
                                    (
                id: Guid.NewGuid(),
                userAccountDataId: otherUser.Id,
                sponsorId: null,
                multiAccountName: "otherMultiAccountName"
                                    );

            otherMultiAccount.SetReflink("otherUserReflink12345");
            otherMultiAccount.SetAsMainAccount();

            _context.UserMultiAccounts.AddRange(myMultiAccount, otherMultiAccount);
            await _context.SaveChangesAsync();

            // Matrices
            var myMatrixPosition = new MatrixPosition
                                   (
                id: Guid.NewGuid(),
                userMultiAccountId: myMultiAccount.Id,
                parentId: null,
                matrixLevel: 0,
                depthLevel: 0,
                left: 1,
                right: 6
                                   );

            _context.MatrixPositions.Add(myMatrixPosition);

            var otherMatrixPosition = new MatrixPosition
                                      (
                id: Guid.NewGuid(),
                userMultiAccountId: otherMultiAccount.Id,
                parentId: myMatrixPosition.Id,
                matrixLevel: 0,
                depthLevel: 2, // Level 2 (Line B of the main account so it's ok)
                left: 2,
                right: 5
                                      );

            _context.MatrixPositions.Add(otherMatrixPosition);

            var otherMatrixPosition2 = new MatrixPosition
                                       (
                id: Guid.NewGuid(),
                userMultiAccountId: null,
                parentId: otherMatrixPosition.Id,
                matrixLevel: 0,
                depthLevel: 3, // Line C
                left: 3,
                right: 4
                                       );

            _context.MatrixPositions.Add(otherMatrixPosition2);
            await _context.SaveChangesAsync();
        }
Exemple #15
0
        async Task AndGivenCreatedDefaultAccountsAndMatricesInDatabase()
        {
            var fakerGenerator = new FakerGenerator();

            var adminUserAccountData1 = fakerGenerator.GetUserAccountDataFakerGenerator()
                                        .RuleFor(x => x.Role, UserRolesHelper.Admin)
                                        .RuleFor(x => x.IsMembershipFeePaid, true)
                                        .Generate();

            var adminUserAccountData2 = fakerGenerator.GetUserAccountDataFakerGenerator()
                                        .RuleFor(x => x.Role, UserRolesHelper.Admin)
                                        .RuleFor(x => x.IsMembershipFeePaid, true)
                                        .Generate();

            var adminUserAccountData3 = fakerGenerator.GetUserAccountDataFakerGenerator()
                                        .RuleFor(x => x.Role, UserRolesHelper.Admin)
                                        .RuleFor(x => x.IsMembershipFeePaid, true)
                                        .Generate();

            var adminUserAccountData4 = fakerGenerator.GetUserAccountDataFakerGenerator()
                                        .RuleFor(x => x.Role, UserRolesHelper.Admin)
                                        .RuleFor(x => x.IsMembershipFeePaid, true)
                                        .Generate();

            var rootUser = fakerGenerator.GetUserAccountDataFakerGenerator()
                           .RuleFor(x => x.Role, UserRolesHelper.Root)
                           .RuleFor(x => x.IsMembershipFeePaid, true)
                           .Generate();

            var sponsorUser = fakerGenerator.GetUserAccountDataFakerGenerator()
                              .RuleFor(x => x.Role, UserRolesHelper.User)
                              .RuleFor(x => x.IsMembershipFeePaid, true)
                              .Generate();

            var user1 = fakerGenerator.GetUserAccountDataFakerGenerator()
                        .RuleFor(x => x.Role, UserRolesHelper.User)
                        .RuleFor(x => x.IsMembershipFeePaid, true)
                        .Generate();

            var testUser = fakerGenerator.GetUserAccountDataFakerGenerator()
                           .RuleFor(x => x.Role, UserRolesHelper.User)
                           .RuleFor(x => x.IsMembershipFeePaid, true)
                           .Generate();

            _context.UserAccountsData.AddRange(adminUserAccountData1, adminUserAccountData2, adminUserAccountData3, adminUserAccountData4, rootUser, sponsorUser, testUser, user1);
            await _context.SaveChangesAsync();

            // Multi accounts
            var rootMultiAccount1 = new UserMultiAccount
                                    (
                id: Guid.NewGuid(),
                userAccountDataId: rootUser.Id,
                sponsorId: null,
                multiAccountName: "otherMultiAccountName"
                                    );

            rootMultiAccount1.SetReflink("otherUserReflink12345");
            rootMultiAccount1.SetAsMainAccount();

            var rootMultiAccount2 = new UserMultiAccount
                                    (
                id: Guid.NewGuid(),
                userAccountDataId: rootUser.Id,
                sponsorId: null,
                multiAccountName: "otherMultiAccountName2"
                                    );

            rootMultiAccount2.SetReflink("otherUserReflink123456789");

            var rootMultiAccount3 = new UserMultiAccount
                                    (
                id: Guid.NewGuid(),
                userAccountDataId: rootUser.Id,
                sponsorId: null,
                multiAccountName: "otherMultiAccountName3"
                                    );

            rootMultiAccount3.SetReflink("3");

            var adminMultiAccount1 = new UserMultiAccount
                                     (
                id: Guid.NewGuid(),
                userAccountDataId: adminUserAccountData1.Id,
                sponsorId: rootMultiAccount2.Id,
                multiAccountName: "myMultiAccountName"
                                     );

            adminMultiAccount1.SetAsMainAccount();

            var adminMultiAccount2 = new UserMultiAccount
                                     (
                id: Guid.NewGuid(),
                userAccountDataId: adminUserAccountData2.Id,
                sponsorId: rootMultiAccount2.Id,
                multiAccountName: "myMultiAccountName"
                                     );

            adminMultiAccount2.SetAsMainAccount();

            var adminMultiAccount3 = new UserMultiAccount
                                     (
                id: Guid.NewGuid(),
                userAccountDataId: adminUserAccountData3.Id,
                sponsorId: rootMultiAccount3.Id,
                multiAccountName: "myMultiAccountName"
                                     );

            adminMultiAccount3.SetAsMainAccount();

            var adminMultiAccount4 = new UserMultiAccount
                                     (
                id: Guid.NewGuid(),
                userAccountDataId: adminUserAccountData4.Id,
                sponsorId: rootMultiAccount3.Id,
                multiAccountName: "myMultiAccountName"
                                     );

            adminMultiAccount4.SetAsMainAccount();

            var sponsorMultiAccount = new UserMultiAccount
                                      (
                id: Guid.NewGuid(),
                userAccountDataId: sponsorUser.Id,
                sponsorId: rootMultiAccount3.Id,
                multiAccountName: "sponsorMultiAccountName"
                                      );

            sponsorMultiAccount.SetAsMainAccount();

            var userMultiAccount1 = new UserMultiAccount
                                    (
                id: Guid.NewGuid(),
                userAccountDataId: user1.Id,
                sponsorId: adminMultiAccount4.Id,
                multiAccountName: "userMultiAccountName1"
                                    );

            userMultiAccount1.SetAsMainAccount();

            var testUserMultiAccount = new UserMultiAccount
                                       (
                id: _userMultiAccountId,
                userAccountDataId: testUser.Id,
                sponsorId: sponsorMultiAccount.Id,
                multiAccountName: "testUserMultiAccountName"
                                       );

            testUserMultiAccount.SetAsMainAccount();

            _context.UserMultiAccounts.AddRange(adminMultiAccount1, adminMultiAccount2, adminMultiAccount3, adminMultiAccount4, rootMultiAccount1, rootMultiAccount2, rootMultiAccount3, sponsorMultiAccount, userMultiAccount1, testUserMultiAccount);
            await _context.SaveChangesAsync();

            // Matrices
            // LVL 0
            var topMatrixPosition = new MatrixPosition
                                    (
                id: Guid.NewGuid(),
                userMultiAccountId: rootMultiAccount1.Id,
                parentId: null,
                matrixLevel: 0,
                depthLevel: 0,
                left: 1,
                right: 38
                                    );

            _context.MatrixPositions.Add(topMatrixPosition);

            var positionLineA1 = new MatrixPosition
                                 (
                id: Guid.NewGuid(),
                userMultiAccountId: rootMultiAccount2.Id,
                parentId: topMatrixPosition.Id,
                matrixLevel: 0,
                depthLevel: 1,
                left: 2,
                right: 15
                                 );

            _context.MatrixPositions.Add(positionLineA1);

            var positionLineA2 = new MatrixPosition
                                 (
                id: Guid.NewGuid(),
                userMultiAccountId: rootMultiAccount3.Id,
                parentId: topMatrixPosition.Id,
                matrixLevel: 0,
                depthLevel: 1,
                left: 16,
                right: 37
                                 );

            _context.MatrixPositions.Add(positionLineA2);

            var positionLineB1 = new MatrixPosition
                                 (
                id: Guid.NewGuid(),
                userMultiAccountId: adminMultiAccount1.Id, // TESTED
                parentId: positionLineA1.Id,
                matrixLevel: 0,
                depthLevel: 2,
                left: 3,
                right: 8
                                 );

            _context.MatrixPositions.Add(positionLineB1);

            var positionLineB2 = new MatrixPosition
                                 (
                id: Guid.NewGuid(),
                userMultiAccountId: adminMultiAccount2.Id,
                parentId: positionLineA1.Id,
                matrixLevel: 0,
                depthLevel: 2,
                left: 9,
                right: 14
                                 );

            _context.MatrixPositions.Add(positionLineB2);

            var positionLineB3 = new MatrixPosition
                                 (
                id: Guid.NewGuid(),
                userMultiAccountId: adminMultiAccount3.Id,
                parentId: positionLineA2.Id,
                matrixLevel: 0,
                depthLevel: 2,
                left: 17,
                right: 22
                                 );

            _context.MatrixPositions.Add(positionLineB3);

            var positionLineB4 = new MatrixPosition
                                 (
                id: Guid.NewGuid(),
                userMultiAccountId: adminMultiAccount4.Id,
                parentId: positionLineA2.Id,
                matrixLevel: 0,
                depthLevel: 2,
                left: 23,
                right: 36
                                 );

            _context.MatrixPositions.Add(positionLineB4);

            var positionLineC1 = new MatrixPosition
                                 (
                id: Guid.NewGuid(),
                userMultiAccountId: null,
                parentId: positionLineB1.Id,
                matrixLevel: 0,
                depthLevel: 3,
                left: 4,
                right: 5
                                 );

            _context.MatrixPositions.Add(positionLineC1);

            var positionLineC2 = new MatrixPosition
                                 (
                id: Guid.NewGuid(),
                userMultiAccountId: null,
                parentId: positionLineB1.Id,
                matrixLevel: 0,
                depthLevel: 3,
                left: 6,
                right: 7
                                 );

            _context.MatrixPositions.Add(positionLineC2);

            var positionLineC3 = new MatrixPosition
                                 (
                id: Guid.NewGuid(),
                userMultiAccountId: null,
                parentId: positionLineB2.Id,
                matrixLevel: 0,
                depthLevel: 3,
                left: 10,
                right: 11
                                 );

            _context.MatrixPositions.Add(positionLineC3);

            var positionLineC4 = new MatrixPosition
                                 (
                id: Guid.NewGuid(),
                userMultiAccountId: null,
                parentId: positionLineB2.Id,
                matrixLevel: 0,
                depthLevel: 3,
                left: 12,
                right: 13
                                 );

            _context.MatrixPositions.Add(positionLineC4);

            var positionLineC5 = new MatrixPosition
                                 (
                id: Guid.NewGuid(),
                userMultiAccountId: null,
                parentId: positionLineB3.Id,
                matrixLevel: 0,
                depthLevel: 3,
                left: 18,
                right: 19
                                 );

            _context.MatrixPositions.Add(positionLineC5);

            var positionLineC6 = new MatrixPosition
                                 (
                id: Guid.NewGuid(),
                userMultiAccountId: null,
                parentId: positionLineB3.Id,
                matrixLevel: 0,
                depthLevel: 3,
                left: 20,
                right: 21
                                 );

            _context.MatrixPositions.Add(positionLineC6);

            var positionLineC7 = new MatrixPosition
                                 (
                id: Guid.NewGuid(),
                userMultiAccountId: null,
                parentId: positionLineB4.Id,
                matrixLevel: 0,
                depthLevel: 3,
                left: 24,
                right: 25
                                 );

            _context.MatrixPositions.Add(positionLineC7);

            var positionLineC8 = new MatrixPosition
                                 (
                id: Guid.NewGuid(),
                userMultiAccountId: sponsorMultiAccount.Id,
                parentId: positionLineB4.Id,
                matrixLevel: 0,
                depthLevel: 3,
                left: 26,
                right: 35
                                 );

            _context.MatrixPositions.Add(positionLineC8);

            var positionLineD1 = new MatrixPosition
                                 (
                id: Guid.NewGuid(),
                userMultiAccountId: userMultiAccount1.Id,
                parentId: positionLineC8.Id,
                matrixLevel: 0,
                depthLevel: 4,
                left: 27,
                right: 32
                                 );

            _context.MatrixPositions.Add(positionLineD1);

            var positionLineD2 = new MatrixPosition
                                 (
                id: Guid.NewGuid(),
                userMultiAccountId: null,
                parentId: positionLineC8.Id,
                matrixLevel: 0,
                depthLevel: 4,
                left: 33,
                right: 34
                                 );

            _context.MatrixPositions.Add(positionLineD2);

            var positionLineE1 = new MatrixPosition
                                 (
                id: Guid.NewGuid(),
                userMultiAccountId: testUserMultiAccount.Id,
                parentId: positionLineD1.Id,
                matrixLevel: 0,
                depthLevel: 5,
                left: 28,
                right: 29
                                 );

            _context.MatrixPositions.Add(positionLineE1);

            var positionLineE2 = new MatrixPosition
                                 (
                id: Guid.NewGuid(),
                userMultiAccountId: null,
                parentId: positionLineD1.Id,
                matrixLevel: 0,
                depthLevel: 5,
                left: 30,
                right: 31
                                 );

            _context.MatrixPositions.Add(positionLineE2);

            // LVL 1
            var topMatrixPositionLvl1 = new MatrixPosition
                                        (
                id: Guid.NewGuid(),
                userMultiAccountId: rootMultiAccount1.Id,
                parentId: null,
                matrixLevel: 1,
                depthLevel: 0,
                left: 1,
                right: 34
                                        );

            _context.MatrixPositions.Add(topMatrixPositionLvl1);

            var positionLineA1Lvl1 = new MatrixPosition
                                     (
                id: Guid.NewGuid(),
                userMultiAccountId: rootMultiAccount2.Id,
                parentId: topMatrixPositionLvl1.Id,
                matrixLevel: 1,
                depthLevel: 1,
                left: 2,
                right: 15
                                     );

            _context.MatrixPositions.Add(positionLineA1Lvl1);

            var positionLineA2Lvl1 = new MatrixPosition
                                     (
                id: Guid.NewGuid(),
                userMultiAccountId: rootMultiAccount3.Id,
                parentId: topMatrixPositionLvl1.Id,
                matrixLevel: 1,
                depthLevel: 1,
                left: 16,
                right: 33
                                     );

            _context.MatrixPositions.Add(positionLineA2Lvl1);

            var positionLineB1Lvl1 = new MatrixPosition
                                     (
                id: Guid.NewGuid(),
                userMultiAccountId: adminMultiAccount2.Id,
                parentId: positionLineA1Lvl1.Id,
                matrixLevel: 1,
                depthLevel: 2,
                left: 3,
                right: 8
                                     );

            _context.MatrixPositions.Add(positionLineB1Lvl1);

            var positionLineB2Lvl1 = new MatrixPosition
                                     (
                id: Guid.NewGuid(),
                userMultiAccountId: adminMultiAccount2.Id,
                parentId: positionLineA1Lvl1.Id,
                matrixLevel: 1,
                depthLevel: 2,
                left: 9,
                right: 14
                                     );

            _context.MatrixPositions.Add(positionLineB2Lvl1);

            var positionLineB3Lvl1 = new MatrixPosition
                                     (
                id: Guid.NewGuid(),
                userMultiAccountId: adminMultiAccount3.Id,
                parentId: positionLineA2Lvl1.Id,
                matrixLevel: 1,
                depthLevel: 2,
                left: 17,
                right: 26
                                     );

            _context.MatrixPositions.Add(positionLineB3Lvl1);

            var positionLineB4Lvl1 = new MatrixPosition
                                     (
                id: Guid.NewGuid(),
                userMultiAccountId: adminMultiAccount4.Id,
                parentId: positionLineA2Lvl1.Id,
                matrixLevel: 1,
                depthLevel: 2,
                left: 27,
                right: 32
                                     );

            _context.MatrixPositions.Add(positionLineB4Lvl1);

            var positionLineC1Lvl1 = new MatrixPosition
                                     (
                id: Guid.NewGuid(),
                userMultiAccountId: null,
                parentId: positionLineB1Lvl1.Id,
                matrixLevel: 1,
                depthLevel: 3,
                left: 4,
                right: 5
                                     );

            _context.MatrixPositions.Add(positionLineC1Lvl1);

            var positionLineC2Lvl1 = new MatrixPosition
                                     (
                id: Guid.NewGuid(),
                userMultiAccountId: null,
                parentId: positionLineB1Lvl1.Id,
                matrixLevel: 1,
                depthLevel: 3,
                left: 6,
                right: 7
                                     );

            _context.MatrixPositions.Add(positionLineC2Lvl1);

            var positionLineC3Lvl1 = new MatrixPosition
                                     (
                id: Guid.NewGuid(),
                userMultiAccountId: null,
                parentId: positionLineB2Lvl1.Id,
                matrixLevel: 1,
                depthLevel: 3,
                left: 10,
                right: 11
                                     );

            _context.MatrixPositions.Add(positionLineC3Lvl1);

            var positionLineC4Lvl1 = new MatrixPosition
                                     (
                id: Guid.NewGuid(),
                userMultiAccountId: null,
                parentId: positionLineB2Lvl1.Id,
                matrixLevel: 1,
                depthLevel: 3,
                left: 12,
                right: 13
                                     );

            _context.MatrixPositions.Add(positionLineC4Lvl1);

            var positionLineC5Lvl1 = new MatrixPosition
                                     (
                id: Guid.NewGuid(),
                userMultiAccountId: null,
                parentId: positionLineB3Lvl1.Id,
                matrixLevel: 1,
                depthLevel: 3,
                left: 18,
                right: 19
                                     );

            _context.MatrixPositions.Add(positionLineC5Lvl1);

            var positionLineC6Lvl1 = new MatrixPosition
                                     (
                id: Guid.NewGuid(),
                userMultiAccountId: userMultiAccount1.Id,
                parentId: positionLineB3Lvl1.Id,
                matrixLevel: 1,
                depthLevel: 3,
                left: 20,
                right: 25
                                     );

            _context.MatrixPositions.Add(positionLineC6Lvl1);

            var positionLineC7Lvl1 = new MatrixPosition
                                     (
                id: Guid.NewGuid(),
                userMultiAccountId: null,
                parentId: positionLineB4Lvl1.Id,
                matrixLevel: 1,
                depthLevel: 3,
                left: 28,
                right: 29
                                     );

            _context.MatrixPositions.Add(positionLineC7Lvl1);

            var positionLineC8Lvl1 = new MatrixPosition
                                     (
                id: Guid.NewGuid(),
                userMultiAccountId: null,
                parentId: positionLineB4Lvl1.Id,
                matrixLevel: 1,
                depthLevel: 3,
                left: 30,
                right: 31
                                     );

            _context.MatrixPositions.Add(positionLineC8Lvl1);

            var positionLineD1Lvl1 = new MatrixPosition
                                     (
                id: Guid.NewGuid(),
                userMultiAccountId: null,
                parentId: positionLineC6Lvl1.Id,
                matrixLevel: 1,
                depthLevel: 4,
                left: 21,
                right: 22
                                     );

            _context.MatrixPositions.Add(positionLineD1Lvl1);

            var positionLineD2Lvl1 = new MatrixPosition
                                     (
                id: Guid.NewGuid(),
                userMultiAccountId: null,
                parentId: positionLineC6Lvl1.Id,
                matrixLevel: 1,
                depthLevel: 4,
                left: 23,
                right: 24
                                     );

            _context.MatrixPositions.Add(positionLineD2Lvl1);
            await _context.SaveChangesAsync();

            // Payments
            var paymentHistory = fakerGenerator.GetPaymentHistoryFakerGenerator()
                                 .RuleFor(x => x.OrderId, _userMultiAccountId)
                                 .RuleFor(x => x.AmountToPay, 10M)
                                 .RuleFor(x => x.PaidAmount, 10M)
                                 .RuleFor(x => x.Status, PaymentStatusHelper.Completed)
                                 .RuleFor(x => x.PaymentFor, PaymentForHelper.MatrixLevelPositionsDictionary[1])
                                 .Generate();

            _context.PaymentHistories.Add(paymentHistory);
            await _context.SaveChangesAsync();
        }
        async Task AndGivenCreatedDefaultAccountsAndMatricesInDatabase()
        {
            var fakerGenerator = new FakerGenerator();

            var existingUserAccountData = fakerGenerator.GetUserAccountDataFakerGenerator()
                                          .RuleFor(x => x.IsMembershipFeePaid, true)
                                          .Generate();

            var otherUser = fakerGenerator.GetUserAccountDataFakerGenerator()
                            .RuleFor(x => x.IsMembershipFeePaid, true)
                            .Generate();

            _context.UserAccountsData.AddRange(existingUserAccountData, otherUser);
            await _context.SaveChangesAsync();

            // Multi accounts
            var otherMultiAccount = fakerGenerator.GetUserMultiAccountFakerGenerator()
                                    .RuleFor(x => x.Id, Guid.Parse("d4887060-fb76-429b-95db-113fef65d68d"))
                                    .RuleFor(x => x.UserAccountDataId, otherUser.Id)
                                    .RuleFor(x => x.IsMainAccount, true)
                                    .Generate();

            var otherMultiAccount2 = fakerGenerator.GetUserMultiAccountFakerGenerator()
                                     .RuleFor(x => x.UserAccountDataId, otherUser.Id)
                                     .Generate();

            var otherMultiAccount3 = fakerGenerator.GetUserMultiAccountFakerGenerator()
                                     .RuleFor(x => x.UserAccountDataId, otherUser.Id)
                                     .Generate();

            var myMultiAccount = fakerGenerator.GetUserMultiAccountFakerGenerator()
                                 .RuleFor(x => x.Id, Guid.Parse("032d748c-9cef-4a5a-92bd-3fd9a4a0e499"))
                                 .RuleFor(x => x.UserAccountDataId, existingUserAccountData.Id)
                                 .RuleFor(x => x.SponsorId, otherMultiAccount.Id)
                                 .RuleFor(x => x.RefLink, null as string)
                                 .RuleFor(x => x.IsMainAccount, true)
                                 .Generate();

            _context.UserMultiAccounts.AddRange(myMultiAccount, otherMultiAccount, otherMultiAccount2, otherMultiAccount3);
            await _context.SaveChangesAsync();

            // Payments
            var payment = fakerGenerator.GetPaymentHistoryFakerGenerator()
                          .RuleFor(x => x.PaymentFor, PaymentForHelper.MatrixLevelPositionsDictionary[0])
                          .RuleFor(x => x.Status, PaymentStatusHelper.Paid)
                          .RuleFor(x => x.OrderId, Guid.Parse("032d748c-9cef-4a5a-92bd-3fd9a4a0e499"))
                          .Generate();

            _context.PaymentHistories.Add(payment);
            await _context.SaveChangesAsync();

            // Matrices
            var topMatrixPosition = new MatrixPosition
                                    (
                id: Guid.NewGuid(),
                userMultiAccountId: otherMultiAccount.Id,
                parentId: null,
                matrixLevel: 0,
                depthLevel: 0,
                left: 1,
                right: 18
                                    );

            _context.MatrixPositions.Add(topMatrixPosition);
            await _context.SaveChangesAsync();

            var positionLineA1 = new MatrixPosition
                                 (
                id: Guid.NewGuid(),
                userMultiAccountId: otherMultiAccount2.Id,
                parentId: topMatrixPosition.Id,
                matrixLevel: 0,
                depthLevel: 1,
                left: 2,
                right: 11
                                 );

            _context.MatrixPositions.Add(positionLineA1);
            await _context.SaveChangesAsync();

            var positionLineA2 = new MatrixPosition
                                 (
                id: Guid.NewGuid(),
                userMultiAccountId: otherMultiAccount2.Id,
                parentId: topMatrixPosition.Id,
                matrixLevel: 0,
                depthLevel: 1,
                left: 12,
                right: 17
                                 );

            _context.MatrixPositions.Add(positionLineA2);
            await _context.SaveChangesAsync();

            var positionLineB1 = new MatrixPosition
                                 (
                id: Guid.NewGuid(),
                userMultiAccountId: otherMultiAccount3.Id,
                parentId: positionLineA1.Id,
                matrixLevel: 0,
                depthLevel: 2,
                left: 3,
                right: 4
                                 );

            _context.MatrixPositions.Add(positionLineB1);
            await _context.SaveChangesAsync();

            var positionLineB2 = new MatrixPosition
                                 (
                id: Guid.NewGuid(),
                userMultiAccountId: otherMultiAccount3.Id,
                parentId: positionLineA1.Id,
                matrixLevel: 0,
                depthLevel: 2,
                left: 5,
                right: 8
                                 );

            _context.MatrixPositions.Add(positionLineB2);
            await _context.SaveChangesAsync();

            var positionLineC1 = new MatrixPosition
                                 (
                id: Guid.NewGuid(),
                userMultiAccountId: null,
                parentId: positionLineB2.Id,
                matrixLevel: 0,
                depthLevel: 3,
                left: 6,
                right: 7
                                 );

            _context.MatrixPositions.Add(positionLineC1);
            await _context.SaveChangesAsync();

            var positionLineC2 = new MatrixPosition
                                 (
                id: Guid.NewGuid(),
                userMultiAccountId: null,
                parentId: positionLineB2.Id,
                matrixLevel: 0,
                depthLevel: 3,
                left: 8,
                right: 9
                                 );

            _context.MatrixPositions.Add(positionLineC2);
            await _context.SaveChangesAsync();

            var positionLineB3 = new MatrixPosition
                                 (
                id: Guid.NewGuid(),
                userMultiAccountId: otherMultiAccount3.Id,
                parentId: positionLineA2.Id,
                matrixLevel: 0,
                depthLevel: 3,
                left: 13,
                right: 14
                                 );

            _context.MatrixPositions.Add(positionLineB3);
            await _context.SaveChangesAsync();

            var positionLineB4 = new MatrixPosition
                                 (
                id: Guid.NewGuid(),
                userMultiAccountId: otherMultiAccount3.Id,
                parentId: positionLineA2.Id,
                matrixLevel: 0,
                depthLevel: 3,
                left: 15,
                right: 16
                                 );

            _context.MatrixPositions.Add(positionLineB4);
            await _context.SaveChangesAsync();
        }
Exemple #17
0
 public PaymentHistoryHelperTests()
 {
     _fakerGenerator = new FakerGenerator();
     _paymentHistoryRepositoryMock = new Mock <IPaymentHistoryRepository>(MockBehavior.Strict);
 }