Exemple #1
0
        public void SpellsRepository_GetKnownSpellRecord_ValidCall()
        {
            //Arrange
            //Create list of Character_Spell
            List <Spell_Character> knownSpells = CreateTestData.GetListOfKnownSpells();
            var mockSet = new Mock <DbSet <Spell_Character> >()
                          .SetupData(knownSpells, o =>
            {
                return(knownSpells.Single(x => x.Character_id.CompareTo(o.First()) == 0));
            });

            //We want to find the record that indicates Caleb can create his tower.
            var expected = CreateTestData.GetSampleKnownSpell();

            using (var mockContext = AutoMock.GetLoose())
            {
                mockContext.Mock <SpellsContext>()
                .Setup(x => x.KnownSpells).Returns(mockSet.Object);
                mockContext.Mock <SpellsContext>()
                .Setup(x => x.Set <Spell_Character>()).Returns(mockSet.Object);

                //Act
                ISpellsRepository toTest = mockContext.Create <SpellsRepository>();
                var actual = toTest.GetKnownSpellRecord(expected.Character_id, expected.Spell_id);

                //Arrange
                actual.Should().BeEquivalentTo(expected);
            }
        }
Exemple #2
0
        public void SpellsRepository_CharacterLearnsSpell_ByIDs_ValidCall()
        {
            //Arrange
            List <Spell_Character> KnownSpells = CreateTestData.GetListOfKnownSpells();
            List <Spell>           spells      = CreateTestData.GetListOfSpells();

            var mockKnownSpells = new Mock <DbSet <Spell_Character> >()
                                  .SetupData(KnownSpells, o =>
            {
                return(KnownSpells.Single(x => x.Spell_id.CompareTo(o.First()) == 0));
            });
            var mockSpells = new Mock <DbSet <Spell> >()
                             .SetupData(spells, o =>
            {
                return(spells.Single(x => x.Spell_id.CompareTo(o.First()) == 0));
            });

            //Caleb learns Eldritch blast, somehow!
            Guid Caleb_id         = Guid.Parse("11111111-2222-3333-4444-555555555555");
            Guid EldritchBlast_id = Guid.Parse("45c1a8cc-2e3e-4e29-8eeb-f9fa0cc9e27e");

            Spell EldritchBlast = new Spell
            {
                Spell_id              = Guid.Parse("45c1a8cc-2e3e-4e29-8eeb-f9fa0cc9e27e"),
                Name                  = "Eldritch Blast",
                Description           = "Cast eldritch blast",
                Level                 = 0,
                School_id             = Guid.Parse("11111111-2222-3333-4444-555555555555"),
                CastingTime           = "1 Action",
                Duration              = "Instant",
                Range                 = "60 feet",
                RequiresVerbal        = true,
                RequiresSomantic      = true,
                RequiresMaterial      = true,
                RequiresConcentration = false
            };

            using (var mockContext = AutoMock.GetLoose())
            {
                mockContext.Mock <SpellsContext>()
                .Setup(x => x.Spells).Returns(mockSpells.Object);
                mockContext.Mock <SpellsContext>()
                .Setup(x => x.KnownSpells).Returns(mockKnownSpells.Object);

                //Act
                ISpellsRepository toTest = mockContext.Create <SpellsRepository>();
                toTest.CharacterLearnsSpell(Caleb_id, EldritchBlast_id);
                var actual = toTest.GetSpellsKnownBy(Caleb_id);


                //Assert
                actual.Should().ContainEquivalentOf(EldritchBlast);
            }
        }
Exemple #3
0
        public void SpellsRepository_CharacterForgetsSpell_ValidCall()
        {
            //Arrange
            List <Spell_Character> KnownSpells = CreateTestData.GetListOfKnownSpells();
            List <Spell>           spells      = CreateTestData.GetListOfSpells();

            var mockKnownSpells = new Mock <DbSet <Spell_Character> >()
                                  .SetupData(KnownSpells, o =>
            {
                return(KnownSpells.Single(x => x.Spell_id.CompareTo(o.First()) == 0));
            });
            var mockSpells = new Mock <DbSet <Spell> >()
                             .SetupData(spells, o =>
            {
                return(spells.Single(x => x.Spell_id.CompareTo(o.First()) == 0));
            });

            //Caleb forgets Web of Fire!
            Guid  Caleb_id  = Guid.Parse("11111111-2222-3333-4444-555555555555");
            Spell WebOfFire = new Spell
            {
                Spell_id              = Guid.Parse("51b4c563-2040-4c7d-a23e-cab8d5d3c73b"),
                Name                  = "Widogast's Web Of Fire",
                Description           = "The caster deals a shitton of fire damage to the target.",
                Level                 = 4,
                School_id             = Guid.Parse("11111111-2222-3333-4444-555555555555"),
                CastingTime           = "1 Action",
                Duration              = "Instant",
                Range                 = "120 feet",
                RequiresVerbal        = true,
                RequiresSomantic      = true,
                RequiresMaterial      = true,
                RequiresConcentration = false
            };

            using (var mockContext = AutoMock.GetLoose())
            {
                mockContext.Mock <SpellsContext>()
                .Setup(x => x.Spells).Returns(mockSpells.Object);
                mockContext.Mock <SpellsContext>()
                .Setup(x => x.KnownSpells).Returns(mockKnownSpells.Object);

                //Act
                ISpellsRepository toTest = mockContext.Create <SpellsRepository>();
                toTest.CharacterForgetsSpell(Caleb_id, WebOfFire.Spell_id);
                var actual = toTest.GetSpellsKnownBy(Caleb_id);

                actual.Should().NotContain(WebOfFire);
            }
        }
