public void GetAllPlansTest() { // Setup dependency var settingsMock = new Mock<ISettings>(); var repositoryMock = new Mock<IRepository>(); var uowMock = new Mock<IUnitOfWork>(); var serviceLocatorMock = new Mock<IServiceLocator>(); serviceLocatorMock.Setup(x => x.GetInstance<IRepository>()) .Returns(repositoryMock.Object); ServiceLocator.SetLocatorProvider(() => serviceLocatorMock.Object); // Arrange decimal expectedResult = 10; List<Plan> plans = new List<Plan>(); for (int i = 0; i < expectedResult; i++) { Plan plan = new Plan { Id = Guid.NewGuid() }; plans.Add(plan); } repositoryMock.Setup(r => r.Query<Plan>()).Returns(plans.AsQueryable()); // Act PlanService bookingService = new PlanService(uowMock.Object, repositoryMock.Object, settingsMock.Object); List<PlanDto> currentResult = bookingService.GetAllPlans(); // Assert repositoryMock.Verify(repo => repo.Query<Plan>()); Assert.AreEqual(expectedResult, currentResult.Count()); }
public void GetPlanById_AnyPlanIds() { // Setup dependency var settingsMock = new Mock<ISettings>(); var repositoryMock = new Mock<IRepository>(); var uowMock = new Mock<IUnitOfWork>(); var serviceLocatorMock = new Mock<IServiceLocator>(); serviceLocatorMock.Setup(x => x.GetInstance<IRepository>()) .Returns(repositoryMock.Object); ServiceLocator.SetLocatorProvider(() => serviceLocatorMock.Object); // Arrange Guid id = Guid.NewGuid(); // Act PlanService bookingService = new PlanService(uowMock.Object, repositoryMock.Object, settingsMock.Object); bookingService.GetPlanById(id); // Assert repositoryMock.Verify(repo => repo.FindById<Plan>(id)); }
public void GetPlanByName_AnyName() { // Setup dependency var settingsMock = new Mock<ISettings>(); var repositoryMock = new Mock<IRepository>(); var uowMock = new Mock<IUnitOfWork>(); var serviceLocatorMock = new Mock<IServiceLocator>(); serviceLocatorMock.Setup(s => s.GetInstance<IRepository>()).Returns(repositoryMock.Object); ServiceLocator.SetLocatorProvider(() => serviceLocatorMock.Object); // Arrange Guid id = Guid.NewGuid(); string planName = "PlanName"; // Act PlanService bookingService = new PlanService(uowMock.Object, repositoryMock.Object, settingsMock.Object); bookingService.GetPlanByName(planName); // Assert repositoryMock.Verify(repo => repo.Query<Plan>()); }
public void PriceExeptGst_AnyPlanId_PlanNotNull() { // Setup dependency var settingsMock = new Mock<ISettings>(); var repositoryMock = new Mock<IRepository>(); var uowMock = new Mock<IUnitOfWork>(); var serviceLocatorMock = new Mock<IServiceLocator>(); serviceLocatorMock.Setup(x => x.GetInstance<IRepository>()) .Returns(repositoryMock.Object); ServiceLocator.SetLocatorProvider(() => serviceLocatorMock.Object); // Arrange Guid id = Guid.NewGuid(); decimal price = 1000; Plan plan = new Plan { Id = id, Price = price }; decimal expectedResult = price / 1.1M; repositoryMock.Setup(r => r.FindById<Plan>(id)).Returns(plan); // Act PlanService bookingService = new PlanService( uowMock.Object, repositoryMock.Object, settingsMock.Object); decimal currentResult = bookingService.PriceExeptGst(id); // Assert repositoryMock.Verify(repo => repo.FindById<Plan>(id)); Assert.AreEqual(expectedResult, currentResult); }
public PaymentService(IUnitOfWork unitOfWork, IRepository repository, ISettings settings) : base(unitOfWork, repository, settings) { Gateway = new BraintreeGateway { Environment = GetEnvironment(), PublicKey = ConfigurationManager.AppSettings["BrainTreePublicKey"], PrivateKey = ConfigurationManager.AppSettings["BrainTreePrivateKey"], MerchantId = ConfigurationManager.AppSettings["BrainTreeMerchantId"] }; planService = new PlanService(unitOfWork, repository, settings); invoiceService = new InvoiceService(unitOfWork, repository, settings); }