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); } }
public void ClassAbilitiesRepo_RemoveClassAbility_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 toBeDeleted = 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 var toTest = mockContext.Create <ClassAbilityRepository>(); toTest.Remove(toBeDeleted); var actual = toTest.GetAll(); //Assert actual.Should().NotContain(toBeDeleted); } }
public void ClassAbilitiesRepo_GetAbility_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.GetClassAbility(); using (var mockContext = AutoMock.GetLoose()) { mockContext.Mock <PlayableClassContext>() .Setup(x => x.Set <ClassAbility>()).Returns(mockSet.Object); //Act var toTest = mockContext.Create <ClassAbilityRepository>(); var actual = toTest.Get(expected.ClassAbility_id); //Assert actual.Should().BeEquivalentTo(expected); } }
public void ClassAbilitiesRepo_GetAbilitiesOfClassAtOrBelowLevel_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)); }); ClassAbility expected = new ClassAbility { ClassAbility_id = Guid.Parse("97bd8231-a001-4228-824f-7606202913b0"), Class_id = Guid.Parse("969c08ca-f983-4ddd-b351-31962f2429cd"), Name = "Vanish", Description = "You can Hide as a bonus action.", LevelLearned = 14 }; var notExpected1 = CreateTestData.GetClassAbility(); var notExpected2 = new ClassAbility { ClassAbility_id = Guid.Parse("19e51104-8590-4199-b7e2-079993bb8ccb"), Class_id = Guid.Parse("4e82620a-0496-4ecc-b6d4-05faa064310b"), Name = "Spell Master", Description = "Choose a 1st level spell and a 2nd level spell in your spellbook. As long as you have them prepared, you can cast them without consuming a spell slot.", LevelLearned = 18 }; using (var mockContext = AutoMock.GetLoose()) { mockContext.Mock <PlayableClassContext>() .Setup(x => x.ClassAbilities).Returns(mockSet.Object); //Act var toTest = mockContext.Create <ClassAbilityRepository>(); var actual = toTest.GetAbilitiesOfClassAtOrBelowLevel(expected.Class_id, 14); //Assert actual.Should().ContainEquivalentOf(expected); actual.Should().NotContain(notExpected1); actual.Should().NotContain(notExpected2); actual.Should().NotContainNulls(); actual.Should().NotBeEmpty(); } }