public async Task Delete_When_Does_Not_Exists() { var assertDatabase = await RfidDatabaseAssert.CreateAsync(); var userRM = Examples.Administrator(); var accessPointRM = Examples.AccessPoint(); await RfidHttpClient.RegisterUserAsync(userRM); using (var authTokenResponseMessage = await RfidHttpClient.GenerateAuthTokenAsync(userRM)) { var authToken = await AuthTokenHelper.FromHttpResponseMessageAsync(authTokenResponseMessage); var token = await authToken.GetTokenAsync(); using (var httpResponse = await RfidHttpClient.RegisterAccessPointAsync(accessPointRM, token)) { RfidAssert.AssertHttpResponse(httpResponse, System.Net.HttpStatusCode.OK); } using (var httpResponse = await RfidHttpClient.DeleteAccessPointAsync("unknown", token)) { RfidAssert.AssertHttpResponse(httpResponse, System.Net.HttpStatusCode.NotFound); } } await assertDatabase.AssertCntAsync(userRM, accessPointRM); }
public async Task Register_When_Access_Point_Already_Exists() { var assertDatabase = await RfidDatabaseAssert.CreateAsync(); var userRM = Examples.Administrator(); var accessPointRM = Examples.AccessPoint("test1"); await RfidHttpClient.RegisterUserAsync(userRM); using (var authTokenResponseMessage = await RfidHttpClient.GenerateAuthTokenAsync(userRM)) { var authToken = await AuthTokenHelper.FromHttpResponseMessageAsync(authTokenResponseMessage); var token = await authToken.GetTokenAsync(); using (var fhttpResponse = await RfidHttpClient.RegisterAccessPointAsync(accessPointRM, token)) using (var shttpResponse = await RfidHttpClient.RegisterAccessPointAsync(accessPointRM, token)) { RfidAssert.AssertHttpResponse(fhttpResponse, System.Net.HttpStatusCode.OK); await RfidAssert.AssertHttpResponseAsync(shttpResponse, System.Net.HttpStatusCode.BadRequest, (false, CommandStatus.Dublicate)); } } await assertDatabase.AssertCntAsync(userRM, accessPointRM); }
public async Task ChangeAccessLevel_When_Not_Authorized() { var assertDatabase = await RfidDatabaseAssert.CreateAsync(); var userRM = Examples.Administrator(); var accessPointRM = Examples.AccessPoint("test", "test", AccessLevel.Low); var accessPointId = 0; await RfidHttpClient.RegisterUserAsync(userRM); using (var authTokenResponse = await RfidHttpClient.GenerateAuthTokenAsync(userRM)) { var authToken = await AuthTokenHelper.FromHttpResponseMessageAsync(authTokenResponse); var token = await authToken.GetTokenAsync(); using (var registerAccessPointResponse = await RfidHttpClient.RegisterAccessPointAsync(accessPointRM, token)) { accessPointId = await RfidDatabase.GetAccessPointIdBySerialNumberAsync(accessPointRM.SerialNumber); using (var activateAccessPointResponse = await RfidHttpClient.ChangeAccessPointAccessLevelAsync(accessPointRM.SerialNumber, AccessLevel.High, "unknown")) { RfidAssert.AssertHttpResponse(activateAccessPointResponse, System.Net.HttpStatusCode.Unauthorized); } } } await assertDatabase.AssertCntAsync(userRM, accessPointRM); await assertDatabase.AssertStateAsync("access_control.AccessPoints", accessPointId, new { Id = accessPointId, LevelId = (int)AccessLevel.Low }); }
public async Task Get_All_Active_When_When_Several_In_Database() { var assertDatabase = await RfidDatabaseAssert.CreateAsync(); var userRM = Examples.Administrator(); var accessPointRM = Examples.AccessPoint(); await RfidHttpClient.RegisterUserAsync(userRM); using (var authTokenResponseMessage = await RfidHttpClient.GenerateAuthTokenAsync(userRM)) { var authToken = await AuthTokenHelper.FromHttpResponseMessageAsync(authTokenResponseMessage); var token = await authToken.GetTokenAsync(); using (await RfidHttpClient.RegisterAccessPointAsync(Examples.AccessPoint("1"), token)) using (await RfidHttpClient.RegisterAccessPointAsync(Examples.AccessPoint("2"), token)) using (await RfidHttpClient.RegisterAccessPointAsync(Examples.AccessPoint("3"), token)) using (await RfidHttpClient.RegisterAccessPointAsync(Examples.AccessPoint("4"), token)) { var actual = await RfidHttpClient.GetAllActiveAccessPointsAsync(token); Assert.Equal(expected: 4, actual: actual.Count); } } }
public async Task Register_When_UnKnown_Access_Point() { var assertDatabase = await RfidDatabaseAssert.CreateAsync(); var userRM = Examples.Administrator(); var accessPointRM = Examples.AccessPoint(); await RfidHttpClient.RegisterUserAsync(userRM); using (var authTokenResponseMessage = await RfidHttpClient.GenerateAuthTokenAsync(userRM)) { var authToken = await AuthTokenHelper.FromHttpResponseMessageAsync(authTokenResponseMessage); var token = await authToken.GetTokenAsync(); using (var httpResponse = await RfidHttpClient.CheckAccessAsync("unknown", accessPointRM.SerialNumber)) { RfidAssert.AssertHttpResponse(httpResponse, System.Net.HttpStatusCode.NotFound); } using (var httpResponse = await RfidHttpClient.RegisterAccessPointAsync(accessPointRM, token)) { RfidAssert.AssertHttpResponse(httpResponse, System.Net.HttpStatusCode.OK); } } await assertDatabase.AssertCntAsync(userRM, accessPointRM, new UnKnownTagMock { Number = "unknown" }); }
public async Task DeActivate_When_Does_Not_Exists() { var assertDatabase = await RfidDatabaseAssert.CreateAsync(); var userRM = Examples.Administrator(); var accessPointRM = Examples.AccessPoint(); var accessPointId = 0; await RfidHttpClient.RegisterUserAsync(userRM); using (var authTokenResponse = await RfidHttpClient.GenerateAuthTokenAsync(userRM)) { var authToken = await AuthTokenHelper.FromHttpResponseMessageAsync(authTokenResponse); var token = await authToken.GetTokenAsync(); using (var registerAccessPointResponse = await RfidHttpClient.RegisterAccessPointAsync(accessPointRM, token)) { accessPointId = await RfidDatabase.GetAccessPointIdBySerialNumberAsync(accessPointRM.SerialNumber); using (var activateAccessPointResponse = await RfidHttpClient.DeActivateAccessPointAsync("unknown", token)) { RfidAssert.AssertHttpResponse(activateAccessPointResponse, System.Net.HttpStatusCode.NotFound); } } } await assertDatabase.AssertCntAsync(userRM, accessPointRM); await assertDatabase.AssertStateAsync("access_control.AccessPoints", accessPointId, new { Id = accessPointId, IsActive = true }); }
public async Task Check_Access_Level_Sufficient_3() { var assertDatabase = await RfidDatabaseAssert.CreateAsync(); var userRM = Examples.Administrator(); var tagRM = Examples.Tag("test", (int)AccessLevel.Mid, "test"); var accessPoint = Examples.AccessPoint("test", "test", AccessLevel.Low); await RfidHttpClient.RegisterUserAsync(userRM); using (var tokenResponse = await RfidHttpClient.GenerateAuthTokenAsync(userRM)) { var authToken = await AuthTokenHelper.FromHttpResponseMessageAsync(tokenResponse); var token = await authToken.GetTokenAsync(); using (var registerTagResponse = await RfidHttpClient.RegisterTagAsync(tagRM, token)) using (var registerAccessPointResponse = await RfidHttpClient.RegisterAccessPointAsync(accessPoint, token)) using (var checkAccessResponse = await RfidHttpClient.CheckAccessAsync(tagRM.Number, accessPoint.SerialNumber)) { RfidAssert.AssertHttpResponse(checkAccessResponse, System.Net.HttpStatusCode.OK); } } await assertDatabase.AssertCntAsync(userRM, tagRM, accessPoint); }
public async Task Check_Access_Level_When_Access_Point_Serial_Number_Does_Not_Exists() { var assertDatabase = await RfidDatabaseAssert.CreateAsync(); var userRM = Examples.Administrator(); var tagRM = Examples.Tag("test", (int)AccessLevel.Mid, "test"); var accessPoint = Examples.AccessPoint("test", "test", AccessLevel.Mid); await RfidHttpClient.RegisterUserAsync(userRM); using (var tokenResponse = await RfidHttpClient.GenerateAuthTokenAsync(userRM)) { var authToken = await AuthTokenHelper.FromHttpResponseMessageAsync(tokenResponse); var token = await authToken.GetTokenAsync(); using (var registerTagResponse = await RfidHttpClient.RegisterTagAsync(tagRM, token)) using (var registerAccessPointResponse = await RfidHttpClient.RegisterAccessPointAsync(accessPoint, token)) using (var checkAccessResponse = await RfidHttpClient.CheckAccessAsync(tagRM.Number, "unknown")) { RfidAssert.AssertHttpResponse(checkAccessResponse, System.Net.HttpStatusCode.NotFound); } } await assertDatabase.AssertCntAsync(userRM, tagRM, accessPoint, Examples.UnKnownAccessPoint("unknown")); }
public async Task Update_When_All_Properties_Provided() { var assertDatabase = await RfidDatabaseAssert.CreateAsync(); var userRM = Examples.Administrator(); var accessPointRM = Examples.AccessPoint(); var accessPointId = 0; var updatedDescription = $"{Guid.NewGuid()}"; await RfidHttpClient.RegisterUserAsync(userRM); using (var authTokenResponseMessage = await RfidHttpClient.GenerateAuthTokenAsync(userRM)) { var authToken = await AuthTokenHelper.FromHttpResponseMessageAsync(authTokenResponseMessage); var token = await authToken.GetTokenAsync(); using (var httpResponse = await RfidHttpClient.RegisterAccessPointAsync(accessPointRM, token)) { RfidAssert.AssertHttpResponse(httpResponse, System.Net.HttpStatusCode.OK); } accessPointId = await RfidDatabase.GetAccessPointIdBySerialNumberAsync(accessPointRM.SerialNumber); var updateRm = new UpdateAccessPointRequestModel { Id = accessPointId, AccessLevel = AccessLevel.High, Description = updatedDescription, Direction = AccessPointDirectionType.Exit, }; using (var httpResponse = await RfidHttpClient.UpdateAccessPointAsync(updateRm, token)) { RfidAssert.AssertHttpResponse(httpResponse, System.Net.HttpStatusCode.OK); } } await assertDatabase.AssertCntAsync(userRM, accessPointRM); await assertDatabase.AssertStateAsync("access_control.AccessPoints", accessPointId, new { Id = accessPointId, LevelId = (int)AccessLevel.High, DirectionId = (int)AccessPointDirectionType.Exit, SerialNumber = accessPointRM.SerialNumber, Description = updatedDescription }); }
public async Task Activate_When_Several() { var assertDatabase = await RfidDatabaseAssert.CreateAsync(); var userRM = Examples.Administrator(); var faccessPointRM = Examples.AccessPoint("test1"); var saccessPointRM = Examples.AccessPoint("test2"); var faccessPointId = 0; var saccessPointId = 0; await RfidHttpClient.RegisterUserAsync(userRM); using (var authTokenResponse = await RfidHttpClient.GenerateAuthTokenAsync(userRM)) { var authToken = await AuthTokenHelper.FromHttpResponseMessageAsync(authTokenResponse); var token = await authToken.GetTokenAsync(); using (var fregisterAccessPointResponse = await RfidHttpClient.RegisterAccessPointAsync(faccessPointRM, token)) using (var sregisterAccessPointResponse = await RfidHttpClient.RegisterAccessPointAsync(saccessPointRM, token)) { faccessPointId = await RfidDatabase.GetAccessPointIdBySerialNumberAsync(faccessPointRM.SerialNumber); saccessPointId = await RfidDatabase.GetAccessPointIdBySerialNumberAsync(saccessPointRM.SerialNumber); await RfidDatabase.DeActivateAccessPointAsync(faccessPointId); await RfidDatabase.DeActivateAccessPointAsync(saccessPointId); using (var activateAccessPointResponse = await RfidHttpClient.ActivateAccessPointAsync(faccessPointRM.SerialNumber, token)) { RfidAssert.AssertHttpResponse(activateAccessPointResponse, System.Net.HttpStatusCode.OK); } } } await assertDatabase.AssertCntAsync(userRM, faccessPointRM, saccessPointRM); await assertDatabase.AssertStateAsync("access_control.AccessPoints", faccessPointId, new { Id = faccessPointId, IsActive = true }); await assertDatabase.AssertStateAsync("access_control.AccessPoints", saccessPointId, new { Id = saccessPointId, IsActive = false }); }
public async Task Register_When_Not_Authorized() { var assertDatabase = await RfidDatabaseAssert.CreateAsync(); var userRM = Examples.Administrator(); var accessPointRM = Examples.AccessPoint(); await RfidHttpClient.RegisterUserAsync(userRM); using (var authTokenResponseMessage = await RfidHttpClient.GenerateAuthTokenAsync(userRM)) { using (var httpResponse = await RfidHttpClient.RegisterAccessPointAsync(accessPointRM, "invalid-access-token")) { RfidAssert.AssertHttpResponse(httpResponse, System.Net.HttpStatusCode.Unauthorized); } } await assertDatabase.AssertCntAsync(userRM); }
public async Task Register_When_Invalid_Data(String serialNumber, String description, int accessLevel) { var assertDatabase = await RfidDatabaseAssert.CreateAsync(); var userRM = Examples.Administrator(); var accessPointRM = Examples.AccessPoint(serialNumber, description, (AccessLevel)accessLevel); await RfidHttpClient.RegisterUserAsync(userRM); using (var authTokenResponseMessage = await RfidHttpClient.GenerateAuthTokenAsync(userRM)) { var authToken = await AuthTokenHelper.FromHttpResponseMessageAsync(authTokenResponseMessage); var token = await authToken.GetTokenAsync(); using (var httpResponse = await RfidHttpClient.RegisterAccessPointAsync(accessPointRM, token)) { RfidAssert.AssertHttpResponse(httpResponse, System.Net.HttpStatusCode.BadRequest); } } await assertDatabase.AssertCntAsync(userRM); }