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 ShouldCorrectlySetEntityStatesForExistingChildEntity()
        {
            //arrange
            EditFormSettingsDescriptor formDescriptor  = Descriptors.InstructorFormWithInlineOfficeAssignment;
            InstructorModel            instructorModel = new InstructorModel
            {
                ID               = 3,
                FirstName        = "John",
                LastName         = "Smith",
                HireDate         = new DateTime(2021, 5, 20),
                OfficeAssignment = new OfficeAssignmentModel
                {
                    Location = "Location1"
                }
            };

            ObservableCollection <IValidatable> modifiedProperties   = CreateValidatablesFromSettings(formDescriptor);
            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";

            IMapper mapper = serviceProvider.GetRequiredService <IMapper>();
            Dictionary <string, object> existing = instructorModel.EntityToObjectDictionary
                                                   (
                mapper,
                formDescriptor.FieldSettings
                                                   );

            Dictionary <string, object> current = modifiedProperties.ValidatableListToObjectDictionary
                                                  (
                mapper,
                formDescriptor.FieldSettings
                                                  );

            EntityMapper.UpdateEntityStates
            (
                existing,
                current,
                formDescriptor.FieldSettings
            );

            InstructorModel currentInstructor = mapper.Map <InstructorModel>(current);

            Assert.Equal(LogicBuilder.Domain.EntityStateType.Unchanged, currentInstructor.EntityState);
            Assert.Equal(LogicBuilder.Domain.EntityStateType.Unchanged, currentInstructor.OfficeAssignment.EntityState);
        }
        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);
        }