public void Setup() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase("TestRunDataBase") .Options; _context = new ApplicationDbContext(options); _emptyContext = new ApplicationDbContext(options); _emptyContext.SaveChanges(); var _mixedAnswersTestRun = new TestRun("john", Guid.NewGuid()); var _textAnswersTestRun = new TestRun("jim", Guid.NewGuid()); _mixedAnswersTestRun.AddAnswer(new Answer(Guid.NewGuid(), "1987")); _mixedAnswersTestRun.AddAnswer(new Answer(Guid.NewGuid(), new List <Guid>() { Guid.NewGuid() })); for (var i = 0; i < 3; i++) { _textAnswersTestRun.AddAnswer(new Answer(Guid.NewGuid(), i.ToString())); } _context.AddRange(_mixedAnswersTestRun); _context.AddRange(_textAnswersTestRun); _context.SaveChanges(); }
public void TestRun_Add_AnswerText_ReturnsAsExpected() { //Arrange var answersIds = GenerateMockAnswersIds(3); var testRun = new TestRun(_user, Guid.NewGuid()); var testQuestionFakeId = new Guid(); //Act testRun.AddAnswer(new Answer(testQuestionFakeId, "johnie")); testRun.AddAnswer(new Answer(testQuestionFakeId, "mnemonic")); //Assert Assert.AreEqual(testRun.Answers.Count, 2); Assert.IsNull(testRun.Answers.ElementAt(0).AnswerText); }
public void TestRun_Answers_Is_Immutable() { //Arrange var testRun = new TestRun(_user, Guid.NewGuid()); var sampleAnswer = new Answer(Guid.NewGuid(), new List<Guid>() {_predefinedId}); testRun.AddAnswer(sampleAnswer); //Act var answers = testRun.Answers.ToList(); answers.Add(new Answer(Guid.NewGuid(), "answer")); //Assert Assert.AreNotEqual(answers, testRun.Answers); Assert.AreNotEqual(answers.Count, testRun.Answers.Count); }
public void TestRun_Returns_Actual_Answer_As_Text_Options_As_Null() { //Arrange var testRun = new TestRun(_user, Guid.NewGuid()); var sampleAnswer = new Answer(Guid.NewGuid(), "answer"); testRun.AddAnswer(sampleAnswer); //Act var answers = testRun.Answers; var actualAnswerOptions = answers.ElementAt(0).AnswerOptions; var actualAnswerText = answers.ElementAt(0).AnswerText; //Assert Assert.IsNotNull(actualAnswerText); Assert.AreEqual(actualAnswerText, "answer"); Assert.IsEmpty(actualAnswerOptions); }
public void TestRun_Returns_Actual_Answer_As_Option_Text_As_Null() { //Arrange var testRun = new TestRun(_user, Guid.NewGuid()); var sampleAnswer = new Answer(Guid.NewGuid(), new List<Guid>() {_predefinedId}); testRun.AddAnswer(sampleAnswer); //Act var answers = testRun.Answers; var actualAnswerOptions = answers.ElementAt(0).AnswerOptions; var actualAnswerText = answers.ElementAt(0).AnswerText; //Assert Assert.IsNotNull(actualAnswerOptions); Assert.AreEqual(actualAnswerOptions.ElementAt(0), _predefinedId); Assert.IsNull(actualAnswerText); }