コード例 #1
0
        public static ResidentResponse AddPersonWithRelatedEntitiesToDb(ResidentContactContext context, int?id = null,
                                                                        string firstname = null, string lastname = null, int?contactTypeLookupId = null, int?contactSubTypeLookupId = null)
        {
            var fixture     = new Fixture();
            var resident    = TestHelper.CreateDatabasePersonEntity(firstname, lastname, id);
            var addedPerson = context.Residents.Add(resident);

            context.SaveChanges();

            var contactType = new ContactTypeLookup {
                Name = fixture.Create <string>()
            };

            contactType.Id = contactTypeLookupId ?? contactType.Id;

            var subContactType = new ContactSubTypeLookup {
                Name = fixture.Create <string>()
            };

            subContactType.Id = contactSubTypeLookupId ?? subContactType.Id;

            context.ContactTypeLookups.Add(contactType);
            context.ContactSubTypeLookups.Add(subContactType);
            context.SaveChanges();

            var contact = TestHelper.CreateDatabaseContactEntity(addedPerson.Entity.Id, contactType.Id, subContactType.Id);

            context.ContactDetails.Add(contact);
            context.SaveChanges();

            return(new ResidentResponse
            {
                Id = resident.Id,
                FirstName = resident.FirstName,
                LastName = resident.LastName,
                Gender = "F",
                DateOfBirth = resident.DateOfBirth,
                ContactInformation =
                    new List <ContactDetailsResponse>
                {
                    new ContactDetailsResponse
                    {
                        Id = contact.Id,
                        Value = contact.ContactValue,
                        AddedBy = contact.AddedBy,
                        Active = contact.IsActive,
                        Default = contact.IsDefault,
                        DateLastModified = contact.DateLastModified,
                        ModifiedBy = contact.ModifiedBy,
                        DateAdded = contact.DateAdded,
                        Type = contactType.Name,
                        SubType = subContactType.Name
                    }
                }
            });
        }
コード例 #2
0
        private ContactTypeLookup AddContactTypeToDatabase()
        {
            var contactType = new ContactTypeLookup {
                Name = _fixture.Create <string>()
            };

            ResidentContactContext.ContactTypeLookups.Add(contactType);
            ResidentContactContext.SaveChanges();
            return(contactType);
        }
コード例 #3
0
        public void ItMapsAContactDatabaseRecordToDomain()
        {
            var contactType = new ContactTypeLookup
            {
                Id   = 2,
                Name = "My type Name"
            };
            var contactSubType = new ContactSubTypeLookup
            {
                Id   = 5,
                Name = "Mobile sub type"
            };
            var contact = new Contact
            {
                Id                   = 5,
                AddedBy              = "adder",
                ContactValue         = "0284628",
                DateAdded            = new DateTime(2012, 04, 05),
                IsActive             = true,
                IsDefault            = false,
                ModifiedBy           = "modifier",
                ContactTypeLookup    = contactType,
                DateLastModified     = new DateTime(2013, 07, 12),
                ContactSubTypeLookup = contactSubType,
            };

            contact.ToDomain().Should().BeEquivalentTo(new ContactDetailsDomain
            {
                Id               = 5,
                Type             = "My type Name",
                AddedBy          = "adder",
                ContactValue     = "0284628",
                DateAdded        = new DateTime(2012, 04, 05),
                IsActive         = true,
                IsDefault        = false,
                ModifiedBy       = "modifier",
                SubType          = "Mobile sub type",
                DateLastModified = new DateTime(2013, 07, 12)
            });
        }