当前位置: 首页>>代码示例>>C#>>正文


C# User.AsQueryable方法代码示例

本文整理汇总了C#中User.AsQueryable方法的典型用法代码示例。如果您正苦于以下问题:C# User.AsQueryable方法的具体用法?C# User.AsQueryable怎么用?C# User.AsQueryable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在User的用法示例。


在下文中一共展示了User.AsQueryable方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RatingCalculator_GuidId

        public void RatingCalculator_GuidId()
        {
            var settingsMock = new Mock<ISettings>();
            var repositoryMock = new Mock<IRepository>();
            var uowMock = new Mock<IUnitOfWork>();
            var serviceLocatorMock = new Mock<IServiceLocator>();
            serviceLocatorMock.Setup(r => r.GetInstance<IRepository>())
                .Returns(repositoryMock.Object);

            ServiceLocator.SetLocatorProvider(() => serviceLocatorMock.Object);

            // Arrange data
            Guid id = Guid.NewGuid();
            User user = new User { Id = id };

            Booking booking = new Booking
            {
                Id = Guid.NewGuid(),
                Specialist = user
            };

            Call call1 = new Call
            {
                Id = Guid.NewGuid(),
                Booking = booking,
                Rating = 2
            };
            Call call2 = new Call
            {
                Id = Guid.NewGuid(),
                Booking = booking,
                Rating = 4
            };

            User[] users = new User[] { user };
            repositoryMock.Setup(r => r.Query<User>()).Returns(users.AsQueryable());

            Booking[] bookings = new Booking[] { booking };
            repositoryMock.Setup(r => r.Query<Booking>()).Returns(bookings.AsQueryable());

            Call[] calls = new Call[] { call1, call2 };
            repositoryMock.Setup(r => r.Query<Call>()).Returns(calls.AsQueryable());

            double expectedValue = 3;

            // Act
            var bookingService = new BookingService(uowMock.Object, repositoryMock.Object, settingsMock.Object);
            double currentValue = bookingService.RatingCalculator(id);

            // Assert
            repositoryMock.Verify(r => r.Query<Call>());//.Where(c=>c.Booking.Specialist.Id == id));
            Assert.AreEqual(expectedValue, currentValue);
        }
开发者ID:nguyenminhthu,项目名称:TeleConsult,代码行数:53,代码来源:BookingServiceTest.cs

示例2: IsUserInRole_GetUserWithWrongRole_ReturnFalse

        public void IsUserInRole_GetUserWithWrongRole_ReturnFalse()
        {
            // Setup dependency
            var settingsMock = new Mock<ISettings>();
            var uowMock = new Mock<IUnitOfWork>();
            var repositoryMock = new Mock<IRepository>();
            var serviceLocatorMock = new Mock<IServiceLocator>();
            serviceLocatorMock.Setup(x => x.GetInstance<IRepository>())
                .Returns(repositoryMock.Object);
            ServiceLocator.SetLocatorProvider(() => serviceLocatorMock.Object);

            // Arrange
            string userName = "FirstName";
            string roleName = string.Empty;
            User user = new User
            {
                Id = Guid.NewGuid(),
                UserName = userName,
                Role = Role.Customer
            };
            bool expectedResult = false;
            User[] users = new User[] { user };
            repositoryMock.Setup(r => r.Query<User>()).Returns(users.AsQueryable());

            // Act
            ManagementService managementService = new ManagementService(uowMock.Object, repositoryMock.Object, settingsMock.Object);
            bool currentResult = managementService.IsUserInRole(userName, roleName);

            // Assert
            repositoryMock.Verify(repo => repo.Query<User>());
            Assert.AreEqual(expectedResult, currentResult);
        }
开发者ID:nguyenminhthu,项目名称:TeleConsult,代码行数:32,代码来源:ManagementServiceTest.cs

