public void Save(Contact contact) { id++; contact.Id = id; Contacts.Add(contact); }
//TODO use autofixture for the data public WhenUserRequestsToSaveContact() { var 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); commandInvoker.Execute<CreateContactCommand, CreateContactQueryResult>(new CreateContactCommand { FirstName = "Andrew", Surname = "Stewart", Address1 = "Address 1", Address2 = "Address 2", CountyId = 1, CountryId = 1, }); }