public async Task <IActionResult> Delete(Guid commissionSplitRulePolicyId) { var scope = AuthenticationService.GetScope(User); var result = await CommissionSplitRulePolicyService.DeleteCommissionSplitRulePolicy(scope, commissionSplitRulePolicyId); if (!result.Success) { return(BadRequest(result.ValidationFailures)); } return(Ok(result)); }
public async Task DeleteCommissionSplitRulePolicy() { var options = TestHelper.GetDbContext("DeleteCommissionSplitRulePolicy"); var user1 = TestHelper.InsertUserDetailed(options); var client1 = TestHelper.InsertClient(options, user1.Organisation); var user2 = TestHelper.InsertUserDetailed(options); var policy1 = new PolicyEntity { Id = Guid.NewGuid(), CompanyId = Guid.NewGuid(), ClientId = client1.Client.Id, UserId = user1.User.Id, Number = "123465", }; var policy2 = new PolicyEntity { Id = Guid.NewGuid(), CompanyId = Guid.NewGuid(), ClientId = client1.Client.Id, UserId = user1.User.Id, Number = "123465", }; var csrp1 = new CommissionSplitRulePolicyEntity { Id = Guid.NewGuid(), PolicyId = policy1.Id, CommissionSplitRuleId = Guid.NewGuid() }; var csrp2 = new CommissionSplitRulePolicyEntity { Id = Guid.NewGuid(), PolicyId = policy1.Id, CommissionSplitRuleId = Guid.NewGuid() }; using (var context = new DataContext(options)) { context.Policy.Add(policy1); context.Policy.Add(policy2); context.CommissionSplitRulePolicy.Add(csrp1); context.CommissionSplitRulePolicy.Add(csrp2); context.SaveChanges(); } using (var context = new DataContext(options)) { var auditService = new AuditServiceMock(); var service = new CommissionSplitRulePolicyService(context, null, auditService); //When var scope = TestHelper.GetScopeOptions(user1); var result = await service.DeleteCommissionSplitRulePolicy(scope, csrp2.Id); //Then Assert.True(result.Success); var actual = await context.CommissionSplitRulePolicy.FindAsync(csrp2.Id); Assert.Null(actual); //Out of scope scope = TestHelper.GetScopeOptions(user2, Scope.User); result = await service.DeleteCommissionSplitRulePolicy(scope, csrp1.Id); Assert.False(result.Success); actual = await context.CommissionSplitRulePolicy.FindAsync(csrp1.Id); Assert.NotNull(actual); } }