Beispiel #1
0
        public void FindByZipcodeTest()
        {
            var instancePath = "xunit_tests/tax-stamper/TaxRatesRepoUSA";
            var logger       = GetLogger(instancePath, "FindByZipcodeTest");

            ITaxRatesRepositoryUSA repository = new SqliteTaxRatesRepositoryUSA(logger, "FindByZipcode_TaxRateRepo", instancePath);

            var record = new TaxRateUSA()
            {
                Zipcode = 68136
                , ZipPlus4StartRange = 0
                , ZipPlus4EndRange   = 9999
                , EffectiveDate      = new DateTime(1960, 2, 10)
                , TaxRateState       = 0.07
                , TaxRateCounty      = 0.05
                , TaxRateCity        = 0.03
                , TaxRateLocal1      = 0.02
                , TaxRateLocal2      = 0.01
            };

            // create record
            long id = repository.Create(record);

            Assert.True(id > 0);

            // fetch record
            var fetchedRecord = repository.FetchByZipcode(68136, 1000, new DateTime(1960, 2, 20));

            Assert.Equal(id, fetchedRecord.Id);

            // fetch record
            var fetchNullRecord = repository.FetchByZipcode(68136, 1000, new DateTime(1960, 1, 20));

            Assert.Null(fetchNullRecord);
        }
Beispiel #2
0
        public void CreateFetchUpdateDeleteTest()
        {
            var instancePath = "xunit_tests/tax-stamper/TaxRatesRepoUSA";
            var logger       = GetLogger(instancePath, "CreateFetchUpdateDeleteTest");

            ITaxRatesRepositoryUSA repository = new SqliteTaxRatesRepositoryUSA(logger, "CFUD_TaxRateRepo", instancePath);

            var record = new TaxRateUSA()
            {
                Zipcode = 68136
                , ZipPlus4StartRange = 0
                , ZipPlus4EndRange   = 9999
                , EffectiveDate      = new DateTime(1941, 1, 1)
                , TaxRateState       = 0.07
                , TaxRateCounty      = 0.05
                , TaxRateCity        = 0.03
                , TaxRateLocal1      = 0.02
                , TaxRateLocal2      = 0.01
            };

            // create record
            long id = repository.Create(record);

            Assert.True(id > 0);

            // fetch record
            var fetchedRecord = repository.FetchById(id);

            Assert.Equal(id, fetchedRecord.Id);

            // update object
            fetchedRecord.TaxRateState  = 0.077;
            fetchedRecord.TaxRateCounty = 0.055;

            // update record
            var updatedRecords = repository.Update(fetchedRecord);

            Assert.Equal(1, updatedRecords);

            // confirm update
            var updatedRecord = repository.FetchById(id);

            Assert.Equal(fetchedRecord.TaxRateState, updatedRecord.TaxRateState);
            Assert.Equal(fetchedRecord.TaxRateCounty, updatedRecord.TaxRateCounty);

            // delete record
            var deletedRecords = repository.Delete(updatedRecord);

            Assert.Equal(1, deletedRecords);

            // confirm deletion
            var deletedRecord = repository.FetchById(id);

            Assert.Null(deletedRecord);
        }
Beispiel #3
0
        public TaxRateUSA FetchById(long id)
        {
            _logger.Verbose($"{this.GetType().Name} IN FetchById");

            var model = new TaxRateUSA();

            using (var connection = GetDatabaseConnection())
            {
                connection.Open();
                model = connection.Query <TaxRateUSA>(GetFetchByIdStatement(), new { Id = id }).FirstOrDefault();
            }

            _logger.Verbose($"{this.GetType().Name} OUT FetchById");
            return(model);
        }
Beispiel #4
0
        public long Update(TaxRateUSA record)
        {
            _logger.Verbose($"{this.GetType().Name} IN Update");

            long rowsUpdated = 0;

            using (var connection = GetDatabaseConnection())
            {
                connection.Open();
                rowsUpdated = connection.Execute(GetUpdateStatement(), record);
            }

            _logger.Verbose($"{this.GetType().Name} OUT Delete, rowsUpdated is {rowsUpdated}");
            return(rowsUpdated);
        }
Beispiel #5
0
        public long Create(TaxRateUSA record)
        {
            _logger.Verbose($"{this.GetType().Name} IN Create");

            long id = 0;

            using (var connection = GetDatabaseConnection())
            {
                connection.Open();
                id = connection.Query <long>(GetInsertStatement(), record).First();
            }

            _logger.Verbose($"{this.GetType().Name} OUT Create, id is {id}");
            return(id);
        }
Beispiel #6
0
        private ITaxRatesRepositoryUSA GetSalesTaxRatesRepositoryUSA(ILogger logger, string name, string instancePath)
        {
            ITaxRatesRepositoryUSA repository = new SqliteTaxRatesRepositoryUSA(logger, name, instancePath);

            var record = new TaxRateUSA()
            {
                Zipcode = 68136
                , ZipPlus4StartRange = 0
                , ZipPlus4EndRange   = 9999
                , EffectiveDate      = new DateTime(1941, 1, 1)
                , TaxRateState       = 0.08
                , TaxRateCounty      = 0.06
                , TaxRateCity        = 0.04
                , TaxRateLocal1      = 0.03
                , TaxRateLocal2      = 0.02
            };

            repository.Create(record);

            return(repository);
        }
Beispiel #7
0
        public TaxRateUSA FetchByZipcode(int zipcode, int zipPlus4, DateTime onDate)
        {
            _logger.Verbose($"{this.GetType().Name} IN FetchByZipcode");

            var model = new TaxRateUSA();

            using (var connection = GetDatabaseConnection())
            {
                connection.Open();
                model = connection.Query <TaxRateUSA>(
                    GetFetchByZipcodeStatement()
                    , new {
                    Zipcode         = zipcode
                    , ZipPlus4      = zipPlus4
                    , EffectiveDate = onDate
                }).FirstOrDefault();
            }

            _logger.Verbose($"{this.GetType().Name} OUT FetchByZipcode");
            return(model);
        }
Beispiel #8
0
        public void CreateTest()
        {
            var instancePath = "xunit_tests/tax-stamper/TaxRatesRepoUSA";
            var logger       = GetLogger(instancePath, "CreateTest");

            ITaxRatesRepositoryUSA repository = new SqliteTaxRatesRepositoryUSA(logger, "CreateTest_TaxRateRepo", instancePath);

            var record = new TaxRateUSA()
            {
                Zipcode = 68136
                , ZipPlus4StartRange = 0
                , ZipPlus4EndRange   = 9999
                , EffectiveDate      = new DateTime(1941, 1, 1)
                , TaxRateState       = 0.07
                , TaxRateCounty      = 0.05
                , TaxRateCity        = 0.03
                , TaxRateLocal1      = 0.02
                , TaxRateLocal2      = 0.01
            };

            long id = repository.Create(record);

            Assert.True(id > 0);
        }