public void Setup() { _mapperService = new Mock <IMapperService>(); _eventBroker = new Mock <IEventBroker>(); _outputWriter = new Mock <IOutputWriter>(); _contactBusinessLogic = new ContactBusinessLogic(new ContactModelFactory()); }
public static Contact ConvertToDbContact(this ContactModel model) { var factory = new DatabaseFactory(); var contactBusinessLogic = new ContactBusinessLogic(new ContactRepository(factory), new DictionaryBusinessLogic<ContactType>(new DictionaryRepository<ContactType>(factory)), new DictionaryBusinessLogic<ContactStatus>(new DictionaryRepository<ContactStatus>(factory)), new DictionaryBusinessLogic<AgeDirection>(new DictionaryRepository<AgeDirection>(factory)), new DictionaryBusinessLogic<ReadyToSellState>(new DictionaryRepository<ReadyToSellState>(factory))); var dbContact = contactBusinessLogic.GetById(model.Id); if (dbContact == null) { dbContact = new Contact(); } dbContact.Age = contactBusinessLogic.GetAllAges().First(x => x.Id == model.AgeDirectionId); dbContact.BirthDate = model.BirthDate; dbContact.Comment = model.Comment; dbContact.CreateDate = DateTime.Now; dbContact.Email = model.Email; dbContact.Ip = model.ContactIp; dbContact.Gender = (GenderEnum)Enum.Parse(typeof(GenderEnum), model.Gender); dbContact.Link = model.ContactLink; dbContact.IsNameChecked = true; dbContact.ReadyToBuyScore = model.ReadyToBuyScore; dbContact.ReadyToSell = contactBusinessLogic.GetAllSellStatuses().First(x => x.Id == model.ReadyToSellId); //dbContact.Telephones = contact.Telephones.Split(';').ToList(); dbContact.Status = contactBusinessLogic.GetAllStatuses().First(x => x.Id == model.StatusId); dbContact.Type = contactBusinessLogic.GetAllTypes().First(x => x.Id == model.ContactTypeId); dbContact.Name = model.Name; //dbContact.Id = model.Id; return dbContact; }
public void WhenGivenRawContactWillCreateContactDomainObject() { //Arrange var dto = new ContactDataTransferObject("SMITH", "JOHN"); _contactBusinessLogic = new ContactBusinessLogic(new ContactModelFactory(_mapperService.Object, _eventBroker.Object)); _mapperService.Setup(ms => ms.Map <ContactDataTransferObject, Contact>(dto)) .Returns(new Contact() { FirstName = "JOHN", LastName = "SMITH" }); _eventBroker.Setup(x => x.Raise(new ContactRegisteredEvent(_outputWriter.Object))); _outputWriter.Setup(x => x.WriteLine(It.IsAny <string>())); //Act var result = _contactBusinessLogic.LoadContact(dto); //Assert Assert.IsTrue(result.FirstName == "JOHN"); Assert.IsTrue(result.LastName == "SMITH"); }
private static Contact TryAddContact(string id, string name ) { try { var contactBusinessLogic = new ContactBusinessLogic(new ContactRepository(_factory), new DictionaryBusinessLogic<ContactType>(new DictionaryRepository<ContactType>(_factory)), new DictionaryBusinessLogic<ContactStatus>(new DictionaryRepository<ContactStatus>(_factory)), new DictionaryBusinessLogic<AgeDirection>(new DictionaryRepository<AgeDirection>(_factory)), new DictionaryBusinessLogic<ReadyToSellState>(new DictionaryRepository<ReadyToSellState>(_factory))); var contact = new Contact() { Ip = id, Name = name, Link = "https://www.facebook.com/app_scoped_user_id/" + id + "/", Gender = GenderEnum.Unknown }; var existContact = contactBusinessLogic.GetByIp(id); if (existContact == null) { contactBusinessLogic.Add(contact); return contact; } return existContact; } catch (Exception ex) { throw; } }