public async Task <IActionResult> Get(Guid commissionId) { var scope = AuthenticationService.GetScope(User); var model = await CommissionService.GetCommission(scope, commissionId); if (model == null) { return(NotFound()); } return(Ok(model)); }
public async Task GetCommission() { var options = TestHelper.GetDbContext("GetCommission"); var user1 = TestHelper.InsertUserDetailed(options); var client1 = TestHelper.InsertClient(options, user1.Organisation); var user2 = TestHelper.InsertUserDetailed(options, user1.Organisation); var user3 = TestHelper.InsertUserDetailed(options); var policy1 = new PolicyEntity { Id = Guid.NewGuid(), CompanyId = Guid.NewGuid(), ClientId = client1.Client.Id, UserId = user1.User.Id }; var commission1 = new CommissionEntity { Id = Guid.NewGuid(), PolicyId = policy1.Id, CommissionTypeId = Guid.NewGuid(), AmountIncludingVAT = 99, VAT = 14, CommissionStatementId = Guid.NewGuid(), SourceData = new Model.Commission.Model.ImportCommission.ImportCommission() { PolicyNumber = "123", AmountIncludingVAT = "50", VAT = "10" } }; using (var context = new DataContext(options)) { context.Policy.Add(policy1); context.Commission.Add(commission1); context.SaveChanges(); } using (var context = new DataContext(options)) { var auditService = new AuditServiceMock(); var service = new CommissionService(context, auditService); //When var scope = TestHelper.GetScopeOptions(user1); var actual = await service.GetCommission(scope, commission1.Id); //Then Assert.Equal(commission1.Id, actual.Id); Assert.Equal(commission1.PolicyId, actual.PolicyId); Assert.Equal(commission1.CommissionTypeId, actual.CommissionTypeId); Assert.Equal(commission1.AmountIncludingVAT, actual.AmountIncludingVAT); Assert.Equal(commission1.VAT, actual.VAT); Assert.Equal(commission1.CommissionStatementId, actual.CommissionStatementId); Assert.Equal(commission1.SourceData, actual.SourceData); //Check scope scope = TestHelper.GetScopeOptions(user2, Scope.User); actual = await service.GetCommission(scope, commission1.Id); Assert.Null(actual); scope = TestHelper.GetScopeOptions(user3, Scope.Organisation); actual = await service.GetCommission(scope, commission1.Id); Assert.Null(actual); } }