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(); }
public async Task GenerateNextMultiAccountName_WhenCalled_ReturnsCorrectMultiAccountName(int numberOfMultiAccounts, string expectedResult) { var userAccountDataId = Guid.NewGuid(); var multiAccounts = _fakeGenerator.GetUserMultiAccountFakerGenerator().Generate(numberOfMultiAccounts); _userAccountDataRepositoryMock.Setup(x => x.GetAsync(userAccountDataId)) .Returns( Task.FromResult(_fakeGenerator.GetUserAccountDataFakerGenerator() .RuleFor(x => x.Login, "TestUser") .RuleFor(x => x.UserMultiAccounts, multiAccounts) .Generate())); var result = await Act(userAccountDataId); result.Should().Be(expectedResult); }
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(); }