예제 #1
0
        public void SpellsRepository_GetSpell_ValidCall()
        {
            //Arrange
            List <Spell> spells  = CreateTestData.GetListOfSpells();
            var          mockSet = new Mock <DbSet <Spell> >()
                                   .SetupData(spells, o =>
            {
                return(spells.Single(x => x.Spell_id.CompareTo(o.First()) == 0));
            });

            using (var mockContext = AutoMock.GetLoose())
            {
                var expected = CreateTestData.GetSampleSpell();
                var id       = expected.Spell_id;

                mockContext.Mock <SpellsContext>()
                .Setup(x => x.Set <Spell>()).Returns(mockSet.Object);

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

                //Assert
                actual.Should().NotBeNull();
                expected.Should().NotBeNull();
                actual.Should().BeOfType <Spell>();
                expected.Should().BeOfType <Spell>();
                actual.Should().BeEquivalentTo(expected);
            };
        }
        public void CharacterCommons_spellExists_returnTrue()
        {
            //Arrange
            List <Spell> listOfSpells = CreateTestData.GetListOfSpells();
            var          mockSet      = new Mock <DbSet <Spell> >()
                                        .SetupData(listOfSpells, o =>
            {
                return(listOfSpells.Single(x => x.Spell_id.CompareTo(o.First()) == 0));
            });
            var realSpell = CreateTestData.GetSampleSpell();

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

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

                //act
                ICharacterCommonFunctions toTest = ProcessorFactory.GetCharacterCommonFunctions(access);
                var actual = toTest.spellExists(realSpell.Spell_id);

                //Assert
                actual.Should().BeTrue();
            }
        }
예제 #3
0
        public void SpellsRepository_RemoveSpell_ValidCall()
        {
            //Arrange

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

            using (var mockContext = AutoMock.GetLoose())
            {
                mockContext.Mock <SpellsContext>()
                .Setup(x => x.Set <Spell>()).Returns(mockSet.Object);
                mockContext.Mock <SpellsContext>()
                //When a removal of a spell object is called, perform a callback to the charList collection, using the same spell object as an argument.
                //This callback then fires, removing the object from the list.
                .Setup(x => x.Set <Spell>().Remove(It.IsAny <Spell>()))
                .Callback <Spell>((entity) => spells.Remove(entity));

                //Act
                ISpellsRepository toTest = mockContext.Create <SpellsRepository>();
                var toBeDeleted          = CreateTestData.GetSampleSpell();
                toTest.Remove(toBeDeleted);
                var NotExpected = CreateTestData.GetSampleSpell();

                //Assert
                spells.Should().NotContain(toBeDeleted);
            }
        }
        public void CharacterCommons_spellExists_returnFalse()
        {
            //Arrange
            List <Spell> listOfSpells = CreateTestData.GetListOfSpells();
            var          mockSet      = new Mock <DbSet <Spell> >()
                                        .SetupData(listOfSpells, o =>
            {
                return(listOfSpells.Single(x => x.Spell_id.CompareTo(o.First()) == 0));
            });
            var false_id = Guid.Parse("720f467c-7621-4dcf-a82f-7af50f253068");

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

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

                //act
                ICharacterCommonFunctions toTest = ProcessorFactory.GetCharacterCommonFunctions(access);
                Action act = () => toTest.spellExists(false_id);

                //Assert
                act.Should().Throw <InvalidOperationException>().WithMessage("Sequence contains no matching element");
            }
        }
        public void CharacterServices_buildKnownSpellRowCM_ValidCall()
        {
            //Arrange
            List <Spell> spells  = CreateTestData.GetListOfSpells();
            var          mockSet = new Mock <DbSet <Spell> >()
                                   .SetupData(spells, o =>
            {
                return(spells.Single(x => x.Spell_id.CompareTo(o.First()) == 0));
            });
            var             record   = CreateTestData.GetSampleSpell();
            KnownSpellRowCM expected = CharacterMapper.mapSpellToKnownSpellRowCM(record);

            expected.Index = 1;

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

                IUnitOfWork     uow     = UoW_Factory.getUnitofWork(mockContext);
                IBaseUserAccess access  = UserAccessFactory.getBaseUserAccess(uow);
                var             creator = ProcessorFactory.getCreateCharacterProcessor(access);
                var             updater = ProcessorFactory.getUpdateCharacterProcessor(access);
                var             builder = ProcessorFactory.GetCharacterCMBuilder(access);

                //Act
                var toTest = ServicesFactory.GetCharacterService(creator, updater, builder);
                var actual = toTest.buildKnownSpellRowCM(1, record.Spell_id);
            }
        }
