public async Task Get_EnabledFeatures() { //Arrange const string enabledFeatureName = "TestFeature"; const string disabledFeatureName = "TestFeature2"; var enabledFeature = new Feature { Name = enabledFeatureName, Enabled = true }; var disabledFeature = new Feature { Name = disabledFeatureName, Enabled = false }; var features = new List <Feature> { enabledFeature, disabledFeature }; _efContextMock.MockAsyncQueryable(features.AsQueryable(), c => c.Feature); //Act var result = await _featureService.Get(); //Assert result.Should().NotBeNull(); result.Should().HaveCount(1); result.First().Should().NotBeNull(); result.First().Name.Should().NotBeNull(); result.First().Name.Should().Be(enabledFeatureName); result.First().Enabled.Should().BeTrue(); }
// GET: Features/Edit/5 public ActionResult CreateEdit(int?id) { Feature feat = featSrv.Get(f => f.FeatureId == id); if (feat != null) { return(PartialView("_PartialCreateEdit", feat)); } else { return(PartialView("_PartialCreateEdit", new Feature())); } }
protected override bool Evaluate(IIdentity identity, string route, string method) { var path = $"{route}/{method}"; var identityId = identity?.Name; // Check feature premission User user = UserService.Get(i => i.IdentityId == identityId); bool isAdmin = user?.Role.IsAdmin ?? false; var permissions = user?.Role?.Permissions ?? new Feature[0]; // Admin has full access bool allowAccess = isAdmin || permissions.Any(i => i.Path.ToLower() == path.ToLower()); Security.Feature = FeatureService.Get(path); Security.User = user; return(allowAccess); }