public void EquipLoadout_LoadoutNameHasExtraWhitespace_ShouldTrimNameAndThenEquipLoadout()
        {
            IConfiguration        config               = Mock.Of <IConfiguration>();
            IBungieApiService     bungieApiService     = Mock.Of <IBungieApiService>();
            IManifestDao          manifestDao          = Mock.Of <IManifestDao>();
            EmissaryDbContext     dbContext            = Mock.Of <EmissaryDbContext>();
            IEmissaryDao          emissaryDao          = Mock.Of <IEmissaryDao>();
            IAuthorizationService authorizationService = Mock.Of <IAuthorizationService>();


            ulong        discordId             = 221313820847636491;
            long         destinyProfileId      = 4611686018467260757;
            int          destinyMembershipType = BungieMembershipType.Steam;
            EmissaryUser user = new EmissaryUser(discordId, destinyProfileId, destinyMembershipType);

            long        destinyCharacterId = 2305843009504575107;
            uint        izanagiHash        = 3211806999;
            long        izanagiInstanceId  = 6917529135183883487;
            DestinyItem izanagiItem        = new DestinyItem(izanagiInstanceId, "Izanagi's Burden", new List <string>()
            {
                "Weapon", "Kinetic Weapon", "Sniper Rifle"
            }, izanagiHash, new List <uint>()
            {
                2, 1, 10
            }, "Exotic");
            Loadout loadout = new Loadout(discordId, destinyCharacterId, "last wish raid", new List <DestinyItem>()
            {
                izanagiItem
            });

            EquipItemsResponse response = new EquipItemsResponse(new List <EquipItemResult>()
            {
                new EquipItemResult(izanagiHash, BungiePlatformErrorCodes.Success)
            });

            ProfileCharactersResponse charactersResponse = new ProfileCharactersResponse();
            DestinyCharacter          titan = new DestinyCharacter(2305843009504575107, DateTimeOffset.Parse("2019-12-24T22:40:31Z"), destinyProfileId, BungieMembershipType.Steam);

            charactersResponse.Characters.Add(titan.CharacterId, titan);

            Mock.Get(bungieApiService).Setup(m => m.EquipItems(It.IsAny <EquipItemsRequest>())).Returns(response);
            Mock.Get(bungieApiService).Setup(m => m.GetProfileCharacters(It.IsAny <ProfileCharactersRequest>())).Returns(charactersResponse);
            Mock.Get(emissaryDao).Setup(m => m.GetUserByDiscordId(It.IsAny <ulong>())).Returns(user);
            Mock.Get(emissaryDao).Setup(m => m.GetLoadout(It.IsAny <ulong>(), It.IsAny <long>(), It.IsAny <string>())).Returns(loadout);
            Mock.Get(authorizationService).Setup(m => m.GetAccessToken(discordId)).Returns("access-token");

            IEmissary emissary = new Emissary(config, bungieApiService, manifestDao, dbContext, emissaryDao, authorizationService);

            EmissaryResult result = emissary.EquipLoadout(discordId, "    \t  last wish raid  \t \n  ");

            Assert.IsTrue(result.Success);
            Mock.Get(emissaryDao).Verify(m => m.GetLoadout(discordId, destinyCharacterId, "last wish raid"));
            // Mock.Get(bungieApiService).Verify(m =>
            //     m.EquipItems(It.Is<EquipItemsRequest>(r =>
            //         r.DestinyCharacterId == destinyCharacterId &&
            //         r.MembershipType == destinyMembershipType &&
            //         r.AccessToken == accessToken &&
            //         r.ItemInstanceIds.Count == loadout.Items.Count &&
            //         r.ItemInstanceIds[0] == izanagiInstanceId)), Times.Once());
        }
Ejemplo n.º 2
0
 private DestinyItem LoadItemFromFile(string path)
 {
     using (var stream = new FileStream(path, FileMode.Open))
     {
         using (var reader = new BinaryReader(stream))
         {
             return(DestinyItem.Load(reader));
         }
     }
 }
