public void AssemblerCorrectlyReadsUserDto()
        {
            var userDto = new UserDto();
            userDto.Id = 1;
            userDto.Username = "******";
            userDto.FirstName = "user";
            userDto.LastName = "name";
            userDto.IsAdmin = true;
            userDto.Status = Constants.Users.ACTIVE;
            var eventAreaDto = new EventAreaDto() { EventName = Constants.EventAreas.CROSS_COUNTRY };

            userDto.EventAreaResponsibilities.Add(eventAreaDto);
            var eventArea = new EventArea() { EventName = Constants.EventAreas.CROSS_COUNTRY };

            _mockUserRepository.Setup(x => x.GetById(userDto.Id)).Returns(It.IsAny<User>());
            _mockEventAreaRepository.Setup(x => x.FindByEventName(It.IsAny<String>())).Returns(new EventArea());

            var user = _assembler.ReadDto(userDto);

            Assert.IsNotNull(user);
            Assert.AreEqual(userDto.Id, user.Id);
            Assert.AreEqual(userDto.Username, user.Username);
            Assert.AreEqual(userDto.FirstName, user.FirstName);
            Assert.AreEqual(userDto.LastName, user.LastName);
            Assert.AreEqual(userDto.IsAdmin, user.IsAdmin);
            Assert.AreEqual(userDto.Status, user.Status);
            Assert.AreEqual(1, user.EventAreaResponsibilities.Count);

            _mockUserRepository.VerifyAll();
            _mockEventAreaRepository.VerifyAll();
        }
        public void LoadData()
        {
            var bobPhillips = new UserDto() { Username = "******", FirstName = "Bob", LastName = "Phillips", IsAdmin = true, Status = Constants.Users.ACTIVE };
            var poleVaultersList = InitialDataProvider.LoadData(bobPhillips);

            Assert.IsNotNull(poleVaultersList);
            foreach (var poleVaulter in poleVaultersList)
                Assert.IsNotNull(poleVaulter.EventParticipation.Where(x => x.EventName == Constants.EventAreas.POLE_VAULT));
        }
        public static IEnumerable<AthleteDto> LoadData(UserDto userDto)
        {
            if (userDto == null)
                throw new ArgumentNullException("userDto");

            var athleteDtos = new List<AthleteDto>();

            foreach (var eventAreaDto in userDto.EventAreaResponsibilities)
            {
                var eventArea = _eventAreaAssembler.ReadDto(eventAreaDto);
                athleteDtos.AddRange(GetAthletesForEventArea(eventArea));
            }

            return athleteDtos;
        }
        public UserDto WriteDto(User user)
        {
            if (user == null)
                throw new NullReferenceException("user");

            var userDto = new UserDto();

            userDto.Id = user.Id;
            userDto.Username = user.Username;
            userDto.FirstName = user.FirstName;
            userDto.LastName = user.LastName;
            userDto.IsAdmin = user.IsAdmin;
            userDto.Status = user.Status;

            foreach (var eventArea in user.EventAreaResponsibilities)
                userDto.EventAreaResponsibilities.Add(_eventAreaAssembler.WriteDto(eventArea));

            return userDto;
        }
        public void LoadData_ReturnsPopulatedOfEventAreaParticipants()
        {
            var userDto = new UserDto();
            var eventAreaDto = new EventAreaDto() { EventName = Constants.EventAreas.POLE_VAULT };
            var athlete = new Athlete();
            var eventArea = new EventArea();
            userDto.EventAreaResponsibilities.Add(eventAreaDto);
            eventArea.Athletes.Add(athlete);

            _mockEventAreaAssembler.Setup(x => x.ReadDto(eventAreaDto)).Returns(eventArea);
            _mockAthleteAssembler.Setup(x => x.WriteDto(athlete)).Returns(new AthleteDto());

            var athletesList = InitialDataProvider.LoadData(userDto);

            _mockEventAreaAssembler.VerifyAll();
            _mockAthleteAssembler.VerifyAll();

            Assert.IsNotNull(athletesList);
            Assert.AreEqual(1, athletesList.Count());
        }
        public User ReadDto(UserDto userDto)
        {
            if (userDto == null)
                throw new NullReferenceException("userDto");

            var user = ObjectFactory.GetInstance<IUserRepository>().GetById(userDto.Id);

            if (user == null)
            {
                user = new User();

                user.Id = userDto.Id;
                user.Username = userDto.Username;
                user.FirstName = userDto.FirstName;
                user.LastName = userDto.LastName;
                user.IsAdmin = userDto.IsAdmin;
                user.Status = userDto.Status;

                foreach (var eventAreaDto in userDto.EventAreaResponsibilities)
                    user.EventAreaResponsibilities.Add(_eventAreaAssembler.ReadDto(eventAreaDto));
            }

            return user;
        }
 public IEnumerable<AthleteDto> LoadInitialData(UserDto userDto)
 {
     return InitialDataProvider.LoadData(userDto);
 }