public void CharacterCommons_AddNoteToDb_ValidCall()
        {
            //Arrange
            List <Note> notes   = new List <Note>();
            var         mockSet = new Mock <DbSet <Note> >()
                                  .SetupData(notes, o =>
            {
                return(notes.Single(x => x.Character_id.CompareTo(o.First()) == 0));
            });
            Note expected = CreateTestData.GetSampleNote();

            using (var mockContext = AutoMock.GetLoose()){
                mockContext.Mock <CharacterContext>()
                .Setup(x => x.Notes).Returns(mockSet.Object);
                mockContext.Mock <CharacterContext>()
                .Setup(x => x.Set <Note>()).Returns(mockSet.Object);

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

                //act
                ICharacterCommonFunctions toTest = ProcessorFactory.GetCharacterCommonFunctions(access);
                toTest.addNote(expected);

                notes.Should().ContainEquivalentOf(expected);
            }
        }
Example #2
0
        public void ItemManagerUserAccess_RemoveItemByID_ValidCall()
        {
            //Arrange

            List <Item> Items   = CreateTestData.GetListOfItems();
            var         mockSet = new Mock <DbSet <Item> >()
                                  .SetupData(Items, o =>
            {
                return(Items.Single(x => x.Item_id.CompareTo(o.First()) == 0));
            });

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

                //Act
                IUnitOfWork             UoW    = mockContext.Create <UnitOfWork>();
                IItemsManagerUserAccess toTest = UserAccessFactory.getItemsManagerUserAccess(UoW);
                var toBeDeleted = CreateTestData.GetSampleItem();
                toTest.RemoveItemById(toBeDeleted.Item_id);
                var NotExpected = CreateTestData.GetSampleItem();

                //Assert
                Items.Should().NotContain(toBeDeleted);
            }
        }
        public void CharacterCommons_RemoveNonExistantSpellFromKnownSpells_ValidCall()
        {
            //Arrange
            List <KnownSpellRowCM> KnownSpellRowCMs = new List <KnownSpellRowCM>();
            List <KnownSpellRowCM> expected         = new List <KnownSpellRowCM>();

            KnownSpellRowCM realSpell = new KnownSpellRowCM()
            {
                Spell_id = CreateTestData.GetSampleSpell().Spell_id
            };

            expected.Add(realSpell);
            KnownSpellRowCMs.Add(realSpell);
            KnownSpellRowCM fakeSpell = new KnownSpellRowCM()
            {
                Spell_id = Guid.Parse("96bd962c-5283-4f28-8a39-e82dbe01ff1a")
            };

            KnownSpellRowCMs.Add(fakeSpell);
            KnownSpellRowCM[] knownSpellArray = KnownSpellRowCMs.ToArray();

            using (var mockContext = AutoMock.GetLoose())
            {
                IUnitOfWork     uow    = UoW_Factory.getUnitofWork(mockContext);
                IBaseUserAccess access = UserAccessFactory.getBaseUserAccess(uow);

                //act
                ICharacterCommonFunctions toTest = ProcessorFactory.GetCharacterCommonFunctions(access);
                var actual = toTest.removeNonExistantSpellCMFromKnownSpells(knownSpellArray, fakeSpell.Spell_id);

                //Assert
                actual.Should().BeEquivalentTo(expected.ToArray());
            }
        }
        public void CharacterCommons_RemoveNonExistantItemFromHeldItems_ValidCall()
        {
            HeldItemRowCM[] heldItems = new HeldItemRowCM[2];
            HeldItemRowCM[] expected  = new HeldItemRowCM[1];
            HeldItemRowCM   realItem  = new HeldItemRowCM
            {
                Item_id = CreateTestData.GetSampleItem().Item_id
            };

            heldItems[0] = realItem;
            expected[0]  = realItem;
            Guid          false_id = Guid.Parse("96bd962c-5283-4f28-8a39-e82dbe01ff1a");
            HeldItemRowCM fakeItem = new HeldItemRowCM
            {
                Item_id = false_id
            };

            heldItems[1] = fakeItem;

            using (var mockContext = AutoMock.GetLoose())
            {
                IUnitOfWork     uow    = UoW_Factory.getUnitofWork(mockContext);
                IBaseUserAccess access = UserAccessFactory.getBaseUserAccess(uow);

                //act
                ICharacterCommonFunctions toTest = ProcessorFactory.GetCharacterCommonFunctions(access);
                var actual = toTest.removeNonExistantItemFromHeldItems(heldItems, false_id);

                //Assert
                actual.Should().BeEquivalentTo(expected);
                actual.Should().NotBeEquivalentTo(heldItems);
            }
        }
        public void CharacterCommons_subclassExists_returnTrue()
        {
            //Arrange
            List <Subclass> subclasses = CreateTestData.GetListOfSubclass();
            var             mockSet    = new Mock <DbSet <Subclass> >()
                                         .SetupData(subclasses, o =>
            {
                return(subclasses.Single(x => x.Subclass_id.CompareTo(o.First()) == 0));
            });
            var realSubclass = CreateTestData.GetSubclass();

            using (var mockContext = AutoMock.GetLoose())
            {
                mockContext.Mock <PlayableClassContext>()
                .Setup(x => x.Subclasses).Returns(mockSet.Object);
                mockContext.Mock <PlayableClassContext>()
                .Setup(x => x.Set <Subclass>()).Returns(mockSet.Object);

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

                //act
                ICharacterCommonFunctions toTest = ProcessorFactory.GetCharacterCommonFunctions(access);
                var actual = toTest.subclassExists(realSubclass.Subclass_id);

                //Assert
                actual.Should().BeTrue();
            }
        }
        public void CharacterCommons_itemExists_returnTrue()
        {
            //Arrange
            List <Item> items   = CreateTestData.GetListOfItems();
            var         mockSet = new Mock <DbSet <Item> >()
                                  .SetupData(items, o =>
            {
                return(items.Single(x => x.Item_id.CompareTo(o.First()) == 0));
            });

            var realItem = CreateTestData.GetSampleItem();

            using (var mockContext = AutoMock.GetLoose())
            {
                mockContext.Mock <ItemsContext>()
                .Setup(x => x.Items).Returns(mockSet.Object);
                mockContext.Mock <ItemsContext>()
                .Setup(x => x.Set <Item>()).Returns(mockSet.Object);

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

                //Act
                ICharacterCommonFunctions toTest = ProcessorFactory.GetCharacterCommonFunctions(access);
                var actual = toTest.itemExists(realItem.Item_id);

                actual.Should().BeTrue();
            }
        }