Ejemplo n.º 3
0
 public bool DeepEquals(TrendingDetail?other)
 {
     return(other is not null &&
            Identifier == other.Identifier &&
            EntityType == other.EntityType &&
            (News is not null ? News.DeepEquals(other.News) : other.News is null) &&
            (Support is not null ? Support.DeepEquals(other.Support) : other.Support is null) &&
            (DestinyItem is not null ? DestinyItem.DeepEquals(other.DestinyItem) : other.DestinyItem is null) &&
            (DestinyActivity is not null ? DestinyActivity.DeepEquals(other.DestinyActivity) : other.DestinyActivity is null) &&
            (DestinyRitual is not null ? DestinyRitual.DeepEquals(other.DestinyRitual) : other.DestinyRitual is null) &&
            (Creation is not null ? Creation.DeepEquals(other.Creation) : other.Creation is null));
 }
        public void ListLoadouts_UserHasOneLoadout_ShouldReturnSuccessWithLoadoutMessageString()
        {
            IConfiguration        config               = Mock.Of <IConfiguration>();
            IBungieApiService     bungieApiService     = Mock.Of <IBungieApiService>();
            IManifestDao          manifestDao          = Mock.Of <IManifestDao>();
            EmissaryDbContext     dbContext            = Mock.Of <EmissaryDbContext>();
            IEmissaryDao          emissaryDao          = Mock.Of <IEmissaryDao>();
            IAuthorizationService authorizationService = Mock.Of <IAuthorizationService>();


            ulong        discordId             = 221313820847636491;
            long         destinyProfileId      = 4611686018467260757;
            int          destinyMembershipType = BungieMembershipType.Steam;
            EmissaryUser user = new EmissaryUser(discordId, destinyProfileId, destinyMembershipType);

            long        titanCharacterId  = 2305843009504575107;
            uint        izanagiHash       = 3211806999;
            long        izanagiInstanceId = 6917529135183883487;
            DestinyItem izanagiItem       = new DestinyItem(izanagiInstanceId, "Izanagi's Burden",
                                                            new List <string>()
            {
                "Weapon", "Kinetic Weapon", "Sniper Rifle"
            }, izanagiHash,
                                                            new List <uint>()
            {
                2, 1, 10
            }, "Exotic");
            Loadout titanLoadout = new Loadout(discordId, titanCharacterId, "raid",
                                               new List <DestinyItem>()
            {
                izanagiItem
            });

            ProfileCharactersResponse charactersResponse = new ProfileCharactersResponse();
            DestinyCharacter          titan = new DestinyCharacter(titanCharacterId, DateTimeOffset.Parse("2019-12-24T22:40:31Z"), destinyProfileId, BungieMembershipType.Steam);

            charactersResponse.Characters.Add(titan.CharacterId, titan);

            IList <Loadout> allLoadoutsForUser = new List <Loadout>()
            {
                titanLoadout
            };

            Mock.Get(emissaryDao).Setup(m => m.GetUserByDiscordId(discordId)).Returns(user);
            Mock.Get(emissaryDao).Setup(m => m.GetAllLoadoutsForUser(discordId)).Returns(allLoadoutsForUser);
            Mock.Get(bungieApiService).Setup(m => m.GetProfileCharacters(It.IsAny <ProfileCharactersRequest>())).Returns(charactersResponse);

            IEmissary      emissary = new Emissary(config, bungieApiService, manifestDao, dbContext, emissaryDao, authorizationService);
            EmissaryResult result   = emissary.ListLoadouts(discordId);

            Assert.IsTrue(result.Success);
            Assert.AreEqual(JsonConvert.SerializeObject(allLoadoutsForUser), result.Message);
        }
        public void EquipLoadout_UnknownErrorCode_ShouldReturnErrorResultWithMessage()
        {
            IConfiguration        config               = Mock.Of <IConfiguration>();
            IBungieApiService     bungieApiService     = Mock.Of <IBungieApiService>();
            IManifestDao          manifestDao          = Mock.Of <IManifestDao>();
            EmissaryDbContext     dbContext            = Mock.Of <EmissaryDbContext>();
            IEmissaryDao          emissaryDao          = Mock.Of <IEmissaryDao>();
            IAuthorizationService authorizationService = Mock.Of <IAuthorizationService>();


            // ulong discordId = 69;

            // long destinyCharacterId = 2305843009504575107;
            uint        izanagiHash       = 3211806999;
            long        izanagiInstanceId = 6917529135183883487;
            DestinyItem izanagiItem       = new DestinyItem(izanagiInstanceId, "Izanagi's Burden", new List <string>()
            {
                "Weapon", "Kinetic Weapon", "Sniper Rifle"
            }, izanagiHash, new List <uint>()
            {
                2, 1, 10
            }, "Exotic");
            // Loadout loadoutToEquip = new Loadout(discordId, destinyCharacterId, "raid", new List<DestinyItem>() { izanagiItem });

            EquipItemResult izanagiEquipResult = new EquipItemResult(izanagiInstanceId, 155);

            EquipItemsResponse equipResponse = new EquipItemsResponse(new List <EquipItemResult>()
            {
                izanagiEquipResult
            });

            ProfileCharactersResponse charactersResponse = new ProfileCharactersResponse();
            DestinyCharacter          titan = new DestinyCharacter(2305843009504575107, DateTimeOffset.Parse("2019-12-24T22:40:31Z"), 420, BungieMembershipType.Steam);

            charactersResponse.Characters.Add(titan.CharacterId, titan);

            Mock.Get(bungieApiService).Setup(m => m.EquipItems(It.IsAny <EquipItemsRequest>())).Returns(equipResponse);
            Mock.Get(emissaryDao).Setup(m => m.GetUserByDiscordId(It.IsAny <ulong>())).Returns(new EmissaryUser());
            Mock.Get(bungieApiService).Setup(m => m.GetProfileCharacters(It.IsAny <ProfileCharactersRequest>())).Returns(charactersResponse);
            Mock.Get(emissaryDao).Setup(m => m.GetLoadout(It.IsAny <ulong>(), It.IsAny <long>(), It.IsAny <string>())).Returns(new Loadout(69, 420, "raid", new List <DestinyItem>()
            {
                izanagiItem
            }));
            Mock.Get(authorizationService).Setup(m => m.GetAccessToken(69)).Returns("access-token");

            IEmissary emissary = new Emissary(config, bungieApiService, manifestDao, dbContext, emissaryDao, authorizationService);

            EmissaryResult result = emissary.EquipLoadout(69, "raid");

            Assert.IsFalse(result.Success);
            Assert.IsTrue(result.ErrorMessage.Contains("155"));
        }
        public void EquipLoadout_AccessTokenExpired_ShouldEmitRequestAuthorizationEvent()
        {
            IConfiguration        config               = Mock.Of <IConfiguration>();
            IBungieApiService     bungieApiService     = Mock.Of <IBungieApiService>();
            IManifestDao          manifestDao          = Mock.Of <IManifestDao>();
            EmissaryDbContext     dbContext            = Mock.Of <EmissaryDbContext>();
            IEmissaryDao          emissaryDao          = Mock.Of <IEmissaryDao>();
            IAuthorizationService authorizationService = Mock.Of <IAuthorizationService>();


            ulong        discordId             = 221313820847636491;
            long         destinyProfileId      = 4611686018467260757;
            int          destinyMembershipType = BungieMembershipType.Steam;
            string       accessToken           = "expired-access-token";
            EmissaryUser user = new EmissaryUser(discordId, destinyProfileId, destinyMembershipType);

            ProfileCharactersResponse charactersResponse = new ProfileCharactersResponse();
            DestinyCharacter          titan = new DestinyCharacter(2305843009504575107, DateTimeOffset.Parse("2019-12-24T22:40:31Z"), destinyProfileId, BungieMembershipType.Steam);

            charactersResponse.Characters.Add(titan.CharacterId, titan);

            long        destinyCharacterId = 2305843009504575107;
            uint        izanagiHash        = 3211806999;
            long        izanagiInstanceId  = 6917529135183883487;
            DestinyItem izanagiItem        = new DestinyItem(izanagiInstanceId, "Izanagi's Burden", new List <string>()
            {
                "Weapon", "Kinetic Weapon", "Sniper Rifle"
            }, izanagiHash, new List <uint>()
            {
                2, 1, 10
            }, "Exotic");
            Loadout loadout = new Loadout(discordId, destinyCharacterId, "raid", new List <DestinyItem>()
            {
                izanagiItem
            });

            Mock.Get(emissaryDao).Setup(m => m.GetUserByDiscordId(It.Is <ulong>(u => u == discordId))).Returns(user);
            Mock.Get(bungieApiService).Setup(m => m.GetProfileCharacters(It.IsAny <ProfileCharactersRequest>())).Returns(charactersResponse);
            Mock.Get(emissaryDao).Setup(m => m.GetLoadout(discordId, destinyCharacterId, "last wish raid")).Returns(loadout);
            Mock.Get(bungieApiService).Setup(m => m.EquipItems(It.IsAny <EquipItemsRequest>())).Throws(new BungieApiException("Unauthorized: Access is denied due to invalid credentials."));

            IEmissary emissary     = new Emissary(config, bungieApiService, manifestDao, dbContext, emissaryDao, authorizationService);
            bool      eventEmitted = false;

            emissary.RequestAuthorizationEvent += (discordId) => eventEmitted = true;
            EmissaryResult result = emissary.EquipLoadout(discordId, "last wish raid");

            Assert.IsFalse(result.Success);
            Assert.IsTrue(eventEmitted);
        }
Ejemplo n.º 7
0
        public void AddOrUpdateLoadout_SameDiscordIdAndSameNameButDifferentDestinyCharacter_ShouldWriteBothToDatabase()
        {
            ulong       discordId          = 221313820847636491;
            long        destinyCharacterId = 2305843009504575107;
            uint        izanagiHash        = 3211806999;
            long        izanagiInstanceId  = 6917529135183883487;
            string      loadoutName        = "crucible";
            DestinyItem izanagiItem        = new DestinyItem(izanagiInstanceId, "Izanagi's Burden", new List <string>()
            {
                "Weapon", "Kinetic Weapon", "Sniper Rifle"
            }, izanagiHash, new List <uint>()
            {
                2, 1, 10
            }, "Exotic");
            Loadout loadout = new Loadout(discordId, destinyCharacterId, loadoutName, new List <DestinyItem>()
            {
                izanagiItem
            });
            Loadout loadout2 = new Loadout(discordId, 69, loadoutName, new List <DestinyItem>()
            {
            });

            using (SqliteConnection connection = new SqliteConnection("DataSource=:memory:")) {
                connection.Open();
                DbContextOptions <EmissaryDbContext> options = new DbContextOptionsBuilder <EmissaryDbContext>()
                                                               .UseSqlite(connection)
                                                               .Options;
                using (EmissaryDbContext dbContext = new EmissaryDbContext(options)) {
                    dbContext.Database.EnsureCreated();
                }
                using (EmissaryDbContext dbContext = new EmissaryDbContext(options)) {
                    LoadoutDao loadoutDao = new LoadoutDao(dbContext);
                    loadoutDao.AddOrUpdateLoadout(loadout);
                }
                using (EmissaryDbContext dbContext = new EmissaryDbContext(options)) {
                    Assert.AreEqual(1, dbContext.Loadouts.Count());
                    Loadout foundLoadout = dbContext.Loadouts.Where(l => l.LoadoutName == loadoutName && l.DiscordId == discordId && l.DestinyCharacterId == destinyCharacterId).AsQueryable().FirstOrDefault();
                    Assert.AreEqual(loadout.DestinyCharacterId, foundLoadout.DestinyCharacterId);
                }
                using (EmissaryDbContext dbContext = new EmissaryDbContext(options)) {
                    LoadoutDao loadoutDao = new LoadoutDao(dbContext);
                    loadoutDao.AddOrUpdateLoadout(loadout2);
                }
                using (EmissaryDbContext dbContext = new EmissaryDbContext(options)) {
                    Assert.AreEqual(2, dbContext.Loadouts.Count());
                    Loadout foundLoadout = dbContext.Loadouts.Where(l => l.LoadoutName == loadoutName && l.DiscordId == discordId && l.DestinyCharacterId == 69).AsQueryable().FirstOrDefault();
                    Assert.AreEqual(69, foundLoadout.DestinyCharacterId);
                }
            }
        }
