public async Task GetAllUsersAsync_Returns_Users()
        {
            // Arrange
            var expectedUserDbos = new List <UserDbo>
            {
                new UserDbo
                {
                    UserId    = 1,
                    FirstName = "John",
                    LastName  = "Doe",
                    Accounts  = new List <AccountDbo>
                    {
                        new AccountDbo
                        {
                            AccountId = 1,
                        }
                    }
                },
                new UserDbo
                {
                    UserId    = 2,
                    FirstName = "Papa",
                    LastName  = "John",
                    Accounts  = new List <AccountDbo>
                    {
                        new AccountDbo
                        {
                            AccountId = 2,
                        }
                    }
                }
            };

            using var dbContext = new UserManagerDbContext(_options);
            dbContext.Users.AddRange(expectedUserDbos);
            dbContext.SaveChanges();

            var expectedUsers = expectedUserDbos.Select(x => new User
            {
                UserId      = x.UserId,
                FirstName   = x.FirstName,
                LastName    = x.LastName,
                DateCreated = x.DateCreated,
            });

            _mockMapper.Setup(m => m.Map <IEnumerable <User> >(It.IsAny <IEnumerable <UserDbo> >()))
            .Returns(expectedUsers);

            var service = new UserService(_mockMapper.Object, dbContext);

            // Act
            var actualUsers = await service.GetAllAsync();

            // Assert
            Assert.NotNull(actualUsers);
            Assert.NotEmpty(actualUsers);
            Assert.Equal(expectedUsers, actualUsers);
        }
        public static UserManagerDbContext Create()
        {
            var options = new DbContextOptionsBuilder <UserManagerDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;

            var context = new UserManagerDbContext(options);

            context.Database.EnsureCreated();

            context.Users.AddRange(new Domain.Entities.User[]
            {
                new Domain.Entities.User()
                {
                    ID                  = 1,
                    Title               = "Ms",
                    FirstName           = "Margaux",
                    LastName            = "Renard",
                    DateOfBirth         = DateTime.UtcNow.AddYears(-25),
                    Email               = "*****@*****.**",
                    PhoneNumber         = "04-10-61-43-38",
                    ProfilePictureURL   = "https://randomuser.me/api/portraits/women/65.jpg",
                    ProfileThumbnailURL = "https://randomuser.me/api/portraits/thumb/women/65.jpg"
                },
                new Domain.Entities.User()
                {
                    ID                  = 2,
                    Title               = "Mr",
                    FirstName           = "Silas",
                    LastName            = "Jensen",
                    DateOfBirth         = DateTime.UtcNow.AddYears(-23),
                    Email               = "*****@*****.**",
                    PhoneNumber         = "81304054",
                    ProfilePictureURL   = "https://randomuser.me/api/portraits/men/77.jpg",
                    ProfileThumbnailURL = "https://randomuser.me/api/portraits/thumb/men/77.jpg"
                },
                new Domain.Entities.User()
                {
                    ID                  = 3,
                    Title               = "Mrs",
                    FirstName           = "Lucy",
                    LastName            = "Petit",
                    DateOfBirth         = DateTime.UtcNow.AddYears(-24),
                    Email               = "*****@*****.**",
                    PhoneNumber         = "03-35-42-32-99",
                    ProfilePictureURL   = "https://randomuser.me/api/portraits/women/2.jpg",
                    ProfileThumbnailURL = "https://randomuser.me/api/portraits/thumb/women/2.jpg"
                },
                new Domain.Entities.User()
                {
                    ID                  = 4,
                    Title               = "Mrs",
                    FirstName           = "Freja",
                    LastName            = "Kristensen",
                    DateOfBirth         = DateTime.UtcNow.AddYears(-19),
                    Email               = "*****@*****.**",
                    PhoneNumber         = "37660020",
                    ProfilePictureURL   = "https://randomuser.me/api/portraits/women/50.jpg",
                    ProfileThumbnailURL = "https://randomuser.me/api/portraits/thumb/women/50.jpg"
                },
                new Domain.Entities.User()
                {
                    ID                  = 5,
                    Title               = "Mr",
                    FirstName           = "Patrick",
                    LastName            = "Anderson",
                    DateOfBirth         = DateTime.UtcNow.AddYears(-20),
                    Email               = "*****@*****.**",
                    PhoneNumber         = "(384)-062-3305",
                    ProfilePictureURL   = "https://randomuser.me/api/portraits/men/99.jpg",
                    ProfileThumbnailURL = "https://randomuser.me/api/portraits/thumb/men/99.jpg"
                }
            });

            context.SaveChanges();

            return(context);
        }