Example #7
0
        public void CMBuilder_buildNewClassRowCM()
        {
            //Arrange
            List <PlayableClass>    playableClasses = CreateTestData.GetPlayableClasses();
            List <ClassesListModel> ClassesLM       = new List <ClassesListModel>();

            foreach (PlayableClass playableClass in playableClasses)
            {
                ReadModelMapper <PlayableClass, ClassesListModel> mapper = new ReadModelMapper <PlayableClass, ClassesListModel>();
                ClassesListModel lm = mapper.mapDataModelToViewModel(playableClass);
                ClassesLM.Add(lm);
            }

            var expected = new ClassRowCM
            {
                Index            = 5,
                Level            = 1,
                RemainingHitDice = 1,
                playableClasses  = ClassesLM.ToArray()
            };

            using (var mockAccess = AutoMock.GetLoose())
            {
                mockAccess.Mock <IBaseUserAccess>()
                .Setup(x => x.GetAllPlayableClasses()).Returns(playableClasses);

                IBaseUserAccess access = mockAccess.Create <IBaseUserAccess>();
                //Act
                ICharacterCMBuilder toTest = ProcessorFactory.GetCharacterCMBuilder(access);
                var actual = toTest.buildNewClassRowCM(5);

                //Assert
                actual.Should().BeEquivalentTo(expected);
            }
        }
        public void PlayableClassRepository_RemoveClass_ValidCall()
        {
            //Arrange
            List <PlayableClass> listofPlayableClass = CreateTestData.GetPlayableClasses();

            var mockSet = new Mock <DbSet <PlayableClass> >()
                          .SetupData(listofPlayableClass, o =>
            {
                return(listofPlayableClass.Single(x => x.Class_id.CompareTo(o.First()) == 0));
            });
            var toBeDeleted = CreateTestData.GetSampleClass();

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

                //Act
                var toTest = mockContext.Create <PlayableClassRepository>();
                toTest.Remove(toBeDeleted);
                var actual = toTest.GetAll();
                //Assert
                actual.Should().NotContain(toBeDeleted);
            }
        }