예제 #6
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);
            }
        }
예제 #7
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);
            }
        }
예제 #8
0
        public void SpellsRepository_GetSpellsOfSchool_ValidCall()
        {
            //Arrange
            List <Spell> spells = CreateTestData.GetListOfSpells();

            List <School> schools = CreateTestData.GetListOfSchools();

            //We're expecting the only Conjutation spell contained within the spells list - Caleb's tower.
            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
            };
            List <Spell> expected = new List <Spell>();

            expected.Add(NineSidedTower);

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

            using (var mockContext = AutoMock.GetLoose())
            {
                mockContext.Mock <SpellsContext>()
                .Setup(x => x.Spells).Returns(spellMockSet.Object);
                //Act
                ISpellsRepository toTest = mockContext.Create <SpellsRepository>();
                var conjuration_id       = NineSidedTower.School_id;
                var actual = toTest.GetSpellsOfSchool(conjuration_id);

                //Assert
                actual.Should().NotBeEmpty();
                actual.Should().NotBeNull();
                actual.Should().BeOfType <List <Spell> >();
                actual.Should().BeEquivalentTo(expected);
            }
        }
        public void SpellsSearch_DescriptionContainsFilter_DescriptionContainsMansion()
        {
            //Arrange
            List <Spell> spells  = CreateTestData.GetListOfSpells();
            var          mockSet = new Mock <DbSet <Spell> >()
                                   .SetupData(spells, o =>
            {
                return(spells.Single(x => x.Spell_id.CompareTo(o.First()) == 0));
            });

            List <Spell> expected = new List <Spell>();
            Spell        Tower    = 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(Tower);

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

                SpellsContext context = mockContext.Create <SpellsContext>();

                //Act
                SpellSearchToDecorate baseObject = new SpellSearchToDecorate(context);
                DescriptionContains   toTest     = new DescriptionContains("Mansion");
                toTest.setToBeDecorated(baseObject);
                var actual = toTest.GetSpells().ToList();

                //Assert
                actual.Should().BeEquivalentTo(expected);
            }
        }
예제 #10
0
        public void CMBuilder_buildKnownSpellRowCM_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 <School> spellSchools   = CreateTestData.GetListOfSchools();
            var           schoolsMockSet = new Mock <DbSet <School> >()
                                           .SetupData(spellSchools, o =>
            {
                return(spellSchools.Single(x => x.School_id.CompareTo(o.First()) == 0));
            });

            Guid Tower_id = Guid.Parse("46d10bb8-84d2-408d-a928-5847ff99461f");
            var  Tower    = spells.Find(x => x.Spell_id == Tower_id);

            KnownSpellRowCM expected = CharacterMapper.mapSpellToKnownSpellRowCM(Tower);

            expected.School = "Conjuration";
            expected.Index  = 0;


            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.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.buildKnownSpellRowCM(Tower.Spell_id);

                //Assert
                actual.Should().BeEquivalentTo(expected);
            }
        }
        public void CharacterCommons_spellCanBeCastByClass_returnFalse()
        {
            List <Spell_Class> spell_Classes = CreateTestData.GetListOfCastableByRecords();
            List <Spell>       spells        = CreateTestData.GetListOfSpells();
            var spellMockSet = new Mock <DbSet <Spell> >()
                               .SetupData(spells, o =>
            {
                return(spells.Single(x => x.Spell_id.CompareTo(o.First()) == 0));
            });
            var castableByMockSet = new Mock <DbSet <Spell_Class> >()
                                    .SetupData(spell_Classes, o =>
            {
                return(spell_Classes.Single(x => x.Spell_id.CompareTo(o.First()) == 0));
            });
            var realSpellID  = CreateTestData.GetSampleSpell().Spell_id;
            var falseClassID = Guid.Parse("16310468-2345-460f-a408-d9f7c908ad2a");

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

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

                //act
                ICharacterCommonFunctions toTest = ProcessorFactory.GetCharacterCommonFunctions(access);
                var actual = toTest.spellCanBeCastByClass(realSpellID, falseClassID);

                //Assert
                actual.Should().BeFalse();
            }
        }
