public void Insert( ) { muscle_log.framework.Models.MuscleLogContext ctx = new muscle_log.framework.Models.MuscleLogContext("metadata=res://*/Models.MuscleLogModel.csdl|res://*/Models.MuscleLogModel.ssdl|res://*/Models.MuscleLogModel.msl;provider=System.Data.SqlClient;provider connection string='data source=MAX-PC;Initial Catalog=muscle-log;User ID=Max-PC;integrated security=SSPI;multipleactiveresultsets=True;application name=EntityFramework'"); var unitOfWork = new EFContextUnitOfWork(ctx); var repo = new Repository<ml_ForumThread>(unitOfWork); ForumThreadService service = new ForumThreadService(repo); int countBefore = service.ListThreads(muscle_log.framework.Util.Enum.Forums.Meta).Count(); ForumThreadViewModel input = new ForumThreadViewModel( ); input.ID = -1; input.UserID = 7; input.Title = "Testeintrag"; input.Body = "Das ist ein Testeintrag. ~*</fsd !§$(%)=&??``´´'<<<><>>>@fsdf%%<%=fds"; input.Forum = muscle_log.framework.Util.Enum.Forums.Meta; service.Save( input ); int countAfter = service.ListThreads(muscle_log.framework.Util.Enum.Forums.Meta).Count(); // there must be one more thread than before Assert.AreEqual( countAfter, ( countBefore + 1 ) ); // the id of the new thread must be bigger than 0 Assert.Greater( input.ID, 0 ); // the members of the input object and the output object must be equal var output = repo.Get(input.ID); Assert.AreNotEqual( input, output ); Assert.AreEqual( input.Title, output.Title ); Assert.AreEqual( input.Body, output.Body ); Assert.AreEqual( input.Forum, output.Forum ); Assert.AreEqual( input.UserID, output.UserID ); unitOfWork.Dispose(); }
private ml_ForumThread ViewModelToModel(ForumThreadViewModel viewModel) { return new ml_ForumThread { Body = viewModel.Body, CRDT = viewModel.CRDT, Forum = viewModel.Forum.ToString(), Title = viewModel.Title, UserID = viewModel.ID }; }
/// <summary> /// saves a forum thread. If it already exists, it will be updated, otherwise created. /// </summary> /// <param name="model">the ForumThreadViewModel object that will be saved</param> /// <returns>the saved ForumThreadViewModel</returns> public void Save(ForumThreadViewModel viewModel) { Save(ViewModelToModel(viewModel)); }