public CreateContactViewModel(UpdateContactQueryResult createContact, IValidationService validationService)
 {
     this.command = createContact.Command;
     this.Counties = createContact.Counties;
     this.Countries = createContact.Countries;
     this.validationService = validationService;
 }
 public CreateContactQueryResult(IList<County> counties, IList<Country> countries)
 {
     Counties = counties;
     Countries = countries;
     Command = new CreateContactCommand();
 }
        //private Contact _contactCreated;
        public WhenUserRequestsToSaveAnInvalidContact()
        {
            _contactRepository = Mock.Of<IContactRepository>();
            //Mock.Get(_contactRepository)
            //    .Setup(q => q.Save(It.IsAny<Contact>()))
            //    .Callback<Contact>(q => _contactCreated = q);

            var countyRepository = Mock.Of<ICountyRepository>();
            Mock.Get(countyRepository)
                .Setup(q => q.GetById(1))
                .Returns(new County(1, "Merseyside"));

            var countryRepository = Mock.Of<ICountryRepository>();
            Mock.Get(countryRepository)
                .Setup(q => q.GetById(1))
                .Returns(new Country(1, "UK"));

            var commandInvoker = new CommandInvoker(new ContactService(countyRepository,
                countryRepository,
                _contactRepository,
                new ValidationService(),
                new ContactAdministrationService(countyRepository,
                    countryRepository,
                    _contactRepository)));

            Mock.Get(countyRepository).Setup(q => q.GetAll()).Returns(_counties);
            Mock.Get(countryRepository).Setup(q => q.GetAll()).Returns(_countries);

            _createContactCommand = new CreateContactCommand
            {
                FirstName = "",
                Surname = "",
                Address1 = "Address 1",
                Address2 = "Address 2",
                CountyId = 1,
                CountryId = 1,
            };
            _createContactResult =
                commandInvoker.Execute<CreateContactCommand, CreateContactQueryResult>(_createContactCommand);
        }
 public ActionResult Create(CreateContactCommand command)
 {
     var response = commandInvoker.Execute<CreateContactCommand, CreateContactQueryResult>(command);
     return ModelState.IsValid ? RedirectToAction("Index") : (ActionResult)View(response);
 }