public async Task SQL_answerValues_Delete_DoesDelete() { // Arrange Random rnd = new Random(); sites site1 = 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)); languages language = new languages { Name = Guid.NewGuid().ToString(), Description = Guid.NewGuid().ToString() }; await language.Create(dbContext).ConfigureAwait(false); #region QuestionSet 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); #endregion #region surveyConfiguration 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); #endregion #region Answer 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); #endregion #region question string type = Guid.NewGuid().ToString(); string questionType = Guid.NewGuid().ToString(); string imagePosition = Guid.NewGuid().ToString(); string fontSize = Guid.NewGuid().ToString(); questions question = new questions { Type = type, QuestionType = questionType, ImagePosition = imagePosition, FontSize = fontSize, QuestionSetId = questionSet.Id, Maximum = rnd.Next(1, 255), Minimum = rnd.Next(1, 255), RefId = rnd.Next(1, 255), MaxDuration = rnd.Next(1, 255), MinDuration = rnd.Next(1, 255), QuestionIndex = rnd.Next(1, 255), ContinuousQuestionId = rnd.Next(1, 255), Prioritised = false, ValidDisplay = false, BackButtonEnabled = false, Image = false }; await question.Create(dbContext).ConfigureAwait(false); #endregion #region Option options option = new options { WeightValue = rnd.Next(1, 255), QuestionId = question.Id, Weight = rnd.Next(1, 255), OptionsIndex = rnd.Next(1, 255), NextQuestionId = rnd.Next(1, 255), ContinuousOptionId = rnd.Next(1, 255) }; await option.Create(dbContext).ConfigureAwait(false); #endregion answer_values answerValue = new answer_values { QuestionId = question.Id, Value = rnd.Next(1, 255).ToString(), Answer = answer, Option = option, AnswerId = answer.Id, Question = question, OptionId = option.Id }; await answerValue.Create(dbContext).ConfigureAwait(false); // Act await answerValue.Delete(dbContext); answer_values dbAnswerValue = dbContext.answer_values.AsNoTracking().First(); answer_value_versions dbVersion = dbContext.answer_value_versions.AsNoTracking().First(); // Assert Assert.NotNull(dbAnswerValue); Assert.NotNull(dbVersion); Assert.AreEqual(dbAnswerValue.QuestionId, answerValue.QuestionId); Assert.AreEqual(dbAnswerValue.AnswerId, answerValue.AnswerId); Assert.AreEqual(dbAnswerValue.OptionId, answerValue.OptionId); Assert.AreEqual(dbAnswerValue.Value, answerValue.Value); Assert.AreEqual(Constants.WorkflowStates.Removed, dbAnswerValue.WorkflowState); }
public async Task AnswerValues_Delete_DoesSetWorkflowStateToRemoved() { //Arrange 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 { CustomerNo = rnd.Next(1, 255), MicrotingUid = rnd.Next(1, 255), OtpCode = rnd.Next(1, 255), SiteId = siteForUnit.Id }; 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); questions question = new questions { Image = randomBool, Maximum = rnd.Next(1, 255), Minimum = rnd.Next(1, 255), Prioritised = randomBool, Type = Guid.NewGuid().ToString(), FontSize = Guid.NewGuid().ToString(), ImagePosition = Guid.NewGuid().ToString(), MaxDuration = rnd.Next(1, 255), MinDuration = rnd.Next(1, 255), QuestionIndex = rnd.Next(1, 255), QuestionType = Guid.NewGuid().ToString(), RefId = rnd.Next(1, 255), ValidDisplay = randomBool, BackButtonEnabled = randomBool, ContinuousQuestionId = rnd.Next(1, 255), QuestionSetId = questionSet.Id }; await question.Create(dbContext).ConfigureAwait(false); options option = new options { Weight = rnd.Next(1, 255), OptionsIndex = rnd.Next(1, 255), QuestionId = question.Id, WeightValue = rnd.Next(1, 255), ContinuousOptionId = rnd.Next(1, 255) }; await option.Create(dbContext).ConfigureAwait(false); questions questionForAnswerValue = new questions { Image = randomBool, Maximum = rnd.Next(1, 255), Minimum = rnd.Next(1, 255), Prioritised = randomBool, Type = Guid.NewGuid().ToString(), FontSize = Guid.NewGuid().ToString(), ImagePosition = Guid.NewGuid().ToString(), MaxDuration = rnd.Next(1, 255), MinDuration = rnd.Next(1, 255), QuestionIndex = rnd.Next(1, 255), QuestionType = Guid.NewGuid().ToString(), RefId = rnd.Next(1, 255), ValidDisplay = randomBool, BackButtonEnabled = randomBool, ContinuousQuestionId = rnd.Next(1, 255), QuestionSetId = questionSet.Id }; await questionForAnswerValue.Create(dbContext).ConfigureAwait(false); answer_values answerValue = new answer_values { Value = rnd.Next(1, 255).ToString(), AnswerId = answer.Id, OptionId = option.Id, QuestionId = question.Id }; await answerValue.Create(dbContext).ConfigureAwait(false); //Act DateTime?oldUpdatedAt = answerValue.UpdatedAt; await answerValue.Delete(dbContext); List <answer_values> answerValues = dbContext.answer_values.AsNoTracking().ToList(); List <answer_value_versions> answerValueVersions = dbContext.answer_value_versions.AsNoTracking().ToList(); //Assert Assert.NotNull(answerValues); Assert.NotNull(answerValueVersions); Assert.AreEqual(1, answerValues.Count()); Assert.AreEqual(2, answerValueVersions.Count()); Assert.AreEqual(answerValue.CreatedAt.ToString(), answerValues[0].CreatedAt.ToString()); Assert.AreEqual(answerValue.Version, answerValues[0].Version); // Assert.AreEqual(answerValue.UpdatedAt.ToString(), answerValues[0].UpdatedAt.ToString()); Assert.AreEqual(answerValues[0].WorkflowState, Constants.WorkflowStates.Removed); Assert.AreEqual(answerValue.Value, answerValues[0].Value); Assert.AreEqual(answerValue.Id, answerValues[0].Id); Assert.AreEqual(answerValue.AnswerId, answer.Id); Assert.AreEqual(answerValue.OptionId, option.Id); Assert.AreEqual(answerValue.QuestionId, question.Id); //Old Version Assert.AreEqual(answerValue.CreatedAt.ToString(), answerValueVersions[0].CreatedAt.ToString()); Assert.AreEqual(1, answerValueVersions[0].Version); // Assert.AreEqual(oldUpdatedAt.ToString(), answerValueVersions[0].UpdatedAt.ToString()); Assert.AreEqual(answerValueVersions[0].WorkflowState, Constants.WorkflowStates.Created); Assert.AreEqual(answerValue.Id, answerValueVersions[0].AnswerValueId); Assert.AreEqual(answerValue.Value, answerValueVersions[0].Value); Assert.AreEqual(answer.Id, answerValueVersions[0].AnswerId); Assert.AreEqual(option.Id, answerValueVersions[0].OptionId); Assert.AreEqual(question.Id, answerValueVersions[0].QuestionId); //New Version Assert.AreEqual(answerValue.CreatedAt.ToString(), answerValueVersions[1].CreatedAt.ToString()); Assert.AreEqual(2, answerValueVersions[1].Version); // Assert.AreEqual(answerValue.UpdatedAt.ToString(), answerValueVersions[1].UpdatedAt.ToString()); Assert.AreEqual(answerValueVersions[1].WorkflowState, Constants.WorkflowStates.Removed); Assert.AreEqual(answerValue.Id, answerValueVersions[1].AnswerValueId); Assert.AreEqual(answerValue.Value, answerValueVersions[1].Value); Assert.AreEqual(answer.Id, answerValueVersions[1].AnswerId); Assert.AreEqual(option.Id, answerValueVersions[1].OptionId); Assert.AreEqual(question.Id, answerValueVersions[1].QuestionId); }