public void GetPaymentDefault_GetByConditions_NullUser() { // 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 List<User> users = new List<User>(); // Act ReportService reportService = new ReportService(uowMock.Object, repositoryMock.Object, settingsMock.Object); var currentResult = reportService.GetPaymentDefault (string.Empty, PaymentDefaultType.CreditCard, 0, 5); // Assert Assert.AreEqual(null, currentResult); }
public void GetPaymentDefault_GetByConditions_Default() { // 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 = 5; List<User> users = new List<User>(); for (int i = 0; i < 20; i++) { User user = new User { Id = Guid.NewGuid(), FirstName = i.ToString(), CreatedDate = DateTime.Now, Role = Role.Customer, PaymentMethod = i%2==0? PaymentMethod.CreditCard:PaymentMethod.PrePayment }; users.Add(user); } repositoryMock.Setup(r => r.Query<User>()).Returns(users.AsQueryable()); // Act ReportService reportService = new ReportService(uowMock.Object, repositoryMock.Object, settingsMock.Object); var currentResult = reportService.GetPaymentDefault (string.Empty, PaymentDefaultType.All, 0, 5); // Assert Assert.AreEqual(expectedResult, currentResult.Count()); Assert.AreEqual(currentResult.Last().PaymentDefault, PaymentMethod.CreditCard); }