Ejemplo n.º 1
0
        public async Task <IActionResult> Claim(Role role)
        {
            var client      = (Guid)HttpContext.Items[CookieIdentificationMiddleware.ClientIdKey];
            var currentRole = _registry.GetRole(client);
            var owner       = _registry.GetOwner(role);
            var success     = true;

            if (currentRole == role)
            {
                if (role != Role.Reader)
                {
                    success = TryDefend(client, role);
                }
            }
            else if (!owner.HasValue)
            {
                _registry.SetClientRole(client, role);
            }
            else
            {
                success = await TryClaimThroughDisputeAsync(client, owner.Value, role);
            }

            if (success)
            {
                return(Ok());
            }
            else
            {
                return(Conflict("The role is occupied."));
            }
        }
Ejemplo n.º 2
0
        public void ShouldStoreNonReaderRoleOwner(Role role)
        {
            _registry.SetClientRole(_client1, role);
            var owner = _registry.GetOwner(role);

            owner.ShouldBe(_client1);
        }