コード例 #1
0
        public async void CreateCharacterWorks(int charId, string name)
        {
            var options = new DbContextOptionsBuilder <Data.D20CharacterDatabaseContext>()
                          .UseInMemoryDatabase("create_character_test").Options;

            using (var db = new Data.D20CharacterDatabaseContext(options))
            {
                Lib.IRepo     sut      = new Data.D20Repo(db);
                Lib.Character testChar = new Lib.Character();
                if (await db.Characters.FirstOrDefaultAsync(c => c.CharacterId == 1) == null)
                {
                    testChar.CharID = 0;
                    testChar.Name   = "No Character";
                    testChar.CampID = 1;
                    testChar.UserID = 1;
                    db.Characters.Add(testChar);
                    db.SaveChanges();
                }
                testChar.CharID = charId;
                testChar.Name   = name;
                testChar.CampID = 1;
                testChar.UserID = 1;
                testChar.CharID = sut.CreateCharacter(testChar);
                Data.Characters test = await db.Characters.FirstOrDefaultAsync(c => c.CharacterName == name);

                bool actual = (test != null && test.CharacterId == testChar.CharID);

                Assert.True(actual);
            }
        }
コード例 #2
0
        public async void JoinCampWorks()
        {
            var options = new DbContextOptionsBuilder <Data.D20CharacterDatabaseContext>()
                          .UseInMemoryDatabase("join_campaign_test").Options;

            using (var db = new Data.D20CharacterDatabaseContext(options))
            {
                Lib.IRepo    sut  = new Data.D20Repo(db);
                Lib.Campaign camp = new Lib.Campaign();
                if (await db.Campaign.FirstOrDefaultAsync(c => c.CampaignId == 1) == null)
                {
                    camp.CampID     = 0;
                    camp.Name       = "No Campaign";
                    camp.Characters = new List <Lib.Character>();
                    camp.GMs        = new List <Lib.User>();
                    db.Campaign.Add(camp);
                    db.SaveChanges();
                }
                camp.CampID     = 0;
                camp.Name       = "Test Campaign";
                camp.Characters = new List <Lib.Character>();
                camp.GMs        = new List <Lib.User>();
                sut.CreateCampaign(camp);
                Data.Campaign testCamp = await db.Campaign.FirstOrDefaultAsync(c => c.CampaignName == camp.Name);

                Lib.Character testChar = new Lib.Character();
                if (await db.Characters.FirstOrDefaultAsync(c => c.CharacterId == 1) == null)
                {
                    testChar.CharID = 0;
                    testChar.Name   = "No Character";
                    testChar.CampID = 1;
                    testChar.UserID = 1;
                    db.Characters.Add(testChar);
                    db.SaveChanges();
                }
                testChar.CharID = 0;
                testChar.Name   = "Test Character";
                testChar.CampID = 0;
                testChar.UserID = 1;
                sut.CreateCharacter(testChar);
                Data.Characters test = await db.Characters.FirstOrDefaultAsync(c => c.CharacterName == testChar.Name);

                bool actual = (testCamp != null && testCamp.CampaignName == camp.Name && test != null && test.CampaignId != testCamp.CampaignId);
                Assert.True(actual);

                sut.JoinCamp(testCamp.CampaignId, test.CharacterId);
                test = await db.Characters.FirstOrDefaultAsync(c => c.CharacterName == testChar.Name);

                actual = (test.CampaignId == testCamp.CampaignId);

                Assert.True(actual);
            }
        }
コード例 #3
0
        public async void CharacterListByUserWorks()
        {
            var options = new DbContextOptionsBuilder <Data.D20CharacterDatabaseContext>()
                          .UseInMemoryDatabase("character_list_by_user_test").Options;

            using (var db = new Data.D20CharacterDatabaseContext(options))
            {
                Lib.IRepo     sut      = new Data.D20Repo(db);
                Lib.Character testChar = new Lib.Character();
                if (await db.Characters.FirstOrDefaultAsync(c => c.CharacterId == 1) == null)
                {
                    testChar.CharID = 0;
                    testChar.Name   = "No Character";
                    testChar.CampID = 1;
                    testChar.UserID = 1;
                    db.Characters.Add(testChar);
                    db.SaveChanges();
                }
                testChar.CharID = 0;
                testChar.Name   = "Test Character";
                testChar.CampID = 1;
                testChar.UserID = 1;
                sut.CreateCharacter(testChar);
                Lib.Character testChar2 = new Lib.Character();
                testChar2.CharID = 0;
                testChar2.Name   = "Test Character2";
                testChar2.CampID = 1;
                testChar2.UserID = 2;
                sut.CreateCharacter(testChar2);
                Data.Characters test = await db.Characters.FirstOrDefaultAsync(c => c.CharacterName == testChar.Name);

                Data.Characters test2 = await db.Characters.FirstOrDefaultAsync(c => c.CharacterName == testChar2.Name);

                bool actual = (test != null && test.GamerId == 1 && test2 != null && test2.GamerId == 2);

                Assert.True(actual);

                IList <Lib.Character> list = (IList <Lib.Character>)sut.CharacterListByUser(2);
                actual = (list.Count == 1 && list[0].Name == test2.CharacterName);

                Assert.True(actual);
            }
        }