public async Task DeleteUserAsyncShouldThrowException() { var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var testUserRepository = new EfDeletableEntityRepository <ApplicationUser>(context); var testUsers = TestDataHelpers.GetTestUsers(); foreach (var tester in testUsers) { await testUserRepository.AddAsync(tester); await testUserRepository.SaveChangesAsync(); } var testAccountRepository = new Mock <IDeletableEntityRepository <Account> >(); var testAccountManagementService = new AccountManagementService(this.userManager.Object, testUserRepository, testAccountRepository.Object, this.positionService.Object, this.feePaymentsRepository.Object); Assert.ThrowsAsync <NullReferenceException>(async() => await testAccountManagementService.DeleteUserAsync("-1", 1)); }
public async Task DeleteUserAsyncShouldDeleteUserAccountCorrectly() { var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var testAccountRepository = new EfDeletableEntityRepository <Account>(context); var testAccounts = TestDataHelpers.GetTestData(); foreach (var acc in testAccounts) { await testAccountRepository.AddAsync(acc); await testAccountRepository.SaveChangesAsync(); } var testUserRepository = new Mock <IDeletableEntityRepository <ApplicationUser> >(); testUserRepository .Setup(a => a.GetByIdWithDeletedAsync(It.IsAny <string>())) .ReturnsAsync(new ApplicationUser() { Id = "1", IsDeleted = false, }); testUserRepository .Setup(a => a.Delete(It.IsAny <ApplicationUser>())); testUserRepository .Setup(a => a.SaveChangesAsync()); var testAccountManagementService = new AccountManagementService(this.userManager.Object, testUserRepository.Object, testAccountRepository, this.positionService.Object, this.feePaymentsRepository.Object); await testAccountManagementService.DeleteUserAsync("1", 1); var account = testAccountRepository.AllWithDeleted().FirstOrDefault(a => a.Id == 1); Assert.IsTrue(account.IsDeleted); }