示例#1
0
        public async Task AddAuditWithUser()
        {
            await SetupNewUser();

            using (var db = _dbHelper.GetDbContext())
            {
                _httpContextAccessor.SetUser(db.Users.First());
                await db.SaveChangesAsync();

                SetupAuditing();
            }

            using (var db = _dbHelper.GetDbContext())
            {
                db.AuditLogs.ShouldBeEmpty();
                var vessel = new Privilege()
                {
                    Code     = "A",
                    DescFre  = "A",
                    DescEng  = "A",
                    IsActive = true
                };
                db.Privileges.Add(vessel);
                db.SaveChanges();
            }

            using (var db = _dbHelper.GetDbContext())
            {
                db.AuditLogs.ShouldNotBeEmpty();
                var hasUser = await db.AuditLogs.Where(e => e.AuditUser != null).AnyAsync();

                _output.WriteLine("has user: " + hasUser);
                hasUser.ShouldBeTrue();
            }
        }
示例#2
0
        public async Task EmptyWhenUserHasNoId()
        {
            _httpContextAccessor.SetUser(new List <Claim>());
            var result = await _handler.HandleAsync();

            result.ShouldBeEmpty();
        }
示例#3
0
        public async Task UserNull()
        {
            _httpContextAccessor.SetUser(new List <Claim>()
            {
                new Claim(ClaimTypes.NameIdentifier, Guid.NewGuid().ToString())
            });

            var result = await _handler.HandleAsync(new CheckUserHasPrivilegeQuery()
            {
                Codes = new[] { DataModel.Lookup.Auth.Privileges.First().Code }
            });

            result.ShouldEqual(false);
        }