private void InitializeDatabase(IApplicationBuilder app) { using (var serviceScope = app.ApplicationServices.CreateScope()) { var services = serviceScope.ServiceProvider; var db = services.GetService <IDbService>(); if (db.LoadRecords <QuestionModel>("Questions", 1, 0, null).Count == 0) { db.InsertManyRecords("Questions", DbSeed.GetQuestions()); } } }
public void GetByIdShouldReturnValue() { // Setup var question = DbSeed.GetQuestions().First(); question.Id = Guid.NewGuid().ToString(); var mock = new Mock <IDbService>(); mock.Setup(p => p.LoadRecordById <QuestionModel>(COLLECTION, question.Id)).Returns(question); var questionsAdmin = new QuestionsAdmin(mock.Object); // Execution var result = questionsAdmin.GetById(question.Id); // Assertion Assert.Equal(question.Id, result.Id); }
public void SaveOrUpdateShouldExcecuteUpsertRecordOnce() { //Setup var question = DbSeed.GetQuestions().First(); var id = Guid.NewGuid().ToString(); var mock = new Mock <IDbService>(); mock.Setup(p => p.InsertRecord(COLLECTION, question)); mock.Setup(p => p.UpsertRecord(COLLECTION, id, question)); var questionsAdmin = new QuestionsAdmin(mock.Object); // Execution questionsAdmin.SaveOrUpdate(question, id); // Assertion mock.Verify(x => x.InsertRecord(COLLECTION, question), Times.Never); mock.Verify(x => x.UpsertRecord(COLLECTION, id, question), Times.Once); }