コード例 #1
0
        public void GetAllPaymentDefault_GetByConditions_CreditCard()
        {
            // 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
            // Arrange

            decimal expectedResult = 10;
            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.GetAllPaymentDefault
                 (PaymentDefaultType.CreditCard);

            // Assert
            Assert.AreEqual(expectedResult, currentResult.Count());
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        public void GetDormantCustomers_GetByConditions_Page3()
        {
            // 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;
            string expectedName = "10";
            List<User> users = new List<User>();
            DateTime startDate = DateTime.Now.AddYears(-1);
            DateTime endDate = DateTime.Now.AddYears(1);

            for (int i = 0; i < 20; i++)
            {
                User user = new User
                {
                    Id = Guid.NewGuid(),
                    FirstName = i.ToString(),
                    CreatedDate = DateTime.Now,
                    Role = Role.Customer
                };
                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
                .GetDormantCustomers( string.Empty, 2, 5);

            // Assert
            Assert.AreEqual(expectedResult, currentResult.Count());
            Assert.AreEqual(expectedName, currentResult.First().FirstName);
        }