Пример #3
0
        public static void InitializeData(this UserManagerDbContext context)
        {
            context.Users.AddRange(new Domain.Entities.User[]
            {
                new Domain.Entities.User()
                {
                    Title               = "Ms",
                    FirstName           = "Margaux",
                    LastName            = "Renard",
                    DateOfBirth         = DateTime.UtcNow.AddYears(-25),
                    Email               = "*****@*****.**",
                    PhoneNumber         = "04-10-61-43-38",
                    ProfilePictureURL   = "https://randomuser.me/api/portraits/women/65.jpg",
                    ProfileThumbnailURL = "https://randomuser.me/api/portraits/thumb/women/65.jpg"
                },
                new Domain.Entities.User()
                {
                    Title               = "Mr",
                    FirstName           = "Silas",
                    LastName            = "Jensen",
                    DateOfBirth         = DateTime.UtcNow.AddYears(-23),
                    Email               = "*****@*****.**",
                    PhoneNumber         = "81304054",
                    ProfilePictureURL   = "https://randomuser.me/api/portraits/men/77.jpg",
                    ProfileThumbnailURL = "https://randomuser.me/api/portraits/thumb/men/77.jpg"
                },
                new Domain.Entities.User()
                {
                    Title               = "Mrs",
                    FirstName           = "Lucy",
                    LastName            = "Petit",
                    DateOfBirth         = DateTime.UtcNow.AddYears(-24),
                    Email               = "*****@*****.**",
                    PhoneNumber         = "03-35-42-32-99",
                    ProfilePictureURL   = "https://randomuser.me/api/portraits/women/2.jpg",
                    ProfileThumbnailURL = "https://randomuser.me/api/portraits/thumb/women/2.jpg"
                },
                new Domain.Entities.User()
                {
                    Title               = "Mrs",
                    FirstName           = "Freja",
                    LastName            = "Kristensen",
                    DateOfBirth         = DateTime.UtcNow.AddYears(-19),
                    Email               = "*****@*****.**",
                    PhoneNumber         = "37660020",
                    ProfilePictureURL   = "https://randomuser.me/api/portraits/women/50.jpg",
                    ProfileThumbnailURL = "https://randomuser.me/api/portraits/thumb/women/50.jpg"
                },
                new Domain.Entities.User()
                {
                    Title               = "Mr",
                    FirstName           = "Patrick",
                    LastName            = "Anderson",
                    DateOfBirth         = DateTime.UtcNow.AddYears(-20),
                    Email               = "*****@*****.**",
                    PhoneNumber         = "(384)-062-3305",
                    ProfilePictureURL   = "https://randomuser.me/api/portraits/men/99.jpg",
                    ProfileThumbnailURL = "https://randomuser.me/api/portraits/thumb/men/99.jpg"
                },
                new Domain.Entities.User()
                {
                    Title               = "Mr",
                    FirstName           = "Ramon",
                    LastName            = "Morrison",
                    DateOfBirth         = DateTime.UtcNow.AddYears(-18),
                    Email               = "*****@*****.**",
                    PhoneNumber         = "(862)-772-9196",
                    ProfilePictureURL   = "https://randomuser.me/api/portraits/men/12.jpg",
                    ProfileThumbnailURL = "https://randomuser.me/api/portraits/thumb/men/12.jpg"
                },
                new Domain.Entities.User()
                {
                    Title               = "Mr",
                    FirstName           = "Léandro",
                    LastName            = "Barbier",
                    DateOfBirth         = DateTime.UtcNow.AddYears(-45),
                    Email               = "*****@*****.**",
                    PhoneNumber         = "05-82-23-85-92",
                    ProfilePictureURL   = "https://randomuser.me/api/portraits/men/99.jpg",
                    ProfileThumbnailURL = "https://randomuser.me/api/portraits/thumb/men/99.jpg"
                },
                new Domain.Entities.User()
                {
                    Title               = "Mr",
                    FirstName           = "Jeremiah",
                    LastName            = "Ross",
                    DateOfBirth         = DateTime.UtcNow.AddYears(-18),
                    Email               = "*****@*****.**",
                    PhoneNumber         = "(534)-585-2027",
                    ProfilePictureURL   = "https://randomuser.me/api/portraits/men/48.jpg",
                    ProfileThumbnailURL = "https://randomuser.me/api/portraits/thumb/men/48.jpg"
                },
                new Domain.Entities.User()
                {
                    Title               = "Miss",
                    FirstName           = "Cathy",
                    LastName            = "Gonzales",
                    DateOfBirth         = DateTime.UtcNow.AddYears(-48),
                    Email               = "*****@*****.**",
                    PhoneNumber         = "05-82-23-85-92",
                    ProfilePictureURL   = "https://randomuser.me/api/portraits/men/27.jpg",
                    ProfileThumbnailURL = "https://randomuser.me/api/portraits/thumb/men/27.jpg"
                },
                new Domain.Entities.User()
                {
                    Title               = "Mr",
                    FirstName           = "Léandro",
                    LastName            = "Barbier",
                    DateOfBirth         = DateTime.UtcNow.AddYears(-38),
                    Email               = "*****@*****.**",
                    PhoneNumber         = "016977 5374",
                    ProfilePictureURL   = "https://randomuser.me/api/portraits/men/64.jpg",
                    ProfileThumbnailURL = "https://randomuser.me/api/portraits/thumb/men/64.jpg"
                },
                new Domain.Entities.User()
                {
                    Title               = "Mr",
                    FirstName           = "Sacha",
                    LastName            = "Vidal",
                    DateOfBirth         = DateTime.UtcNow.AddYears(-22),
                    Email               = "*****@*****.**",
                    PhoneNumber         = "01-23-36-89-76",
                    ProfilePictureURL   = "https://randomuser.me/api/portraits/men/9.jpg",
                    ProfileThumbnailURL = "https://randomuser.me/api/portraits/thumb/men/9.jpg"
                },
                new Domain.Entities.User()
                {
                    Title               = "Mr",
                    FirstName           = "Cecil",
                    LastName            = "White",
                    DateOfBirth         = DateTime.UtcNow.AddYears(-38),
                    Email               = "*****@*****.**",
                    PhoneNumber         = "016977 5374",
                    ProfilePictureURL   = "https://randomuser.me/api/portraits/men/29.jpg",
                    ProfileThumbnailURL = "https://randomuser.me/api/portraits/thumb/men/29.jpg"
                }
            });

            context.SaveChanges();
        }