コード例 #1
0
        private static async Task <List <Contractor> > SeedContractors(string tradeCode, string expectedProperty, DateTime effectiveDate, DateTime termDate)
        {
            var stringGenerator = new Generator <string>()
                                  .AddDefaultGenerators();
            var contractorGenerator = new Generator <Contractor>()
                                      .AddDefaultGenerators()
                                      .AddValue(null, (Contractor c) => c.Contracts);

            var contractors = contractorGenerator.GenerateList(10);
            var contracts   = contractors.Select(c => new Contract
            {
                ContractReference   = stringGenerator.Generate(),
                ContractorReference = c.Reference,
                EffectiveDate       = effectiveDate,
                TerminationDate     = termDate
            }).ToList();
            var sorCode = new ScheduleOfRates
            {
                Code      = stringGenerator.Generate(),
                TradeCode = tradeCode,
                Enabled   = true
            };
            var sorContracts = contracts.Select(c => new SORContract
            {
                ContractReference = c.ContractReference,
                SorCodeCode       = sorCode.Code,
                Cost = null
            }).ToList();

            var propMaps = contracts.Select(c => new PropertyContract
            {
                PropRef           = expectedProperty,
                ContractReference = c.ContractReference
            }).ToList();

            await InMemoryDb.Instance.Contractors.AddRangeAsync(contractors);

            await InMemoryDb.Instance.SORCodes.AddAsync(sorCode);

            await InMemoryDb.Instance.Contracts.AddRangeAsync(contracts);

            await InMemoryDb.Instance.SORContracts.AddRangeAsync(sorContracts);

            await InMemoryDb.Instance.PropertyContracts.AddRangeAsync(propMaps);

            await InMemoryDb.Instance.SaveChangesAsync();

            return(contractors);
        }
コード例 #2
0
        public async Task CanGetCosts()
        {
            // arrange
            var      generator = new Generator <SORContract>();
            Contract contract  = new Contract
            {
                ContractorReference = "contractor",
                ContractReference   = "contract",
                TerminationDate     = DateTime.UtcNow.Date.AddYears(1),
                EffectiveDate       = DateTime.UtcNow.Date.AddDays(-7)
            };

            ScheduleOfRates sor = new ScheduleOfRates
            {
                Code            = "code",
                Cost            = 1,
                Enabled         = true,
                LongDescription = "",
            };

            generator
            .AddDefaultGenerators()
            .AddValue(sor, (SORContract c) => c.SorCode)
            .AddValue(contract, (SORContract c) => c.Contract);
            var expectedContract = generator.Generate();

            await InMemoryDb.Instance.SORContracts.AddAsync(expectedContract);

            await InMemoryDb.Instance.SaveChangesAsync();

            // act
            var result = await _classUnderTest.GetCost(contract.ContractorReference, sor.Code);

            // assert
            result.Should().Be(expectedContract.Cost);
        }