Ejemplo n.º 8
0
 public void Update(TrendingDetail?other)
 {
     if (other is null)
     {
         return;
     }
     if (Identifier != other.Identifier)
     {
         Identifier = other.Identifier;
         OnPropertyChanged(nameof(Identifier));
     }
     if (EntityType != other.EntityType)
     {
         EntityType = other.EntityType;
         OnPropertyChanged(nameof(EntityType));
     }
     if (!News.DeepEquals(other.News))
     {
         News.Update(other.News);
         OnPropertyChanged(nameof(News));
     }
     if (!Support.DeepEquals(other.Support))
     {
         Support.Update(other.Support);
         OnPropertyChanged(nameof(Support));
     }
     if (!DestinyItem.DeepEquals(other.DestinyItem))
     {
         DestinyItem.Update(other.DestinyItem);
         OnPropertyChanged(nameof(DestinyItem));
     }
     if (!DestinyActivity.DeepEquals(other.DestinyActivity))
     {
         DestinyActivity.Update(other.DestinyActivity);
         OnPropertyChanged(nameof(DestinyActivity));
     }
     if (!DestinyRitual.DeepEquals(other.DestinyRitual))
     {
         DestinyRitual.Update(other.DestinyRitual);
         OnPropertyChanged(nameof(DestinyRitual));
     }
     if (!Creation.DeepEquals(other.Creation))
     {
         Creation.Update(other.Creation);
         OnPropertyChanged(nameof(Creation));
     }
 }
Ejemplo n.º 9
0
        public void AddOrUpdateLoadout_LoadoutAlreadyExistsUpdateItWithNewValue_ShouldWriteToDatabase()
        {
            ulong       discordId          = 221313820847636491;
            long        destinyCharacterId = 2305843009504575107;
            uint        izanagiHash        = 3211806999;
            long        izanagiInstanceId  = 6917529135183883487;
            string      loadoutName        = "crucible";
            DestinyItem izanagiItem        = new DestinyItem(izanagiInstanceId, "Izanagi's Burden", new List <string>()
            {
                "Weapon", "Kinetic Weapon", "Sniper Rifle"
            }, izanagiHash, new List <uint>()
            {
                2, 1, 10
            }, "Exotic");
            Loadout loadout = new Loadout(discordId, destinyCharacterId, loadoutName, new List <DestinyItem>()
            {
                izanagiItem
            });

            using (SqliteConnection connection = new SqliteConnection("DataSource=:memory:")) {
                connection.Open();
                DbContextOptions <EmissaryDbContext> options = new DbContextOptionsBuilder <EmissaryDbContext>()
                                                               .UseSqlite(connection)
                                                               .Options;
                using (EmissaryDbContext dbContext = new EmissaryDbContext(options)) {
                    dbContext.Database.EnsureCreated();
                }
                using (EmissaryDbContext dbContext = new EmissaryDbContext(options)) {
                    LoadoutDao loadoutDao = new LoadoutDao(dbContext);
                    loadoutDao.AddOrUpdateLoadout(loadout);
                    Assert.AreEqual(1, dbContext.Loadouts.Count());
                }
                // now let's update the loadout contents and assert again
                using (EmissaryDbContext dbContext = new EmissaryDbContext(options)) {
                    LoadoutDao loadoutDao = new LoadoutDao(dbContext);
                    loadout.Items.Remove(loadout.Items.Single(item => item.Name == "Izanagi's Burden"));
                    loadoutDao.AddOrUpdateLoadout(loadout);
                }
                using (EmissaryDbContext dbContext = new EmissaryDbContext(options)) {
                    Assert.AreEqual(1, dbContext.Loadouts.Count());
                    Loadout foundLoadout = dbContext.Loadouts.Where(l => l.LoadoutName == loadoutName && l.DiscordId == discordId).AsQueryable().FirstOrDefault();
                    Assert.AreEqual(0, foundLoadout.Items.Count);
                }
            }
        }
Ejemplo n.º 10
0
        public void SaveLoadout_NewLoadoutForRegisteredUser_ShouldSucceedAndWriteToDatabase()
        {
            IConfiguration        config               = Mock.Of <IConfiguration>();
            IBungieApiService     bungieApiService     = Mock.Of <IBungieApiService>();
            IManifestDao          manifestDao          = Mock.Of <IManifestDao>();
            EmissaryDbContext     dbContext            = Mock.Of <EmissaryDbContext>();
            IEmissaryDao          emissaryDao          = Mock.Of <IEmissaryDao>();
            IAuthorizationService authorizationService = Mock.Of <IAuthorizationService>();


            ulong        discordId             = 221313820847636491;
            long         destinyCharacterId    = 2305843009504575107;
            long         destinyProfileId      = 4611686018467260757;
            int          destinyMembershipType = BungieMembershipType.Steam;
            EmissaryUser user = new EmissaryUser(discordId, destinyProfileId, destinyMembershipType);

            uint        izanagiHash       = 3211806999;
            long        izanagiInstanceId = 6917529135183883487;
            DestinyItem izanagiItem       = new DestinyItem(izanagiInstanceId, "Izanagi's Burden", new List <string>()
            {
                "Weapon", "Kinetic Weapon", "Sniper Rifle"
            }, izanagiHash, new List <uint>()
            {
                2, 1, 10
            }, "Exotic");
            Loadout loadoutToSave = new Loadout(discordId, destinyCharacterId, "crucible", new List <DestinyItem>()
            {
                izanagiItem
            });

            Mock.Get(emissaryDao).Setup(m => m.GetUserByDiscordId(discordId)).Returns(user);
            Mock.Get(emissaryDao).Setup(m => m.GetAllLoadoutsForUser(discordId)).Returns(new List <Loadout>());

            IEmissary      emissary = new Emissary(config, bungieApiService, manifestDao, dbContext, emissaryDao, authorizationService);
            EmissaryResult result   = emissary.SaveLoadout(discordId, loadoutToSave, "crucible");

            Assert.IsTrue(result.Success);
            Mock.Get(emissaryDao)
            .Verify(m =>
                    m.AddOrUpdateLoadout(It.Is <Loadout>(l =>
                                                         l.DiscordId == loadoutToSave.DiscordId &&
                                                         l.DestinyCharacterId == loadoutToSave.DestinyCharacterId &&
                                                         l.LoadoutName == loadoutToSave.LoadoutName)), Times.Once());
        }
