public void ShouldCorrectlySetEntityStatesForAddedObjectGraphWithChildEntity()
        {
            //arrange
            DataFormSettingsDescriptor formDescriptor  = Descriptors.InstructorFormWithInlineOfficeAssignment;
            InstructorModel            instructorModel = null;

            ObservableCollection <IValidatable> modifiedProperties   = CreateValidatablesFormSettings(formDescriptor, typeof(InstructorModel));
            IDictionary <string, IValidatable>  propertiesDictionary = modifiedProperties.ToDictionary(property => property.Name);

            propertiesDictionary["ID"].Value        = 3;
            propertiesDictionary["FirstName"].Value = "John";
            propertiesDictionary["LastName"].Value  = "Smith";
            propertiesDictionary["HireDate"].Value  = new DateTime(2021, 5, 20);
            propertiesDictionary["OfficeAssignment.Location"].Value = "Location1";

            InstructorModel currentInstructor = serviceProvider.GetRequiredService <IEntityStateUpdater>().GetUpdatedModel
                                                (
                instructorModel,
                instructorModel.EntityToObjectDictionary
                (
                    serviceProvider.GetRequiredService <IMapper>(),
                    formDescriptor.FieldSettings
                ),
                modifiedProperties,
                formDescriptor.FieldSettings
                                                );

            Assert.Equal(LogicBuilder.Domain.EntityStateType.Added, currentInstructor.EntityState);
            Assert.Equal(LogicBuilder.Domain.EntityStateType.Added, currentInstructor.OfficeAssignment.EntityState);
        }
        public void ShouldCorrectlySetEntityStatesForAddedObjectGraph()
        {
            //arrange
            DataFormSettingsDescriptor formDescriptor  = Descriptors.DepartmentForm;
            DepartmentModel            departmentModel = null;

            ObservableCollection <IValidatable> modifiedProperties   = CreateValidatablesFormSettings(formDescriptor, typeof(DepartmentModel));
            IDictionary <string, IValidatable>  propertiesDictionary = modifiedProperties.ToDictionary(property => property.Name);

            propertiesDictionary["DepartmentID"].Value = 1;
            propertiesDictionary["Name"].Value         = "Mathematics";
            propertiesDictionary["Budget"].Value       = 100000m;
            propertiesDictionary["StartDate"].Value    = new DateTime(2021, 5, 20);
            propertiesDictionary["InstructorID"].Value = 1;
            propertiesDictionary["Courses"].Value      = new ObservableCollection <CourseModel>
                                                         (
                new List <CourseModel>
            {
                new CourseModel
                {
                    CourseID = 1,
                    Credits  = 3,
                    Title    = "Trigonometry"
                },
                new CourseModel
                {
                    CourseID = 2,
                    Credits  = 4,
                    Title    = "Physics"
                },
                new CourseModel
                {
                    CourseID = 4,
                    Credits  = 5,
                    Title    = "Algebra"
                }
            }
                                                         );

            DepartmentModel currentDepartment = serviceProvider.GetRequiredService <IEntityStateUpdater>().GetUpdatedModel
                                                (
                departmentModel,
                departmentModel.EntityToObjectDictionary
                (
                    serviceProvider.GetRequiredService <IMapper>(),
                    formDescriptor.FieldSettings
                ),
                modifiedProperties,
                formDescriptor.FieldSettings
                                                );

            Assert.Equal(LogicBuilder.Domain.EntityStateType.Added, currentDepartment.EntityState);
            Assert.Equal(LogicBuilder.Domain.EntityStateType.Added, currentDepartment.Courses.Single(c => c.CourseID == 1).EntityState);
            Assert.Equal(LogicBuilder.Domain.EntityStateType.Added, currentDepartment.Courses.Single(c => c.CourseID == 2).EntityState);
            Assert.Equal(LogicBuilder.Domain.EntityStateType.Added, currentDepartment.Courses.Single(c => c.CourseID == 4).EntityState);
            Assert.Equal(3, currentDepartment.Courses.Count);
        }
        public void ShouldCorrectlySetEntityStatesForMultiSelects()
        {
            //arrange
            DataFormSettingsDescriptor formDescriptor = Descriptors.ResidencyForm;
            ResidencyModel             residencyModel = new ResidencyModel
            {
                UserId                 = 3,
                CitizenshipStatus      = "US",
                ResidentState          = "OH",
                HasValidDriversLicense = true,
                StatesLivedIn          = new List <StateLivedInModel>
                {
                    new StateLivedInModel
                    {
                        StateLivedInId = 1,
                        UserId         = 3,
                        State          = "GA"
                    },
                    new StateLivedInModel
                    {
                        StateLivedInId = 2,
                        UserId         = 3,
                        State          = "MI"
                    },
                    new StateLivedInModel
                    {
                        StateLivedInId = 3,
                        UserId         = 3,
                        State          = "OH"
                    }
                }
            };

            ObservableCollection <IValidatable> modifiedProperties   = CreateValidatablesFormSettings(formDescriptor, typeof(ResidencyModel));
            IDictionary <string, IValidatable>  propertiesDictionary = modifiedProperties.ToDictionary(property => property.Name);

            propertiesDictionary["UserId"].Value                 = 3;
            propertiesDictionary["CitizenshipStatus"].Value      = "US";
            propertiesDictionary["ResidentState"].Value          = "OH";
            propertiesDictionary["HasValidDriversLicense"].Value = true;
            propertiesDictionary["StatesLivedIn"].Value          = new ObservableCollection <StateLivedInModel>
                                                                   (
                new List <StateLivedInModel>
            {
                new StateLivedInModel
                {
                    StateLivedInId = 1,
                    UserId         = 3,
                    State          = "GA"
                },
                new StateLivedInModel
                {
                    StateLivedInId = 2,
                    UserId         = 3,
                    State          = "MI"
                },
                new StateLivedInModel
                {
                    StateLivedInId = 4,
                    UserId         = 3,
                    State          = "IN"
                }
            }
                                                                   );

            ResidencyModel currentResidency = serviceProvider.GetRequiredService <IEntityStateUpdater>().GetUpdatedModel
                                              (
                residencyModel,
                residencyModel.EntityToObjectDictionary
                (
                    serviceProvider.GetRequiredService <IMapper>(),
                    formDescriptor.FieldSettings
                ),
                modifiedProperties,
                formDescriptor.FieldSettings
                                              );

            Assert.Equal(LogicBuilder.Domain.EntityStateType.Modified, currentResidency.EntityState);
            Assert.Equal(LogicBuilder.Domain.EntityStateType.Unchanged, currentResidency.StatesLivedIn.Single(c => c.State == "GA").EntityState);
            Assert.Equal(LogicBuilder.Domain.EntityStateType.Unchanged, currentResidency.StatesLivedIn.Single(c => c.State == "MI").EntityState);
            Assert.Equal(LogicBuilder.Domain.EntityStateType.Deleted, currentResidency.StatesLivedIn.Single(c => c.State == "OH").EntityState);
            Assert.Equal(LogicBuilder.Domain.EntityStateType.Added, currentResidency.StatesLivedIn.Single(c => c.State == "IN").EntityState);

            Assert.Equal(4, currentResidency.StatesLivedIn.Count);
        }
        public void ShouldCorrectlySetEntityStatesForMultiSelects()
        {
            //arrange
            DataFormSettingsDescriptor formDescriptor  = Descriptors.InstructorFormWithInlineOfficeAssignment;
            InstructorModel            instructorModel = new InstructorModel
            {
                ID               = 3,
                FirstName        = "John",
                LastName         = "Smith",
                HireDate         = new DateTime(2021, 5, 20),
                OfficeAssignment = new OfficeAssignmentModel
                {
                    Location = "Location1"
                },
                Courses = new List <CourseAssignmentModel>
                {
                    new CourseAssignmentModel
                    {
                        CourseID     = 1,
                        InstructorID = 3,
                        CourseTitle  = "Chemistry"
                    },
                    new CourseAssignmentModel
                    {
                        CourseID     = 2,
                        InstructorID = 3,
                        CourseTitle  = "Physics"
                    },
                    new CourseAssignmentModel
                    {
                        CourseID     = 3,
                        InstructorID = 3,
                        CourseTitle  = "Mathematics"
                    }
                }
            };

            ObservableCollection <IValidatable> modifiedProperties   = CreateValidatablesFormSettings(formDescriptor, typeof(InstructorModel));
            IDictionary <string, IValidatable>  propertiesDictionary = modifiedProperties.ToDictionary(property => property.Name);

            propertiesDictionary["ID"].Value        = 3;
            propertiesDictionary["FirstName"].Value = "John";
            propertiesDictionary["LastName"].Value  = "Smith";
            propertiesDictionary["HireDate"].Value  = new DateTime(2021, 5, 20);
            propertiesDictionary["OfficeAssignment.Location"].Value = "Location1";
            propertiesDictionary["Courses"].Value = new ObservableCollection <CourseAssignmentModel>
                                                    (
                new List <CourseAssignmentModel>
            {
                new CourseAssignmentModel
                {
                    CourseID     = 1,
                    InstructorID = 3,
                    CourseTitle  = "Chemistry"
                },
                new CourseAssignmentModel
                {
                    CourseID     = 2,
                    InstructorID = 3,
                    CourseTitle  = "Physics"
                },
                new CourseAssignmentModel
                {
                    CourseID     = 4,
                    InstructorID = 3,
                    CourseTitle  = "Algebra"
                }
            }
                                                    );

            InstructorModel currentInstructor = serviceProvider.GetRequiredService <IEntityStateUpdater>().GetUpdatedModel
                                                (
                instructorModel,
                instructorModel.EntityToObjectDictionary
                (
                    serviceProvider.GetRequiredService <IMapper>(),
                    formDescriptor.FieldSettings
                ),
                modifiedProperties,
                formDescriptor.FieldSettings
                                                );

            Assert.Equal(LogicBuilder.Domain.EntityStateType.Modified, currentInstructor.EntityState);
            Assert.Equal(LogicBuilder.Domain.EntityStateType.Unchanged, currentInstructor.Courses.Single(c => c.CourseID == 1).EntityState);
            Assert.Equal(LogicBuilder.Domain.EntityStateType.Unchanged, currentInstructor.Courses.Single(c => c.CourseID == 2).EntityState);
            Assert.Equal(LogicBuilder.Domain.EntityStateType.Deleted, currentInstructor.Courses.Single(c => c.CourseID == 3).EntityState);
            Assert.Equal(LogicBuilder.Domain.EntityStateType.Added, currentInstructor.Courses.Single(c => c.CourseID == 4).EntityState);
            Assert.Equal(LogicBuilder.Domain.EntityStateType.Unchanged, currentInstructor.OfficeAssignment.EntityState);
            Assert.Equal(4, currentInstructor.Courses.Count);
        }
        public void ShouldCorrectlySetEntityStatesForAddedObjectGraph()
        {
            //arrange
            DataFormSettingsDescriptor formDescriptor = Descriptors.AcademicForm;
            AcademicModel academicModel = null;

            ObservableCollection <IValidatable> modifiedProperties   = CreateValidatablesFormSettings(formDescriptor, typeof(AcademicModel));
            IDictionary <string, IValidatable>  propertiesDictionary = modifiedProperties.ToDictionary(property => property.Name);

            propertiesDictionary["LastHighSchoolLocation"].Value = "NC";
            propertiesDictionary["NcHighSchoolName"].Value       = "NCSCHOOL1";
            propertiesDictionary["FromDate"].Value          = new DateTime(2019, 5, 20);
            propertiesDictionary["ToDate"].Value            = new DateTime(2021, 5, 20);
            propertiesDictionary["GraduationStatus"].Value  = "DP";
            propertiesDictionary["EarnedCreditAtCmc"].Value = true;
            propertiesDictionary["Institutions"].Value      = new ObservableCollection <InstitutionModel>
                                                              (
                new List <InstitutionModel>
            {
                new InstitutionModel
                {
                    InstitutionId       = 1,
                    InstitutionState    = "FL",
                    InstitutionName     = "I1",
                    StartYear           = "2011",
                    EndYear             = "2013",
                    HighestDegreeEarned = "CT"
                },
                new InstitutionModel
                {
                    InstitutionId       = 2,
                    InstitutionState    = "GA",
                    InstitutionName     = "I1",
                    StartYear           = "2012",
                    EndYear             = "2014",
                    HighestDegreeEarned = "DP"
                },
                new InstitutionModel
                {
                    InstitutionId       = 4,
                    InstitutionState    = "AL",
                    InstitutionName     = "I2",
                    StartYear           = "2016",
                    EndYear             = "2019",
                    HighestDegreeEarned = "MA"
                }
            }
                                                              );

            AcademicModel currentAcademic = serviceProvider.GetRequiredService <IEntityStateUpdater>().GetUpdatedModel
                                            (
                academicModel,
                academicModel.EntityToObjectDictionary
                (
                    serviceProvider.GetRequiredService <IMapper>(),
                    formDescriptor.FieldSettings
                ),
                modifiedProperties,
                formDescriptor.FieldSettings
                                            );

            Assert.Equal(LogicBuilder.Domain.EntityStateType.Added, currentAcademic.EntityState);
            Assert.Equal(LogicBuilder.Domain.EntityStateType.Added, currentAcademic.Institutions.Single(c => c.InstitutionId == 1).EntityState);
            Assert.Equal(LogicBuilder.Domain.EntityStateType.Added, currentAcademic.Institutions.Single(c => c.InstitutionId == 2).EntityState);
            Assert.Equal(LogicBuilder.Domain.EntityStateType.Added, currentAcademic.Institutions.Single(c => c.InstitutionId == 4).EntityState);
            Assert.Equal(3, currentAcademic.Institutions.Count);
        }