Пример #1
0
 public void BaseSetup()
 {
     _factory        = new MockWebApplicationFactory <TStartup>(_connection);
     Client          = _factory.CreateClient();
     DatabaseContext = new UhContext(_builder.Options);
     DatabaseContext.Database.EnsureCreated();
     _transaction = DatabaseContext.Database.BeginTransaction();
 }
Пример #2
0
        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);
        }
Пример #3
0
        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);
        }
Пример #4
0
        public void RunBeforeAnyTests()
        {
            var builder = new DbContextOptionsBuilder();

            builder.UseNpgsql(ConnectionString.TestDatabase());
            UhContext = new UhContext(builder.Options);

            UhContext.Database.EnsureCreated();
            _transaction = UhContext.Database.BeginTransaction();
        }
Пример #5
0
        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);
        }
Пример #7
0
        public void RunBeforeAnyTests()
        {
            DbContextOptionsBuilder builder = new DbContextOptionsBuilder();

            string TEST_UH_URL = Environment.GetEnvironmentVariable("TEST_UH_URL") ??
                                 @"Server=localhost;Database=uhsimulator;User Id='sa';Password='******';";

            builder.UseSqlServer(TEST_UH_URL);

            _uhContext = new UhContext(builder.Options);
            _uhContext.Database.BeginTransaction();
        }
Пример #8
0
        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
                    }
                }
            });
        }
Пример #9
0
        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();
        }
Пример #10
0
        protected override void ConfigureWebHost(IWebHostBuilder builder)
        {
            builder.ConfigureAppConfiguration(b => b.AddEnvironmentVariables())
            .UseStartup <Startup>();
            builder.ConfigureServices(services =>
            {
                var dbBuilder = new DbContextOptionsBuilder();
                dbBuilder.UseNpgsql(_connection);
                var context = new UhContext(dbBuilder.Options);
                services.AddSingleton(context);

                var serviceProvider = services.BuildServiceProvider();
                var dbContext       = serviceProvider.GetRequiredService <UhContext>();

                dbContext.Database.EnsureCreated();
            });
        }
Пример #11
0
        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);
        }
Пример #12
0
 public TenancyGateway(UhContext databaseContext)
 {
     _uhContext = databaseContext;
 }
Пример #13
0
 public PropertyGateway(UhContext uhContext)
 {
     _uhContext = uhContext;
 }