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_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);
        }
Exemple #3
0
        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 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_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 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 });
        }
Exemple #7
0
        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 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_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);
        }
Exemple #10
0
        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 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 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 });
        }
Exemple #14
0
        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 });
        }
Exemple #15
0
        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 });
        }
Exemple #16
0
        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 });
        }
Exemple #17
0
        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);
        }
Exemple #18
0
        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_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);
        }
Exemple #20
0
        public async Task Change_Access_Level_When_Tag_Does_Not_Exists()
        {
            var assertDatabase = await RfidDatabaseAssert.CreateAsync();

            var userRM = Examples.Administrator();

            await RfidHttpClient.RegisterUserAsync(userRM);

            using (var authHttpResponse = await RfidHttpClient.GenerateAuthTokenAsync(userRM))
            {
                var authToken = await AuthTokenHelper.FromHttpResponseMessageAsync(authHttpResponse);

                var token = await authToken.GetTokenAsync();

                using (var activateHttpResponse = await RfidHttpClient.ChangeTagAccessLevelAsync(new ChangeTagAccessLevelRequestModel {
                    Id = 0, AccessLevel = AccessLevel.High
                }, token))
                {
                    RfidAssert.AssertHttpResponse(activateHttpResponse, System.Net.HttpStatusCode.NotFound);
                }
            }

            await assertDatabase.AssertCntAsync(userRM);
        }