//Adds in Database /// <summary> /// Adds in Database /// </summary> /// <param name="Booktype"></param> /// <param name="id"></param> public void Add(string Booktype, int id) { using (context) { PersonBookType UserAccountBookAdding = new PersonBookType() { BookType = Booktype, PersonAccountId = id }; context.PersonBookTypes.Add(UserAccountBookAdding); context.SaveChanges(); } }
public void CreatePersonBookType_Saves_In_Database() { var Personbook = new PersonBookType() { BookType = "Goshko", PersonAccountId = 1 }; var MockSet = new Mock <DbSet <PersonBookType> >(); var MockContext = new Mock <ApplicationContexts>(); MockContext.Setup(x => x.PersonBookTypes).Returns(MockSet.Object); var service = new PersonBookTypeController(MockContext.Object); service.Add(Personbook.BookType, Personbook.PersonAccountId); MockSet.Verify(x => x.Add(It.IsAny <PersonBookType>()), Times.Once()); MockContext.Verify(x => x.SaveChanges(), Times.Once()); }