Ejemplo n.º 11
0
        public void EquipLoadout_ItemHasBeenDismantled_ShouldReturnErrorResult()
        {
            IConfiguration        config               = Mock.Of <IConfiguration>();
            IBungieApiService     bungieApiService     = Mock.Of <IBungieApiService>();
            IManifestDao          manifestDao          = Mock.Of <IManifestDao>();
            EmissaryDbContext     dbContext            = Mock.Of <EmissaryDbContext>();
            IEmissaryDao          emissaryDao          = Mock.Of <IEmissaryDao>();
            IAuthorizationService authorizationService = Mock.Of <IAuthorizationService>();

            long        wendigoInstanceId = 6917529112673221040;
            DestinyItem wendigoItem       = new DestinyItem(wendigoInstanceId, "Wendigo GL3", new List <string>()
            {
            }, 69, new List <uint>()
            {
            }, "Legendary");
            EquipItemResult wendigoEquipResult = new EquipItemResult(wendigoInstanceId, BungiePlatformErrorCodes.DestinyItemNotFound);

            EquipItemsResponse equipResponse = new EquipItemsResponse(new List <EquipItemResult>()
            {
                wendigoEquipResult
            });

            ProfileCharactersResponse charactersResponse = new ProfileCharactersResponse();
            DestinyCharacter          titan = new DestinyCharacter(2305843009504575107, DateTimeOffset.Parse("2019-12-24T22:40:31Z"), 420, BungieMembershipType.Steam);

            charactersResponse.Characters.Add(titan.CharacterId, titan);

            Mock.Get(bungieApiService).Setup(m => m.EquipItems(It.IsAny <EquipItemsRequest>())).Returns(equipResponse);
            Mock.Get(emissaryDao).Setup(m => m.GetUserByDiscordId(It.IsAny <ulong>())).Returns(new EmissaryUser());
            Mock.Get(bungieApiService).Setup(m => m.GetProfileCharacters(It.IsAny <ProfileCharactersRequest>())).Returns(charactersResponse);
            Mock.Get(emissaryDao).Setup(m => m.GetLoadout(It.IsAny <ulong>(), It.IsAny <long>(), It.IsAny <string>())).Returns(new Loadout(69, 420, "raid", new List <DestinyItem>()
            {
                wendigoItem
            }));
            Mock.Get(authorizationService).Setup(m => m.GetAccessToken(69)).Returns("access-token");


            IEmissary emissary = new Emissary(config, bungieApiService, manifestDao, dbContext, emissaryDao, authorizationService);

            EmissaryResult result = emissary.EquipLoadout(69, "raid");

            Assert.IsFalse(result.Success);
            Assert.IsTrue(result.ErrorMessage.Contains("dismantled"));
        }
Ejemplo n.º 12
0
        public void RemoveLoadout_LoadoutDoesExist_ShouldRemoveAndUpdateDatabase()
        {
            ulong discordId        = 221313820847636491;
            long  titanCharacterId = 2305843009504575107;

            uint        izanagiHash       = 3211806999;
            long        izanagiInstanceId = 6917529135183883487;
            DestinyItem izanagiItem       = new DestinyItem(izanagiInstanceId, "Izanagi's Burden",
                                                            new List <string>()
            {
                "Weapon", "Kinetic Weapon", "Sniper Rifle"
            }, izanagiHash,
                                                            new List <uint>()
            {
                2, 1, 10
            }, "Exotic");
            Loadout titanLoadout = new Loadout(discordId, titanCharacterId, "raid",
                                               new List <DestinyItem>()
            {
                izanagiItem
            });

            using (SqliteConnection connection = new SqliteConnection("DataSource=:memory:")) {
                connection.Open();
                DbContextOptions <EmissaryDbContext> options = new DbContextOptionsBuilder <EmissaryDbContext>()
                                                               .UseSqlite(connection)
                                                               .Options;
                using (EmissaryDbContext dbContext = new EmissaryDbContext(options)) {
                    dbContext.Database.EnsureCreated();
                    dbContext.Loadouts.Add(titanLoadout);
                    dbContext.SaveChanges();
                }
                using (EmissaryDbContext dbContext = new EmissaryDbContext(options)) {
                    LoadoutDao loadoutDao = new LoadoutDao(dbContext);
                    Assert.AreEqual(1, dbContext.Loadouts.Count());
                    loadoutDao.RemoveLoadout(discordId, titanCharacterId, "raid");
                    Assert.AreEqual(0, dbContext.Loadouts.Count());
                }
                using (EmissaryDbContext dbContext = new EmissaryDbContext(options)) {
                    Assert.AreEqual(0, dbContext.Loadouts.Count());
                }
            }
        }
Ejemplo n.º 13
0
        public bool Equals(TrendingDetail input)
        {
            if (input == null)
            {
                return(false);
            }

            return
                ((
                     Identifier == input.Identifier ||
                     (Identifier != null && Identifier.Equals(input.Identifier))
                     ) &&
                 (
                     EntityType == input.EntityType ||
                     (EntityType != null && EntityType.Equals(input.EntityType))
                 ) &&
                 (
                     News == input.News ||
                     (News != null && News.Equals(input.News))
                 ) &&
                 (
                     Support == input.Support ||
                     (Support != null && Support.Equals(input.Support))
                 ) &&
                 (
                     DestinyItem == input.DestinyItem ||
                     (DestinyItem != null && DestinyItem.Equals(input.DestinyItem))
                 ) &&
                 (
                     DestinyActivity == input.DestinyActivity ||
                     (DestinyActivity != null && DestinyActivity.Equals(input.DestinyActivity))
                 ) &&
                 (
                     DestinyRitual == input.DestinyRitual ||
                     (DestinyRitual != null && DestinyRitual.Equals(input.DestinyRitual))
                 ) &&
                 (
                     Creation == input.Creation ||
                     (Creation != null && Creation.Equals(input.Creation))
                 ));
        }
Ejemplo n.º 14
0
        public void DeleteLoadout_LoadoutNameDoesntMatchExactly_ShouldReturnErrorResultAndNotChangeDatabase()
        {
            IConfiguration        config               = Mock.Of <IConfiguration>();
            IBungieApiService     bungieApiService     = Mock.Of <IBungieApiService>();
            IManifestDao          manifestDao          = Mock.Of <IManifestDao>();
            EmissaryDbContext     dbContext            = Mock.Of <EmissaryDbContext>();
            IEmissaryDao          emissaryDao          = Mock.Of <IEmissaryDao>();
            IAuthorizationService authorizationService = Mock.Of <IAuthorizationService>();


            ulong  discordId   = 69;
            string loadoutName = "last wish raid";
            ProfileCharactersResponse charactersResponse = new ProfileCharactersResponse();
            DestinyCharacter          titan = new DestinyCharacter(2305843009504575107, DateTimeOffset.Parse("2019-12-24T22:40:31Z"), 420, BungieMembershipType.Steam);

            charactersResponse.Characters.Add(titan.CharacterId, titan);
            DestinyItem izanagiItem = new DestinyItem(6917529135183883487, "Izanagi's Burden", new List <string>()
            {
                "Weapon", "Kinetic Weapon", "Sniper Rifle"
            }, 3211806999, new List <uint>()
            {
                2, 1, 10
            }, "Exotic");
            Loadout savedLoadout = new Loadout(discordId, titan.CharacterId, loadoutName, new List <DestinyItem>()
            {
                izanagiItem
            });

            Mock.Get(emissaryDao).Setup(m => m.GetUserByDiscordId(discordId)).Returns(new EmissaryUser());
            Mock.Get(emissaryDao).Setup(m => m.GetLoadout(discordId, titan.CharacterId, loadoutName)).Returns(savedLoadout);
            Mock.Get(bungieApiService).Setup(m => m.GetProfileCharacters(It.IsAny <ProfileCharactersRequest>())).Returns(charactersResponse);

            IEmissary      emissary = new Emissary(config, bungieApiService, manifestDao, dbContext, emissaryDao, authorizationService);
            EmissaryResult result   = emissary.DeleteLoadout(discordId, "Last Wish Raid");

            Assert.IsFalse(result.Success);
            Assert.IsTrue(result.ErrorMessage.Contains("not found"));
            Mock.Get(emissaryDao).Verify(m => m.RemoveLoadout(It.IsAny <ulong>(), It.IsAny <long>(), It.IsAny <string>()), Times.Never());
        }
