Beispiel #1
0
        public async Task <IActionResult> Insert([FromBody] CommissionStatementEdit commissionStatement)
        {
            var scope = AuthenticationService.GetScope(User);

            var result = await CommissionStatementService.InsertCommissionStatement(scope, commissionStatement);

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

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

            var user1 = TestHelper.InsertUserDetailed(options);

            //Given
            var cs1 = new CommissionStatementEdit
            {
                CompanyId          = Guid.NewGuid(),
                AmountIncludingVAT = 100,
                VAT       = 10,
                Date      = DateTime.Now,
                Processed = true,
                Notes     = "note 1"
            };

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

                //When
                var scopeOptions = TestHelper.GetScopeOptions(user1);
                var result       = await service.InsertCommissionStatement(scopeOptions, cs1);

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

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

                Assert.Equal(cs1.CompanyId, actual.CompanyId);
                Assert.Equal(cs1.Date.Value.Date, actual.Date);
                Assert.Equal(cs1.AmountIncludingVAT, actual.AmountIncludingVAT);
                Assert.Equal(cs1.VAT, actual.VAT);
                Assert.Equal(user1.Organisation.Id, user1.Organisation.Id);
                Assert.Equal(cs1.Processed, actual.Processed);
                Assert.Equal(cs1.Notes, actual.Notes);
            }
        }