Beispiel #1
0
        public ActivateKeyOutput ActivateKey(ActivateKeyInput input)
        {
            IList <Key> keys = KeyRepository.GetAll().Where(r => r.KeyValue == input.Key && r.OwnerUserId == null).ToList();

            if (keys.Count != 1)
            {
                throw new KeyActivationException(input.Key);
            }

            Key keyEntity = keys.Single();

            keyEntity.OwnerUserId = Session.UserId;
            KeyRepository.Update(keyEntity);

            GameRepository.Includes.Add(r => r.Location);
            GameRepository.Includes.Add(r => r.GameStatus);
            GameRepository.Includes.Add(r => r.GameTasks);
            GameRepository.Includes.Add(r => r.LastModifierUser);
            GameRepository.Includes.Add(r => r.CreatorUser);

            GameLightDto activatedGame = GameRepository.Get(keyEntity.GameId).MapTo <GameLightDto>();

            GameRepository.Includes.Clear();

            UowManager.Current.Completed += (sender, e) =>
            {
                GameChangesNotifier.RaiseOnKeyActivated(new KeyActivatedMessage(activatedGame, Session.UserId, input.Key));
            };

            return(new ActivateKeyOutput()
            {
                ActivatedGame = activatedGame
            });
        }
Beispiel #2
0
        public RetrieveGameCollectionOutput RetrieveGameCollection(RetrieveGameCollectionInput input)
        {
            if (Session.UserId == null)
            {
                return(new RetrieveGameCollectionOutput());
            }

            KeyRepository.Includes.Add(r => r.Game);
            KeyRepository.Includes.Add(r => r.Game.Location);
            KeyRepository.Includes.Add(r => r.Game.GameStatus);
            KeyRepository.Includes.Add(r => r.Game.GameTasks);
            KeyRepository.Includes.Add(r => r.Game.GameTasks.Select(e => e.GameTaskType));
            //KeyRepository.Includes.Add(r => r.Game.GameTasks.SelectMany(e => e.Conditions));
            //KeyRepository.Includes.Add(r => r.Game.GameTasks.SelectMany(e => e.Conditions.Select(k => k.ConditionType)));
            //KeyRepository.Includes.Add(r => r.Game.GameTasks.SelectMany(e => e.Tips));

            List <GameLightDto> gameCollection = GamePolicy.CanRetrieveManyEntitiesLight(
                KeyRepository.GetAll()
                .Where(r => r.OwnerUserId == Session.UserId).Select(r => r.Game))
                                                 .ToList().MapIList <Game, GameLightDto>().ToList();

            KeyRepository.Includes.Clear();

            return(new RetrieveGameCollectionOutput()
            {
                GameCollection = gameCollection
            });
        }
        public async Task GetAll_UserIdIsSet_SetsCorrectResourceAndMethod()
        {
            var sut = new KeyRepository(_requestFactory);

            await sut.GetAll(0);

            _requestFactory.Received().Create("users/{userId}/keys", Method.Get);
        }
        public async Task GetAll_UserIdIsSet_AddsUserIdUrlSegment()
        {
            const uint expected = 0;
            var        sut      = new KeyRepository(_requestFactory);

            await sut.GetAll(expected);

            _request.Received().AddUrlSegmentIfNotNull("userId", expected);
        }
        public async Task DeleteKeyFromFileRepositoryTest()
        {
            this.Initialize();

            var keyRepository = new KeyRepository(VaultName);
            var isInserted = await keyRepository.Add(KeyWithIdentifier);
            Assert.IsTrue(isInserted);
            Assert.IsTrue(keyRepository.GetAll().Result.Count() == 1);

            var newKeyRepository = new KeyRepository(VaultName);
            Assert.IsTrue(newKeyRepository.GetAll().Result.Count() == 1);
            var isDeleted = await newKeyRepository.Delete(newKeyRepository.GetAll().Result.First());
            Assert.IsTrue(isDeleted);
            Assert.IsTrue(!newKeyRepository.GetAll().Result.Any());

            newKeyRepository = new KeyRepository(VaultName);
            Assert.IsTrue(!newKeyRepository.GetAll().Result.Any());
        }
        public async Task AddKeyToFileRepositoryTest()
        {
            var keyRepository = new KeyRepository(VaultName);
            var isInserted = await keyRepository.Add(KeyWithIdentifier);
            Assert.IsTrue(isInserted);
            Assert.IsTrue(keyRepository.GetAll().Result.Count() == 1);

            var newKeyRepository = new KeyRepository(VaultName);
            Assert.IsTrue(newKeyRepository.GetAll().Result.Count() == 1);
        }
        public async Task DeleteKeyFromFileRepositoryTest()
        {
            this.Initialize();

            var keyRepository = new KeyRepository(VaultName);
            var isInserted    = await keyRepository.Add(KeyWithIdentifier);

            Assert.IsTrue(isInserted);
            Assert.IsTrue(keyRepository.GetAll().Result.Count() == 1);

            var newKeyRepository = new KeyRepository(VaultName);

            Assert.IsTrue(newKeyRepository.GetAll().Result.Count() == 1);
            var isDeleted = await newKeyRepository.Delete(newKeyRepository.GetAll().Result.First());

            Assert.IsTrue(isDeleted);
            Assert.IsTrue(!newKeyRepository.GetAll().Result.Any());

            newKeyRepository = new KeyRepository(VaultName);
            Assert.IsTrue(!newKeyRepository.GetAll().Result.Any());
        }
        public async Task AddKeyToFileRepositoryTest()
        {
            var keyRepository = new KeyRepository(VaultName);
            var isInserted    = await keyRepository.Add(KeyWithIdentifier);

            Assert.IsTrue(isInserted);
            Assert.IsTrue(keyRepository.GetAll().Result.Count() == 1);

            var newKeyRepository = new KeyRepository(VaultName);

            Assert.IsTrue(newKeyRepository.GetAll().Result.Count() == 1);
        }