/// <summary> /// CreateEntiy /// </summary> /// <param name="product">The entity.</param> /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns> public bool CreateEntiy(ContactDto t) { var dbEntity = typeAdapter.ConvertDtoToEntities(t); entiesrepository.Add(dbEntity); entiesrepository.Save(); return(true); }
public void ICanAdd_Exposes_Add_Entity() { var repo = new ContactRepository( new ConcurrentDictionary <int, Contact>()); repo.Add(new Contact()); }
public void ICanUpdate_Exposes_Update_Multiple_Entities() { var repo = new ContactRepository(); IList <Contact> contacts = new List <Contact> { new Contact { Name = "Contact 1" }, new Contact { Name = "Contact 2" }, new Contact { Name = "Contact 3" }, }; repo.Add(contacts); foreach (var contact in contacts) { contact.Name += " New Name"; } repo.Update(contacts); }
public void RepositoryTest_AddContainsKey_Fail() { //Arrange var contactsDto = new List <ContactDto>() { new WorkDto() { TaxId = 1, Name = "Name", Address = "address1", Company = "Company", EmailAddress = "*****@*****.**", PhoneNumber = "000000000", Title = "Title", Url = "www.url.com" } }; var repository = new ContactRepository(contactsDto); //Act var result = repository.Add(new WorkContact { TaxId = 1 }); //Assert Assert.AreEqual(result, false); }
public void RepositoryTest_Add_Success() { //Arrange var contactsDto = new List <ContactDto>(); var repository = new ContactRepository(contactsDto); var dateTime = DateTime.Now; WorkContact wc = new WorkContact() { TaxId = 1, Name = "Name", Address = "address1", Company = "Company", DateModified = dateTime, EmailAddress = "*****@*****.**", PhoneNumber = "000000000", Title = "Title", Url = "www.url.com" }; //Act repository.Add(wc); //Assert Assert.AreEqual(contactsDto.Count, 1); Assert.IsInstanceOfType(contactsDto[0], typeof(WorkDto)); Assert.AreEqual(contactsDto[0].Address, wc.Address); Assert.AreEqual(contactsDto[0].DateCreated, wc.DateCreated); Assert.AreEqual(contactsDto[0].DateModified, wc.DateModified); Assert.AreEqual(contactsDto[0].Name, wc.Name); Assert.AreEqual(contactsDto[0].PhoneNumber, wc.PhoneNumber); Assert.AreEqual(contactsDto[0].TaxId, wc.TaxId); Assert.AreEqual(((WorkDto)contactsDto[0]).Title, wc.Title); Assert.AreEqual(((WorkDto)contactsDto[0]).Url, wc.Url); }
/// <summary> /// Checks requirements aand saves given entities to database. /// </summary> /// <param name="collection">Represents contact collection to save.</param> /// <returns></returns> public async Task <bool> Save(IEnumerable <Contact> collection) { try { foreach (var item in collection) { //Checking if any contact with same name and lastname exists in database. If yes, we just add the missing phones to this existing contact. Contact existingContact = await _contactRepository.FindByNameAndLastName(item.Name, item.LastName); if (existingContact != null) { //Getting the phone numbers that does not exist in database. List <string> newPhones = item.Phones.Except(existingContact.Phones).ToList(); existingContact.Phones.AddRange(newPhones); await _contactRepository.Update(item.Name, item.LastName, existingContact); } else { await _contactRepository.Add(item); } } return(true); } catch (Exception) { return(false); } }
public async Task ShouldAddContactTest() { var options = await SeededDb("ShouldAddContactTest"); var contact = new Contact() { PersonId = Guid.Parse("2fc4d2c4-3749-485f-8373-2c0d57bcb000"), Type = ContactType.Whatsapp, Value = "55999999991" }; Guid id; using (var context = new BraviApiDbContext(options)) { var repository = new ContactRepository(context); await repository.Add(contact); id = contact.Id; } using (var context = new BraviApiDbContext(options)) { Assert.Equal(SeededContacts.Count + 1, await context.Contacts.CountAsync()); var dbContact = await context.Contacts.FindAsync(id); Assert.Equal(contact.PersonId, dbContact.PersonId); Assert.Equal(contact.Type, dbContact.Type); Assert.Equal(contact.Value, dbContact.Value); } }
public ActionResult Add(Contact contact) { ViewBag.Title = "Evolent Contacts Edit"; IContactRepository _service = new ContactRepository(); _service.Add(contact); return(RedirectToAction("Index")); }
public void ICanAdd_Exposes_Add_Multiple_Entities() { var repo = new ContactRepository( new ConcurrentDictionary <int, Contact>()); repo.Add(new List <Contact> { new Contact(), new Contact() }); }
public IActionResult Add([Required][FromBody] Contact contact) { if (contact.Id < 1 || string.IsNullOrWhiteSpace(contact.Firstname) || string.IsNullOrWhiteSpace(contact.Lastname) || string.IsNullOrWhiteSpace(contact.Email)) { return(BadRequest("Invalid input (e.g. required field missing or empty)")); } repository.Add(contact); return(CreatedAtRoute(nameof(Add), contact)); }
public void Add_A_Contact_When_Partial_Populated_Should_Be_Two() { fixture.PopulatePartial(); var repository = new ContactRepository(fixture.context); repository.Add(ContactEntityTypeConfiguration.ContactSeed.ElementAt(2)); var contactCount = repository.Get().Count(); Assert.Equal(2, contactCount); }
private async Task SaveContact(Contact contact) { using var unitOfWork = _provider.GetService <UnitOfWork>(); var contactRepository = new ContactRepository(unitOfWork); unitOfWork.Begin(); await contactRepository.Add(contact); await unitOfWork.CommitAsync(); }
public IHttpActionResult AddContact(Contact item) { if (_repository.Add(item)) { return(Ok()); } else { return(InternalServerError()); } }
public void AddContactService(ContactDTO entity) { Contact contact = new Contact { Sender = entity.Sender, ContactMessage = entity.ContactMessage, SendingDate = entity.SendingDate, IsRead = entity.IsRead }; contactRepository.Add(contact); }
public void RepositoryTest_AddNull_Fail() { //Arrange var contactsDto = new List <ContactDto>(); var repository = new ContactRepository(contactsDto); //Act var result = repository.Add(null); //Assert Assert.AreEqual(result, false); }
public async Task SaveTest() { string updateString = "Save this update."; Contact newContact = new Contact() { FirstName = "New", LastName = "SaveUser", Address1 = "Address1", Address2 = "Address2", CellPhone = "8005551212", HomePhone = "8005551212", WorkPhone = "8005551212", Notes = String.Empty, ZipCode = "99999", EMail = "*****@*****.**", CityId = 1 }; using (DBContext db = new DBContext(settings.Database.ConnectionString, logger)) { Assert.NotNull(db); UnitOfWork uow = new UnitOfWork(db, logger); ContactRepository repos = new ContactRepository(settings, logger, uow, db); Contact contact = await repos.FindByPK(new PrimaryKey() { Key = 11 }); contact.Notes = updateString; int rows = await repos.Update(contact); Assert.Equal(1, rows); ICollection <Contact> contacts = await repos.FindAll(); Assert.Null(contacts.Where(c => c.LastName == newContact.LastName && c.FirstName == newContact.FirstName).FirstOrDefault()); int key = (int)await repos.Add(newContact); Assert.True(await uow.Save()); contact = await repos.FindByPK(new PrimaryKey() { Key = 11 }); Assert.Equal(contact.Notes, updateString); Assert.True(key > 0); Assert.NotNull(await repos.FindByPK(new PrimaryKey() { Key = key })); } }
public bool AddContact(tb_Contact contact) { try { _repository = new ContactRepository(); _repository.Add(contact); return true; } catch { return false; } }
public void ICanUpdate_Exposes_Update_Entity() { var repo = new ContactRepository(); var contact = new Contact { Name = "Name" }; repo.Add(contact); contact.Name = "New Name"; repo.Update(contact); }
public void ICanGet_Exposes_Get_With_Result() { var repo = new ContactRepository(); var contact = new Contact { Name = "Test User" }; repo.Add(contact); var result = repo.Get(1, x => new { contact.ContactId, contact.Name }); result.Name.ShouldEqual(contact.Name); }
public void ICanUpdate_Exposes_Update_Entity() { var repo = new ContactRepository( new ConcurrentDictionary <int, Contact>()); var contact = new Contact { Name = "Name" }; repo.Add(contact); contact.Name = "New Name"; repo.Update(contact); }
public void Given_ContactRepository_AddContact() { ContactEntity entity = new ContactEntity() { ID = 4, FirstName = "Prakash", LastName = "Rao", Email = "*****@*****.**", PhoneNumber = "569896655", IsActive = true }; objRepo.Add(entity); databaseContext.SaveChanges(); var result = objRepo.GetAll().ToList(); Assert.AreEqual(result.Count, 4); }
public void ICanGet_Exposes_Get_By_Id() { var repo = new ContactRepository(); var contact = new Contact { Name = "Test User", ContactTypeId = 1 }; repo.Add(contact); var result = repo.Get(contact.ContactId); result.Name.ShouldEqual(contact.Name); result.ContactTypeId.ShouldEqual(contact.ContactTypeId); }
public void ICanGet_Exposes_Get_With_Result() { var repo = new ContactRepository( new ConcurrentDictionary <int, Contact>()); var contact = new Contact { Name = "Test User" }; repo.Add(contact); var result = repo.Get(1, x => new { contact.ContactId, contact.Name }); result.Name.Should().Be(contact.Name); }
public void ICanGet_Exposes_GetAll() { var repo = new ContactRepository(); for (int i = 1; i <= 5; i++) { var contact = new Contact { Name = "Test User " + i }; repo.Add(contact); } IEnumerable <Contact> result = repo.GetAll().ToList(); result.Count().ShouldEqual(5); }
public void New_contacts_should_be_added_to_the_repository() { var repository = new ContactRepository(); var contact = new Contact() { Id = new Guid(), Name = "Effie Trinket", Account = "254994573", Address = "Capitol", CreditCard = "5678901234561234", PinNumber = "5773" }; repository.Add(contact); var result = repository.Contacts.Single(c => c.Name == "Effie Trinket"); Assert.Equal(contact.Id, result.Id); }