示例3: GetUserConfirmation_AnyResult_CallsQueryMethodOfRepository

        public void GetUserConfirmation_AnyResult_CallsQueryMethodOfRepository()
        {
            var settingsMock = new Mock<ISettings>();
            var componentsMock = new Mock<IComponents>();
            var repositoryMock = new Mock<IRepository>();
            var uowMock = new Mock<IUnitOfWork>();
            var serviceLocatorMock = new Mock<IServiceLocator>();
            serviceLocatorMock.Setup(x => x.GetInstance<IRepository>())
                .Returns(repositoryMock.Object);
            serviceLocatorMock.Setup(x => x.GetInstance<IUnitOfWork>())
                .Returns(uowMock.Object);
            ServiceLocator.SetLocatorProvider(() => serviceLocatorMock.Object);

            // Arrange
            Guid id = Guid.NewGuid();
            Guid userId = Guid.NewGuid();
            User user = new User()
            {
                Id = userId

            };
            UserConfirmation userConfirmation = new UserConfirmation()
            {
                Id = id,
                User =user,
                Type = ConfirmedType.ChangeEmail
            };

            User[] users = new User[] { user };
            repositoryMock.Setup(r => r.Query<User>()).Returns(users.AsQueryable());

            UserConfirmation[] userConfirmations = new UserConfirmation[] { userConfirmation };
            repositoryMock.Setup(r => r.Query<UserConfirmation>()).Returns(userConfirmations.AsQueryable());

            repositoryMock.Setup(r => r.CreateUnitOfWork()).Returns(uowMock.Object);
            // Act
            var userService = new UserService(uowMock.Object,repositoryMock.Object, settingsMock.Object, componentsMock.Object);
            UserConfirmationDto actuauserConfirmationDto = userService.GetUserConfirmation(userId, userConfirmation.Type);

            // Assert
            repositoryMock.Verify(repo => repo.Query<UserConfirmation>());
            Assert.AreEqual(actuauserConfirmationDto.Id, userConfirmation.Id);
        }
开发者ID:nguyenminhthu,项目名称:TeleConsult,代码行数:43,代码来源:UserServiceTest.cs

示例4: GetUserbyUserName_AnyUserName_CallsQueryMethodOfRepository

        public void GetUserbyUserName_AnyUserName_CallsQueryMethodOfRepository()
        {
            var settingsMock = new Mock<ISettings>();
            var componentsMock = new Mock<IComponents>();
            var repositoryMock = new Mock<IRepository>();
            var uowMock = new Mock<IUnitOfWork>();
            var serviceLocatorMock = new Mock<IServiceLocator>();
            serviceLocatorMock.Setup(x => x.GetInstance<IRepository>())
                .Returns(repositoryMock.Object);
            serviceLocatorMock.Setup(x => x.GetInstance<IUnitOfWork>())
                .Returns(uowMock.Object);
            ServiceLocator.SetLocatorProvider(() => serviceLocatorMock.Object);

            // Arrange
            string token = Guid.NewGuid().ToString();
            Guid id = Guid.NewGuid();
            User user = new User()
            {
                Id = id,
                AuthToken = token,
                UserName = "ThanhTien1",
                Email = "[email protected]",
                MobilePhone = "0978069219"
            };
            User[] users = new User[] { user };
            repositoryMock.Setup(r => r.Query<User>()).Returns(users.AsQueryable());
            repositoryMock.Setup(r => r.CreateUnitOfWork()).Returns(uowMock.Object);
            // Act
            var userService = new UserService(uowMock.Object,repositoryMock.Object, settingsMock.Object, componentsMock.Object);
            UserDto actualUser = userService.GetByUserName(user.UserName);

            // Assert
            repositoryMock.Verify(repo => repo.Query<User>());
            Assert.AreEqual(actualUser.UserName, user.UserName);
        }
开发者ID:nguyenminhthu,项目名称:TeleConsult,代码行数:35,代码来源:UserServiceTest.cs

