public async Task Answer_update_DoesUpdate() { Random rnd = new Random(); bool randomBool = rnd.Next(0, 2) > 0; sites site = new sites { Name = Guid.NewGuid().ToString(), MicrotingUid = rnd.Next(1, 255) }; await site.Create(dbContext).ConfigureAwait(false); sites siteForUnit = new sites { Name = Guid.NewGuid().ToString(), MicrotingUid = rnd.Next(1, 255) }; await siteForUnit.Create(dbContext).ConfigureAwait(false); units unit = new units { SiteId = siteForUnit.Id, CustomerNo = rnd.Next(1, 255), MicrotingUid = rnd.Next(1, 255), OtpCode = rnd.Next(1, 255) }; await unit.Create(dbContext).ConfigureAwait(false); languages language = new languages { Description = Guid.NewGuid().ToString(), Name = Guid.NewGuid().ToString() }; await language.Create(dbContext).ConfigureAwait(false); question_sets questionSet = new question_sets { Name = Guid.NewGuid().ToString(), Share = randomBool, HasChild = randomBool, PosiblyDeployed = randomBool }; await questionSet.Create(dbContext).ConfigureAwait(false); survey_configurations surveyConfiguration = new survey_configurations { Name = Guid.NewGuid().ToString(), Start = DateTime.Now, Stop = DateTime.Now, TimeOut = rnd.Next(1, 255), TimeToLive = rnd.Next(1, 255), QuestionSetId = questionSet.Id }; await surveyConfiguration.Create(dbContext).ConfigureAwait(false); answers answer = new answers { AnswerDuration = rnd.Next(1, 255), FinishedAt = DateTime.Now, LanguageId = language.Id, SiteId = site.Id, SurveyConfiguration = surveyConfiguration, TimeZone = Guid.NewGuid().ToString(), UnitId = unit.Id, UtcAdjusted = randomBool, QuestionSetId = questionSet.Id, SurveyConfigurationId = surveyConfiguration.Id }; await answer.Create(dbContext).ConfigureAwait(false); //Act DateTime?oldUpdatedAt = answer.UpdatedAt; int oldAnswerDuration = answer.AnswerDuration; DateTime oldFinishedAt = answer.FinishedAt; string oldTimeZone = answer.TimeZone; bool oldUtcAdjusted = answer.UtcAdjusted; answer.AnswerDuration = rnd.Next(1, 255); answer.FinishedAt = DateTime.Now; answer.TimeZone = Guid.NewGuid().ToString(); answer.UtcAdjusted = randomBool; await answer.Update(dbContext).ConfigureAwait(false); List <answers> answers = dbContext.answers.AsNoTracking().ToList(); List <answer_versions> answerVersions = dbContext.answer_versions.AsNoTracking().ToList(); //Assert Assert.NotNull(answers); Assert.NotNull(answerVersions); Assert.AreEqual(1, answers.Count()); Assert.AreEqual(2, answerVersions.Count()); Assert.AreEqual(answer.CreatedAt.ToString(), answers[0].CreatedAt.ToString()); Assert.AreEqual(answer.Version, answers[0].Version); // Assert.AreEqual(answer.UpdatedAt.ToString(), answers[0].UpdatedAt.ToString()); Assert.AreEqual(answers[0].WorkflowState, Constants.WorkflowStates.Created); Assert.AreEqual(answer.Id, answers[0].Id); Assert.AreEqual(answer.AnswerDuration, answers[0].AnswerDuration); Assert.AreEqual(answer.FinishedAt.ToString(), answers[0].FinishedAt.ToString()); Assert.AreEqual(answer.LanguageId, language.Id); Assert.AreEqual(answer.SiteId, site.Id); Assert.AreEqual(answer.TimeZone, answers[0].TimeZone); Assert.AreEqual(answer.UnitId, unit.Id); Assert.AreEqual(answer.UtcAdjusted, answers[0].UtcAdjusted); Assert.AreEqual(answer.QuestionSetId, questionSet.Id); Assert.AreEqual(answer.SurveyConfigurationId, surveyConfiguration.Id); //Version 1 Old Version Assert.AreEqual(answer.CreatedAt.ToString(), answerVersions[0].CreatedAt.ToString()); Assert.AreEqual(1, answerVersions[0].Version); // Assert.AreEqual(oldUpdatedAt.ToString(), answerVersions[0].UpdatedAt.ToString()); Assert.AreEqual(answerVersions[0].WorkflowState, Constants.WorkflowStates.Created); Assert.AreEqual(oldAnswerDuration, answerVersions[0].AnswerDuration); Assert.AreEqual(oldFinishedAt.ToString(), answerVersions[0].FinishedAt.ToString()); Assert.AreEqual(oldUtcAdjusted, answerVersions[0].UtcAdjusted); Assert.AreEqual(oldTimeZone, answerVersions[0].TimeZone); //Version 2 Updated Version Assert.AreEqual(answer.CreatedAt.ToString(), answerVersions[1].CreatedAt.ToString()); Assert.AreEqual(2, answerVersions[1].Version); // Assert.AreEqual(answer.UpdatedAt.ToString(), answerVersions[1].UpdatedAt.ToString()); Assert.AreEqual(answerVersions[1].WorkflowState, Constants.WorkflowStates.Created); Assert.AreEqual(answer.Id, answerVersions[1].AnswerId); Assert.AreEqual(answer.AnswerDuration, answerVersions[1].AnswerDuration); Assert.AreEqual(answer.FinishedAt.ToString(), answerVersions[1].FinishedAt.ToString()); Assert.AreEqual(language.Id, answerVersions[1].LanguageId); Assert.AreEqual(site.Id, answerVersions[1].SiteId); Assert.AreEqual(answer.TimeZone, answerVersions[1].TimeZone); Assert.AreEqual(unit.Id, answerVersions[1].UnitId); Assert.AreEqual(answer.UtcAdjusted, answerVersions[1].UtcAdjusted); Assert.AreEqual(questionSet.Id, answerVersions[1].QuestionSetId); Assert.AreEqual(surveyConfiguration.Id, answerVersions[1].SurveyConfigurationId); }
public async Task SQL_answers_Update_DoesUpdate_UTCAdjustedFalse() { // Arrange Random rnd = new Random(); sites site1 = await testHelpers.CreateSite(Guid.NewGuid().ToString(), rnd.Next(1, 255)); sites site2 = await testHelpers.CreateSite(Guid.NewGuid().ToString(), rnd.Next(1, 255)); units unit1 = await testHelpers.CreateUnit(rnd.Next(1, 255), rnd.Next(1, 255), site1, rnd.Next(1, 255)); units unit2 = await testHelpers.CreateUnit(rnd.Next(1, 255), rnd.Next(1, 255), site1, rnd.Next(1, 255)); languages language = new languages(); language.Name = Guid.NewGuid().ToString(); language.Description = Guid.NewGuid().ToString(); await language.Create(dbContext).ConfigureAwait(false); languages language2 = new languages(); language2.Name = Guid.NewGuid().ToString(); language2.Description = Guid.NewGuid().ToString(); await language2.Create(dbContext).ConfigureAwait(false); string name = Guid.NewGuid().ToString(); question_sets questionSet = new question_sets { Name = name, Share = false, HasChild = false, PosiblyDeployed = false }; await questionSet.Create(dbContext).ConfigureAwait(false); string name2 = Guid.NewGuid().ToString(); question_sets questionSet2 = new question_sets { Name = name2, Share = false, HasChild = false, PosiblyDeployed = false }; await questionSet2.Create(dbContext).ConfigureAwait(false); survey_configurations surveyConfiguration = new survey_configurations { Name = Guid.NewGuid().ToString(), Stop = DateTime.Now, Start = DateTime.Now, TimeOut = rnd.Next(1, 255), TimeToLive = rnd.Next(1, 255), QuestionSetId = questionSet.Id }; await surveyConfiguration.Create(dbContext).ConfigureAwait(false); survey_configurations surveyConfiguration2 = new survey_configurations { Name = Guid.NewGuid().ToString(), Stop = DateTime.Now, Start = DateTime.Now, TimeOut = rnd.Next(1, 255), TimeToLive = rnd.Next(1, 255), QuestionSetId = questionSet2.Id }; await surveyConfiguration2.Create(dbContext).ConfigureAwait(false); answers answer = new answers { SiteId = site1.Id, QuestionSetId = questionSet.Id, SurveyConfigurationId = surveyConfiguration.Id, UnitId = unit1.Id, TimeZone = Guid.NewGuid().ToString(), FinishedAt = DateTime.Now, LanguageId = language.Id, AnswerDuration = rnd.Next(1, 255), UtcAdjusted = true }; await answer.Create(dbContext).ConfigureAwait(false); // Act answer.SiteId = site2.Id; answer.QuestionSetId = questionSet2.Id; answer.SurveyConfigurationId = surveyConfiguration2.Id; answer.UnitId = unit2.Id; answer.TimeZone = Guid.NewGuid().ToString(); answer.FinishedAt = DateTime.Now; answer.LanguageId = language.Id; answer.AnswerDuration = rnd.Next(1, 255); answer.UtcAdjusted = false; await answer.Update(dbContext).ConfigureAwait(false); answers dbAnswer = dbContext.answers.AsNoTracking().First(); answer_versions dbVersion = dbContext.answer_versions.AsNoTracking().First(); // Assert Assert.NotNull(dbAnswer); Assert.NotNull(dbVersion); Assert.AreEqual(dbAnswer.SiteId, answer.SiteId); Assert.AreEqual(dbAnswer.QuestionSetId, answer.QuestionSetId); Assert.AreEqual(dbAnswer.SurveyConfigurationId, answer.SurveyConfigurationId); Assert.AreEqual(dbAnswer.UnitId, answer.UnitId); Assert.AreEqual(dbAnswer.TimeZone, answer.TimeZone); Assert.AreEqual(dbAnswer.FinishedAt.ToString(), answer.FinishedAt.ToString()); Assert.AreEqual(dbAnswer.LanguageId, answer.LanguageId); Assert.AreEqual(dbAnswer.AnswerDuration, answer.AnswerDuration); Assert.AreEqual(dbAnswer.UtcAdjusted, answer.UtcAdjusted); }