Ejemplo n.º 15
0
        public void ListLoadouts_UserHasLoadoutsOnDifferentCharacters_ShouldReturnLoadoutsForCurrentCharacterOnly()
        {
            IConfiguration        config               = Mock.Of <IConfiguration>();
            IBungieApiService     bungieApiService     = Mock.Of <IBungieApiService>();
            IManifestDao          manifestDao          = Mock.Of <IManifestDao>();
            EmissaryDbContext     dbContext            = Mock.Of <EmissaryDbContext>();
            IEmissaryDao          emissaryDao          = Mock.Of <IEmissaryDao>();
            IAuthorizationService authorizationService = Mock.Of <IAuthorizationService>();


            ulong        discordId             = 221313820847636491;
            long         destinyProfileId      = 4611686018467260757;
            int          destinyMembershipType = BungieMembershipType.Steam;
            EmissaryUser user = new EmissaryUser(discordId, destinyProfileId, destinyMembershipType);

            long        titanCharacterId  = 2305843009504575107;
            uint        izanagiHash       = 3211806999;
            long        izanagiInstanceId = 6917529135183883487;
            DestinyItem izanagiItem       = new DestinyItem(izanagiInstanceId, "Izanagi's Burden",
                                                            new List <string>()
            {
                "Kinetic Weapon", "Weapon", "Sniper Rifle"
            }, izanagiHash,
                                                            new List <uint>()
            {
                2, 1, 10
            }, "Exotic");
            uint        suddenDeathHash       = 1879212552;
            long        suddenDeathInstanceId = 6917529043814140192;
            DestinyItem suddenDeathItem       = new DestinyItem(suddenDeathInstanceId, "A Sudden Death",
                                                                new List <string>()
            {
                "Energy Weapon", "Weapon", "Shotgun"
            }, suddenDeathHash,
                                                                new List <uint>()
            {
                3, 1, 11
            }, "Exotic");

            Loadout titanLoadout = new Loadout(discordId, titanCharacterId, "raid",
                                               new List <DestinyItem>()
            {
                izanagiItem
            });
            Loadout titanLoadout2 = new Loadout(discordId, titanCharacterId, "raid2", new List <DestinyItem>()
            {
                suddenDeathItem
            });
            Loadout titanLoadout3 = new Loadout(discordId, titanCharacterId, "raid3", new List <DestinyItem>()
            {
                izanagiItem, suddenDeathItem
            });
            Loadout warlockLoadout = new Loadout(discordId, 69, "raid", new List <DestinyItem>()
            {
                izanagiItem
            });
            Loadout hunterLoadout = new Loadout(discordId, 420, "raid", new List <DestinyItem>()
            {
                izanagiItem
            });
            IList <Loadout> allLoadoutsForUser = new List <Loadout>()
            {
                titanLoadout, titanLoadout2, titanLoadout3, warlockLoadout, hunterLoadout
            };
            // need this for verification
            IList <Loadout> titanLoadouts = new List <Loadout>()
            {
                titanLoadout, titanLoadout2, titanLoadout3
            };

            // assemble so that titan is the most recently played character
            ProfileCharactersResponse charactersResponse = new ProfileCharactersResponse();
            DestinyCharacter          titan = new DestinyCharacter(titanCharacterId, DateTimeOffset.Parse("2019-12-24T22:40:31Z"), destinyProfileId, BungieMembershipType.Steam);

            charactersResponse.Characters.Add(titan.CharacterId, titan);

            Mock.Get(emissaryDao).Setup(m => m.GetUserByDiscordId(discordId)).Returns(user);
            Mock.Get(emissaryDao).Setup(m => m.GetAllLoadoutsForUser(discordId)).Returns(allLoadoutsForUser);
            Mock.Get(bungieApiService).Setup(m => m.GetProfileCharacters(It.IsAny <ProfileCharactersRequest>())).Returns(charactersResponse);

            IEmissary      emissary = new Emissary(config, bungieApiService, manifestDao, dbContext, emissaryDao, authorizationService);
            EmissaryResult result   = emissary.ListLoadouts(discordId);

            Assert.IsTrue(result.Success);
            Assert.AreEqual(JsonConvert.SerializeObject(titanLoadouts), result.Message);
        }
Ejemplo n.º 16
0
        public void GetAllLoadoutsForUser_MultipleLoadoutsOnMultipleCharacters_ShouldReturnLoadoutsForAllCharacters()
        {
            ulong discordId = 221313820847636491;

            long        titanCharacterId  = 2305843009504575107;
            uint        izanagiHash       = 3211806999;
            long        izanagiInstanceId = 6917529135183883487;
            DestinyItem izanagiItem       = new DestinyItem(izanagiInstanceId, "Izanagi's Burden",
                                                            new List <string>()
            {
                "Kinetic Weapon", "Weapon", "Sniper Rifle"
            }, izanagiHash,
                                                            new List <uint>()
            {
                2, 1, 10
            }, "Exotic");
            uint        suddenDeathHash       = 1879212552;
            long        suddenDeathInstanceId = 6917529043814140192;
            DestinyItem suddenDeathItem       = new DestinyItem(suddenDeathInstanceId, "A Sudden Death",
                                                                new List <string>()
            {
                "Energy Weapon", "Weapon", "Shotgun"
            }, suddenDeathHash,
                                                                new List <uint>()
            {
                3, 1, 11
            }, "Legendary");

            Loadout titanLoadout = new Loadout(discordId, titanCharacterId, "raid",
                                               new List <DestinyItem>()
            {
                izanagiItem
            });
            Loadout titanLoadout2 = new Loadout(discordId, titanCharacterId, "raid2", new List <DestinyItem>()
            {
                suddenDeathItem
            });
            Loadout titanLoadout3 = new Loadout(discordId, titanCharacterId, "raid3", new List <DestinyItem>()
            {
                izanagiItem, suddenDeathItem
            });
            Loadout warlockLoadout = new Loadout(discordId, 69, "raid", new List <DestinyItem>()
            {
                izanagiItem
            });
            Loadout hunterLoadout = new Loadout(discordId, 420, "raid", new List <DestinyItem>()
            {
                izanagiItem
            });

            IList <Loadout> allLoadoutsForUser = new List <Loadout>()
            {
                titanLoadout, titanLoadout2, titanLoadout3, warlockLoadout, hunterLoadout
            };

            using (SqliteConnection connection = new SqliteConnection("DataSource=:memory:")) {
                connection.Open();
                DbContextOptions <EmissaryDbContext> options = new DbContextOptionsBuilder <EmissaryDbContext>()
                                                               .UseSqlite(connection)
                                                               .Options;
                using (EmissaryDbContext dbContext = new EmissaryDbContext(options)) {
                    dbContext.Database.EnsureCreated();
                    dbContext.Loadouts.Add(titanLoadout);
                    dbContext.Loadouts.Add(titanLoadout2);
                    dbContext.Loadouts.Add(titanLoadout3);
                    dbContext.Loadouts.Add(warlockLoadout);
                    dbContext.Loadouts.Add(hunterLoadout);
                    dbContext.SaveChanges();
                }
                using (EmissaryDbContext dbContext = new EmissaryDbContext(options)) {
                    LoadoutDao      loadoutDao      = new LoadoutDao(dbContext);
                    IList <Loadout> loadoutsForUser = loadoutDao.GetAllLoadoutsForUser(discordId);
                    Assert.AreEqual(5, loadoutsForUser.Count);
                }
            }
        }
