Beispiel #1
0
        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();
        }
Beispiel #2
0
        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 override Task <ContactModel> CreateNewContact(ContactModel request, ServerCallContext context)
        {
            ContactModel response = repository.AddContact(request);

            return(Task.FromResult(response));
        }