public void GetMortgageShouldReturnFromRepository()
        {
            var mockRepo        = new Mock <IMortgageRepo>();
            var fakemortagedata = new List <Mortgage> {
                new Mortgage
                {
                    CancellationFee    = (decimal)259.99,
                    EffectiveEndDate   = DateTime.UtcNow,
                    EffectiveStartDate = DateTime.UtcNow,
                    EstablishmentFee   = (decimal)259.99,
                    InterestRepayment  = (InterestRepayment)Enum.Parse(typeof(InterestRepayment), "InterestOnly"),
                    MortgageId         = 1,
                    MortgageType       = (MortgageType)Enum.Parse(typeof(MortgageType), "Fixed"),
                    Name          = "Fixed Home Loan (Interest Only)",
                    TermsInMonths = 12
                }
            };

            mockRepo.Setup(x => x.GetAllMortgages()).Returns(fakemortagedata);
            var msMortgageService = new MortgageService(mockRepo.Object);

            //Act
            var response = msMortgageService.GetAllMortgages();

            //Assert
            Assert.AreEqual(fakemortagedata, response);
        }
Exemplo n.º 2
0
        private MortgageService CreateMortgageService()
        {
            var userId  = Guid.Parse(User.Identity.GetUserId());
            var service = new MortgageService(userId);

            return(service);
        }
Exemplo n.º 3
0
        public async Task <ActionResult> Index()
        {
            MortgageService mortgageService = new MortgageService();

            var mortgageData = await mortgageService.GetAllMortgagesAsync();

            //var mortgageData = new List<Mortgage>
            //{
            //    new Mortgage
            //    {
            //        MortgageId = 1,
            //        Name = "Fixed Home Loan (Interest Only)",
            //        MortgageType = MortgageType.Fixed,
            //        InterestRepayment = InterestRepayment.InterestOnly,
            //        EffectiveStartDate = new DateTime(2018,06,04,16,25,52),
            //        EffectiveEndDate = new DateTime(2018,06,04,16,25,52),
            //        TermsInMonths = 12,
            //        CancellationFee = 259.99M,
            //        EstablishmentFee = 259.99M,
            //        InterestRate = 4.99M
            //    },
            //    new Mortgage
            //    {
            //        MortgageId = 2,
            //        Name = "Fixed Home Loan (Principal and Interest)",
            //        MortgageType = MortgageType.Fixed,
            //        InterestRepayment = InterestRepayment.PrincipalAndInterest,
            //        EffectiveStartDate = new DateTime(2018,06,04,16,25,52),
            //        EffectiveEndDate = new DateTime(2018,06,04,16,25,52),
            //        TermsInMonths = 12,
            //        CancellationFee = 259.99M,
            //        EstablishmentFee = 259.99M,
            //        InterestRate = 4.81M

            //    },
            //    new Mortgage
            //    {
            //        MortgageId = 3,
            //        Name = "Variable Home Loan (Interest Only)",
            //        MortgageType = MortgageType.Variable,
            //        InterestRepayment = InterestRepayment.InterestOnly,
            //        EffectiveStartDate = new DateTime(2018,06,04,16,25,52),
            //        EffectiveEndDate = new DateTime(2018,06,04,16,25,52),
            //        TermsInMonths = 12,
            //        CancellationFee = 259.99M,
            //        EstablishmentFee = 259.99M,
            //        InterestRate = 5.24M
            //    }
            //};

            //Order Mortgage by Type then by Interest Rate
            var sortedMortgage = mortgageData.OrderBy(x => x.MortgageType).ThenBy(x => x.InterestRate);

            return(View(sortedMortgage));
        }
Exemplo n.º 4
0
        public void It_Should_Get_The_History_List()
        {
            //Arrange
            var             expectedList = entryList;
            MortgageService service      = new MortgageService(repositoryServiceMock.Object);

            //Act
            var historyList = service.GetHistory();

            //Assert
            Assert.AreEqual(expectedList.Count, historyList.Count());
        }
Exemplo n.º 5
0
        public void It_Should_Get_The_History_List_With_The_Same_Items()
        {
            //Arrange
            var             expectedList = entryList;
            MortgageService service      = new MortgageService(repositoryServiceMock.Object);

            //Act
            var historyList = service.GetHistory();

            //Assert
            Assert.AreEqual(expectedList.FirstOrDefault().Id, historyList.FirstOrDefault().Id);
        }
Exemplo n.º 6
0
        public void It_Should_Call_Save_When_Saving_An_Entry()
        {
            //Arrange
            repositoryServiceMock.Setup(s => s.Save(It.IsAny <MortgageEntry>())).Verifiable();

            MortgageService service = new MortgageService(repositoryServiceMock.Object);

            //Act
            var result = service.SaveCalculationEntry(_mortgageEntry);

            //Assert
            repositoryServiceMock.Verify(r => r.Save(It.IsAny <MortgageEntry>()), Times.Once());
        }
Exemplo n.º 7
0
        public TurnServiceTests()
        {
            fakeDice        = new FakeDice();
            fakeBailAdvisor = new FakeBailAdvisor();
            board           = new Board(fakeDice);
            moveService     = new MoveService(board);
            player          = new Player("horse");
            var mortgageBroker  = new MortgageBroker();
            var mortgageAdvisor = new MortgageAdvisor();
            var mortgageService = new MortgageService(board, mortgageAdvisor, mortgageBroker);

            turnService = new TurnService(moveService, mortgageService, fakeBailAdvisor);
        }
Exemplo n.º 8
0
        public void It_Should_Return_False_When_Saving_An_Entry_And_Exception_Is_Thrown()
        {
            //Arrange
            repositoryServiceMock.Setup(s => s.Save(It.IsAny <MortgageEntry>())).Throws(new NotImplementedException());

            MortgageService service = new MortgageService(repositoryServiceMock.Object);

            //Act
            var result = service.SaveCalculationEntry(_mortgageEntry);

            //Assert
            Assert.AreEqual(result, false);
        }
