コード例 #1
0
        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 });
        }
コード例 #2
0
        public async Task ChangeAccessLevel_When_Several()
        {
            var assertDatabase = await RfidDatabaseAssert.CreateAsync();

            var userRM         = Examples.Administrator();
            var faccessPointRM = Examples.AccessPoint("test1", "test1", AccessLevel.Low);
            var saccessPointRM = Examples.AccessPoint("test2", "test2", AccessLevel.High);

            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);

                        using (var factivateAccessPointResponse = await RfidHttpClient.ChangeAccessPointAccessLevelAsync(faccessPointRM.SerialNumber, AccessLevel.Mid, token))
                            using (var sactivateAccessPointResponse = await RfidHttpClient.ChangeAccessPointAccessLevelAsync(saccessPointRM.SerialNumber, AccessLevel.Low, token))
                            {
                                RfidAssert.AssertHttpResponse(factivateAccessPointResponse, System.Net.HttpStatusCode.OK);
                                RfidAssert.AssertHttpResponse(sactivateAccessPointResponse, System.Net.HttpStatusCode.OK);
                            }
                    }
            }

            await assertDatabase.AssertCntAsync(userRM, faccessPointRM, saccessPointRM);

            await assertDatabase.AssertStateAsync("access_control.AccessPoints", faccessPointId, new { Id = faccessPointId, LevelId = (int)AccessLevel.Mid });

            await assertDatabase.AssertStateAsync("access_control.AccessPoints", saccessPointId, new { Id = saccessPointId, LevelId = (int)AccessLevel.Low });
        }