Пример #1
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);
            }
        }
Пример #2
0
        public void PlayableClassManager_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
                IUnitOfWork             worker = mockContext.Create <UnitOfWork>();
                IClassManagerUserAccess toTest = UserAccessFactory.GetClassManagerUserAccess(worker);
                toTest.RemovePlayableClass(toBeDeleted);

                //Assert
                listofPlayableClass.Should().NotContain(toBeDeleted);
            }
        }
Пример #3
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);
            }
        }
Пример #4
0
        public void RaceManager_RemoveRace_ValidCall()
        {
            //Arrange
            List <Race> races   = CreateTestData.GetListOfRace();
            var         mockSet = new Mock <DbSet <Race> >()
                                  .SetupData(races, o =>
            {
                return(races.Single(x => x.Race_id.CompareTo(o.First()) == 0));
            });
            var toBeDeleted = CreateTestData.GetSampleRace();

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

                //Act
                IUnitOfWork            worker = mockContext.Create <UnitOfWork>();
                IRaceManagerUserAccess toTest = UserAccessFactory.GetRaceManagerUserAccess(worker);
                toTest.RemoveRace(toBeDeleted);

                //Assert
                races.Should().NotContain(toBeDeleted);
            }
        }
Пример #5
0
        public void PlayableClassManager_AddAbility_ValidCall()
        {
            //Arrange
            List <ClassAbility> listofClassAbility = new List <ClassAbility>();
            var mockSet = new Mock <DbSet <ClassAbility> >()
                          .SetupData(listofClassAbility, o =>
            {
                return(listofClassAbility.Single(x => x.Class_id.CompareTo(o.First()) == 0));
            });
            var expected = CreateTestData.GetClassAbility();

            using (var mockContext = AutoMock.GetLoose())
            {
                mockContext.Mock <PlayableClassContext>()
                //The argument for setup *MUST* be an exact match for the syntax we use in the implementation. Otherwise, the test will fail!
                .Setup(x => x.Set <ClassAbility>()).Returns(mockSet.Object);

                //Act
                IUnitOfWork             worker = mockContext.Create <UnitOfWork>();
                IClassManagerUserAccess toTest = UserAccessFactory.GetClassManagerUserAccess(worker);
                toTest.AddAbility(expected);

                //Assert
                listofClassAbility.Should().ContainEquivalentOf(expected);
            }
        }
Пример #6
0
        public void PlayableClassManager_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
                IUnitOfWork             worker = mockContext.Create <UnitOfWork>();
                IClassManagerUserAccess toTest = UserAccessFactory.GetClassManagerUserAccess(worker);

                toTest.RemoveSubclassAbility(notExpected);

                //Assert
                listofSubclassAbility.Should().NotContain(notExpected);
            }
        }
Пример #7
0
        public void PlayableClassManager_AddSubclasses_ValidCall()
        {
            //Arrange
            List <Subclass> listofSubclass = new List <Subclass>();

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

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

                //Act
                IUnitOfWork             worker = mockContext.Create <UnitOfWork>();
                IClassManagerUserAccess toTest = UserAccessFactory.GetClassManagerUserAccess(worker);
                toTest.AddSubclasses(expected);

                //Assert
                listofSubclass.Should().BeEquivalentTo(expected);
            }
        }
Пример #8
0
        public void PlayableClassManager_GetAllClassAbilities_ValidCall()
        {
            //Arrange
            List <ClassAbility> listofClassAbility = CreateTestData.GetListOfClassAbility();

            var mockSet = new Mock <DbSet <ClassAbility> >()
                          .SetupData(listofClassAbility, o =>
            {
                return(listofClassAbility.Single(x => x.ClassAbility_id.CompareTo(o.First()) == 0));
            });
            var expected = CreateTestData.GetListOfClassAbility();

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

                //Act
                IUnitOfWork             worker = mockContext.Create <UnitOfWork>();
                IClassManagerUserAccess toTest = UserAccessFactory.GetClassManagerUserAccess(worker);
                var actual = toTest.GetAllClassAbilities();

                //Assert
                actual.Should().BeEquivalentTo(expected);
            }
        }
Пример #9
0
        public void SPellManagerUserAccess_AddSpellMaterials_ValidCall()
        {
            //Arrange
            List <Material> Materials = new List <Material>();
            var             mockSet   = new Mock <DbSet <Material> >()
                                        .SetupData(Materials, o =>
            {
                return(Materials.Single(x => x.Spell_id.CompareTo(o.First()) == 0));
            });

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

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

                //Act
                IUnitOfWork             UoW    = mockContext.Create <UnitOfWork>();
                ISpellManagerUserAccess toTest = UserAccessFactory.getSpellManagerUserAccess(UoW);
                toTest.AddSpellMaterials(expected);
                var actual = toTest.GetSpellMaterials(expected.Spell_id);

                //Assert
                actual.Should().NotBeNull();
                expected.Should().NotBeNull();
                actual.Should().BeOfType <Material>();
                expected.Should().BeOfType <Material>();
                actual.Should().BeEquivalentTo(expected);
            }
        }
