Ejemplo n.º 1
0
        public async Task <IActionResult> Get(Guid commissionSplitRuleId)
        {
            var scope = AuthenticationService.GetScope(User);

            var model = await CommissionSplitService.GetCommissionSplitRule(scope, commissionSplitRuleId);

            if (model == null)
            {
                return(NotFound());
            }

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

            var user1 = TestHelper.InsertUserDetailed(options);
            var user2 = TestHelper.InsertUserDetailed(options, user1.Organisation);
            var user3 = TestHelper.InsertUserDetailed(options);

            var csr1 = new CommissionSplitRuleEntity
            {
                Id        = Guid.NewGuid(),
                UserId    = user1.User.Id,
                Name      = "Com Split Rule 1",
                IsDefault = true,
                Split     = new List <CommissionSplit>()
                {
                    new CommissionSplit()
                    {
                        UserId     = user1.User.Id,
                        Percentage = 100
                    }
                }
            };

            var csr2 = new CommissionSplitRuleEntity
            {
                Id        = Guid.NewGuid(),
                UserId    = user2.User.Id,
                Name      = "Com Split Rule 2",
                IsDefault = true,
                Split     = new List <CommissionSplit>()
                {
                    new CommissionSplit()
                    {
                        UserId     = user2.User.Id,
                        Percentage = 100
                    }
                }
            };

            var csr3 = new CommissionSplitRuleEntity
            {
                Id        = Guid.NewGuid(),
                UserId    = user3.User.Id,
                Name      = "Com Split Rule 3",
                IsDefault = true,
                Split     = new List <CommissionSplit>()
                {
                    new CommissionSplit()
                    {
                        UserId     = user3.User.Id,
                        Percentage = 100
                    }
                }
            };

            using (var context = new DataContext(options))
            {
                context.CommissionSplitRule.Add(csr2);
                context.CommissionSplitRule.Add(csr1);
                context.CommissionSplitRule.Add(csr3);

                context.SaveChanges();
            }

            using (var context = new DataContext(options))
            {
                var auditService = new AuditServiceMock();
                var service      = new CommissionSplitService(context, auditService);

                //When
                var scope  = TestHelper.GetScopeOptions(user1);
                var actual = await service.GetCommissionSplitRule(scope, csr1.Id);

                //Then
                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);

                //Check scope
                actual = await service.GetCommissionSplitRule(scope, csr3.Id);

                Assert.Null(actual);
            }
        }