public void CanUpdatePortfolioInCreateOrUpdate() { portfolioRepository.Setup(m => m.UpdatePortfolioNameAndNotes(It.IsAny <Portfolio>())) .Callback <Portfolio>(p => { int index = ListPortfolios.IndexOf(ListPortfolios.FirstOrDefault(c => c.Id == p.Id)); ListPortfolios[index].Name = p.Name; ListPortfolios[index].Notes = p.Notes; }); portfolioRepository.Setup(m => m.IsExist(It.IsAny <int>())) .Returns((int id) => ListPortfolios.Any(p => p.Id == id)); customerService.Setup(m => m.GetCustomerByProfileId(It.IsAny <string>())) .Returns(new Customer { Id = 23123, Name = "Misha" }); UnitOfWork.Setup(m => m.Portfolios).Returns(portfolioRepository.Object); portfolioService = new PortfolioService(UnitOfWork.Object, validateService, customerService.Object, map, positionService.Object); portfolioService.CreateOrUpdatePortfolio(new PortfolioDTO { Id = 1, Name = "Update Name", Notes = "New Notes" }, ""); Assert.IsTrue(ListPortfolios.Count() == 2); Assert.IsTrue(ListPortfolios.FirstOrDefault(c => c.Id == 1).Name == "Update Name"); Assert.IsTrue(ListPortfolios.FirstOrDefault(c => c.Id == 1).Notes == "New Notes"); }
public void CanNotCreateOrUpdateNullReferencePortfolio() { UnitOfWork.Setup(m => m.Portfolios).Returns(portfolioRepository.Object); portfolioService = new PortfolioService(UnitOfWork.Object, validateService, customerService.Object, map, positionService.Object); portfolioService.CreateOrUpdatePortfolio(null, ""); }
public void CanNotCreateOrUpdatePortfolioWithPercenWinsLessThanZero() { UnitOfWork.Setup(m => m.Portfolios).Returns(portfolioRepository.Object); portfolioService = new PortfolioService(UnitOfWork.Object, validateService, customerService.Object, map, positionService.Object); portfolioService.CreateOrUpdatePortfolio(new PortfolioDTO { PercentWins = -1 }, ""); }
public void CanCreatePortfolioInCreateOrUpdate() { portfolioRepository.Setup(m => m.Create(It.IsAny <Portfolio>())) .Callback <Portfolio>(ListPortfolios.Add); portfolioRepository.Setup(m => m.IsExist(It.IsAny <int>())) .Returns((int id) => ListPortfolios.Any(p => p.Id == id)); customerService.Setup(m => m.GetCustomerByProfileId(It.IsAny <string>())) .Returns(new Customer { Id = 23123, Name = "Misha" }); UnitOfWork.Setup(m => m.Portfolios).Returns(portfolioRepository.Object); portfolioService = new PortfolioService(UnitOfWork.Object, validateService, customerService.Object, map, positionService.Object); portfolioService.CreateOrUpdatePortfolio(new PortfolioDTO(), ""); Assert.IsTrue(ListPortfolios.Count() == 3); }