public static TenancyInformationResponse AddPersonWithRelatedEntitiesToDb(UhContext context, string tenancyReference = null, string agreementId = null, string tenureTypeId = null, string address = null, string postcode = null, string propertyReference = null) { var agreementLookup = AddAgreementTypeToDatabase(context, agreementId); var tenureTypeLookup = AddTenureTypeToDatabase(context, tenureTypeId); var tenancyAgreement = TestHelper.CreateDatabaseTenancyEntity(tenancyReference, agreementLookup.UhAgreementTypeId, propertyReference, tenureTypeLookup.UhTenureTypeId); context.UhTenancyAgreements.Add(tenancyAgreement); context.SaveChanges(); var property = TestHelper.CreateDatabaseProperty(propertyReference ?? tenancyAgreement.PropertyReference, address, postcode); context.UhProperties.Add(property); context.SaveChanges(); var resident = TestHelper.CreateDatabaseResident(tenancyAgreement.HouseholdReference); context.UhResidents.Add(resident); context.SaveChanges(); return(new TenancyInformationResponse { TenancyAgreementReference = tenancyAgreement.TenancyAgreementReference, HouseholdReference = tenancyAgreement.HouseholdReference, PropertyReference = property.PropertyReference, Address = property.AddressLine1, Postcode = property.Postcode, PaymentReference = tenancyAgreement.PaymentReference, CommencementOfTenancyDate = tenancyAgreement.CommencementOfTenancy?.ToString("yyyy-MM-dd"), EndOfTenancyDate = tenancyAgreement.EndOfTenancy?.ToString("yyyy-MM-dd"), CurrentBalance = tenancyAgreement.CurrentRentBalance?.ToString(CultureInfo.CurrentCulture), Present = tenancyAgreement.IsPresent, Terminated = tenancyAgreement.IsTerminated, Service = tenancyAgreement.ServiceCharge?.ToString(CultureInfo.CurrentCulture), OtherCharge = tenancyAgreement.OtherCharges?.ToString(CultureInfo.CurrentCulture), AgreementType = $"{tenancyAgreement.UhAgreementTypeId}: {agreementLookup?.Description}", TenureType = $"{tenureTypeLookup.UhTenureTypeId}: {tenureTypeLookup?.Description}", Residents = new List <Resident> { new Resident { FirstName = resident.FirstName, LastName = resident.LastName, DateOfBirth = resident.DateOfBirth.ToString("yyyy-MM-dd"), PersonNumber = resident.PersonNumber, Responsible = resident.Responsible, Title = resident.Title } } }); }
private static UhTenureType AddTenureTypeToDatabase(UhContext context, string tenureTypeId = null) { var tenureLookup = TestHelper.CreateTenureTypeLookup(); tenureLookup.UhTenureTypeId = tenureTypeId ?? tenureLookup.UhTenureTypeId; context.UhTenure.Add(tenureLookup); context.SaveChanges(); return(tenureLookup); }
private static UhAgreementType AddAgreementTypeToDatabase(UhContext context, string agreementId = null) { var agreementLookup = TestHelper.CreateAgreementTypeLookup(); agreementLookup.UhAgreementTypeId = agreementId ?? agreementLookup.UhAgreementTypeId; context.UhTenancyAgreementsType.Add(agreementLookup); context.SaveChanges(); return(agreementLookup); }
private UHProperty AddPropertyToDatabase() { var expectedProperty = _fixture .Build <UHProperty>() .Create(); UhContext.UhProperties.Add(expectedProperty); UhContext.SaveChanges(); return(expectedProperty); }
public void CanGetADatabaseEntity() { var databaseEntity = new Fixture().Create <UhTenancyAgreement>(); UhContext.Add(databaseEntity); UhContext.SaveChanges(); var result = UhContext.UhTenancyAgreements.ToList().LastOrDefault(); result.Should().BeEquivalentTo(databaseEntity); }
private void AddPropertiesToDatabase(int times) { var expectedProperties = new List <UHProperty>(); for (var i = 0; i < times; i++) { expectedProperties.Add(_fixture.Build <UHProperty>().Create()); expectedProperties.Last().PostCode = "A0 0AA"; } UhContext.UhProperties.AddRangeAsync(expectedProperties); UhContext.SaveChanges(); }
public void GetByIdWillOnlyGetLookupValuesForZAGTypeLookups() { var tagRef = _fixture.Create <string>().Substring(0, 11); var(uhTenancy, _, agreementTypeLookup, property) = SaveTenancyPropertyAndLookups(tagRef); var nonZagAgreementTypeLookup = _fixture.Build <UhAgreementType>() .With(a => a.LookupType, "TAG") .With(a => a.UhAgreementTypeId, agreementTypeLookup.UhAgreementTypeId) .Create(); UhContext.UhTenancyAgreementsType.Add(nonZagAgreementTypeLookup); UhContext.SaveChanges(); var expected = uhTenancy.ToDomain(agreementTypeLookup); var response = _classUnderTest.GetById(uhTenancy.TenancyAgreementReference); response.Should().BeEquivalentTo(expected); }