Ejemplo n.º 17
0
        public void GetLoadout_LoadoutExistsAndThenLoadoutValueIsChanged_ShouldReturnLoadoutThenUpdatedLoadout()
        {
            ulong discordId        = 221313820847636491;
            long  titanCharacterId = 2305843009504575107;

            uint        izanagiHash       = 3211806999;
            long        izanagiInstanceId = 6917529135183883487;
            DestinyItem izanagiItem       = new DestinyItem(izanagiInstanceId, "Izanagi's Burden",
                                                            new List <string>()
            {
                "Weapon", "Kinetic Weapon", "Sniper Rifle"
            }, izanagiHash,
                                                            new List <uint>()
            {
                2, 1, 10
            }, "Exotic");
            Loadout titanLoadout = new Loadout(discordId, titanCharacterId, "raid",
                                               new List <DestinyItem>()
            {
                izanagiItem
            });

            uint        suddenDeathHash       = 1879212552;
            long        suddenDeathInstanceId = 6917529043814140192;
            DestinyItem suddenDeathItem       = new DestinyItem(suddenDeathInstanceId, "A Sudden Death",
                                                                new List <string>()
            {
                "Energy Weapon", "Weapon", "Shotgun"
            }, suddenDeathHash,
                                                                new List <uint>()
            {
                3, 1, 11
            }, "Exotic");

            using (SqliteConnection connection = new SqliteConnection("DataSource=:memory:")) {
                connection.Open();
                DbContextOptions <EmissaryDbContext> options = new DbContextOptionsBuilder <EmissaryDbContext>()
                                                               .UseSqlite(connection)
                                                               .Options;
                using (EmissaryDbContext dbContext = new EmissaryDbContext(options)) {
                    dbContext.Database.EnsureCreated();
                }
                using (EmissaryDbContext dbContext = new EmissaryDbContext(options)) {
                    LoadoutDao loadoutDao = new LoadoutDao(dbContext);
                    dbContext.Loadouts.Add(titanLoadout);
                    dbContext.SaveChanges();
                }
                using (EmissaryDbContext dbContext = new EmissaryDbContext(options)) {
                    LoadoutDao loadoutDao = new LoadoutDao(dbContext);
                    Assert.AreEqual(1, dbContext.Loadouts.Count());
                    Loadout foundLoadout = loadoutDao.GetLoadout(discordId, titanCharacterId, "raid");
                    Assert.AreEqual(1, foundLoadout.Items.Count);
                    Assert.AreEqual(izanagiInstanceId, foundLoadout.Items[0].ItemInstanceId);
                    titanLoadout.Items.Add(suddenDeathItem);
                    loadoutDao.AddOrUpdateLoadout(titanLoadout);
                }
                using (EmissaryDbContext dbContext = new EmissaryDbContext(options)) {
                    LoadoutDao loadoutDao = new LoadoutDao(dbContext);
                    Assert.AreEqual(1, dbContext.Loadouts.Count());
                    Loadout foundLoadout = loadoutDao.GetLoadout(discordId, titanCharacterId, "raid");
                    Assert.AreEqual(2, foundLoadout.Items.Count);
                    Assert.AreEqual(izanagiInstanceId, foundLoadout.Items[0].ItemInstanceId);
                    Assert.AreEqual(suddenDeathInstanceId, foundLoadout.Items[1].ItemInstanceId);
                }
            }
        }
Ejemplo n.º 18
0
        public void CurrentlyEquipped_MultipleCharacters_ShouldReturnEquippedItemsForMostRecentlyPlayedCharacter()
        {
            IConfiguration        config               = Mock.Of <IConfiguration>();
            IBungieApiService     bungieApiService     = Mock.Of <IBungieApiService>();
            IManifestDao          manifestDao          = Mock.Of <IManifestDao>();
            EmissaryDbContext     dbContext            = Mock.Of <EmissaryDbContext>();
            IEmissaryDao          emissaryDao          = Mock.Of <IEmissaryDao>();
            IAuthorizationService authorizationService = Mock.Of <IAuthorizationService>();

            ulong        discordId             = 221313820847636491;
            long         destinyProfileId      = 4611686018467260757;
            int          destinyMembershipType = BungieMembershipType.Steam;
            EmissaryUser user = new EmissaryUser();

            user.DiscordId             = discordId;
            user.DestinyProfileId      = destinyProfileId;
            user.DestinyMembershipType = destinyMembershipType;
            Mock.Get(emissaryDao).Setup(m => m.GetUserByDiscordId(discordId)).Returns(user);

            ProfileCharactersResponse charactersResponse = new ProfileCharactersResponse();
            DestinyCharacter          warlock            = new DestinyCharacter(2305843009470834170, DateTimeOffset.Parse("2019-12-13T02:31:43Z"), destinyProfileId, BungieMembershipType.Steam);
            // titan is the most recently played character
            DestinyCharacter titan  = new DestinyCharacter(2305843009504575107, DateTimeOffset.Parse("2019-12-24T22:40:31Z"), destinyProfileId, BungieMembershipType.Steam);
            DestinyCharacter hunter = new DestinyCharacter(2305843009557154440, DateTimeOffset.Parse("2019-11-25T03:34:56Z"), destinyProfileId, BungieMembershipType.Steam);

            charactersResponse.Characters.Add(warlock.CharacterId, warlock);
            charactersResponse.Characters.Add(titan.CharacterId, titan);
            charactersResponse.Characters.Add(hunter.CharacterId, hunter);
            Mock.Get(bungieApiService).Setup(m => m.GetProfileCharacters(It.Is <ProfileCharactersRequest>(r => r.DestinyProfileId == destinyProfileId && r.MembershipType == destinyMembershipType))).Returns(charactersResponse);

            uint izanagiHash       = 3211806999;
            long izanagiInstanceId = 6917529135183883487;

            DestinyGenericItem[]       equippedItems     = new DestinyGenericItem[] { new DestinyGenericItem(izanagiHash, izanagiInstanceId) };
            CharacterEquipmentResponse equipmentResponse = new CharacterEquipmentResponse(equippedItems);

            Mock.Get(bungieApiService).Setup(m => m.GetCharacterEquipment(It.Is <CharacterEquipmentRequest>(r => r.DestinyCharacterId == titan.CharacterId && r.DestinyProfileId == destinyProfileId && r.DestinyMembershipType == destinyMembershipType))).Returns(equipmentResponse);

            DestinyItem izanagiItem = new DestinyItem(izanagiInstanceId, "Izanagi's Burden",
                                                      new List <string>()
            {
                "Kinetic Weapon", "Weapon", "Sniper Rifle"
            }, izanagiHash,
                                                      new List <uint>()
            {
                2, 1, 10
            }, "Exotic");
            IList <DestinyItem> expectedLoadoutItems = new List <DestinyItem>()
            {
                izanagiItem
            };
            Loadout expectedLoadout = new Loadout(discordId, titan.CharacterId, "unsaved loadout", expectedLoadoutItems);

            // IBungieApiService bungieApiService = Mock.Of<IBungieApiService>(x =>
            // x.GetProfileCharacters(charactersRequest) == charactersResponse &&
            // x.GetCharacterEquipment(equipmentRequest) == equipmentResponse
            // );

            ManifestItemDefinition izanagiItemDefinition = new ManifestItemDefinition("Izanagi's Burden", "Exotic", new uint[] { 2, 1, 10 });

            Mock.Get(manifestDao).Setup(m => m.GetItemDefinition(izanagiHash)).Returns(izanagiItemDefinition);
            Mock.Get(manifestDao).Setup(m => m.GetItemCategoryDefinition(1)).Returns(new ManifestItemCategoryDefinition("Weapon"));
            Mock.Get(manifestDao).Setup(m => m.GetItemCategoryDefinition(2)).Returns(new ManifestItemCategoryDefinition("Kinetic Weapon"));
            Mock.Get(manifestDao).Setup(m => m.GetItemCategoryDefinition(10)).Returns(new ManifestItemCategoryDefinition("Sniper Rifle"));

            IEmissary emissary = new Emissary(config, bungieApiService, manifestDao, dbContext, emissaryDao, authorizationService);

            EmissaryResult result = emissary.CurrentlyEquipped(discordId);

            Assert.IsTrue(result.Success);
            Assert.AreEqual(JsonConvert.SerializeObject(expectedLoadout), result.Message);
        }
