public async Task InsertCommissionSplitRule()
        {
            var options = TestHelper.GetDbContext("InsertCommissionSplitRule");

            var user1 = TestHelper.InsertUserDetailed(options);
            var user2 = TestHelper.InsertUserDetailed(options);

            using (var context = new DataContext(options))
            {
                var csr1 = new CommissionSplitRule
                {
                    UserId    = user1.User.Id,
                    Name      = "Com Split Rule 1",
                    IsDefault = true,
                    Split     = new List <CommissionSplit>()
                    {
                        new CommissionSplit()
                        {
                            UserId     = user1.User.Id,
                            Percentage = 100
                        }
                    }
                };

                var auditService = new AuditServiceMock();
                var service      = new CommissionSplitService(context, auditService);

                //When
                var scope  = TestHelper.GetScopeOptions(user1);
                var result = await service.InsertCommissionSplitRule(scope, csr1);

                //Then
                Assert.True(result.Success);

                var actual = await context.CommissionSplitRule.FindAsync(((CommissionSplitRule)result.Tag).Id);

                Assert.Equal(csr1.Id, actual.Id);
                Assert.Equal(csr1.Name, actual.Name);
                Assert.Equal(csr1.UserId, actual.UserId);
                Assert.Equal(csr1.IsDefault, actual.IsDefault);
                Assert.Equal(csr1.Split, actual.Split);

                //Out of scope
                scope  = TestHelper.GetScopeOptions(user2, Scope.User);
                result = await service.InsertCommissionSplitRule(scope, csr1);

                Assert.False(result.Success);
                Assert.Equal("'User' does not exist.", result.ValidationFailures.First().ErrorMessage);
            }
        }
示例#2
0
        public async Task <IActionResult> Insert([FromBody] CommissionSplitRule commissionSplitRule)
        {
            var scope = AuthenticationService.GetScope(User);

            var result = await CommissionSplitService.InsertCommissionSplitRule(scope, commissionSplitRule);

            if (!result.Success)
            {
                return(BadRequest(result.ValidationFailures));
            }

            return(Ok(result));
        }