public void InsertSteamIdentity()
        {
            // arrange

            // act
            var result = _steamIdentityService.Upsert(SteamIdentity()).GetAwaiter().GetResult();
            // assert
            var steamIdentities = _steamIdentityService.FindAll().GetAwaiter().GetResult();

            steamIdentities.Should().HaveCount(1);
        }
        private async Task OverWriteExistingSteamIdOrSaveNewOne(ExternalLoginInfo info, LiteDbUser user)
        {
            var steam = CrawlSteamIdentity(info);
            //Todo get existing one and give it to the player or save it as a new one
            var realSteamIdentity = await _steamIdentityService.FindOne(steam.Id);

            if (realSteamIdentity != null)
            {
                realSteamIdentity.LiteDbUser = user;
                await _steamIdentityService.Upsert(realSteamIdentity);
            }
            else
            {
                steam.LiteDbUser = user;
                await _steamIdentityService.Upsert(steam);
            }
        }
        public static LiteDbUser InsertUserAndSteamIdentity(SteamIdentityService steamIdentityService,
                                                            UserManager <LiteDbUser> userManager, string userName = "******", string steamIdentityId = "1")
        {
            var user     = UserServiceTests.SetUpUser(userManager, userName);
            var identity = SteamIdentityServiceTest.SteamIdentity(steamIdentityId);

            identity.LiteDbUser   = user;
            identity.LiteDbUserId = user.Id.ToString();
            steamIdentityService.Upsert(identity).GetAwaiter().GetResult();
            return(user);
        }
        public void IsModSomeWhere()
        {
            // arrange
            var pavlovServers = InitializePavlovServer(_sshServerSerivce, _pavlovServerService);
            var user          = UserServiceTests.SetUpUser(_userManager);
            var steamIdentity = SteamIdentityServiceTest.SteamIdentity();

            steamIdentity.LiteDbUser   = user;
            steamIdentity.LiteDbUserId = user.Id.ToString();
            _steamIdentityService.Upsert(steamIdentity).GetAwaiter().GetResult();
            _serverSelectedModsService.Insert(new ServerSelectedMods
            {
                PavlovServer = pavlovServers.First(),
                LiteDbUser   = user
            }).GetAwaiter().GetResult();
            // act
            var isMod = _pavlovServerService.IsModSomeWhere(user, _serverSelectedModsService).GetAwaiter().GetResult();

            // assert
            isMod.Should().BeTrue();
        }
        public async Task <IActionResult> SaveSteamIdentity(SteamIdentity steamIdentity)
        {
            var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
            var bla    = await _steamIdentityService.FindOne(new ObjectId(userId));

            var hisOwn       = userId == steamIdentity.LiteDbUserId;
            var currentOwner = await _steamIdentityService.FindOne(steamIdentity.Id);

            steamIdentity.LiteDbUsers = (await _userService.FindAll()).ToList();
            if (userId != steamIdentity.LiteDbUserId)
            {
                if (!await RightsHandler.IsUserAtLeastInRole("Mod", HttpContext.User, _userService))
                {
                    return(Unauthorized());
                }
            }

            ViewBag.IsOwnSteamIdentity = hisOwn;
            steamIdentity.LiteDbUser   = (await _userService.FindAll())
                                         .FirstOrDefault(x => x.Id == new ObjectId(steamIdentity.LiteDbUserId));

            if (!ModelState.IsValid)
            {
                return(View("SteamIdentity", steamIdentity));
            }

            if (userId != steamIdentity.LiteDbUserId)
            {
                if (!await RightsHandler.IsUserAtLeastInRole("Mod", HttpContext.User, _userService))
                {
                    return(Unauthorized());
                }
            }


            var alreadyOculus = await _steamIdentityService.FindOculus(steamIdentity.OculusId);

            if (steamIdentity.Id != alreadyOculus.Id)
            {
                return(BadRequest("The oculusId already exists!"));
            }

            if (currentOwner == null || steamIdentity.LiteDbUserId == currentOwner.LiteDbUser?.Id.ToString() || currentOwner.LiteDbUser == null)
            {
                await _steamIdentityService.Upsert(steamIdentity);
            }
            else
            {
                return(BadRequest("That would be a duplicate entry!"));
            }



            if (ModelState.ErrorCount > 0)
            {
                return(await EditSteamIdentity(steamIdentity));
            }

            if (hisOwn)
            {
                return(RedirectToAction("Index", "Manage"));
            }
            return(await Index());
        }