Ejemplo n.º 19
0
        public void CurrentlyEquipped_CurrentGearDoesNotMatchAnySavedLoadouts_ShouldReturnLoadoutNameUnsavedLoadout()
        {
            IConfiguration        config               = Mock.Of <IConfiguration>();
            IBungieApiService     bungieApiService     = Mock.Of <IBungieApiService>();
            IManifestDao          manifestDao          = Mock.Of <IManifestDao>();
            EmissaryDbContext     dbContext            = Mock.Of <EmissaryDbContext>();
            IEmissaryDao          emissaryDao          = Mock.Of <IEmissaryDao>();
            IAuthorizationService authorizationService = Mock.Of <IAuthorizationService>();



            ulong       discordId          = 69;
            long        destinyCharacterId = 420;
            string      loadoutName        = "last wish raid";
            DestinyItem destinyItem1       = new DestinyItem(6969, "dummy item 1", new List <string>()
            {
                "Weapon", "Kinetic Weapon"
            }, 420420, new List <uint>()
            {
                1, 2
            }, "Legendary");
            DestinyItem destinyItem2 = new DestinyItem(9696, "dummy item 2", new List <string>()
            {
                "Armor", "Helmet"
            }, 240240, new List <uint>()
            {
                3, 4
            }, "Legendary");
            List <DestinyItem> loadoutItems = new List <DestinyItem>()
            {
                destinyItem1, destinyItem2
            };
            Loadout savedLoadout = new Loadout(discordId, destinyCharacterId, loadoutName, loadoutItems);

            long         destinyProfileId = 42069;
            EmissaryUser user             = new EmissaryUser(discordId, destinyProfileId, BungieMembershipType.Steam);

            Mock.Get(emissaryDao).Setup(m => m.GetUserByDiscordId(discordId)).Returns(user);
            Mock.Get(emissaryDao).Setup(m => m.GetAllLoadoutsForUser(discordId)).Returns(new List <Loadout>()
            {
                savedLoadout
            });
            Mock.Get(emissaryDao).Setup(m => m.GetLoadout(discordId, destinyCharacterId, loadoutName)).Returns(savedLoadout);

            ProfileCharactersResponse charactersResponse = new ProfileCharactersResponse();
            DestinyCharacter          character          = new DestinyCharacter(destinyCharacterId, DateTimeOffset.Parse("2019-12-24T22:40:31Z"), destinyProfileId, BungieMembershipType.Steam);

            charactersResponse.Characters.Add(character.CharacterId, character);

            CharacterEquipmentResponse equipmentResponse = new CharacterEquipmentResponse();
            DestinyGenericItem         genericItem1      = new DestinyGenericItem(destinyItem1.ItemHash, destinyItem1.ItemInstanceId);

            equipmentResponse.Items = new List <DestinyGenericItem>()
            {
                genericItem1
            };

            Mock.Get(bungieApiService).Setup(m => m.GetProfileCharacters(It.IsAny <ProfileCharactersRequest>())).Returns(charactersResponse);
            Mock.Get(bungieApiService).Setup(m => m.GetCharacterEquipment(It.IsAny <CharacterEquipmentRequest>())).Returns(equipmentResponse);

            Mock.Get(manifestDao).Setup(m => m.GetItemDefinition(destinyItem1.ItemHash)).Returns(new ManifestItemDefinition(destinyItem1.Name, destinyItem1.TierTypeName, destinyItem1.CategoryHashes));
            Mock.Get(manifestDao).Setup(m => m.GetItemCategoryDefinition(1)).Returns(new ManifestItemCategoryDefinition("Weapon"));
            Mock.Get(manifestDao).Setup(m => m.GetItemCategoryDefinition(2)).Returns(new ManifestItemCategoryDefinition("Kinetic Weapon"));

            IEmissary emissary = new Emissary(config, bungieApiService, manifestDao, dbContext, emissaryDao, authorizationService);

            EmissaryResult result = emissary.CurrentlyEquipped(discordId);

            Loadout actualLoadout = JsonConvert.DeserializeObject <Loadout>(result.Message);

            Assert.AreEqual("unsaved loadout", actualLoadout.LoadoutName);
        }