예제 #12
0
        public void SpellSearchFacade_GetByNameContainingTOWER_ReturnPagedList()
        {
            //ensure that capitalization does not effect the search result.
            //Arrange
            List <Spell> spells  = CreateTestData.GetListOfSpells();
            var          mockSet = new Mock <DbSet <Spell> >()
                                   .SetupData(spells, o =>
            {
                return(spells.Single(x => x.Spell_id.CompareTo(o.First()) == 0));
            });

            List <foundSpellCM> expectedList = new List <foundSpellCM>();
            foundSpellCM        tower        = new foundSpellCM
            {
                Spell_id = Guid.Parse("46d10bb8-84d2-408d-a928-5847ff99461f"),
                Name     = "Widogast's Nascent Nine-sided Tower"
            };

            expectedList.Add(tower);
            IPagedList <foundSpellCM> expected = expectedList.ToPagedList(1, 20);

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

                SpellsContext context = mockContext.Create <SpellsContext>();

                //Act
                var toTest = new SpellSearchFacade(context);
                var actual = toTest.searchSpellsToPagedList("TOWER", "Name", 1);

                //Assert
                actual.Should().BeEquivalentTo(expected);
            }
        }
예제 #13
0
        public void SpellsRepository_GetSpellsCastableBy_ValidCall()
        {
            //Arrange
            List <Spell> spells = CreateTestData.GetListOfSpells();

            List <Spell_Class> CastableByRecords = CreateTestData.GetListOfCastableByRecords();

            //I expect three spells - Web of Fire, Voltaic Bolt, and the Tower, all of which can be cast by a wizard.
            List <Spell> expected       = new List <Spell>();
            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);
            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 VoltaicBolt = new Spell
            {
                Spell_id              = Guid.Parse("a9756f3d-55d0-40cd-8083-6b547e4932ab"),
                Name                  = "Brenatto's Voltaic Bolt",
                Description           = "The caster's next ranged attack deals an additional 3d6 lightning damage",
                Level                 = 1,
                School_id             = Guid.Parse("11111111-2222-3333-4444-555555555555"),
                CastingTime           = "1 Bonus Action",
                Duration              = "1 round",
                Range                 = "30 feet",
                RequiresVerbal        = false,
                RequiresSomantic      = true,
                RequiresMaterial      = true,
                RequiresConcentration = false
            };

            expected.Add(VoltaicBolt);

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

            var SpellCastableByMockSet = new Mock <DbSet <Spell_Class> >()
                                         .SetupData(CastableByRecords, o =>
            {
                return(CastableByRecords.Single(x => x.Class_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.CastableByRecords).Returns(SpellCastableByMockSet.Object);


                //Act
                ISpellsRepository toTest = mockContext.Create <SpellsRepository>();
                Guid WIzard_id           = Guid.Parse("b74e228f-015d-45b4-af0f-a6781976535a");
                var  actual = toTest.GetSpellsCastableBy(WIzard_id).ToList();

                //Assert
                actual.Should().NotBeEmpty();
                actual.Should().NotBeNull();
                actual.Should().BeOfType <List <Spell> >();
                actual.Should().BeEquivalentTo(expected);
            }
        }
예제 #14
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);
            }
        }
        public void CharacterServices_ExistingCharacterLearnsSpell_ValidCall()
        {
            //Arrange
            List <Spell>       listOfSpells     = CreateTestData.GetListOfSpells();
            List <Spell_Class> listOfCastableBy = CreateTestData.GetListOfCastableByRecords();
            List <Character_Class_Subclass> listofKnownClasses = CreateTestData.GetListOfCharacter_Class_Subclass();
            List <Spell_Character>          listOfKnownSpells  = new List <Spell_Character>();

            //Caleb should learn how to cast his tower spell.
            Spell_Character expected = CreateTestData.GetSampleKnownSpell();
            Guid            Caleb_id = expected.Character_id;
            Guid            User_id  = Guid.Parse("5f0d6374-fe3e-4337-9a0a-787db1f7b628");
            Guid            Tower_id = expected.Spell_id;

            var spellMockSet = new Mock <DbSet <Spell> >()
                               .SetupData(listOfSpells, o =>
            {
                return(listOfSpells.Single(x => x.Spell_id.CompareTo(o.First()) == 0));
            });
            var castableByMockSet = new Mock <DbSet <Spell_Class> >()
                                    .SetupData(listOfCastableBy, o =>
            {
                return(listOfCastableBy.Single(x => x.Class_id.CompareTo(o.First()) == 0));
            });
            var knownClassesMockSet = new Mock <DbSet <Character_Class_Subclass> >()
                                      .SetupData(listofKnownClasses, o =>
            {
                return(listofKnownClasses.Single(x => x.Character_id.CompareTo(o.First()) == 0));
            });
            var knownSpellsMockSet = new Mock <DbSet <Spell_Character> >()
                                     .SetupData(listOfKnownSpells, o =>
            {
                return(listOfKnownSpells.Single(x => x.Spell_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.Set <Spell>()).Returns(spellMockSet.Object);

                mockContext.Mock <SpellsContext>()
                .Setup(x => x.CastableByRecords).Returns(castableByMockSet.Object);
                mockContext.Mock <SpellsContext>()
                .Setup(x => x.Set <Spell_Class>()).Returns(castableByMockSet.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 <PlayableClassContext>()
                .Setup(x => x.KnownClasses).Returns(knownClassesMockSet.Object);
                mockContext.Mock <PlayableClassContext>()
                .Setup(x => x.Set <Character_Class_Subclass>()).Returns(knownClassesMockSet.Object);

                //Act
                ICharacterServices toTest = mockContext.Create <CharacterServices>();
                toTest.ExistingCharacterLearnsSpell(User_id, Caleb_id, Tower_id);

                //Assert
                listOfKnownSpells.Should().ContainEquivalentOf(expected);
                listOfKnownSpells.Where(x => x.Spell_id == expected.Spell_id && x.Character_id == expected.Character_id).Count().Should().Be(1);
            }
        }
예제 #16
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);
            }
        }