Пример #10
0
        public void SpellManagerUserAccess_DeleteSpellMaterialsById_ValidCall()
        {
            //Arrange
            List <Material> Materials = CreateTestData.GetListOfMaterials();
            var             mockSet   = new Mock <DbSet <Material> >()
                                        .SetupData(Materials, o =>
            {
                return(Materials.Single(x => x.Spell_id.CompareTo(o.First()) == 0));
            });

            using (var mockContext = AutoMock.GetLoose())
            {
                mockContext.Mock <SpellsContext>()
                .Setup(x => x.Materials).Returns(mockSet.Object);
                mockContext.Mock <SpellsContext>()
                .Setup(x => x.Materials.Remove(It.IsAny <Material>()))
                .Callback <Material>((entity) => Materials.Remove(entity));

                var toBeDeleted = CreateTestData.GetSampleMaterial();

                //act
                IUnitOfWork             UoW    = mockContext.Create <UnitOfWork>();
                ISpellManagerUserAccess toTest = UserAccessFactory.getSpellManagerUserAccess(UoW);
                toTest.DeleteSpellMaterialsById(toBeDeleted.Spell_id);

                //Assert
                Materials.Should().NotContain(toBeDeleted);
            }
        }
Пример #11
0
        public void ItemManagerUserAccess_SettAllTagsForItem_ValidCall()
        {
            //Arrange
            List <Item_Tag> itemTags  = new List <Item_Tag>();
            List <Tag>      tags      = CreateTestData.GetListOfTags();
            var             ITmockSet = new Mock <DbSet <Item_Tag> >()
                                        .SetupData(itemTags, o =>
            {
                return(itemTags.Single(x => x.Item_id.CompareTo(o.First()) == 0));
            });
            var tagsMockSet = new Mock <DbSet <Tag> >()
                              .SetupData(tags, o =>
            {
                return(tags.Single(x => x.Tag_id.CompareTo(o.First()) == 0));
            });
            //Whisper is assigned all tags!
            List <Tag>  expected = CreateTestData.GetListOfTags();
            List <Guid> tag_ids  = new List <Guid>();

            foreach (Tag tag in expected)
            {
                tag_ids.Add(tag.Tag_id);
            }

            Guid whisper_id = Guid.Parse("709135c3-6f89-46cb-80ae-4097b621e3b0");

            using (var mockContext = AutoMock.GetLoose())
            {
                mockContext.Mock <ItemsContext>()
                .Setup(x => x.Tags).Returns(tagsMockSet.Object);
                mockContext.Mock <ItemsContext>()
                .Setup(x => x.Item_Tags).Returns(ITmockSet.Object);

                //Act
                //Act
                IUnitOfWork             UoW    = mockContext.Create <UnitOfWork>();
                IItemsManagerUserAccess toTest = UserAccessFactory.getItemsManagerUserAccess(UoW);
                toTest.SetAllTagsForItem(whisper_id, tag_ids);
                var actual = toTest.GetTagsForItem(whisper_id);


                //Assert
                actual.Should().BeEquivalentTo(expected);
            }
        }
Пример #12
0
        public void ItemManagerUserAccess_SetTagForItem_ValidCall()
        {
            //Arrange
            List <Item_Tag> itemTags  = new List <Item_Tag>();
            List <Tag>      tags      = CreateTestData.GetListOfTags();
            var             ITmockSet = new Mock <DbSet <Item_Tag> >()
                                        .SetupData(itemTags, o =>
            {
                return(itemTags.Single(x => x.Item_id.CompareTo(o.First()) == 0));
            });
            var tagsMockSet = new Mock <DbSet <Tag> >()
                              .SetupData(tags, o =>
            {
                return(tags.Single(x => x.Tag_id.CompareTo(o.First()) == 0));
            });

            List <Tag> expected = new List <Tag>();
            Tag        weapon   = new Tag
            {
                Tag_id  = Guid.Parse("172e8478-e1bd-49ba-a7a7-6455d5a58c6e"),
                TagName = "Weapon"
            };

            expected.Add(weapon);
            Guid whisper_id = Guid.Parse("709135c3-6f89-46cb-80ae-4097b621e3b0");

            using (var mockContext = AutoMock.GetLoose())
            {
                mockContext.Mock <ItemsContext>()
                .Setup(x => x.Tags).Returns(tagsMockSet.Object);
                mockContext.Mock <ItemsContext>()
                .Setup(x => x.Item_Tags).Returns(ITmockSet.Object);

                //Act
                IUnitOfWork             UoW    = mockContext.Create <UnitOfWork>();
                IItemsManagerUserAccess toTest = UserAccessFactory.getItemsManagerUserAccess(UoW);
                toTest.SetTagForItem(whisper_id, weapon.Tag_id);
                var actual = toTest.GetTagsForItem(whisper_id);


                //Assert
                actual.Should().BeEquivalentTo(expected);
            }
        }
Пример #13
0
        public void RaceManager_AddRaceAbility_ValidCall()
        {
            List <RaceAbility> raceAbilities = new List <RaceAbility>();
            var mockSet = new Mock <DbSet <RaceAbility> >()
                          .SetupData(raceAbilities, o =>
            {
                return(raceAbilities.Single(x => x.RaceAbility_id.CompareTo(o.First()) == 0));
            });
            var expected = CreateTestData.GetSampleRaceAbility();

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

                //Act
                IUnitOfWork            worker = mockContext.Create <UnitOfWork>();
                IRaceManagerUserAccess toTest = UserAccessFactory.GetRaceManagerUserAccess(worker);
                toTest.AddRaceAbility(expected);

                //Assert
                raceAbilities.Should().ContainEquivalentOf(expected);
            }
        }