Ejemplo n.º 20
0
        public void EquipLoadout_ExoticWeaponAndArmorCurrentlyEquipped_ShouldPutExoticsAtEndOfEquipRequestList()
        {
            IConfiguration        config               = Mock.Of <IConfiguration>();
            IBungieApiService     bungieApiService     = Mock.Of <IBungieApiService>();
            IManifestDao          manifestDao          = Mock.Of <IManifestDao>();
            EmissaryDbContext     dbContext            = Mock.Of <EmissaryDbContext>();
            IEmissaryDao          emissaryDao          = Mock.Of <IEmissaryDao>();
            IAuthorizationService authorizationService = Mock.Of <IAuthorizationService>();

            ulong discordId = 221313820847636491;

            long izanagiInstanceId              = 6917529135183883487;
            long recluseInstanceId              = 6917529123204409619;
            long wendigoInstanceId              = 6917529112673221040;
            long maskOfRullInstanceId           = 6917529110566559001;
            long reverieDawnInstanceId          = 6917529138010460936;
            long plateOfTranscendenceInstanceId = 6917529109687230597;
            long peacekeepersInstanceId         = 6917529122999918127;
            long markOfTheGreatHuntInstanceId   = 6917529128966008940;

            DestinyItem izanagiItem = new DestinyItem(izanagiInstanceId, "Izanagi's Burden", new List <string>()
            {
            }, 69, new List <uint>()
            {
            }, "Exotic");
            DestinyItem recluseItem = new DestinyItem(recluseInstanceId, "The Recluse", new List <string>()
            {
            }, 69, new List <uint>()
            {
            }, "Legendary");
            DestinyItem wendigoItem = new DestinyItem(wendigoInstanceId, "Wendigo GL3", new List <string>()
            {
            }, 69, new List <uint>()
            {
            }, "Legendary");
            DestinyItem maskOfRullItem = new DestinyItem(maskOfRullInstanceId, "Mask of Rull", new List <string>()
            {
            }, 69, new List <uint>()
            {
            }, "Legendary");
            DestinyItem reverieDawnItem = new DestinyItem(reverieDawnInstanceId, "Reverie Dawn Gauntlets", new List <string>()
            {
            }, 69, new List <uint>()
            {
            }, "Legendary");
            DestinyItem plateOfTranscendenceItem = new DestinyItem(plateOfTranscendenceInstanceId, "Plate of Transcendence", new List <string>()
            {
            }, 69, new List <uint>()
            {
            }, "Legendary");
            DestinyItem peacekeepersItem = new DestinyItem(peacekeepersInstanceId, "Peacekeepers", new List <string>()
            {
            }, 69, new List <uint>()
            {
            }, "Exotic");
            DestinyItem markOfTheGreatHuntItem = new DestinyItem(markOfTheGreatHuntInstanceId, "Mark of the Great Hunt", new List <string>()
            {
            }, 69, new List <uint>()
            {
            }, "Legendary");

            IList <DestinyItem> loadoutItems = new List <DestinyItem>()
            {
                izanagiItem, recluseItem, wendigoItem, maskOfRullItem, reverieDawnItem, plateOfTranscendenceItem, peacekeepersItem, markOfTheGreatHuntItem
            };

            Loadout savedLoadout = new Loadout(discordId, 420, "last wish raid", loadoutItems);

            ProfileCharactersResponse charactersResponse = new ProfileCharactersResponse();
            DestinyCharacter          titan = new DestinyCharacter(2305843009504575107, DateTimeOffset.Parse("2019-12-24T22:40:31Z"), 69, BungieMembershipType.Steam);

            charactersResponse.Characters.Add(titan.CharacterId, titan);

            IList <long> originalItemInstanceIdsOrder = new List <long>()
            {
                izanagiInstanceId, recluseInstanceId, wendigoInstanceId, maskOfRullInstanceId, reverieDawnInstanceId, plateOfTranscendenceInstanceId, peacekeepersInstanceId, markOfTheGreatHuntInstanceId
            };

            IList <long> expectedItemInstanceIdsOrder = new List <long>()
            {
                recluseInstanceId, wendigoInstanceId, maskOfRullInstanceId, reverieDawnInstanceId, plateOfTranscendenceInstanceId, markOfTheGreatHuntInstanceId, izanagiInstanceId, peacekeepersInstanceId
            };

            EquipItemResult    izanagiEquipResult              = new EquipItemResult(izanagiInstanceId, BungiePlatformErrorCodes.Success);
            EquipItemResult    recluseEquipResult              = new EquipItemResult(recluseInstanceId, BungiePlatformErrorCodes.Success);
            EquipItemResult    wendigoEquipResult              = new EquipItemResult(wendigoInstanceId, BungiePlatformErrorCodes.Success);
            EquipItemResult    maskOfRullEquipResult           = new EquipItemResult(maskOfRullInstanceId, BungiePlatformErrorCodes.Success);
            EquipItemResult    reverieDawnEquipResult          = new EquipItemResult(reverieDawnInstanceId, BungiePlatformErrorCodes.Success);
            EquipItemResult    plateOfTranscendenceEquipResult = new EquipItemResult(plateOfTranscendenceInstanceId, BungiePlatformErrorCodes.Success);
            EquipItemResult    peacekeepersEquipResult         = new EquipItemResult(peacekeepersInstanceId, BungiePlatformErrorCodes.Success);
            EquipItemResult    markOfTheGreatHuntEquipResult   = new EquipItemResult(markOfTheGreatHuntInstanceId, BungiePlatformErrorCodes.Success);
            EquipItemsResponse equipResponse = new EquipItemsResponse(new List <EquipItemResult>()
            {
                izanagiEquipResult, recluseEquipResult, wendigoEquipResult, maskOfRullEquipResult, reverieDawnEquipResult, plateOfTranscendenceEquipResult, peacekeepersEquipResult, markOfTheGreatHuntEquipResult
            });


            Mock.Get(emissaryDao).Setup(m => m.GetLoadout(discordId, It.IsAny <long>(), "last wish raid")).Returns(savedLoadout);
            Mock.Get(bungieApiService).Setup(m => m.GetProfileCharacters(It.IsAny <ProfileCharactersRequest>())).Returns(charactersResponse);
            Mock.Get(emissaryDao).Setup(m => m.GetUserByDiscordId(discordId)).Returns(new EmissaryUser());
            Mock.Get(bungieApiService).Setup(m => m.EquipItems(It.IsAny <EquipItemsRequest>())).Returns(equipResponse);
            Mock.Get(authorizationService).Setup(m => m.GetAccessToken(discordId)).Returns("access-token");

            IEmissary      emissary = new Emissary(config, bungieApiService, manifestDao, dbContext, emissaryDao, authorizationService);
            EmissaryResult result   = emissary.EquipLoadout(discordId, "last wish raid");

            Assert.IsTrue(result.Success);
            Mock.Get(bungieApiService).Verify(m => m.EquipItems(It.Is <EquipItemsRequest>(r => r.ItemInstanceIds.SequenceEqual(expectedItemInstanceIdsOrder))), Times.Once());
        }
Ejemplo n.º 21
0
        public void SaveLoadout_OverwriteExistingLoadout_ShouldSucceedAndWriteToDatabase()
        {
            IConfiguration    config           = Mock.Of <IConfiguration>();
            IBungieApiService bungieApiService = Mock.Of <IBungieApiService>();
            IManifestDao      manifestDao      = Mock.Of <IManifestDao>();
            // EmissaryDbContext dbContext = Mock.Of<EmissaryDbContext>();
            // IEmissaryDao emissaryDao = Mock.Of<IEmissaryDao>();
            IAuthorizationService authorizationService = Mock.Of <IAuthorizationService>();

            ulong discordId          = 221313820847636491;
            long  destinyCharacterId = 2305843009504575107;
            // long destinyProfileId = 4611686018467260757;
            // int destinyMembershipType = BungieMembershipType.Steam;
            // EmissaryUser user = new EmissaryUser(discordId, destinyProfileId, destinyMembershipType, "");

            uint        izanagiHash       = 3211806999;
            long        izanagiInstanceId = 6917529135183883487;
            DestinyItem izanagiItem       = new DestinyItem(izanagiInstanceId, "Izanagi's Burden", new List <string>()
            {
                "Weapon", "Kinetic Weapon", "Sniper Rifle"
            }, izanagiHash, new List <uint>()
            {
                2, 1, 10
            }, "Exotic");
            Loadout loadoutToSave = new Loadout(discordId, destinyCharacterId, "crucible", new List <DestinyItem>()
            {
                izanagiItem
            });

            using (SqliteConnection connection = new SqliteConnection("DataSource=:memory:")) {
                connection.Open();
                DbContextOptions <EmissaryDbContext> options = new DbContextOptionsBuilder <EmissaryDbContext>()
                                                               .UseSqlite(connection)
                                                               .Options;
                using (EmissaryDbContext dbContext = new EmissaryDbContext(options)) {
                    dbContext.Database.EnsureCreated();
                    IList <Loadout> existingLoadoutsForUser = dbContext.Loadouts.Where(l => l.DiscordId == discordId).ToList();
                    Assert.AreEqual(0, existingLoadoutsForUser.Count);
                }
                using (EmissaryDbContext dbContext = new EmissaryDbContext(options)) {
                    IEmissaryDao emissaryDao = new EmissaryDao(dbContext);
                    IEmissary    emissary    = new Emissary(config, bungieApiService, manifestDao, dbContext, emissaryDao, authorizationService);
                    emissary.SaveLoadout(discordId, loadoutToSave, "crucible");
                }
                using (EmissaryDbContext dbContext = new EmissaryDbContext(options)) {
                    IList <Loadout> existingLoadoutsForUser = dbContext.Loadouts.Where(l => l.DiscordId == discordId).ToList();
                    Assert.AreEqual(1, existingLoadoutsForUser.Count);
                    Assert.AreEqual(1, existingLoadoutsForUser[0].Items.Count);
                }
                using (EmissaryDbContext dbContext = new EmissaryDbContext(options)) {
                    IEmissaryDao emissaryDao = new EmissaryDao(dbContext);
                    IEmissary    emissary    = new Emissary(config, bungieApiService, manifestDao, dbContext, emissaryDao, authorizationService);
                    loadoutToSave.Items.Remove(loadoutToSave.Items.Single(item => item.Name == "Izanagi's Burden"));
                    EmissaryResult result = emissary.SaveLoadout(discordId, loadoutToSave, "crucible");
                    Assert.IsTrue(result.Success);
                }
                using (EmissaryDbContext dbContext = new EmissaryDbContext(options)) {
                    IList <Loadout> existingLoadoutsForUser = dbContext.Loadouts.Where(l => l.DiscordId == discordId).ToList();
                    Assert.AreEqual(1, existingLoadoutsForUser.Count);
                    Assert.AreEqual(0, existingLoadoutsForUser[0].Items.Count);
                }
            }
        }