예제 #1
0
        public async Task <IActionResult> Index(string sortColumn, string sortDirection, int pageSize = 0, int pageNumber = 0, string filters = null)
        {
            var scope = AuthenticationService.GetScope(User);

            var options = new CommissionErrorQueryOptions(scope, sortColumn, sortDirection, pageSize, pageNumber, filters);

            var results = await CommissionErrorService.GetErrors(options);

            return(Ok(results));
        }
        public async Task GetErrors()
        {
            var options = TestHelper.GetDbContext("GetErrors");

            var user1   = TestHelper.InsertUserDetailed(options);
            var client1 = TestHelper.InsertClient(options, user1.Organisation);
            var company = TestHelper.InsertCompany(options);

            var statement = TestHelper.InsertCommissionStatement(options, user1.Organisation, company.Id);

            var user2 = TestHelper.InsertUserDetailed(options);

            var policyType = TestHelper.InsertPolicyType(options);

            var commissionType = TestHelper.InsertCommissionType(options, policyType.Id);

            var error1 = new CommissionErrorEntity
            {
                Id = Guid.NewGuid(),
                CommissionStatementId = statement.Id,
                PolicyId         = Guid.NewGuid(),
                ClientId         = Guid.NewGuid(),
                CommissionTypeId = commissionType.Id,
                Data             = new ImportCommission()
            };

            var error2 = new CommissionErrorEntity
            {
                Id = Guid.NewGuid(),
                CommissionStatementId = Guid.NewGuid(),
                PolicyId         = Guid.NewGuid(),
                ClientId         = Guid.NewGuid(),
                CommissionTypeId = Guid.NewGuid(),
                Data             = new ImportCommission()
            };

            var error3 = new CommissionErrorEntity
            {
                Id = Guid.NewGuid(),
                CommissionStatementId = statement.Id,
                PolicyId         = Guid.NewGuid(),
                ClientId         = Guid.NewGuid(),
                CommissionTypeId = Guid.NewGuid(),
                Data             = new ImportCommission()
            };

            var error4 = new CommissionErrorEntity
            {
                Id = Guid.NewGuid(),
                CommissionStatementId = Guid.NewGuid(),
                PolicyId         = Guid.NewGuid(),
                ClientId         = Guid.NewGuid(),
                CommissionTypeId = Guid.NewGuid(),
                Data             = new ImportCommission()
            };

            using (var context = new DataContext(options))
            {
                context.CommissionError.Add(error1);
                context.CommissionError.Add(error4);
                context.CommissionError.Add(error2);
                context.CommissionError.Add(error3);
                context.SaveChanges();

                var service = new CommissionErrorService(context, null, null, null, null, null, null);

                //When
                var scope        = TestHelper.GetScopeOptions(user1);
                var queryOptions = new CommissionErrorQueryOptions(scope, "", "", 10, 1, $"commissionStatementId={statement.Id}");
                var results      = await service.GetErrors(queryOptions);

                //Then
                Assert.Equal(2, results.TotalItems);
                Assert.Equal(2, results.Items.Count());

                var actual = results.Items.ToList()[0];
                Assert.Equal(error1.Id, actual.Id);
                Assert.Equal(error1.CommissionStatementId, actual.CommissionStatementId);
                Assert.Equal(error1.PolicyId, actual.PolicyId);
                Assert.Equal(error1.ClientId, actual.ClientId);
                Assert.Equal(error1.CommissionTypeId, actual.CommissionTypeId);
                Assert.Equal(error1.Data, actual.Data);
                Assert.Equal(policyType.Code, actual.PolicyTypeCode);
                Assert.Equal(company.Id, actual.CompanyId);
                Assert.Equal(company.Name, actual.CompanyName);

                actual = results.Items.ToList()[1];
                Assert.Equal(error3.Id, actual.Id);
                Assert.Null(actual.PolicyTypeCode);

                //Scope checked
                scope        = TestHelper.GetScopeOptions(user2);
                queryOptions = new CommissionErrorQueryOptions(scope, "", "", 10, 1);
                results      = await service.GetErrors(queryOptions);

                Assert.Empty(results.Items);
            }
        }