public async void Modify_NoExistingId_ReturnsFalse()
        {
            // Arrange
            var options = Arrange.NewMemoryDBWithTestData();

            using (var context = new CeloPracticalChallengeDBContext(options)) {
                var userRepository = new RandomUserRepository(context);

                // Act
                var user = new Entities.RandomUser {
                    Id            = -2,
                    Email         = "*****@*****.**",
                    Title         = "Mr",
                    FirstName     = "New",
                    LastName      = "User",
                    DateOfBirth   = new DateTime(1990, 1, 1),
                    PhoneNumber   = "(204)-997-2604",
                    ThrumbnailURL = "https://randomuser.me/api/portraits/thumb/men/61.jpg",
                    LargeImageURL = "https://randomuser.me/api/portraits/portraits/men/61.jpg",
                };

                bool ret = await userRepository.ModifyAsync(user);

                // Assert
                Assert.False(ret);
            }
        }
        public void List_NullParameters_ThrowExceptionAsync()
        {
            // Arrange
            var options = Arrange.NewMemoryDBWithTestData();

            using (var context = new CeloPracticalChallengeDBContext(options)) {
                var userRepository = new RandomUserRepository(context);
                // Assert
                Assert.ThrowsAsync <ArgumentNullException>(async() => {
                    // Act
                    var users = await userRepository.ListAsync(null);
                });
            }
        }
        public async void Get_NonExistingId_ReturnsNull()
        {
            // Arrange
            var options = Arrange.NewMemoryDBWithTestData();

            using (var context = new CeloPracticalChallengeDBContext(options)) {
                var userRepository = new RandomUserRepository(context);

                // Act
                var user = await userRepository.GetAsync(999);

                // Assert
                Assert.Null(user);
            }
        }
        public async void Delete_NoExistingId_ReturnsFalse()
        {
            // Arrange
            var options = Arrange.NewMemoryDBWithTestData();

            using (var context = new CeloPracticalChallengeDBContext(options)) {
                var userRepository = new RandomUserRepository(context);

                // Act
                bool ret = await userRepository.DeleteAsync(999);

                // Assert
                Assert.False(ret);
            }
        }
        public async void Get_IdTwo_ReturnsIdTwo()
        {
            // Arrange
            var options = Arrange.NewMemoryDBWithTestData();

            using (var context = new CeloPracticalChallengeDBContext(options)) {
                var userRepository = new RandomUserRepository(context);

                // Act
                var user = await userRepository.GetAsync(2);

                // Assert
                Assert.Equal(2, user.Id);
            }
        }
        public async void List_LastIsChen_ReturnsChenAsync()
        {
            // Arrange
            var options = Arrange.NewMemoryDBWithTestData();

            using (var context = new CeloPracticalChallengeDBContext(options)) {
                var userRepository = new RandomUserRepository(context);

                // Act
                var users = await userRepository.ListAsync(
                    new ResourceParameters.RandomUsersResourceParameters {
                    LastName = "Chen"
                });

                // Assert
                Assert.All(users, u => Assert.Equal("Chen", u.LastName));
            }
        }
        public async void List_ResultsIsThree_ReturnsThreeUsersAsync()
        {
            // Arrange
            var options = Arrange.NewMemoryDBWithTestData();

            using (var context = new CeloPracticalChallengeDBContext(options)) {
                var userRepository = new RandomUserRepository(context);

                // Act
                var users = await userRepository.ListAsync(
                    new ResourceParameters.RandomUsersResourceParameters {
                    Results = 3
                });

                // Assert
                Assert.Equal(3, users.Count());
            }
        }
        public static IRandomUserRepository NewRepositoryForTesting()
        {
            var context = new CeloPracticalChallengeDBContext(NewMemoryDBWithTestData());

            return(new RandomUserRepository(context));
        }
        public static DbContextOptions <CeloPracticalChallengeDBContext> NewMemoryDBWithTestData()
        {
            var options = new DbContextOptionsBuilder <CeloPracticalChallengeDBContext>()
                          .UseInMemoryDatabase($"DBForTesting{Guid.NewGuid()}")
                          .Options;

            using (var context = new CeloPracticalChallengeDBContext(options)) {
                context.RandomUser.Add(new Entities.RandomUser {
                    Id            = 1,
                    Email         = "*****@*****.**",
                    Title         = "Ms",
                    FirstName     = "Jessica",
                    LastName      = "Green",
                    DateOfBirth   = new DateTime(1975, 2, 1),
                    PhoneNumber   = "(768)-085-8755",
                    ThrumbnailURL = "https://randomuser.me/api/portraits/thumb/women/35.jpg",
                    LargeImageURL = "https://randomuser.me/api/portraits/women/35.jpg",
                });
                context.RandomUser.Add(new Entities.RandomUser {
                    Id            = 2,
                    Email         = "*****@*****.**",
                    Title         = "Mr",
                    FirstName     = "Nathaniel",
                    LastName      = "Harris",
                    DateOfBirth   = new DateTime(1990, 1, 1),
                    PhoneNumber   = "(204)-997-2604",
                    ThrumbnailURL = "https://randomuser.me/api/portraits/thumb/men/61.jpg",
                    LargeImageURL = "https://randomuser.me/api/portraits/portraits/men/61.jpg",
                });
                context.RandomUser.Add(new Entities.RandomUser {
                    Id            = 3,
                    Email         = "*****@*****.**",
                    Title         = "Mr",
                    FirstName     = "Jake",
                    LastName      = "Morris",
                    DateOfBirth   = new DateTime(1981, 1, 1),
                    PhoneNumber   = "(204)-997-2604",
                    ThrumbnailURL = "https://randomuser.me/api/portraits/thumb/men/64.jpg",
                    LargeImageURL = "https://randomuser.me/api/portraits/portraits/men/64.jpg",
                });
                context.RandomUser.Add(new Entities.RandomUser {
                    Id            = 4,
                    Email         = "*****@*****.**",
                    Title         = "Mrs",
                    FirstName     = "Evie",
                    LastName      = "Chen",
                    DateOfBirth   = new DateTime(1980, 1, 1),
                    PhoneNumber   = "(204)-997-2604",
                    ThrumbnailURL = "https://randomuser.me/api/portraits/thumb/women/47.jpg",
                    LargeImageURL = "https://randomuser.me/api/portraits/portraits/women/47.jpg",
                });
                context.RandomUser.Add(new Entities.RandomUser {
                    Id            = 5,
                    Email         = "*****@*****.**",
                    Title         = "Mrs",
                    FirstName     = "Jessica",
                    LastName      = "Kumar",
                    DateOfBirth   = new DateTime(1948, 1, 1),
                    PhoneNumber   = "(204)-997-2604",
                    ThrumbnailURL = "https://randomuser.me/api/portraits/thumb/women/35.jpg",
                    LargeImageURL = "https://randomuser.me/api/portraits/portraits/women/35.jpg",
                });

                context.SaveChanges();
            }

            return(options);
        }
Exemplo n.º 10
0
 public RandomUserRepository(CeloPracticalChallengeDBContext context)
 {
     _context = context ?? throw new ArgumentNullException(nameof(context));;
 }