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

            ITaxRatesRepositoryCA repository = new SqliteTaxRatesRepositoryCA(logger, "FindByZipcode_TaxRateRepo", instancePath);

            var record = new TaxRateCA()
            {
                ForwardStationArea  = "K8N"
                , LocalDeliveryUnit = "5W6"
                , EffectiveDate     = new DateTime(1960, 2, 10)
                , TaxRateGST        = 0.07
                , TaxRatePST        = 0.05
                , TaxRateHST        = 0.03
            };

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

            Assert.True(id > 0);

            // fetch record
            var fetchedRecord = repository.FetchByZipcode("K8N", "5W6", new DateTime(1960, 2, 20));

            Assert.Equal(id, fetchedRecord.Id);

            // fetch record
            var fetchNullRecord = repository.FetchByZipcode("K8N", "5W6", new DateTime(1960, 1, 20));

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

            ITaxRatesRepositoryCA repository = new SqliteTaxRatesRepositoryCA(logger, "CFUD_TaxRateRepo", instancePath);

            var record = new TaxRateCA()
            {
                ForwardStationArea  = "K8N"
                , LocalDeliveryUnit = "5W6"
                , EffectiveDate     = new DateTime(1941, 1, 1)
                , TaxRateGST        = 0.07
                , TaxRatePST        = 0.05
                , TaxRateHST        = 0.03
            };

            // 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.TaxRateGST = 0.077;
            fetchedRecord.TaxRatePST = 0.055;

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

            Assert.Equal(1, updatedRecords);

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

            Assert.Equal(fetchedRecord.TaxRateGST, updatedRecord.TaxRateGST);
            Assert.Equal(fetchedRecord.TaxRatePST, updatedRecord.TaxRatePST);

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

            Assert.Equal(1, deletedRecords);

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

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

            var model = new TaxRateCA();

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

            _logger.Verbose($"{this.GetType().Name} OUT FetchById");
            return(model);
        }
Exemple #4
0
        public long Update(TaxRateCA 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);
        }
Exemple #5
0
        public long Create(TaxRateCA 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);
        }
Exemple #6
0
        private ITaxRatesRepositoryCA GetSalesTaxRatesRepositoryCA(ILogger logger, string name, string instancePath)
        {
            ITaxRatesRepositoryCA repository = new SqliteTaxRatesRepositoryCA(logger, name, instancePath);

            var record = new TaxRateCA()
            {
                ForwardStationArea  = "K8N"
                , LocalDeliveryUnit = "5W6"
                , EffectiveDate     = new DateTime(1960, 2, 10)
                , TaxRateGST        = 0.08
                , TaxRatePST        = 0.06
                , TaxRateHST        = 0.04
            };

            repository.Create(record);

            return(repository);
        }
Exemple #7
0
        public TaxRateCA FetchByZipcode(string ForwardStationArea, string localDeliveryUnit, DateTime onDate)
        {
            _logger.Verbose($"{this.GetType().Name} IN FetchByZipcode");

            var model = new TaxRateCA();

            using (var connection = GetDatabaseConnection())
            {
                connection.Open();
                model = connection.Query <TaxRateCA>(
                    GetFetchByZipcodeStatement()
                    , new {
                    ForwardStationArea  = ForwardStationArea
                    , LocalDeliveryUnit = localDeliveryUnit
                    , EffectiveDate     = onDate
                }).FirstOrDefault();
            }

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

            ITaxRatesRepositoryCA repository = new SqliteTaxRatesRepositoryCA(logger, "CreateTest_TaxRateRepo", instancePath);

            var record = new TaxRateCA()
            {
                ForwardStationArea  = "K8N"
                , LocalDeliveryUnit = "5W6"
                , EffectiveDate     = new DateTime(1941, 1, 1)
                , TaxRateGST        = 0.07
                , TaxRatePST        = 0.05
                , TaxRateHST        = 0.03
            };

            long id = repository.Create(record);

            Assert.True(id > 0);
        }