예제 #17
0
        public void CMBUilder_buildSpellDetailsCM_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 <School> spellSchools   = CreateTestData.GetListOfSchools();
            var           schoolsMockSet = new Mock <DbSet <School> >()
                                           .SetupData(spellSchools, o =>
            {
                return(spellSchools.Single(x => x.School_id.CompareTo(o.First()) == 0));
            });
            List <Material> materials        = CreateTestData.GetListOfMaterials();
            var             materialsMockSet = new Mock <DbSet <Material> >()
                                               .SetupData(materials, o =>
            {
                return(materials.Single(x => x.Spell_id.CompareTo(o.First()) == 0));
            });


            var VoltaicBolt_id = Guid.Parse("a9756f3d-55d0-40cd-8083-6b547e4932ab");

            //I expect to get the details CM for Brenatto's Voltaic Bolt
            var expected = new SpellDetailsCM
            {
                Spell_id              = Guid.Parse("a9756f3d-55d0-40cd-8083-6b547e4932ab"),
                Name                  = "Brenatto's Voltaic Bolt",
                Description           = "The caster's next ranged attack deals an additional 3d6 lightning damage",
                Level                 = 1,
                School                = "Evocation",
                CastingTime           = "1 Bonus Action",
                Duration              = "1 round",
                Range                 = "30 feet",
                RequiresVerbal        = false,
                RequiresSomantic      = true,
                RequiresMaterial      = true,
                RequiresConcentration = false,
                Material              = "A bit of fleece"
            };

            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.Set <School>()).Returns(schoolsMockSet.Object);
                mockContext.Mock <SpellsContext>()
                .Setup(x => x.Schools).Returns(schoolsMockSet.Object);

                mockContext.Mock <SpellsContext>()
                .Setup(x => x.Materials).Returns(materialsMockSet.Object);
                mockContext.Mock <SpellsContext>()
                .Setup(x => x.Set <Material>()).Returns(materialsMockSet.Object);

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

                //Act
                ICharacterCMBuilder toTest = ProcessorFactory.GetCharacterCMBuilder(access);
                var actual = toTest.buildSpellDetailsCM(VoltaicBolt_id);

                //Assert
                actual.Should().BeEquivalentTo(expected);
            }
        }