Exemplo n.º 9
0
        public void It_Should_Return_True_When_Saved_An_Entry()
        {
            //Arrange
            repositoryServiceMock.Setup(s => s.Save(It.IsAny <MortgageEntry>())).Verifiable();

            MortgageService service = new MortgageService(repositoryServiceMock.Object);

            //Act
            var result = service.SaveCalculationEntry(_mortgageEntry);

            //Assert
            Assert.AreEqual(result, true);
        }
        public void CheckMortgage_MaturityPeriodNotFoundReturnsNull()
        {
            var options   = new DbContextOptionsBuilder <MortgageDbContext>().UseInMemoryDatabase(databaseName: "MortgageDbTest2").Options;
            var dbContext = new MortgageDbContext(options);

            Seed(dbContext);

            var service = new MortgageService(new MortgageRateRepository(dbContext));

            var res = service.CheckMortgage(0, 99, 0, 0);

            Assert.Null(res);
        }
        public void GetMortgageRates_ReturnsRatesList()
        {
            var options   = new DbContextOptionsBuilder <MortgageDbContext>().UseInMemoryDatabase(databaseName: "MortgageDbTest1").Options;
            var dbContext = new MortgageDbContext(options);

            Seed(dbContext);

            var service = new MortgageService(new MortgageRateRepository(dbContext));

            var rates = service.GetMortgageRates();

            Assert.NotEmpty(rates);
            Assert.Equal(12, rates.Count);
        }
        public void CheckMortgage_ReturnsNotFeasibleResult_MortgageMoreThanHome()
        {
            var options   = new DbContextOptionsBuilder <MortgageDbContext>().UseInMemoryDatabase(databaseName: "MortgageDbTest4").Options;
            var dbContext = new MortgageDbContext(options);

            Seed(dbContext);

            var service = new MortgageService(new MortgageRateRepository(dbContext));

            var res = service.CheckMortgage(200000, 10, 150000, 160000);

            Assert.NotNull(res);
            Assert.False(res.IsFeasible);
        }
Exemplo n.º 13
0
        public void It_Should_Get_An_Empty_List()
        {
            //Arrange
            var expectedList = entryList;

            repositoryServiceMock.Setup(s => s.WhereAllEq <MortgageEntry>(filters, null)).Returns(new List <MortgageEntry>());
            MortgageService service = new MortgageService(repositoryServiceMock.Object);

            //Act
            var historyList = service.GetHistory();

            //Assert
            Assert.AreNotEqual(expectedList.Count, historyList.Count());
            Assert.AreEqual(historyList.Count(), 0);
        }
        public void CheckMortgage_IsFeasible()
        {
            var options   = new DbContextOptionsBuilder <MortgageDbContext>().UseInMemoryDatabase(databaseName: "MortgageDbTest5").Options;
            var dbContext = new MortgageDbContext(options);

            Seed(dbContext);

            var service = new MortgageService(new MortgageRateRepository(dbContext));

            var res = service.CheckMortgage(60000, 10, 200000, 250000);

            Assert.NotNull(res);
            Assert.True(res.IsFeasible);
            Assert.True(Math.Abs(1781.75546 - res.MonthlyCost) < 0.00001);
            //Assert.Equal(1781.7554685308316,res.MonthlyCost);
        }
Exemplo n.º 15
0
        private IEnumerable <Dto.Mortgage> GetFromCache()
        {
            ObjectCache cache = MemoryCache.Default;

            if (cache.Get("MortgageData") is List <Dto.Mortgage> mortgageData)
            {
                return(mortgageData);
            }

            var mortgageService = new MortgageService();

            mortgageData = mortgageService.GetAllMortgages();
            //Cache mortgageData for 24 hours
            CacheItemPolicy policy = new CacheItemPolicy {
                AbsoluteExpiration = DateTimeOffset.Now.AddHours(24)
            };

            cache.Add("MortgageData", mortgageData, policy);

            return(mortgageData);
        }
Exemplo n.º 16
0
        [CacheWebApi(Duration = 1440)] //Cache the response to 24 hours
        public IEnumerable <Dto.Mortgage> Get()
        {
            var mortgageService = new MortgageService();

            return(mortgageService.GetAllMortgages().OrderBy(m => m.MortgageType).ThenBy(n => n.InterestRate));
        }
Exemplo n.º 17
0
 public MortgageServiceShould()
 {
     _mortgageService = new MortgageService();
 }
 public void TestGetMortage()
 {
     MortgageService Mc      = new MortgageService();
     var             results = Mc.GetAllMortgages();
 }
        // GET: api/Mortgage
        public IEnumerable <Dto.Mortgage> Get()
        {
            var mortgageService = new MortgageService();

            return(mortgageService.GetAllMortgages());
        }
Exemplo n.º 20
0
        //GET: api/Mortgage/5
        public Dto.Mortgage Get(int id)
        {
            var mortgageService = new MortgageService();

            return(mortgageService.GetAllMortgages().FirstOrDefault(x => x.MortgageId == id));
        }
        // GET: api/mortgage?loanAmount=1000&duration=2&interestRate=5.24
        public LoanDetails Get(double loanAmount, int duration, double interestRate)
        {
            var mortgageService = new MortgageService();

            return(mortgageService.CalculateLoanDetails(loanAmount, duration, interestRate));
        }
Exemplo n.º 22
0
 public ApiController()
 {
     mortgageService = new MortgageService();
 }
 public MortgageServiceUnitTest()
 {
     _mortgageService = new MortgageService();
 }