public void MustBeAdmin_Admin_Succeeds(string role) { var ctx = Creator.GetContext(role: role); _context.Setup(c => c.HttpContext).Returns(ctx); var validator = new DummyValidatorBase(_context.Object, _logger.Object); validator.MustBeAdmin(); var valres = validator.Validate(_context.Object); valres.Errors.Should().BeEmpty(); }
public void MustBeAdmin_NonAdmin_ReturnsError(string role) { var ctx = Creator.GetContext(role: role); _context.Setup(c => c.HttpContext).Returns(ctx); var validator = new DummyValidatorBase(_context.Object, _logger.Object); validator.MustBeAdmin(); var valres = validator.Validate(_context.Object); valres.Errors.Should() .ContainSingle(x => x.ErrorMessage == "Must be admin") .And .HaveCount(1); }