Example #9
0
        public void SubclassAbilitiesRepo_RemoveSubclassAbility_ValidCall()
        {
            //Arrange
            List <SubclassAbility> listofSubclassAbility = CreateTestData.GetListOfSubclassAbility();
            SubclassAbility        notExpected           = CreateTestData.GetSubclassAbility();

            var mockSet = new Mock <DbSet <SubclassAbility> >()
                          .SetupData(listofSubclassAbility, o =>
            {
                return(listofSubclassAbility.Single(x => x.Subclass_id.CompareTo(o.First()) == 0));
            });

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

                //Act
                var toTest = mockContext.Create <SubclassAbilityRepository>();
                toTest.Remove(notExpected);

                //Assert
                listofSubclassAbility.Should().NotContain(notExpected);
            }
        }
Example #10
0
        public void SubclassAbilitiesRepo_GetSubclassAbility_ValidCall()
        {
            //Arrange
            List <SubclassAbility> listofSubclassAbility = CreateTestData.GetListOfSubclassAbility();
            SubclassAbility        expected = CreateTestData.GetSubclassAbility();
            var mockSet = new Mock <DbSet <SubclassAbility> >()
                          .SetupData(listofSubclassAbility, o =>
            {
                return(listofSubclassAbility.Single(x => x.SubclassAbility_id.CompareTo(o.First()) == 0));
            });

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

                //Act
                var toTest = mockContext.Create <SubclassAbilityRepository>();
                var actual = toTest.Get(expected.SubclassAbility_id);

                //Assert
                actual.Should().NotBeNull();
                actual.Should().BeOfType <SubclassAbility>();
                actual.Should().BeEquivalentTo(expected);
            }
        }
        public void StatsRepository_GetStatsRecord_ValidCall()
        {
            List <Stats> statsList = CreateTestData.GetListOfStats();
            var          mockSet   = new Mock <DbSet <Stats> >()
                                     .SetupData(statsList, o =>
            {
                return(statsList.Single(x => x.Character_id.CompareTo(o.First()) == 0));
            });

            using (var mockContext = AutoMock.GetLoose())
            {
                var expected = CreateTestData.GetSampleStats();
                mockContext.Mock <CharacterContext>()
                .Setup(x => x.Set <Stats>()).Returns(mockSet.Object);

                //Act
                IStatsRepository toTest = mockContext.Create <StatsRepository>();
                var actual = toTest.Get(expected.Character_id);

                actual.Should().NotBeNull();
                expected.Should().NotBeNull();
                actual.Should().BeOfType <Stats>();
                expected.Should().BeOfType <Stats>();
                actual.Should().BeEquivalentTo(expected);
            }
        }
        public void EFRepository__GetNote_ValidCall()
        {
            //Arrange
            List <Note> listOfNotes = CreateTestData.GetListOfNotes();
            var         mockSet     = new Mock <DbSet <Note> >()
                                      .SetupData(listOfNotes, o =>
            {
                return(listOfNotes.Single(x => x.Note_id.CompareTo(o.First()) == 0));
            });

            using (var mockContext = AutoMock.GetLoose())
            {
                var expected = CreateTestData.GetSampleNote();
                mockContext.Mock <CharacterContext>()
                .Setup(x => x.Set <Note>()).Returns(mockSet.Object);

                //Act
                INotesRepository toTest = mockContext.Create <NotesRepository>();
                var actual = toTest.Get(expected.Note_id);

                //Assert
                actual.Should().NotBeNull();
                expected.Should().NotBeNull();
                actual.Should().BeOfType <Note>();
                expected.Should().BeOfType <Note>();
                actual.Should().BeEquivalentTo(expected);
            }
        }
        public void EFRepository_AddNote_ValidCall()
        {
            List <Note> listOfNotes = CreateTestData.GetListOfNotes();
            var         mockSet     = new Mock <DbSet <Note> >()
                                      .SetupData(listOfNotes, o =>
            {
                return(listOfNotes.Single(x => x.Note_id.CompareTo(o.First()) == 0));
            });

            using (var mockContext = AutoMock.GetLoose())
            {
                var expected = CreateTestData.GetSampleNote();
                var id       = Guid.Parse("b346eee6-eba7-4ea7-be2e-911bb9034233");
                expected.Note_id = id;

                mockContext.Mock <CharacterContext>()
                .Setup(x => x.Set <Note>()).Returns(mockSet.Object);

                //Act
                INotesRepository toTest = mockContext.Create <NotesRepository>();
                toTest.Add(expected);
                var actual = toTest.Get(id);

                //Assert
                actual.Should().NotBeNull();
                expected.Should().NotBeNull();
                actual.Should().BeOfType <Note>();
                expected.Should().BeOfType <Note>();
                actual.Should().BeEquivalentTo(expected);
            }
        }
        public void EFRepository__DeleteNote_ValidCall()
        {
            //Arrange
            List <Note> listOfNotes = CreateTestData.GetListOfNotes();
            var         mockSet     = new Mock <DbSet <Note> >()
                                      .SetupData(listOfNotes, o =>
            {
                return(listOfNotes.Single(x => x.Note_id.CompareTo(o.First()) == 0));
            });

            using (var mockContext = AutoMock.GetLoose())
            {
                var ToBeDeleted = CreateTestData.GetSampleNote();

                mockContext.Mock <CharacterContext>()
                .Setup(x => x.Set <Note>()).Returns(mockSet.Object);

                //Act
                INotesRepository toTest = mockContext.Create <NotesRepository>();
                toTest.Remove(ToBeDeleted.Note_id);

                //Assert
                listOfNotes.Should().NotBeEmpty();
                listOfNotes.Should().NotContain(ToBeDeleted);
                listOfNotes.Should().BeOfType <List <Note> >();
            }
        }
