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);
            }
        }
        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);
            }
        }
Ejemplo n.º 3
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);
            }
        }