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 Delete_When_Not_Authorized() { var assertDatabase = await RfidDatabaseAssert.CreateAsync(); var userRM = Examples.Administrator(); var tagRM = Examples.Tag(); await RfidHttpClient.RegisterUserAsync(userRM); using (var authHttpResponse = await RfidHttpClient.GenerateAuthTokenAsync(userRM)) { var authToken = await AuthTokenHelper.FromHttpResponseMessageAsync(authHttpResponse); var token = await authToken.GetTokenAsync(); using (var registerTagHttpResponse = await RfidHttpClient.RegisterTagAsync(tagRM, token)) { RfidAssert.AssertHttpResponse(registerTagHttpResponse, System.Net.HttpStatusCode.OK); using (var activateHttpResponse = await RfidHttpClient.DeleteTagAsync(tagRM.Number, null)) { RfidAssert.AssertHttpResponse(activateHttpResponse, System.Net.HttpStatusCode.Unauthorized); } } } var tagId = await RfidDatabase.GetTagIdByNumberAsync(tagRM.Number); await assertDatabase.AssertCntAsync(userRM, tagRM); await assertDatabase.AssertStateAsync("[access_control].[Tags]", tagId, new { Id = tagId, IsActive = true, IsDeleted = false }); }
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 Change_Access_Level_When_Not_Authorized() { var assertDatabase = await RfidDatabaseAssert.CreateAsync(); var userRM = Examples.Administrator(); var tagRM = Examples.Tag(); var tagId = 0; await RfidHttpClient.RegisterUserAsync(userRM); using (var authHttpResponse = await RfidHttpClient.GenerateAuthTokenAsync(userRM)) { var authToken = await AuthTokenHelper.FromHttpResponseMessageAsync(authHttpResponse); var token = await authToken.GetTokenAsync(); using (var registerTagHttpResponse = await RfidHttpClient.RegisterTagAsync(tagRM, token)) { RfidAssert.AssertHttpResponse(registerTagHttpResponse, System.Net.HttpStatusCode.OK); tagId = await RfidDatabase.GetTagIdByNumberAsync(tagRM.Number); using (var activateHttpResponse = await RfidHttpClient.ChangeTagAccessLevelAsync(new ChangeTagAccessLevelRequestModel { Id = tagId, AccessLevel = AccessLevel.High }, null)) { RfidAssert.AssertHttpResponse(activateHttpResponse, System.Net.HttpStatusCode.Unauthorized); } } } await assertDatabase.AssertCntAsync(userRM, tagRM); await assertDatabase.AssertStateAsync("[access_control].[Tags]", tagId, new { Id = tagId, IsActive = true, LevelId = (int)AccessLevel.Mid }); }
public async Task Register_When_User_Already_Exists() { var assertDatabase = await RfidDatabaseAssert.CreateAsync(); var userRM = Examples.Administrator(); var ftagRM = Examples.Tag(); var stagRM = Examples.Tag(Guid.NewGuid(), "test"); await RfidHttpClient.RegisterUserAsync(userRM); using (var httpResponse = await RfidHttpClient.GenerateAuthTokenAsync(userRM)) { var authToken = await AuthTokenHelper.FromHttpResponseMessageAsync(httpResponse); var token = await authToken.GetTokenAsync(); using (var fhttpResponse = await RfidHttpClient.RegisterTagAsync(ftagRM, token)) using (var shttpResponse = await RfidHttpClient.RegisterTagAsync(stagRM, token)) { RfidAssert.AssertHttpResponse(fhttpResponse, System.Net.HttpStatusCode.OK); RfidAssert.AssertHttpResponse(shttpResponse, System.Net.HttpStatusCode.OK); } } await assertDatabase.AssertCntAsync(userRM, ftagRM, stagRM); }
public async Task Register_When_UnAuthorized() { var assertDatabase = await RfidDatabaseAssert.CreateAsync(); var tagRM = Examples.Tag(); using (var httpResponse = await RfidHttpClient.RegisterTagAsync(tagRM, null)) { RfidAssert.AssertHttpResponse(httpResponse, System.Net.HttpStatusCode.Unauthorized); } await assertDatabase.AssertCntAsync(); }
public async Task Activate_When_One_Active_And_One_Not_Active_Tag() { var assertDatabase = await RfidDatabaseAssert.CreateAsync(); var userRM = Examples.Administrator(); var ftagRM = Examples.Tag(); var stagRM = Examples.Tag(Guid.NewGuid(), "test"); await RfidHttpClient.RegisterUserAsync(userRM); using (var authHttpResponse = await RfidHttpClient.GenerateAuthTokenAsync(userRM)) { var authToken = await AuthTokenHelper.FromHttpResponseMessageAsync(authHttpResponse); var token = await authToken.GetTokenAsync(); using (var fregisterTagHttpResponse = await RfidHttpClient.RegisterTagAsync(ftagRM, token)) using (var sregisterTagHttpResponse = await RfidHttpClient.RegisterTagAsync(stagRM, token)) { RfidAssert.AssertHttpResponse(fregisterTagHttpResponse, System.Net.HttpStatusCode.OK); RfidAssert.AssertHttpResponse(sregisterTagHttpResponse, System.Net.HttpStatusCode.OK); await RfidDatabase.DeActivateTagAsync(ftagRM.Number); using (var factivateHttpResponse = await RfidHttpClient.ActivateTagAsync(ftagRM.Number, token)) using (var sactivateHttpResponse = await RfidHttpClient.ActivateTagAsync(stagRM.Number, token)) { RfidAssert.AssertHttpResponse(factivateHttpResponse, System.Net.HttpStatusCode.OK); RfidAssert.AssertHttpResponse(sactivateHttpResponse, System.Net.HttpStatusCode.OK); } } } var ftagId = await RfidDatabase.GetTagIdByNumberAsync(ftagRM.Number); var stagId = await RfidDatabase.GetTagIdByNumberAsync(stagRM.Number); await assertDatabase.AssertCntAsync(userRM, ftagRM, stagRM); await assertDatabase.AssertStateAsync("access_control.Tags", ftagId, new { Id = ftagId, IsActive = true }); await assertDatabase.AssertStateAsync("access_control.Tags", stagId, new { Id = stagId, IsActive = true }); }
public async Task Change_Access_Level_When_Tag_Already_Has_The_Same_Access_level() { var assertDatabase = await RfidDatabaseAssert.CreateAsync(); var userRM = Examples.Administrator(); var tagRM = Examples.Tag(); var tagId = 0; await RfidHttpClient.RegisterUserAsync(userRM); using (var authHttpResponse = await RfidHttpClient.GenerateAuthTokenAsync(userRM)) { var authToken = await AuthTokenHelper.FromHttpResponseMessageAsync(authHttpResponse); var token = await authToken.GetTokenAsync(); using (var registerTagHttpResponse = await RfidHttpClient.RegisterTagAsync(tagRM, token)) { RfidAssert.AssertHttpResponse(registerTagHttpResponse, System.Net.HttpStatusCode.OK); tagId = await RfidDatabase.GetTagIdByNumberAsync(tagRM.Number); using (var factivateHttpResponse = await RfidHttpClient.ChangeTagAccessLevelAsync(new ChangeTagAccessLevelRequestModel { Id = tagId, AccessLevel = AccessLevel.Low }, token)) using (var sactivateHttpResponse = await RfidHttpClient.ChangeTagAccessLevelAsync(new ChangeTagAccessLevelRequestModel { Id = tagId, AccessLevel = AccessLevel.Low }, token)) { RfidAssert.AssertHttpResponse(factivateHttpResponse, System.Net.HttpStatusCode.OK); RfidAssert.AssertHttpResponse(sactivateHttpResponse, System.Net.HttpStatusCode.OK); } } } tagId = await RfidDatabase.GetTagIdByNumberAsync(tagRM.Number); await assertDatabase.AssertCntAsync(userRM, tagRM); await assertDatabase.AssertStateAsync("access_control.Tags", tagId, new { Id = tagId, IsActive = true, LevelId = (int)AccessLevel.Low }); }
public async Task Update_When_User_Changed() { var assertDatabase = await RfidDatabaseAssert.CreateAsync(); var userRM = Examples.Administrator(); var tagRM = Examples.Tag(); var tagId = 0; var tagNewUsername = "******"; var tagUpdateRM = (UpdateTagRequestModel)null; await RfidHttpClient.RegisterUserAsync(userRM); using (var httpResponse = await RfidHttpClient.GenerateAuthTokenAsync(userRM)) { var authToken = await AuthTokenHelper.FromHttpResponseMessageAsync(httpResponse); var token = await authToken.GetTokenAsync(); using (var tagHttpResponse = await RfidHttpClient.RegisterTagAsync(tagRM, token)) { RfidAssert.AssertHttpResponse(tagHttpResponse, System.Net.HttpStatusCode.OK); } tagId = await RfidDatabase.GetTagIdByNumberAsync(tagRM.Number); tagUpdateRM = Examples.TagUpdate(tagId, tagNewUsername); using (var tagHttpResponse = await RfidHttpClient.UpdateTagAsync(tagUpdateRM, token)) { RfidAssert.AssertHttpResponse(tagHttpResponse, System.Net.HttpStatusCode.OK); } } await assertDatabase.AssertCntAsync(userRM, tagRM, tagUpdateRM); var expectedUserId = await RfidDatabase.GetTagUserIdByUserNameAsync(tagNewUsername); await assertDatabase.AssertStateAsync("access_control.Tags", tagId, new { UserId = expectedUserId }); }
public async Task Register_When_Tag_Already_Exists() { var assertDatabase = await RfidDatabaseAssert.CreateAsync(); var userRM = Examples.Administrator(); var tagRM = Examples.Tag(); await RfidHttpClient.RegisterUserAsync(userRM); using (var httpResponse = await RfidHttpClient.GenerateAuthTokenAsync(userRM)) { var authToken = await AuthTokenHelper.FromHttpResponseMessageAsync(httpResponse); var token = await authToken.GetTokenAsync(); using (var fhttpResponse = await RfidHttpClient.RegisterTagAsync(tagRM, token)) using (var shttpResponse = await RfidHttpClient.RegisterTagAsync(tagRM, token)) { RfidAssert.AssertHttpResponse(fhttpResponse, System.Net.HttpStatusCode.OK); await RfidAssert.AssertHttpResponseAsync(shttpResponse, System.Net.HttpStatusCode.BadRequest, (false, CommandStatus.Dublicate)); } } }
public async Task Register_When_New_Tag() { var assertDatabase = await RfidDatabaseAssert.CreateAsync(); var userRM = Examples.Administrator(); var tagRM = Examples.Tag(); await RfidHttpClient.RegisterUserAsync(userRM); using (var httpResponse = await RfidHttpClient.GenerateAuthTokenAsync(userRM)) { var authToken = await AuthTokenHelper.FromHttpResponseMessageAsync(httpResponse); var token = await authToken.GetTokenAsync(); using (var tagHttpResponse = await RfidHttpClient.RegisterTagAsync(tagRM, token)) { RfidAssert.AssertHttpResponse(tagHttpResponse, System.Net.HttpStatusCode.OK); } } await assertDatabase.AssertCntAsync(userRM, tagRM); }
public async Task Register_When_Invalid(String number, int accessLevel, String userName) { var assertDatabase = await RfidDatabaseAssert.CreateAsync(); var userRM = Examples.Administrator(); var tagRM = Examples.Tag(number, accessLevel, userName); await RfidHttpClient.RegisterUserAsync(userRM); using (var httpResponse = await RfidHttpClient.GenerateAuthTokenAsync(userRM)) { var authToken = await AuthTokenHelper.FromHttpResponseMessageAsync(httpResponse); var token = await authToken.GetTokenAsync(); using (var tagHttpResponse = await RfidHttpClient.RegisterTagAsync(tagRM, token)) { RfidAssert.AssertHttpResponse(tagHttpResponse, System.Net.HttpStatusCode.BadRequest); } } await assertDatabase.AssertCntAsync(userRM); }