public void TestRetrieveQueryableDataFileAlreadyLoaded() { //Create the mock file loader Mock <IAnswerDataJsonFileLoader> mockFileLoader = CreateMockFileLoader(); //Create an AnswerDB instance AnswerDB testAnswerDB = new AnswerDB(mockFileLoader.Object, TestDataFileName); //Retrieve the test data, which will be our expected data List <Answer> expectedAnswers = CreateTestData(); //Retrieve the Querable from the DB IQueryable <Answer> answerQueryable = testAnswerDB.GetAnswerQueryable(); //Verify that the file loader was called correctly mockFileLoader.Verify(mock => mock.LoadAnswerDataFromFile( It.Is <string>(fileName => fileName == TestDataFileName)), Times.Once); //That should have loaded the file to the DB. Retrieve the queryable again. answerQueryable = testAnswerDB.GetAnswerQueryable(); //Verify that we actually got a queryable Assert.That(answerQueryable, Is.Not.Null); //Verify that the queryable returns the correct data List <Answer> actualAnswers = answerQueryable.ToList(); expectedAnswers.Zip(actualAnswers, Tuple.Create) .ToList() .ForEach(answerTuple => DataComparers.CompareAnswers(answerTuple.Item1, answerTuple.Item2)); //Verify that the file loader was not called again mockFileLoader.Verify(mock => mock.LoadAnswerDataFromFile(It.IsAny <string>()), Times.Once); }
public static int InsertAnswer(string Sender, int Room_Id, string answerData) { int id = -1; AnswerDB answerDB = new AnswerDB(); Answer answer = new Answer(); if (answer != null) { answer.Sender = Sender; answer.Room_Id = Room_Id; answer.AnswerData = answerData; id = answerDB.InsertAnswer(answer); } return(id); }
public static int DeleteAnswer(int Id) { int flag = 0; AnswerDB answerDB = new AnswerDB(); bool s = answerDB.DeleteAnswer(Id); if (s) { flag = 1; } else { flag = 0; } return(flag); }
// Answers: public static string[] GetAnswers(int room_id) { AnswerDB answerDB = new AnswerDB(); Answers answers = answerDB.SelectByRoomId(room_id); if (answers != null) { string[] answerSTR = new string[answers.Count]; string str = null; for (int i = 0; i < answers.Count; i++) { Answer answer = answers[i]; str = "{\"Id\":\"" + answer.Id + "\",\"Sender\":\"" + answer.Sender + "\",\"Room_Id\":\"" + answer.Room_Id + "\",\"AnswerData\":[" + answer.AnswerData + "]}"; answerSTR[i] = str; str = null; } return(answerSTR); } else { return(null); } }