Example #15
0
        public void ItemsRepository_GetItem_ValidCall()
        {
            //Arrange
            List <Item> Items   = CreateTestData.GetListOfItems();
            var         mockSet = new Mock <DbSet <Item> >()
                                  .SetupData(Items, o =>
            {
                return(Items.Single(x => x.Item_id.CompareTo(o.First()) == 0));
            });

            using (var mockContext = AutoMock.GetLoose())
            {
                var expected = CreateTestData.GetSampleItem();
                var id       = expected.Item_id;

                mockContext.Mock <ItemsContext>()
                .Setup(x => x.Set <Item>()).Returns(mockSet.Object);

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

                //Assert
                actual.Should().NotBeNull();
                expected.Should().NotBeNull();
                actual.Should().BeOfType <Item>();
                expected.Should().BeOfType <Item>();
                actual.Should().BeEquivalentTo(expected);
            };
        }
        public void PlayableClassRepository_CharacterForgetsClass_ValidCall()
        {
            //Arrange
            List <Character_Class_Subclass> listofCharacter_Class_Subclass = CreateTestData.GetListOfCharacter_Class_Subclass();

            var mockSet = new Mock <DbSet <Character_Class_Subclass> >()
                          .SetupData(listofCharacter_Class_Subclass, o =>
            {
                return(listofCharacter_Class_Subclass.Single(x => x.Class_id.CompareTo(o.First()) == 0));
            });
            var toBeDeleted = new Character_Class_Subclass
            {
                Character_id = Guid.Parse("6983e8dc-3e3c-4853-ac49-ba33f236723a"),
                Class_id     = Guid.Parse("15478d70-f96e-4c14-aeaf-4a1e35605874")
            };

            using (var mockContext = AutoMock.GetLoose())
            {
                mockContext.Mock <PlayableClassContext>()
                .Setup(x => x.KnownClasses).Returns(mockSet.Object);

                //Act
                var toTest = mockContext.Create <PlayableClassRepository>();
                toTest.CharacterForgetsClass(toBeDeleted.Character_id, toBeDeleted.Class_id);

                //Assert
                listofCharacter_Class_Subclass.Should().NotContain(toBeDeleted);
            }
        }
