예제 #1
0
        public async Task surveyConfiguration_Delete_DoesDelete()
        {
            // 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

            await surveyConfiguration.Delete(dbContext);

            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.AreEqual(oldName, 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);
            Assert.AreEqual(surveyConfiguration.WorkflowState, Constants.WorkflowStates.Removed);
        }
        public async Task SurveyConfigurations_Delete_DoesSetWorkflowStateToRemoved()
        {
            //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;

            await surveyConfiguration.Delete(dbContext);

            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.Removed);
            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(surveyConfiguration.Name, surveyConfigurationVersions[0].Name);
            Assert.AreEqual(surveyConfiguration.Start.ToString(), surveyConfigurationVersions[0].Start.ToString());
            Assert.AreEqual(surveyConfiguration.Stop.ToString(), surveyConfigurationVersions[0].Stop.ToString());
            Assert.AreEqual(surveyConfiguration.TimeOut, surveyConfigurationVersions[0].TimeOut);
            Assert.AreEqual(surveyConfiguration.TimeToLive, 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.Removed);
            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);
        }