예제 #1
0
        public void GetTaxInfo_GivenAnExistingCountryAndProvince_ReturnsRecordFromDatabase()
        {
            // arrange
            var data = new List <SalesTaxInfo>()
            {
                new SalesTaxInfo()
                {
                    Country    = "Canada",
                    Province   = "Quebec",
                    Federal    = 0.05f,
                    Provincial = 0.0975f
                }
            };
            var expected = data[0];
            Mock <DbSet <SalesTaxInfo> > mockTaxesSet = EntityMockFactory.CreateSet(data.AsQueryable());
            Mock <AccountingDb>          mockContext  = new Mock <AccountingDb>();

            mockContext.Setup(c => c.Taxes).Returns(mockTaxesSet.Object);
            SalesTaxRepository sut = new SalesTaxRepository(mockContext.Object);

            // act
            var actual = sut.GetTaxInfo("Canada", "Quebec");

            // assert
            mockContext.Verify(c => c.Taxes, Times.Once());
            Assert.AreEqual(expected.Federal, actual.Federal);
            Assert.AreEqual(expected.Provincial, actual.Provincial);
        }
예제 #2
0
        public void AddTaxInfo_GivenAnExistingTaxInfo_ThrowsException()
        {
            // arrange
            SalesTaxInfo duplicateTax = new SalesTaxInfo()
            {
                Country  = "Canada",
                Province = "Quebec"
            };
            var data = new List <SalesTaxInfo>()
            {
                new SalesTaxInfo()
                {
                    Country  = "Canada",
                    Province = "Quebec"
                }
            };
            Mock <DbSet <SalesTaxInfo> > mockTaxesSet = EntityMockFactory.CreateSet(data.AsQueryable());
            Mock <AccountingDb>          mockContext  = new Mock <AccountingDb>();

            mockContext.Setup(c => c.Taxes).Returns(mockTaxesSet.Object);
            SalesTaxRepository sut = new SalesTaxRepository(mockContext.Object);

            // act
            sut.AddTaxInfo(duplicateTax);

            // assert
            // exception should be thrown
        }
예제 #3
0
        public void UodateTaxInfo_GivenAnUpdatedInfo_UpdatesRecordInDatabase()
        {
            // arrange
            SalesTaxInfo update = new SalesTaxInfo()
            {
                Country    = "Canada",
                Province   = "Quebec",
                Federal    = 0.05f,
                Provincial = 0.0975f
            };
            var data = new List <SalesTaxInfo>()
            {
                new SalesTaxInfo()
                {
                    Country    = "Canada",
                    Province   = "Quebec",
                    Federal    = 0.12f,
                    Provincial = 0.04f
                }
            };
            var actual = data[0];
            Mock <DbSet <SalesTaxInfo> > mockTaxesSet = EntityMockFactory.CreateSet(data.AsQueryable());
            Mock <AccountingDb>          mockContext  = new Mock <AccountingDb>();

            mockContext.Setup(c => c.Taxes).Returns(mockTaxesSet.Object);
            SalesTaxRepository sut = new SalesTaxRepository(mockContext.Object);

            // act
            sut.UpdateTaxInfo(update);

            // assert
            mockContext.Verify(c => c.Taxes, Times.Once());
            Assert.AreEqual(0.05f, actual.Federal);
            Assert.AreEqual(0.0975f, actual.Provincial);
        }
예제 #4
0
 public AccountingService(IPaymentInfoRepository paymentRepository,
                          SalesTaxRepository taxRepository, ObjectCache cache)
 {
     this.paymentRepo = paymentRepository;
     this.taxRepo     = taxRepository;
     this.cache       = cache;
 }
예제 #5
0
        public void AddTaxInfo_GivenANewTaxInfo_AddsToTheDatabase()
        {
            // arrange
            SalesTaxInfo newTax = new SalesTaxInfo()
            {
                Country  = "Canada",
                Province = "Ontario"
            };
            List <SalesTaxInfo>          data         = new List <SalesTaxInfo>();
            Mock <DbSet <SalesTaxInfo> > mockTaxesSet = EntityMockFactory.CreateSet(data.AsQueryable());
            Mock <AccountingDb>          mockContext  = new Mock <AccountingDb>();

            mockContext.Setup(c => c.Taxes).Returns(mockTaxesSet.Object);
            SalesTaxRepository sut = new SalesTaxRepository(mockContext.Object);

            // act
            sut.AddTaxInfo(newTax);

            // assert
            mockContext.Verify(c => c.Taxes, Times.Exactly(2));
            mockTaxesSet.Verify(s => s.Add(newTax), Times.Once());
            mockContext.Verify(c => c.SaveChanges(), Times.Once());
        }