Exemple #4
0
        public void SpellsRepository_GetKnownSpellRecordsForCharacter_ValidCall()
        {
            List <Spell_Character> knownSpells = CreateTestData.GetListOfKnownSpells();
            var mockSet = new Mock <DbSet <Spell_Character> >()
                          .SetupData(knownSpells, o =>
            {
                return(knownSpells.Single(x => x.Character_id.CompareTo(o.First()) == 0));
            });

            List <Spell_Character> expected    = new List <Spell_Character>();
            Spell_Character        Caleb_Tower = CreateTestData.GetSampleKnownSpell();

            expected.Add(Caleb_Tower);

            Spell_Character Caleb_WebOfFire = new Spell_Character()
            {
                Character_id = Guid.Parse("11111111-2222-3333-4444-555555555555"),
                Spell_id     = Guid.Parse("51b4c563-2040-4c7d-a23e-cab8d5d3c73b")
            };

            expected.Add(Caleb_WebOfFire);

            Guid Caleb_id = Guid.Parse("11111111-2222-3333-4444-555555555555");

            using (var mockContext = AutoMock.GetLoose())
            {
                mockContext.Mock <SpellsContext>()
                .Setup(x => x.KnownSpells).Returns(mockSet.Object);
                mockContext.Mock <SpellsContext>()
                .Setup(x => x.Set <Spell_Character>()).Returns(mockSet.Object);

                //Act
                ISpellsRepository toTest = mockContext.Create <SpellsRepository>();
                var actual = toTest.GetKnownSpellRecordsForCharacter(Caleb_id);

                //Arrange
                actual.Should().BeEquivalentTo(expected);
            }
        }
Exemple #5
0
        public void CMBuilder_buildKnownSpellRowCMsForCharacter_ValidCall()
        {
            //Arrange
            List <Spell> spells        = CreateTestData.GetListOfSpells();
            var          spellsMockSet = new Mock <DbSet <Spell> >()
                                         .SetupData(spells, o =>
            {
                return(spells.Single(x => x.Spell_id.CompareTo(o.First()) == 0));
            });

            List <Spell_Character> knownSpells = CreateTestData.GetListOfKnownSpells();
            var knownSpellsMockSet             = new Mock <DbSet <Spell_Character> >()
                                                 .SetupData(knownSpells, o =>
            {
                return(knownSpells.Single(x => x.Character_id.CompareTo(o.First()) == 0));
            });

            List <School> spellSchools   = CreateTestData.GetListOfSchools();
            var           schoolsMockSet = new Mock <DbSet <School> >()
                                           .SetupData(spellSchools, o =>
            {
                return(spellSchools.Single(x => x.School_id.CompareTo(o.First()) == 0));
            });


            //Caleb knows both his tower and Web of Fire, so we want to return CMs for both spells.
            Guid Caleb_id = Guid.Parse("11111111-2222-3333-4444-555555555555");

            List <KnownSpellRowCM> expected = new List <KnownSpellRowCM>();
            Guid            Tower_id        = Guid.Parse("46d10bb8-84d2-408d-a928-5847ff99461f");
            var             Tower           = spells.Find(x => x.Spell_id == Tower_id);
            KnownSpellRowCM TowerRow        = CharacterMapper.mapSpellToKnownSpellRowCM(Tower);

            TowerRow.School = "Conjuration";
            TowerRow.Index  = 0;
            expected.Add(TowerRow);

            Guid            WoF_id       = Guid.Parse("51b4c563-2040-4c7d-a23e-cab8d5d3c73b");
            var             WebOfFire    = spells.Find(x => x.Spell_id == WoF_id);
            KnownSpellRowCM WebOfFireRow = CharacterMapper.mapSpellToKnownSpellRowCM(WebOfFire);

            WebOfFireRow.School = "Evocation";
            WebOfFireRow.Index  = 1;
            expected.Add(WebOfFireRow);



            using (var mockContext = AutoMock.GetLoose())
            {
                mockContext.Mock <SpellsContext>()
                .Setup(x => x.Set <Spell>()).Returns(spellsMockSet.Object);
                mockContext.Mock <SpellsContext>()
                .Setup(x => x.Spells).Returns(spellsMockSet.Object);

                mockContext.Mock <SpellsContext>()
                .Setup(x => x.KnownSpells).Returns(knownSpellsMockSet.Object);
                mockContext.Mock <SpellsContext>()
                .Setup(x => x.Set <Spell_Character>()).Returns(knownSpellsMockSet.Object);

                mockContext.Mock <SpellsContext>()
                .Setup(x => x.Set <School>()).Returns(schoolsMockSet.Object);
                mockContext.Mock <SpellsContext>()
                .Setup(x => x.Schools).Returns(schoolsMockSet.Object);

                IUnitOfWork     uow    = UoW_Factory.getUnitofWork(mockContext);
                IBaseUserAccess access = UserAccessFactory.getBaseUserAccess(uow);

                //Act
                ICharacterCMBuilder toTest = ProcessorFactory.GetCharacterCMBuilder(access);
                var actual = toTest.buildKnownSpellRowCMsForCharacter(Caleb_id);

                //Assert
                actual.Should().BeEquivalentTo(expected);
            }
        }