示例5: GetListUserFromAWFSearchResults_AnyResult_CallsQueryMethodOfRepository

        public void GetListUserFromAWFSearchResults_AnyResult_CallsQueryMethodOfRepository()
        {
            var settingsMock = new Mock<ISettings>();
            var componentsMock = new Mock<IComponents>();
            var repositoryMock = new Mock<IRepository>();
            var uowMock = new Mock<IUnitOfWork>();
            var serviceLocatorMock = new Mock<IServiceLocator>();
            serviceLocatorMock.Setup(x => x.GetInstance<IRepository>())
                .Returns(repositoryMock.Object);
            serviceLocatorMock.Setup(x => x.GetInstance<IUnitOfWork>())
                .Returns(uowMock.Object);
            ServiceLocator.SetLocatorProvider(() => serviceLocatorMock.Object);

            // Arrange
            string token = Guid.NewGuid().ToString();
            Guid id1 = Guid.NewGuid();
            Guid id2 = Guid.NewGuid();
            Guid profileId = Guid.NewGuid();
            User user1 = new User()
            {
                Id = id1,
                CreatedDate = DateTime.Now
            };
            User user2 = new User()
            {
                Id = id2,
                CreatedDate = DateTime.Now
            };
            SearchDocumentResult searchResult1 = new SearchDocumentResult()
            {
                Id = id1
            };
            SearchDocumentResult searchResult2 = new SearchDocumentResult()
            {
                Id = id2
            };
            List<SearchDocumentResult> searchResults = new List<SearchDocumentResult>();
            searchResults.Add(searchResult1);
            searchResults.Add(searchResult2);

            User[] users = new User[] { user1, user2 };
            repositoryMock.Setup(r => r.Query<User>()).Returns(users.AsQueryable());
            repositoryMock.Setup(r => r.CreateUnitOfWork()).Returns(uowMock.Object);
            // Act
            var userService = new UserService(uowMock.Object,repositoryMock.Object, settingsMock.Object, componentsMock.Object);
            List<UserDto> actuaUsers = userService.GetListUserFromAWFSearchResults(searchResults);

            // Assert
            repositoryMock.Verify(repo => repo.Query<User>());
            Assert.AreEqual(actuaUsers.Count(),searchResults.Count());
        }
开发者ID:nguyenminhthu,项目名称:TeleConsult,代码行数:51,代码来源:UserServiceTest.cs

示例6: GetDateSentEmail_AnyId_CallsQueryMethodOfRepository

        public void GetDateSentEmail_AnyId_CallsQueryMethodOfRepository()
        {
            var settingsMock = new Mock<ISettings>();
            var componentsMock = new Mock<IComponents>();
            var repositoryMock = new Mock<IRepository>();
            var uowMock = new Mock<IUnitOfWork>();
            var serviceLocatorMock = new Mock<IServiceLocator>();
            serviceLocatorMock.Setup(x => x.GetInstance<IRepository>())
                .Returns(repositoryMock.Object);
            serviceLocatorMock.Setup(x => x.GetInstance<IUnitOfWork>())
                .Returns(uowMock.Object);
            ServiceLocator.SetLocatorProvider(() => serviceLocatorMock.Object);

            // Arrange
            string token = Guid.NewGuid().ToString();
            Guid id = Guid.NewGuid();
            User user = new User()
            {
                Id = id,
              CreatedDate = DateTime.Now
            };
            User[] users = new User[] { user };
            repositoryMock.Setup(r => r.Query<User>()).Returns(users.AsQueryable());
            repositoryMock.Setup(r => r.CreateUnitOfWork()).Returns(uowMock.Object);
            // Act
            var userService = new UserService(uowMock.Object,repositoryMock.Object, settingsMock.Object, componentsMock.Object);
            DateTime actualdate = userService.GetDateSentEmail(id);

            // Assert
            repositoryMock.Verify(repo => repo.Query<User>());
            Assert.AreEqual(actualdate, user.CreatedDate);
        }
开发者ID:nguyenminhthu,项目名称:TeleConsult,代码行数:32,代码来源:UserServiceTest.cs

示例7: GetById_AnyId_CallsFindByIdMethodOfRepository

        public void GetById_AnyId_CallsFindByIdMethodOfRepository()
        {
            // Setup dependency
            var settingsMock = new Mock<ISettings>();
            var uowMock = new Mock<IUnitOfWork>();
            var componentsMock = new Mock<IComponents>();
            var repositoryMock = new Mock<IRepository>();
            var serviceLocatorMock = new Mock<IServiceLocator>();
            serviceLocatorMock.Setup(x => x.GetInstance<IRepository>())
                .Returns(repositoryMock.Object);
            ServiceLocator.SetLocatorProvider(() => serviceLocatorMock.Object);

            // Arrange
            Guid id = Guid.NewGuid();
            User user = new User
            {
                Id = id,
                UserName = "ThanhTien",
                Email = "[email protected]"
            };

            User[] users = new User[] { user };
            repositoryMock.Setup(r => r.Query<User>()).Returns(users.AsQueryable());
            // Act

            var userService = new UserService(uowMock.Object,repositoryMock.Object, settingsMock.Object, componentsMock.Object);
            userService.GetUserById(id);

            // Assert
            repositoryMock.Verify(repo => repo.Query<User>());
        }
开发者ID:nguyenminhthu,项目名称:TeleConsult,代码行数:31,代码来源:UserServiceTest.cs


注:本文中的User.AsQueryable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。