Esempio n. 1
0
        public async Task Activate_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);

                    await RfidDatabase.DeActivateTagAsync(tagRM.Number);

                    using (var activateHttpResponse = await RfidHttpClient.ActivateTagAsync(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 = false });
        }
Esempio n. 2
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 });
        }
Esempio n. 3
0
        public async Task Acitvate_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.ActivateTagAsync("unknown", token))
                {
                    RfidAssert.AssertHttpResponse(activateHttpResponse, System.Net.HttpStatusCode.NotFound);
                }
            }

            await assertDatabase.AssertCntAsync(userRM);
        }