Exemple #6
0
        public void SpellsRepository_GetSpellsKnownBy_ValidCall()
        {
            //Arrange

            //Create list of spells
            List <Spell> spells = CreateTestData.GetListOfSpells();
            //Create list of Character_Spell
            List <Spell_Character> knownSpells = CreateTestData.GetListOfKnownSpells();

            //We'll be looking for spells that Caleb knows!
            List <Spell> expected  = new List <Spell>();
            Spell        WebOfFire = new Spell
            {
                Spell_id              = Guid.Parse("51b4c563-2040-4c7d-a23e-cab8d5d3c73b"),
                Name                  = "Widogast's Web Of Fire",
                Description           = "The caster deals a shitton of fire damage to the target.",
                Level                 = 4,
                School_id             = Guid.Parse("11111111-2222-3333-4444-555555555555"),
                CastingTime           = "1 Action",
                Duration              = "Instant",
                Range                 = "120 feet",
                RequiresVerbal        = true,
                RequiresSomantic      = true,
                RequiresMaterial      = true,
                RequiresConcentration = false
            };

            expected.Add(WebOfFire);
            Spell nineSidedTower = new Spell
            {
                Spell_id              = Guid.Parse("46d10bb8-84d2-408d-a928-5847ff99461f"),
                Name                  = "Widogast's Nascent Nine-sided Tower",
                Description           = "A flavored Magnificent Mansion",
                Level                 = 7,
                School_id             = Guid.Parse("361bd911-0702-437f-ab59-a29da0f9fba4"),
                CastingTime           = "1 minute",
                Range                 = "100 feet",
                Duration              = "24 hours",
                RequiresVerbal        = true,
                RequiresSomantic      = true,
                RequiresMaterial      = false,
                RequiresConcentration = true
            };

            expected.Add(nineSidedTower);

            var spellMockSet = new Mock <DbSet <Spell> >()
                               .SetupData(spells, o =>
            {
                return(spells.Single(x => x.Spell_id.CompareTo(o.First()) == 0));
            });

            var knownSpellsMockSet = new Mock <DbSet <Spell_Character> >()
                                     .SetupData(knownSpells, o =>
            {
                return(knownSpells.Single(x => x.Character_id.CompareTo(o.First()) == 0));
            });

            using (var mockContext = AutoMock.GetLoose())
            {
                mockContext.Mock <SpellsContext>()
                .Setup(x => x.Spells).Returns(spellMockSet.Object);
                mockContext.Mock <SpellsContext>()
                .Setup(x => x.KnownSpells).Returns(knownSpellsMockSet.Object);

                //Act
                ISpellsRepository toTest = mockContext.Create <SpellsRepository>();
                var Caleb_id             = Guid.Parse("11111111-2222-3333-4444-555555555555");
                var actual = toTest.GetSpellsKnownBy(Caleb_id).ToList();

                //Assert
                actual.Should().NotBeEmpty();
                actual.Should().NotBeNull();
                actual.Should().BeOfType <List <Spell> >();
                actual.Should().BeEquivalentTo(expected);
            }
        }