Example #17
0
        public void ItemsRepository_GetHeldItemRecord_ValidCall()
        {
            //Arrange
            List <Character_Item> heldItems = CreateTestData.GetListOfHeldItems();


            var heldItemsMockSet = new Mock <DbSet <Character_Item> >()
                                   .SetupData(heldItems, o =>
            {
                return(heldItems.Single(x => x.Character_id.CompareTo(o.First()) == 0));
            });


            var expected = CreateTestData.GetSampleHeldItem();

            using (var mockContext = AutoMock.GetLoose())
            {
                mockContext.Mock <ItemsContext>()
                .Setup(x => x.HeldItems).Returns(heldItemsMockSet.Object);

                mockContext.Mock <ItemsContext>()
                .Setup(x => x.Set <Character_Item>()).Returns(heldItemsMockSet.Object);

                //Act
                IItemsRepository toTest = mockContext.Create <ItemsRepository>();
                var actual = toTest.GetHeldItemRecord(expected.Character_id, expected.Item_id);

                //Assert
                actual.Should().BeEquivalentTo(expected);
            }
        }
        public void CharacterCommons_CharacterLearnsSpell_ValidCall()
        {
            //Arrange
            List <Spell_Character> knownSpells = new List <Spell_Character>();
            var mockSet = new Mock <DbSet <Spell_Character> >()
                          .SetupData(knownSpells, o =>
            {
                return(knownSpells.Single(x => x.Character_id.CompareTo(o.First()) == 0));
            });
            Spell_Character 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);

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

                //act
                ICharacterCommonFunctions toTest = ProcessorFactory.GetCharacterCommonFunctions(access);
                toTest.characterLearnsSpell(expected.Character_id, expected.Spell_id);

                //Assert
                knownSpells.Should().ContainEquivalentOf(expected);
            }
        }
