public MainWindowViewModel() { PhoneBookRepo = new PhoneBookRepository(); ResetGrid(); Contact = new Contact(); this.SubmitCmd = new DelegateCommand(Submit, CanSubmit); }
public async Task AddContact_NewContact() { var dbContext = DbContextMocker.GetPhoneBookDbContext(nameof(AddContact_NewContact)); PhoneBookRepository repository = new PhoneBookRepository(dbContext); Contact newContact = new Contact() { ContactId = 0, FirstName = "Freddie", LastName = "Philips", ContactPhones = new List <ContactPhone>() { new ContactPhone() { ContactId = 0, ContactPhoneId = 0, CountryCode = "40", AreaCode = "80", PhoneNumber = "74521397" } } }; repository.AddContact(newContact); await repository.SaveAsync(); Assert.True(dbContext.Contacts.Any(c => c.FirstName.Equals("Freddie") && c.LastName.Equals("Philips"))); Assert.NotEmpty(dbContext.Contacts.First(c => c.FirstName.Equals("Freddie") && c.LastName.Equals("Philips")).ContactPhones); dbContext.Dispose(); }
public GetById(ITestOutputHelper output) { _output = output; var dbOptions = new DbContextOptionsBuilder <PhoneBookContext>() .UseInMemoryDatabase(databaseName: "TestPhoneBook") .Options; _phoneBookContext = new PhoneBookContext(dbOptions); _phoneBookRepository = new PhoneBookRepository(_phoneBookContext); }
public async Task GetContactById_ContactDoesNotExist() { var dbContext = DbContextMocker.GetPhoneBookDbContext(nameof(GetContactById_ContactDoesNotExist)); PhoneBookRepository repository = new PhoneBookRepository(dbContext); Contact contact = await repository.GetContact(1000); dbContext.Dispose(); Assert.Null(contact); }
public async Task FindContactInContext_ContactDoesNotExist() { var dbContext = DbContextMocker.GetPhoneBookDbContext(nameof(FindContactInContext_ContactDoesNotExist)); PhoneBookRepository repository = new PhoneBookRepository(dbContext); int id = 2000; Contact contact = await repository.FindAsync(id); dbContext.Dispose(); Assert.Null(contact); }
public async Task GetContactById_ContactExists() { var dbContext = DbContextMocker.GetPhoneBookDbContext(nameof(GetContactById_ContactExists)); PhoneBookRepository repository = new PhoneBookRepository(dbContext); Contact contact = await repository.GetContact(1); dbContext.Dispose(); Assert.NotNull(contact); Assert.NotEmpty(contact.ContactPhones); }
public async Task SearchContactsByLastName_ContactDoesNotExist() { var dbContext = DbContextMocker.GetPhoneBookDbContext(nameof(SearchContactsByLastName_ContactDoesNotExist)); PhoneBookRepository repository = new PhoneBookRepository(dbContext); string lastName = "Brown"; IEnumerable <Contact> contacts = await repository.SearchContactsByNameAsync(lastName); dbContext.Dispose(); Assert.Equal(new List <Contact>(), contacts); }
public async Task ContactExists_BooleanResponse_ContactDoesNotExist() { var dbContext = DbContextMocker.GetPhoneBookDbContext(nameof(ContactExists_BooleanResponse_ContactDoesNotExist)); PhoneBookRepository repository = new PhoneBookRepository(dbContext); int id = 2000; bool contactExists = await repository.ContactExistsAsync(id); dbContext.Dispose(); Assert.False(contactExists); }
public async Task SearchContactsByLastName_ContactExists() { var dbContext = DbContextMocker.GetPhoneBookDbContext(nameof(SearchContactsByLastName_ContactExists)); PhoneBookRepository repository = new PhoneBookRepository(dbContext); string lastName = "Doe"; IEnumerable <Contact> contacts = await repository.SearchContactsByNameAsync(lastName); dbContext.Dispose(); Assert.NotNull(contacts); Assert.All <Contact>(contacts, c => c.LastName.Equals(lastName)); }
public async Task FindContactInContext_ContactExists() { var dbContext = DbContextMocker.GetPhoneBookDbContext(nameof(FindContactInContext_ContactExists)); PhoneBookRepository repository = new PhoneBookRepository(dbContext); int id = 2; Contact contact = await repository.FindAsync(id); dbContext.Dispose(); Assert.NotNull(contact); Assert.Equal(id, contact.ContactId); Assert.NotNull(contact.ContactPhones); Assert.NotEmpty(contact.ContactPhones); }
public async Task GetContactPhone_ContactExists() { var dbContext = DbContextMocker.GetPhoneBookDbContext(nameof(GetContactPhone_ContactExists)); PhoneBookRepository repository = new PhoneBookRepository(dbContext); int contactId = 2; int contactPhoneId = 2; ContactPhone contactPhone = await repository.GetContactPhone(contactId, contactPhoneId); dbContext.Dispose(); Assert.NotNull(contactPhone); Assert.Equal(contactPhoneId, contactPhone.ContactPhoneId); Assert.Equal(contactId, contactPhone.ContactId); Assert.NotNull(contactPhone.Contact); }
public async Task SearchContactsByPhone_ContactExists() { var dbContext = DbContextMocker.GetPhoneBookDbContext(nameof(SearchContactsByPhone_ContactExists)); PhoneBookRepository repository = new PhoneBookRepository(dbContext); string phone = "322209999999"; IEnumerable <Contact> contacts = await repository.SearchContactsByPhoneAsync(phone); dbContext.Dispose(); Assert.NotNull(contacts); Assert.Single(contacts); Assert.Single(contacts.First().ContactPhones); Assert.All <Contact>(contacts, c => string.Concat(c.ContactPhones.First().CountryCode, c.ContactPhones.First().AreaCode, c.ContactPhones.First().PhoneNumber) .Equals(phone)); }
public void GetAll_ReturnsAListOfPhoneBooks() { // Arrange var options = new DbContextOptionsBuilder <PhoneBookApiContext>() .UseInMemoryDatabase(databaseName: "phone_book_get_all") .Options; using (var context = new PhoneBookApiContext(options)) { context.PhoneBooks.Add(GetFakePhoneBooks()[0]); context.PhoneBooks.Add(GetFakePhoneBooks()[1]); context.SaveChanges(); var phoneBookRepository = new PhoneBookRepository(context); // Act var result = phoneBookRepository.GetAll().ToList(); Assert.IsType <List <PhoneBook> >(result); Assert.Equal(2, result.Count()); } }
public void Get_ReturnsAPhoneBook() { // Arrange var options = new DbContextOptionsBuilder <PhoneBookApiContext>() .UseInMemoryDatabase(databaseName: "phone_book_get_by_id") .Options; var testId = 1; using (var context = new PhoneBookApiContext(options)) { context.PhoneBooks.Add(GetFakePhoneBooks()[0]); context.PhoneBooks.Add(GetFakePhoneBooks()[1]); context.SaveChanges(); var phoneBookRepository = new PhoneBookRepository(context); // Act var result = phoneBookRepository.GetById(1); // Assert Assert.IsType <PhoneBook>(result); Assert.Equal(testId, result.PhoneBookId); } }
public void QueryContactTypesMock() { var contactTypes = new List <ContactType> { new ContactType() { Name = "Work" }, new ContactType() { Name = "Cell phone" }, new ContactType() { Name = "Home" } }.AsQueryable(); var mockSet = new Mock <DbSet <ContactType> >(); mockSet.As <IQueryable <ContactType> >().Setup(m => m.Provider).Returns(contactTypes.Provider); mockSet.As <IQueryable <ContactType> >().Setup(m => m.Expression).Returns(contactTypes.Expression); mockSet.As <IQueryable <ContactType> >().Setup(m => m.ElementType).Returns(contactTypes.ElementType); mockSet.As <IQueryable <ContactType> >().Setup(m => m.GetEnumerator()).Returns(contactTypes.GetEnumerator()); var mockContext = new Mock <PhoneBookContext>(); mockContext.Setup(c => c.ContactTypes).Returns(mockSet.Object); var service = new PhoneBookRepository <ContactType>(mockContext.Object); var returnedContactTypes = service.GetEntities().ToList(); Assert.AreEqual(contactTypes.Count(), returnedContactTypes.Count()); Assert.AreEqual("Work", returnedContactTypes[0].Name); Assert.AreEqual("Cell phone", returnedContactTypes[1].Name); Assert.AreEqual("Home", returnedContactTypes[2].Name); }
public async Task AddContact_NewContactPhone() { var dbContext = DbContextMocker.GetPhoneBookDbContext(nameof(AddContact_NewContactPhone)); PhoneBookRepository repository = new PhoneBookRepository(dbContext); Contact newContact = new Contact() { ContactId = 0, FirstName = "John", LastName = "Doe", ContactPhones = new List <ContactPhone>() { new ContactPhone() { ContactPhoneId = 0, ContactId = 0, CountryCode = "00", AreaCode = "001", PhoneNumber = "123456" } } }; repository.AddContact(newContact); await repository.SaveAsync(); Assert.True(dbContext.Contacts.Where(c => c.FirstName.Equals("John") && c.LastName.Equals("Doe")).Count() == 1); Assert.NotEmpty(dbContext.Contacts.First(c => c.FirstName.Equals("John") && c.LastName.Equals("Doe")).ContactPhones); Assert.Contains(dbContext.Contacts .First(c => c.FirstName.Equals("John") && c.LastName.Equals("Doe")) .ContactPhones, p => (p.CountryCode + p.AreaCode + p.PhoneNumber).Equals("00001123456")); dbContext.Dispose(); }
public UserRepository(PhoneBookRepository _EntityContex) : base(_EntityContex) { PhoneDB = _EntityContex; }
public PhoneBookRecordAction() { _phoneBookRecordRepository = new PhoneBookRecordRepository(); _phoneBookRepository = new PhoneBookRepository(); }
public PhoneBookService() { _phoneBookRepository = new PhoneBookRepository(); }
/// <summary> /// Constructor /// </summary> /// <param name="repository"></param> public PhoneBookController(PhoneBookRepository repository) { _repository = repository; }
public void Setup() { this._phoneBookRepo = new PhoneBookRepository(dbContext); this._phoneBookEntryRepo = new PhoneBookEntryRepository(dbContext); }
public void Setup() { this._repo = new PhoneBookRepository(dbContext); }
public ContactItemsRepository(PhoneBookRepository _EntityContex) : base(_EntityContex) { PhoneDB = _EntityContex; }
public void QueryContactTypesMock() { var contactTypes = new List<ContactType> { new ContactType() { Name = "Work" }, new ContactType() { Name = "Cell phone" }, new ContactType() { Name = "Home" } }.AsQueryable(); var mockSet = new Mock<DbSet<ContactType>>(); mockSet.As<IQueryable<ContactType>>().Setup(m => m.Provider).Returns(contactTypes.Provider); mockSet.As<IQueryable<ContactType>>().Setup(m => m.Expression).Returns(contactTypes.Expression); mockSet.As<IQueryable<ContactType>>().Setup(m => m.ElementType).Returns(contactTypes.ElementType); mockSet.As<IQueryable<ContactType>>().Setup(m => m.GetEnumerator()).Returns(contactTypes.GetEnumerator()); var mockContext = new Mock<PhoneBookContext>(); mockContext.Setup(c => c.ContactTypes).Returns(mockSet.Object); var service = new PhoneBookRepository<ContactType>(mockContext.Object); var returnedContactTypes = service.GetEntities().ToList(); Assert.AreEqual(contactTypes.Count(), returnedContactTypes.Count()); Assert.AreEqual("Work", returnedContactTypes[0].Name); Assert.AreEqual("Cell phone", returnedContactTypes[1].Name); Assert.AreEqual("Home", returnedContactTypes[2].Name); }
public PhoneBookController(ILogger <PhoneBookController> logger, PhoneBookRepository repository) { _logger = logger; _repository = repository; }
public PhoneBookService(ILogger <PhoneBookService> logger, PhoneBookRepository repository) { this.logger = logger; this.repository = repository; }