Beispiel #1
0
        public void GetUserByUsernameShouldNotThrowExceptionIfUsernameIsInDB(string username, bool useAsync)
        {
            //Arrange
            var options = new DbContextOptionsBuilder <Project2DBContext>()
                          .UseInMemoryDatabase(databaseName: "StaticFilledUserDB")
                          .Options;
            bool        result = true;
            AppUserRepo uRepo;

            //Act
            using (var context = new Project2DBContext(options))
            {
                uRepo = new AppUserRepo(context);
                if (useAsync)
                {
                    uRepo.GetUserByUsernameAsync(username).Wait();
                }
                else
                {
                    uRepo.GetUserByUsername(username);
                }
            }
            //If exception is throw, test will exit before reaching Assert
            //Assert
            Assert.True(result);
        }
Beispiel #2
0
        public void GetUserByUsernameShouldReturnUserWithMatchingUsername(string username, bool useAsync)
        {
            //Arrange
            var options = new DbContextOptionsBuilder <Project2DBContext>()
                          .UseInMemoryDatabase(databaseName: "StaticFilledUserDB")
                          .Options;

            AppUser     u;
            AppUserRepo uRepo;

            //Act
            using (var context = new Project2DBContext(options))
            {
                uRepo = new AppUserRepo(context);
                if (useAsync)
                {
                    u = uRepo.GetUserByUsernameAsync(username).Result;
                }
                else
                {
                    u = uRepo.GetUserByUsername(username);
                }
            }

            //Assert
            Assert.Equal(username, u.Username);
        }
Beispiel #3
0
        public void GetUserByUsernameShouldThrowExceptionIfUsernameNotFound(string username, bool useAsync)
        {
            //Arrange
            var options = new DbContextOptionsBuilder <Project2DBContext>()
                          .UseInMemoryDatabase(databaseName: "StaticFilledUserDB")
                          .Options;

            bool        result = false;
            AppUserRepo uRepo;

            //Act
            using (var context = new Project2DBContext(options))
            {
                uRepo = new AppUserRepo(context);
                try
                {
                    if (useAsync)
                    {
                        uRepo.GetUserByUsernameAsync(username).Wait();
                    }
                    else
                    {
                        uRepo.GetUserByUsername(username);
                    }
                }
                catch (NotSupportedException)
                {
                    result = true;
                }
                catch (AggregateException)
                {
                    result = true;
                }
            }
            //Assert
            Assert.True(result);
        }