Пример #1
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);
        }
Пример #2
0
        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);
        }
Пример #3
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 Register_When_Several_Access_Points()
        {
            var assertDatabase = await RfidDatabaseAssert.CreateAsync();

            var userRM         = Examples.Administrator();
            var faccessPointRM = Examples.AccessPoint("test1");
            var saccessPointRM = Examples.AccessPoint("test2");

            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(faccessPointRM, token))
                    using (var shttpResponse = await RfidHttpClient.RegisterAccessPointAsync(saccessPointRM, token))
                    {
                        RfidAssert.AssertHttpResponse(fhttpResponse, System.Net.HttpStatusCode.OK);
                        RfidAssert.AssertHttpResponse(shttpResponse, System.Net.HttpStatusCode.OK);
                    }
            }

            await assertDatabase.AssertCntAsync(userRM, faccessPointRM, saccessPointRM);
        }
        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 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 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);
                            }
            }
        }
Пример #8
0
        public async Task RefereshToken_When_Refresh_Token_Is_Valid()
        {
            var assertDatabase = await RfidDatabaseAssert.CreateAsync();

            var requestModel = Examples.Administrator();

            await RfidHttpClient.RegisterUserAsync(requestModel);

            using (var genResponse = await RfidHttpClient.GenerateAuthTokenAsync(requestModel.Email, requestModel.Password))
            {
                var jtoken = await genResponse.Content.AsJObjectAsync();

                using (var refreshResponse = await RfidHttpClient.RefreshAuthTokenAsync(jtoken.Token(), jtoken.RefreshToken()))
                {
                    await AssertAuthTokenResponseAsync(refreshResponse, System.Net.HttpStatusCode.OK);

                    var rtoken = await refreshResponse.Content.AsJObjectAsync();

                    Assert.NotEqual(expected: jtoken.Token(), actual: rtoken.Token());
                    Assert.NotEqual(expected: jtoken.RefreshToken(), actual: rtoken.RefreshToken());
                }
            }

            await assertDatabase.AssertCntAsync(requestModel);
        }
Пример #9
0
        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"));
        }
Пример #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 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 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
            });
        }
Пример #13
0
        public async Task GenerateToken_When_User_Exists_But_Password_Incorect()
        {
            var assertDatabase = await RfidDatabaseAssert.CreateAsync();

            var requestModel = Examples.Administrator();

            await RfidHttpClient.RegisterUserAsync(requestModel);

            using (var httpResponse = await RfidHttpClient.GenerateAuthTokenAsync(requestModel.Email, Path.GetRandomFileName()))
            {
                await AssertAuthTokenResponseAsync(httpResponse, System.Net.HttpStatusCode.NotFound);
            }

            await assertDatabase.AssertCntAsync(requestModel);
        }
Пример #14
0
        public async Task GenerateToken_When_User_Exists()
        {
            var assertDatabase = await RfidDatabaseAssert.CreateAsync();

            var registerUserRM = Examples.Administrator();

            await RfidHttpClient.RegisterUserAsync(registerUserRM);

            using (var httpResponse = await RfidHttpClient.GenerateAuthTokenAsync(registerUserRM.Email, registerUserRM.Password))
            {
                await AssertAuthTokenResponseAsync(httpResponse, System.Net.HttpStatusCode.OK);
            }

            await assertDatabase.AssertCntAsync(registerUserRM);
        }
Пример #15
0
        public async Task RefreshToken_When_Auth_Token_Generated_With_Different_Alg()
        {
            var assertDatabase = await RfidDatabaseAssert.CreateAsync();

            var requestModel = Examples.Administrator();

            await RfidHttpClient.RegisterUserAsync(requestModel);

            var auth      = new RFID.REST.Areas.Auth.Services.Auth(null, null, Settings.GetDevelopmentAuthSettings());
            var fakeToken = auth.GenerateToken(requestModel.Email, UserRoles.Admin, SecurityAlgorithms.HmacSha384);

            using (var httpResponse = await RfidHttpClient.RefreshAuthTokenAsync(fakeToken.Token, fakeToken.RefreshToken))
            {
                await AssertAuthTokenResponseAsync(httpResponse, System.Net.HttpStatusCode.NotFound);
            }

            await assertDatabase.AssertCntAsync(requestModel);
        }
Пример #16
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 });
        }
        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 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 });
        }
Пример #19
0
        public async Task GenerateToken_When_Several_Users_Exists()
        {
            var assertDatabase = await RfidDatabaseAssert.CreateAsync();

            var fregisterUserRM = Examples.Administrator();
            var sregisterUserRM = Examples.Administrator("*****@*****.**", "123");

            await RfidHttpClient.RegisterUserAsync(fregisterUserRM);

            await RfidHttpClient.RegisterUserAsync(sregisterUserRM);

            using (var fhttpResponse = await RfidHttpClient.GenerateAuthTokenAsync(fregisterUserRM.Email, fregisterUserRM.Password))
                using (var shttpResponse = await RfidHttpClient.GenerateAuthTokenAsync(sregisterUserRM.Email, sregisterUserRM.Password))
                {
                    await AssertAuthTokenResponseAsync(fhttpResponse, System.Net.HttpStatusCode.OK);
                    await AssertAuthTokenResponseAsync(shttpResponse, System.Net.HttpStatusCode.OK);
                }

            await assertDatabase.AssertCntAsync(fregisterUserRM, sregisterUserRM);
        }
Пример #20
0
        public async Task RefreshToken_When_User_Refresh_Token_Is_Invalid()
        {
            var assertDatabase = await RfidDatabaseAssert.CreateAsync();

            var requestModel = Examples.Administrator();

            await RfidHttpClient.RegisterUserAsync(requestModel);

            using (var genResponse = await RfidHttpClient.GenerateAuthTokenAsync(requestModel.Email, requestModel.Password))
            {
                var jtoken = await genResponse.Content.AsJObjectAsync();

                using (var refreshResponse = await RfidHttpClient.RefreshAuthTokenAsync(jtoken.Token(), Path.GetRandomFileName()))
                {
                    await AssertAuthTokenResponseAsync(refreshResponse, System.Net.HttpStatusCode.NotFound);
                }
            }

            await assertDatabase.AssertCntAsync(requestModel);
        }
Пример #21
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 });
        }
Пример #22
0
        public async Task Delete_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.DeleteTagAsync("unknown", token))
                {
                    RfidAssert.AssertHttpResponse(activateHttpResponse, System.Net.HttpStatusCode.NotFound);
                }
            }

            await assertDatabase.AssertCntAsync(userRM);
        }
Пример #23
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 });
        }
Пример #24
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);
        }
Пример #25
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);
        }
Пример #26
0
        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_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);
        }
Пример #28
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);
        }