Exemple #1
0
        public void ContactAddedToExistingScheme_SchemeUpdateIsAudited_ContactCreateIsAudited()
        {
            using (DatabaseWrapper database = new DatabaseWrapper())
            {
                var context      = database.WeeeContext;
                var organisation = Organisation.CreateSoleTrader("test name");
                var scheme       = new Scheme(organisation);

                organisation = context.Organisations.Add(organisation);
                scheme       = context.Schemes.Add(scheme);

                context.SaveChanges(); // This will reset the change tracker

                scheme.AddOrUpdateMainContactPerson(new Contact("first", "last", "position"));

                var schemeChanges  = context.ChangeTracker.Entries <Scheme>();
                var contactChanges = context.ChangeTracker.Entries <Contact>();

                Assert.Equal(EntityState.Added, contactChanges.Single().State);
                Assert.Equal(EntityState.Modified, schemeChanges.Single().State);
            }
        }
        private async Task CreateScheme(DatabaseWrapper db)
        {
            const Domain.Obligation.ObligationType obligationType = Domain.Obligation.ObligationType.B2B;

            var contact = new Domain.Organisation.Contact("firstName", "LastName", "Position");

            Organisation organisation = Organisation.CreateSoleTrader("Test Organisation");
            var          address      = new Address("address1", "address2", "town", "county", "postcode", db.WeeeContext.Countries.First(), "telephone", "email");

            organisation.AddOrUpdateAddress(Domain.AddressType.RegisteredOrPPBAddress, address);

            Domain.UKCompetentAuthority authority = db.WeeeContext.UKCompetentAuthorities.Single(c => c.Abbreviation == UKCompetentAuthorityAbbreviationType.EA);

            Scheme scheme1 = new Scheme(organisation);

            scheme1.UpdateScheme("BBB", "TT", "Test", obligationType, authority);
            scheme1.AddOrUpdateMainContactPerson(contact);
            scheme1.AddOrUpdateAddress(address);
            db.WeeeContext.Organisations.Add(organisation);
            db.WeeeContext.Schemes.Add(scheme1);
            await db.WeeeContext.SaveChangesAsync();
        }