public async Task surveyConfiguration_Update_DoesUpdate() { // Arrange Random rnd = new Random(); question_sets questionSet = new question_sets() { ParentId = 0 }; await questionSet.Create(dbContext).ConfigureAwait(false); string oldName = Guid.NewGuid().ToString(); survey_configurations surveyConfiguration = new survey_configurations { Name = oldName, 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); // Act string newName = Guid.NewGuid().ToString(); surveyConfiguration.Name = newName; await surveyConfiguration.Update(dbContext).ConfigureAwait(false); survey_configurations dbSurveyConfigurations = dbContext.survey_configurations.AsNoTracking().First(); survey_configuration_versions dbSurveyConfigurationVersions = dbContext.survey_configuration_versions.AsNoTracking().First(); // Assert Assert.NotNull(dbSurveyConfigurations); Assert.NotNull(dbSurveyConfigurationVersions); Assert.AreNotEqual(oldName, dbSurveyConfigurations.Name); Assert.AreEqual(newName, dbSurveyConfigurations.Name); Assert.AreEqual(surveyConfiguration.Stop.ToString(), dbSurveyConfigurations.Stop.ToString()); Assert.AreEqual(surveyConfiguration.Start.ToString(), dbSurveyConfigurations.Start.ToString()); Assert.AreEqual(surveyConfiguration.TimeOut, dbSurveyConfigurations.TimeOut); Assert.AreEqual(surveyConfiguration.TimeToLive, dbSurveyConfigurations.TimeToLive); }
public async Task SurveyConfigurations_Update_DoesUpdate() { //Arrange Random rnd = new Random(); question_sets questionSet = new question_sets() { ParentId = 0 }; 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); //Act DateTime?oldUpdatedAt = surveyConfiguration.UpdatedAt; string oldName = surveyConfiguration.Name; DateTime?oldStart = surveyConfiguration.Start; DateTime?oldStop = surveyConfiguration.Stop; int? oldTimeOut = surveyConfiguration.TimeOut; int? oldTimeToLive = surveyConfiguration.TimeToLive; surveyConfiguration.Name = Guid.NewGuid().ToString(); surveyConfiguration.Start = DateTime.Now; surveyConfiguration.Stop = DateTime.Now; surveyConfiguration.TimeOut = rnd.Next(1, 255); surveyConfiguration.TimeToLive = rnd.Next(1, 255); await surveyConfiguration.Update(dbContext).ConfigureAwait(false); List <survey_configurations> surveyConfigurations = dbContext.survey_configurations.AsNoTracking().ToList(); List <survey_configuration_versions> surveyConfigurationVersions = dbContext.survey_configuration_versions.AsNoTracking().ToList(); Assert.NotNull(surveyConfigurations); Assert.NotNull(surveyConfigurationVersions); Assert.AreEqual(1, surveyConfigurations.Count()); Assert.AreEqual(2, surveyConfigurationVersions.Count()); Assert.AreEqual(surveyConfiguration.CreatedAt.ToString(), surveyConfigurations[0].CreatedAt.ToString()); Assert.AreEqual(surveyConfiguration.Version, surveyConfigurations[0].Version); // Assert.AreEqual(surveyConfiguration.UpdatedAt.ToString(), surveyConfigurations[0].UpdatedAt.ToString()); Assert.AreEqual(surveyConfigurations[0].WorkflowState, Constants.WorkflowStates.Created); Assert.AreEqual(surveyConfiguration.Id, surveyConfigurations[0].Id); Assert.AreEqual(surveyConfiguration.Name, surveyConfigurations[0].Name); Assert.AreEqual(surveyConfiguration.Start.ToString(), surveyConfigurations[0].Start.ToString()); Assert.AreEqual(surveyConfiguration.Stop.ToString(), surveyConfigurations[0].Stop.ToString()); Assert.AreEqual(surveyConfiguration.TimeOut, surveyConfigurations[0].TimeOut); Assert.AreEqual(surveyConfiguration.TimeToLive, surveyConfigurations[0].TimeToLive); //Old Version Assert.AreEqual(surveyConfiguration.CreatedAt.ToString(), surveyConfigurationVersions[0].CreatedAt.ToString()); Assert.AreEqual(1, surveyConfigurationVersions[0].Version); // Assert.AreEqual(oldUpdatedAt.ToString(), surveyConfigurationVersions[0].UpdatedAt.ToString()); Assert.AreEqual(surveyConfigurationVersions[0].WorkflowState, Constants.WorkflowStates.Created); Assert.AreEqual(surveyConfiguration.Id, surveyConfigurationVersions[0].SurveyConfigurationId); Assert.AreEqual(oldName, surveyConfigurationVersions[0].Name); Assert.AreEqual(oldStart.ToString(), surveyConfigurationVersions[0].Start.ToString()); Assert.AreEqual(oldStop.ToString(), surveyConfigurationVersions[0].Stop.ToString()); Assert.AreEqual(oldTimeOut, surveyConfigurationVersions[0].TimeOut); Assert.AreEqual(oldTimeToLive, surveyConfigurationVersions[0].TimeToLive); //New Version Assert.AreEqual(surveyConfiguration.CreatedAt.ToString(), surveyConfigurationVersions[1].CreatedAt.ToString()); Assert.AreEqual(2, surveyConfigurationVersions[1].Version); // Assert.AreEqual(surveyConfiguration.UpdatedAt.ToString(), surveyConfigurationVersions[1].UpdatedAt.ToString()); Assert.AreEqual(surveyConfigurationVersions[1].WorkflowState, Constants.WorkflowStates.Created); Assert.AreEqual(surveyConfiguration.Id, surveyConfigurationVersions[1].SurveyConfigurationId); Assert.AreEqual(surveyConfiguration.Name, surveyConfigurationVersions[1].Name); Assert.AreEqual(surveyConfiguration.Start.ToString(), surveyConfigurationVersions[1].Start.ToString()); Assert.AreEqual(surveyConfiguration.Stop.ToString(), surveyConfigurationVersions[1].Stop.ToString()); Assert.AreEqual(surveyConfiguration.TimeOut, surveyConfigurationVersions[1].TimeOut); Assert.AreEqual(surveyConfiguration.TimeToLive, surveyConfigurationVersions[1].TimeToLive); }