Ejemplo n.º 1
0
        public async Task DeleteContact_DeleteSuccessful_KeyNotFoundException()
        {
            // Arrange
            var dbContext = DbContextMocker.GetContactDbContext(nameof(DeleteContact_DeleteSuccessful_KeyNotFoundException));
            ContactBookService contactBookService = new ContactBookService(dbContext);

            Contact contact = new Contact()
            {
                ContactId      = 26,
                FirstName      = "Raymond",
                Surname        = "Ndlovus",
                BirthDate      = new DateTime(1978, 11, 21),
                UpdatedDate    = DateTime.Now,
                ContactDetails = new List <ContactDetail>()
                {
                    new ContactDetail()
                    {
                        ContactDetailId = 26,
                        ContactId       = 26,
                        Description     = "Description for testing.",
                        Address         = "Address for testing",
                        Cell            = "0782829225",
                        Email           = "*****@*****.**",
                        Telephone       = "0112348734"
                    }
                }
            };

            // Act
            await contactBookService.CreateContact(contact);

            await contactBookService.SaveAsync();

            Contact delContact = await dbContext.Contacts.FindAsync(26);

            await contactBookService.DeleteContact(delContact);

            await contactBookService.SaveAsync();

            bool isDeleted = dbContext.Contacts.Any(c => c.ContactId.Equals(26));

            // Assert
            Assert.False(isDeleted);
        }
Ejemplo n.º 2
0
        public async Task CreateContact_NewContactDetailSuccessful_True()
        {
            // Arrange
            var dbContext = DbContextMocker.GetContactDbContext(nameof(CreateContact_NewContactDetailSuccessful_True));
            ContactBookService contactBookService = new ContactBookService(dbContext);

            Contact contact = new Contact()
            {
                ContactId      = 25,
                FirstName      = "Jacobs",
                Surname        = "Ndlovus",
                BirthDate      = new DateTime(1978, 11, 21),
                UpdatedDate    = DateTime.Now,
                ContactDetails = new List <ContactDetail>()
                {
                    new ContactDetail()
                    {
                        ContactDetailId = 25,
                        ContactId       = 25,
                        Description     = "Description for testing.",
                        Address         = "Address for testing",
                        Cell            = "0782829225",
                        Email           = "*****@*****.**",
                        Telephone       = "0112348734"
                    }
                }
            };

            // Act
            await contactBookService.CreateContact(contact);

            await contactBookService.SaveAsync();

            bool isContactDetailSaved = dbContext.ContactDetails.Any(cd => cd.ContactId.Equals(25) && cd.ContactDetailId.Equals(25) && cd.Cell.Equals("0782829225") && cd.Email.Equals("*****@*****.**"));

            // Assert
            Assert.True(isContactDetailSaved);
        }