コード例 #1
0
        public void GetUserByPhone_FailCase()
        {
            UserCrudService _userService = new UserCrudService();
            User            user         = _userService.GetUserByPhone("00123456788");

            Assert.IsNull(user);
        }
コード例 #2
0
        public async void Create_User()
        {
            var options = new DbContextOptionsBuilder <DashboardDbContext>()
                          .UseInMemoryDatabase(databaseName: "Create_New_User")
                          .Options;

            var user = new User()
            {
                UserId   = 1,
                Email    = "*****@*****.**",
                Name     = "John",
                Surname  = "Smith",
                Password = "******",
                IsActive = true
            };

            using (var context = new DashboardDbContext(options))
            {
                var mockCheckEmailService = new CheckEmailService(new DashboardDbContext(options), new Mock <ILogger <CheckEmailService> >().Object);

                var service = new UserCrudService(context, _mockLogger.Object, mockCheckEmailService, _mockSendGridService.Object);
                await service.CreateUserAsync(user);

                await context.SaveChangesAsync();
            }

            using (var context = new DashboardDbContext(options))
            {
                Assert.Equal(1, context.Users.CountAsync().Result);
                Assert.Equal(user.Name, context.Users.SingleAsync().Result.Name);
            }
        }
コード例 #3
0
        public void GetAllUsers()
        {
            UserCrudService _userService = new UserCrudService();
            List <User>     _usersList   = _userService.GetAllUsers();

            Assert.IsNotNull(_usersList);
        }
コード例 #4
0
        public void GetUserById()
        {
            UserCrudService _userService = new UserCrudService();
            User            user         = _userService.GetUserByPhone("0123456788");
            User            idResult     = _userService.GetUserById(user.Id);

            Assert.IsNotNull(idResult);
        }
コード例 #5
0
        public void DeleteUser()
        {
            UserCrudService _userService = new UserCrudService();
            User            user         = _userService.GetUserByPhone("0123456788");

            _userService.DeleteUser(user.Id);

            User deletedUser = _userService.GetUserByPhone("0123456788");

            Assert.IsNull(deletedUser);
        }
コード例 #6
0
        public void UpdateUser()
        {
            UserCrudService _userService = new UserCrudService();
            User            user         = _userService.GetUserByPhone("0123456788");
            User            updateInfo   = new User {
                Id = user.Id, FamilyId = user.FamilyId, FirstName = "Foo", LastName = "Ipsum", Role = "Mother", Password = "******", Phone = "0123456788"
            };

            _userService.UpdateUser(updateInfo, user.Id);

            User getUpdatedUser = _userService.GetUserById(user.Id);

            Assert.AreNotEqual(user.FirstName, getUpdatedUser.FirstName);
        }
コード例 #7
0
        public void RegisterUser()
        {
            UserCrudService _userService = new UserCrudService();

            User _user = new User {
                FamilyId = ObjectId.GenerateNewId().Increment, FirstName = "Lorem", LastName = "Ipsum", Role = "Mother", Password = "******", Phone = "0123456788"
            };

            _userService.Register(_user);

            User _getCreatedUser = _userService.GetUserByPhone("0123456788");

            Assert.AreEqual(_user.Phone, _getCreatedUser.Phone);
        }
コード例 #8
0
        public async void Get_One()
        {
            var options = new DbContextOptionsBuilder <DashboardDbContext>()
                          .UseInMemoryDatabase(databaseName: "Get_One")
                          .Options;

            var user1 = new User()
            {
                UserId   = 1,
                Email    = "*****@*****.**",
                Name     = "John",
                Surname  = "Smith",
                Password = "******",
                IsActive = true
            };

            var user2 = new User()
            {
                UserId   = 2,
                Email    = "*****@*****.**",
                Name     = "John",
                Surname  = "Smith",
                Password = "******",
                IsActive = true
            };

            using (var context = new DashboardDbContext(options))
            {
                var mockCheckEmailService = new CheckEmailService(new DashboardDbContext(options), new Mock <ILogger <CheckEmailService> >().Object);

                var service = new UserCrudService(context, _mockLogger.Object, mockCheckEmailService, _mockSendGridService.Object);
                await service.CreateUserAsync(user1);

                await service.CreateUserAsync(user2);

                await context.SaveChangesAsync();
            }

            using (var context = new DashboardDbContext(options))
            {
                var mockCheckEmailService = new CheckEmailService(new DashboardDbContext(options), new Mock <ILogger <CheckEmailService> >().Object);

                var service = new UserCrudService(context, _mockLogger.Object, mockCheckEmailService, _mockSendGridService.Object);
                var result  = await service.GetOneAsync(user1.UserId);

                Assert.Equal(user1.Email, result.Email);
            }
        }
コード例 #9
0
        public async void Authorize_Valid_User()
        {
            var options = new DbContextOptionsBuilder <DashboardDbContext>()
                          .UseInMemoryDatabase(databaseName: "Authorize_Valid_User")
                          .Options;

            var user = new User()
            {
                Email    = "*****@*****.**",
                Password = "******",
                IsActive = true
            };

            using (var context = new DashboardDbContext(options))
            {
                var serviceCheckEmail = new CheckEmailService(context, _mockLoggerCheckEmail.Object);
                var serviceCrud       = new UserCrudService(context, _mockLoggerUserCrud.Object, serviceCheckEmail, _mockSendGridService.Object);

                var userCreate = new User()
                {
                    Email    = user.Email,
                    Password = user.Password,
                    IsActive = user.IsActive
                };

                await serviceCrud.CreateUserAsync(userCreate);

                await context.SaveChangesAsync();
            }

            using (var context = new DashboardDbContext(options))
            {
                var serviceAuth = new UserAuthService(context, _mockLogger.Object);
                var result      = serviceAuth.AuthUser(user);

                Assert.Equal(1, await context.Users.CountAsync());
                Assert.NotNull(result);
                Assert.Equal(user.Email, result.Email);
            }
        }