Example #19
0
        public void SubclassRepo_GetAllSubclassesForClass_ValidCall()
        {
            //Arrange
            List <Subclass> subclasses        = CreateTestData.GetListOfSubclass();
            var             subclassesMockSet = new Mock <DbSet <Subclass> >()
                                                .SetupData(subclasses, o =>
            {
                return(subclasses.Single(x => x.Subclass_id.CompareTo(o.First()) == 0));
            });

            List <Subclass> expected   = new List <Subclass>();
            Subclass        gunslinger = CreateTestData.GetSubclass();

            expected.Add(gunslinger);

            using (var mockContext = AutoMock.GetLoose())
            {
                mockContext.Mock <PlayableClassContext>()
                .Setup(x => x.Subclasses).Returns(subclassesMockSet.Object);

                //Act
                var toTest = mockContext.Create <SubclassRepository>();
                var actual = toTest.GetAllSubclassesForClass(gunslinger.Class_id);

                //Assert
                actual.Should().NotBeNull();
                expected.Should().NotBeNull();
                actual.Should().BeOfType <List <Subclass> >();
                expected.Should().BeOfType <List <Subclass> >();
                actual.Should().BeEquivalentTo(expected);
            }
        }
        public void CharacterCommons_CharacterObtainsItem_ValidCall()
        {
            //Arrange
            List <Character_Item> heldItems = new List <Character_Item>();
            var mockSet = new Mock <DbSet <Character_Item> >()
                          .SetupData(heldItems, o =>
            {
                return(heldItems.Single(x => x.Character_id.CompareTo(o.First()) == 0));
            });
            Character_Item expected = new Character_Item
            {
                Character_id = CreateTestData.getSampleCharacter().Character_id,
                Item_id      = CreateTestData.GetSampleItem().Item_id,
                count        = 1
            };

            using (var mockContext = AutoMock.GetLoose())
            {
                mockContext.Mock <ItemsContext>()
                .Setup(x => x.HeldItems).Returns(mockSet.Object);
                mockContext.Mock <ItemsContext>()
                .Setup(x => x.Set <Character_Item>()).Returns(mockSet.Object);

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

                //act
                ICharacterCommonFunctions toTest = ProcessorFactory.GetCharacterCommonFunctions(access);
                toTest.addHeldItemToDb(expected.Character_id, expected.Item_id);

                //Assert
                heldItems.Should().ContainEquivalentOf(expected);
            }
        }
        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);
            }
        }
        public void CharacterCommons_itemExists_returnFalse()
        {
            //Arrange
            List <Item> items   = CreateTestData.GetListOfItems();
            var         mockSet = new Mock <DbSet <Item> >()
                                  .SetupData(items, o =>
            {
                return(items.Single(x => x.Item_id.CompareTo(o.First()) == 0));
            });

            var false_id = Guid.Parse("720f467c-7621-4dcf-a82f-7af50f253068");

            using (var mockContext = AutoMock.GetLoose())
            {
                mockContext.Mock <ItemsContext>()
                .Setup(x => x.Items).Returns(mockSet.Object);
                mockContext.Mock <ItemsContext>()
                .Setup(x => x.Set <Item>()).Returns(mockSet.Object);

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

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

                //Assert
                act.Should().Throw <InvalidOperationException>().WithMessage("Sequence contains no matching element");
            }
        }
        public void CharacterSerivces_buildHeldItemRowCM_ValidCall()
        {
            List <Item> items        = CreateTestData.GetListOfItems();
            var         itemsMockSet = new Mock <DbSet <Item> >()
                                       .SetupData(items, o =>
            {
                return(items.Single(x => x.Item_id.CompareTo(o.First()) == 0));
            });
            HeldItemRowCM expected = CharacterMapper.mapItemToHeldItemRowCM(CreateTestData.GetSampleItem());
            Item          record   = CreateTestData.GetSampleItem();

            expected.Count      = 1;
            expected.isAttuned  = false;
            expected.isEquipped = false;
            expected.Index      = 1;
            using (var mockContext = AutoMock.GetLoose())
            {
                mockContext.Mock <ItemsContext>()
                .Setup(x => x.Set <Item>()).Returns(itemsMockSet.Object);
                mockContext.Mock <ItemsContext>()
                .Setup(x => x.Items).Returns(itemsMockSet.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.buildHeldItemRowCM(1, record.Item_id);

                actual.Should().BeEquivalentTo(expected);
            }
        }
        public void CharacterCommons_RemoveNonExistantClassIDFromSelectedClasses_ValidCall()
        {
            //Arrange
            Guid[] selectedClasses = new Guid[2];
            Guid[] expected        = new Guid[1];
            var    falseClass_id   = Guid.Parse("96bd962c-5283-4f28-8a39-e82dbe01ff1a");

            selectedClasses[0] = CreateTestData.GetSampleClass().Class_id;
            expected[0]        = CreateTestData.GetSampleClass().Class_id;
            selectedClasses[1] = falseClass_id;

            using (var mockContext = AutoMock.GetLoose())
            {
                IUnitOfWork     uow    = UoW_Factory.getUnitofWork(mockContext);
                IBaseUserAccess access = UserAccessFactory.getBaseUserAccess(uow);

                //act
                ICharacterCommonFunctions toTest = ProcessorFactory.GetCharacterCommonFunctions(access);
                var actual = toTest.removeNonExistantClassIdFromSelectedClasses(selectedClasses, falseClass_id);

                //Assert
                actual.Should().BeEquivalentTo(expected);
                actual.Should().NotBeEquivalentTo(selectedClasses);
            }
        }
        public void PlayableClassRepository_GetPlayableClass_ValidCall()
        {
            //Arrange

            List <PlayableClass> playableClasses = CreateTestData.GetPlayableClasses();

            var mockSet = new Mock <DbSet <PlayableClass> >()
                          .SetupData(playableClasses, o =>
            {
                return(playableClasses.Single(x => x.Class_id.CompareTo(o.First()) == 0));
            });
            var expected = CreateTestData.GetSampleClass();

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

                //Act
                var toTest = mockContext.Create <PlayableClassRepository>();
                var actual = toTest.Get(expected.Class_id);

                //Assert
                actual.Should().BeEquivalentTo(expected);
            }
        }
        public void CharacterCommons_CharacterLearnsClassSubclass_ValidCall()
        {
            List <Character_Class_Subclass> knownClasses = new List <Character_Class_Subclass>();
            var mockSet = new Mock <DbSet <Character_Class_Subclass> >()
                          .SetupData(knownClasses, o =>
            {
                return(knownClasses.Single(x => x.Character_id.CompareTo(o.First()) == 0));
            });
            Character_Class_Subclass expected = CreateTestData.GetCharacter_Class_Subclass();

            using (var mockContext = AutoMock.GetLoose())
            {
                mockContext.Mock <PlayableClassContext>()
                .Setup(x => x.KnownClasses).Returns(mockSet.Object);
                mockContext.Mock <PlayableClassContext>()
                .Setup(x => x.Set <Character_Class_Subclass>()).Returns(mockSet.Object);

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

                //act
                ICharacterCommonFunctions toTest = ProcessorFactory.GetCharacterCommonFunctions(access);
                toTest.characterLearnsClass(expected);

                //Assert
                knownClasses.Should().ContainEquivalentOf(expected);
            }
        }
        public void PlayableClassRepository_GetClassesOfCharacter_ValidCall()
        {
            //Arrange
            List <PlayableClass>            playableClasses = CreateTestData.GetPlayableClasses();
            List <Character_Class_Subclass> knownclasses    = CreateTestData.GetListOfCharacter_Class_Subclass();

            var classMockSet = new Mock <DbSet <PlayableClass> >()
                               .SetupData(playableClasses, o =>
            {
                return(playableClasses.Single(x => x.Class_id.CompareTo(o.First()) == 0));
            });
            var knownClassesMockSet = new Mock <DbSet <Character_Class_Subclass> >()
                                      .SetupData(knownclasses, o =>
            {
                return(knownclasses.Single(x => x.Character_id.CompareTo(o.First()) == 0));
            });
            var Percy_id = Guid.Parse("6983e8dc-3e3c-4853-ac49-ba33f236723a");
            var expected = CreateTestData.GetSampleClass();

            using (var mockContext = AutoMock.GetLoose())
            {
                mockContext.Mock <PlayableClassContext>()
                .Setup(x => x.Classes).Returns(classMockSet.Object);
                mockContext.Mock <PlayableClassContext>()
                .Setup(x => x.KnownClasses).Returns(knownClassesMockSet.Object);

                //Act
                var toTest = mockContext.Create <PlayableClassRepository>();
                var actual = toTest.GetClassesOfCharacter(Percy_id);

                //Assert
                actual.Should().ContainEquivalentOf(expected);
            }
        }
        public void completePersonalInformation()
        {
            var testData  = new CreateTestData();
            var myAccount = new MyAccountPage(driver);

            string password  = testData.generatePassword(10, true);
            string firstName = testData.GenRandomFirstName();

            enteredFirstName = firstName;
            string lastName = testData.GenRandomLastName();

            enteredLastName = lastName;



            mrRadioBtn.Click();
            firstNamefield.Click();
            firstNamefield.SendKeys(firstName);
            lastNamefield.Click();
            lastNamefield.SendKeys(lastName);
            passwordField.SendKeys(password);
            string autoCompletedFirstName = addressFirstNameField.GetAttribute("value");
            string autoCompletedLastName  = addressLastNameField.GetAttribute("value");

            Assert.AreEqual(firstName, autoCompletedFirstName);
            Assert.AreEqual(lastName, autoCompletedLastName);
        }
        public void PlayableClassRepository_GetAllKnownClassRecordsOfCharacter_ValidCall()
        {
            //Arrange
            List <Character_Class_Subclass> listofCharacter_Class_Subclass = CreateTestData.GetListOfCharacter_Class_Subclass();

            var mockSet = new Mock <DbSet <Character_Class_Subclass> >()
                          .SetupData(listofCharacter_Class_Subclass, o =>
            {
                return(listofCharacter_Class_Subclass.Single(x => x.Class_id.CompareTo(o.First()) == 0));
            });
            var expected = new Character_Class_Subclass
            {
                Character_id     = Guid.Parse("da7d6227-d330-44ab-8001-880dbf52110a"),
                Class_id         = Guid.Parse("969c08ca-f983-4ddd-b351-31962f2429cd"),
                Subclass_id      = Guid.Parse("c7de67ae-3a65-4261-9c09-05a7b0c527bb"),
                RemainingHitDice = 20,
                ClassLevel       = 20
            };

            using (var mockContext = AutoMock.GetLoose())
            {
                mockContext.Mock <PlayableClassContext>()
                .Setup(x => x.KnownClasses).Returns(mockSet.Object);

                //Act
                var toTest = mockContext.Create <PlayableClassRepository>();
                var actual = toTest.GetAllKnownClassRecordsOfCharacter(expected.Character_id);

                //Assert
                actual.Should().ContainEquivalentOf(expected);
            }
        }
