Example #1
0
        public void SpellsRepository_GetSpellMaterials_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);

                Material expected = new Material()
                {
                    Spell_id  = Guid.Parse("caf8b2d1-7903-493c-bc3a-ec2fc554d533"),
                    materials = "Diamonds worth 300 gp, which the spell consumes."
                };

                //act
                ISpellsRepository toTest = mockContext.Create <SpellsRepository>();
                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);
            }
        }
Example #2
0
        public void SpellsRepository_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
                ISpellsRepository toTest = mockContext.Create <SpellsRepository>();
                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);
            }
        }