public void GetServiceProfile_Night_ReturnsServiceProfileWithCorrectTimes() { // Arrange int serviceProfileId = InsertServiceProfile("Night"); InsertTimeSlots(serviceProfileId, 17, 00, 24, 00); InsertTimeSlots(serviceProfileId, 00, 00, 05, 00); InsertAccessControlListValue("test", 1, 1, serviceProfileId); var repo = new AccessControlRepository(_testDbConnectionString); // Act var result = repo.GetServiceProfile("test", 1, 1); // Assert Assert.AreEqual(7, result.Count(t => t.StartHour == 17)); Assert.AreEqual(7, result.Count(t => t.StartHour == 00)); Assert.IsTrue(result.All(t => t.StartMinutes == 0)); Assert.AreEqual(7, result.Count(t => t.EndHour == 24)); Assert.AreEqual(7, result.Count(t => t.EndHour == 05)); Assert.IsTrue(result.All(t => t.EndMinutes == 0)); Assert.AreEqual(2, result.Count(t => t.DayOfWeek == 0)); Assert.AreEqual(2, result.Count(t => t.DayOfWeek == 1)); Assert.AreEqual(2, result.Count(t => t.DayOfWeek == 2)); Assert.AreEqual(2, result.Count(t => t.DayOfWeek == 3)); Assert.AreEqual(2, result.Count(t => t.DayOfWeek == 4)); Assert.AreEqual(2, result.Count(t => t.DayOfWeek == 5)); Assert.AreEqual(2, result.Count(t => t.DayOfWeek == 6)); }
public void HasAccess_NotFoundEmpty_ReturnsFalse() { // Arrange var repo = new AccessControlRepository(_testDbConnectionString); // Act var result = repo.HasAccess("test", 1, 1); // Assert Assert.AreEqual(false, result); }
public void HasAccess_WithoutPool_Found_ReturnsTrue() { // Arrange int serviceProfileId = InsertServiceProfile("7x24"); InsertAccessControlListValue("test", 1, 1, serviceProfileId); var repo = new AccessControlRepository(_testDbConnectionString); // Act var result = repo.HasAccess("test", 1, 1); // Assert Assert.AreEqual(true, result); }
public void CanExit_NotFoundWrongRecord_Location_ReturnsFalse() { // Arrange int serviceProfileId = InsertServiceProfile("7x24"); InsertAccessControlListValue("test", 1, 1, serviceProfileId); var repo = new AccessControlRepository(_testDbConnectionString); // Act var result = repo.CanExit("test", 1, 2); // Assert Assert.AreEqual(false, result); }
public void HasAccess_NotFoundWrongRecord_Name_ReturnsFalse() { // Arrange int serviceProfileId = InsertServiceProfile("7x24"); InsertAccessControlListValue("test", 1, 1, serviceProfileId); var repo = new AccessControlRepository(_testDbConnectionString); // Act var result = repo.HasAccess("othername", 1, 1); // Assert Assert.AreEqual(false, result); }
public void HasAccess_WithPoolOverMaxAllowed_ReturnsFalse() { // Arrange int serviceProfileId = InsertServiceProfile("7x24"); int poolId = InsertPool(1, 2, 1); InsertAccessControlListValue("test", 1, 1, serviceProfileId, poolId); var repo = new AccessControlRepository(_testDbConnectionString); // Act var result = repo.HasAccess("test", 1, 1); // Assert Assert.AreEqual(false, result); Assert.AreEqual(2, GetPoolOccupied("test", 1, 1)); }
public void CanExit_WithPool_Occupied0() { // Arrange int serviceProfileId = InsertServiceProfile("7x24"); int poolId = InsertPool(1, 1, 1); InsertAccessControlListValue("test", 1, 1, serviceProfileId, poolId); var repo = new AccessControlRepository(_testDbConnectionString); // Act var result = repo.CanExit("test", 1, 1); // Assert Assert.AreEqual(true, result); Assert.AreEqual(0, GetPoolOccupied("test", 1, 1)); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. //public void Configure(IApplicationBuilder app, IHostingEnvironment env) //{ // if (env.IsDevelopment()) // { // app.UseDeveloperExceptionPage(); // } // app.UseMvc(); //} private void ConfigurePolicies(IServiceCollection services) { var appSettings = new Framework.Builders.AppSettings(); var repository = new AccessControlRepository(appSettings, new Common.Factories.AshleyHsDbConnectionFactory(appSettings)); AccessControlService accessControlService = new AccessControlService(repository); List <Common.Models.SecureResource> resources = accessControlService.GetResourceListAsync().Result as List <Common.Models.SecureResource>; foreach (var resource in resources) { foreach (var accessControl in resource.AccessControl) //not efficient but the numbers should be small { var roles = accessControl.Value.Select(role => role.Name).ToList(); services.AddAuthorization(options => options.AddPolicy($"{resource.Name.ToLower()}_{accessControl.Key.ToLower()}_roles", policy => { policy.AuthenticationSchemes.Add(JwtBearerDefaults.AuthenticationScheme); policy.Requirements.Add(new RoleListRequirement(roles)); } )); } } }
public AccessController() { AccessControlRepository = new AccessControlRepository("Server=tcp:iotmadrid.database.windows.net,1433;Initial Catalog=IOTMadrid;Persist Security Info=False;User ID=iotmadrid;Password=IotH4ckF3est!;Connection Timeout=30;"); }