Example #30
0
        public void ItemManagerUserAccess_AddItem_ValidCall()
        {
            //Arrange
            List <Item> items   = new List <Item>();
            var         mockSet = new Mock <DbSet <Item> >()
                                  .SetupData(items, o =>
            {
                return(items.Single(x => x.Item_id.CompareTo(o.First()) == 0));
            });

            using (var mockContext = AutoMock.GetLoose())
            {
                var expected = CreateTestData.GetSampleItem();
                var id       = expected.Item_id;

                mockContext.Mock <ItemsContext>()
                .Setup(x => x.Set <Item>()).Returns(mockSet.Object);

                //Act
                IUnitOfWork             UoW    = mockContext.Create <UnitOfWork>();
                IItemsManagerUserAccess toTest = UserAccessFactory.getItemsManagerUserAccess(UoW);
                toTest.AddItem(expected);
                var actual = toTest.GetItem(id);

                //Assert
                actual.Should().NotBeNull();
                expected.Should().NotBeNull();
                actual.Should().BeOfType <Item>();
                expected.Should().BeOfType <Item>();
                actual.Should().BeEquivalentTo(expected);
            }
        }
        private CreateTestData GetCreateTestData(IProjectRepository sut, string projectId=null)
        {
            var returnValue = new CreateTestData();
            if(string.IsNullOrEmpty(projectId))
            {
                returnValue.Project = this.CreateTestProject(sut);
            }
            else 
            {
                returnValue.Project = sut.GetProject(projectId);
            }
            var componentList = this.CreateTestComponentList(returnValue.Project.Id, 5, sut);
            var configurationList = this.CreateTestConfigurationList(returnValue.Project.Id, 3, sut);

            returnValue.EnvironmentComponentList = (from i in componentList
                                                    select GetCreateTestDeployEnvironmentConfiguration(i)).ToList();

            returnValue.EnvironmentConfigurationList = (from i in configurationList
                                                            select GetCreateTestDeployEnvironmentConfiguration(i)).ToList();

            returnValue.EnvironmentName = this.Fixture.Create<string>("EnvironmentName");

            return returnValue;
        }