Exemple #1
0
        static int Insert_should_assign_identity_to_new_entity()
        {
            // arrange
            Module4.IContactRepository repository = CreateRepository();
            var contact = new Module4.Contact
            {
                FirstName = "Joe",
                LastName  = "Blow",
                Email     = "*****@*****.**",
                Company   = "Microsoft",
                Title     = "Developer"
            };
            var address = new Module4.Address
            {
                AddressType   = "Home",
                StreetAddress = "123 Main Street",
                City          = "Baltimore",
                StateId       = 1,
                PostalCode    = "22222"
            };

            contact.Addresses.Add(address);

            // act
            //repository.Add(contact);
            repository.Save(contact);

            // assert
            Debug.Assert(contact.Id != 0);
            Console.WriteLine("*** Contact Inserted ***");
            Console.WriteLine($"New ID: {contact.Id}");
            return(contact.Id);
        }
Exemple #2
0
        static void Modify_should_update_existing_entity(int id)
        {
            // arrange
            Module4.IContactRepository repository = CreateRepository();

            // act
            //var contact = repository.Find(id);
            var contact = repository.GetFullContact(id);

            contact.FirstName = "Bob";
            contact.Addresses[0].StreetAddress = "456 Main Street";
            //repository.Update(contact);
            repository.Save(contact);

            // create a new repository for verification purposes
            Module4.IContactRepository repository2 = CreateRepository();
            //var modifiedContact = repository2.Find(id);
            var modifiedContact = repository2.GetFullContact(id);

            // assert
            Console.WriteLine("*** Contact Modified ***");
            Runner.Extensions.Output(modifiedContact);
            Debug.Assert(modifiedContact.FirstName == "Bob");
            Debug.Assert(modifiedContact.Addresses.First().StreetAddress == "456 Main Street");
        }