public void Save()
        {
            var individualEntity =
                new IndividualEntity
                    {
                        Id = Id,
                        LastName = LastName,
                        FirstName = FirstName,
                        MiddleName = MiddleInitial,
                        Suffix = Suffix,
                        DateOfBirth = DateOfBirth,
                    };

            var studentId = individualEntity.Id;
            if (studentId > 0)
            {
                _individualRepo.Update(individualEntity);
            }
            else
            {
                studentId = _individualRepo.Create(individualEntity);
            }

            var studentEntity = _studentRepo.Retrieve(studentId);
            if (studentEntity != null)
            {
                Id = studentEntity.Id;
                
                studentEntity.HighSchoolName = HighSchool.Name;
                studentEntity.HighSchoolCity = HighSchool.City;
                studentEntity.HighSchoolState = HighSchool.State;

                _studentRepo.Update(studentEntity);

                return;
            }
            
            var retVal =
                _studentRepo.Create(
                    new StudentEntity
                        {
                            Id = studentId,
                            HighSchoolName = this.HighSchool.Name,
                            HighSchoolCity = this.HighSchool.City,
                            HighSchoolState = this.HighSchool.State,
                        });

            if (retVal != studentId)
            {
                throw new InvalidOperationException(
                    string.Format("Create failed for student (Id={0})", 
                    studentId));
            }

            Id = studentId;
        }
        public void Get_WhenValidApplicationIsPassed_ExpectEntityHasProperId()
        {
            // Arrange
            const int id = 7;
            const int studentId = 11;

            var application =
                new ApplicationEntity
                    {
                        Id = id,
                        StudentId = studentId,
                    };
            var student = new StudentEntity { Id = studentId, };
            var individual = new IndividualEntity { Id = studentId, };

            var stubApplicationRepo = new Mock<IRepository<ApplicationEntity>>();
            stubApplicationRepo.Setup(e => e.Retrieve(id))
                .Returns(application);

            var stubStudentRepo = new Mock<IRepository<StudentEntity>>();
            stubStudentRepo.Setup(e => e.Retrieve(studentId))
                .Returns(student);

            var stubIndividualRepo = new Mock<IRepository<IndividualEntity>>();
            stubIndividualRepo.Setup(e => e.Retrieve(studentId))
                .Returns(individual);

            var classUnderTest = new Application(stubIndividualRepo.Object, stubStudentRepo.Object, stubApplicationRepo.Object);

            // Act
            classUnderTest.Get(id);

            // Assert
            var actual = classUnderTest.Id;
            Assert.AreEqual(id, actual);
        }
Exemplo n.º 3
0
        internal void LoadData(
            IndividualEntity individual, 
            StudentEntity student)
        {
            Id = student.Id;

            LastName = individual.LastName;
            FirstName = individual.FirstName;
            MiddleInitial = GetMiddleInitial(individual.MiddleName);
            Suffix = individual.Suffix;
            DateOfBirth = individual.DateOfBirth;

            this.HighSchool = 
                new School
                    {
                        Name = student.HighSchoolName, 
                        City = student.HighSchoolCity, 
                        State = student.HighSchoolState,
                    };
        }