public void GetTop5OriginalsTest()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "InHarmonyTestControllerDB")
                          .Options;

            using (var context = new ApplicationDbContext(options))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                Repository         repository     = new Repository(context, _repositoryLogger);
                BusinessLogicClass logic          = new BusinessLogicClass(repository, _mapperClass, _repositoryLogger);
                SongController     songController = new SongController(logic, _songControllerLogger);
                // create a few songs...
                for (int i = 0; i < 5; i++)
                {
                    var song = new Song();
                    repository.songs.Add(song);
                }

                context.SaveChanges();

                var s = songController.GetTop5Originals();

                Assert.Equal(5, s.Result.Count);
            }
        }
        public void GetOriginalsongsByLyricsTest()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "InHarmonyTestControllerDB")
                          .Options;

            using (var context = new ApplicationDbContext(options))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                Repository         repository     = new Repository(context, _repositoryLogger);
                BusinessLogicClass logic          = new BusinessLogicClass(repository, _mapperClass, _repositoryLogger);
                SongController     songController = new SongController(logic, _songControllerLogger);
                // create a song
                var song = new Song {
                    Lyrics = "thicc dummy data"
                };

                repository.songs.Add(song);
                context.SaveChanges();

                var s = songController.GetOriginalsongsByLyrics(song.Lyrics);

                Assert.NotEmpty(s.Result);
            }
        }
Exemplo n.º 3
0
        public async Task SaveUserToDbTest()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "InHarmonyTestLogicDB")
                          .Options;

            using (var context = new ApplicationDbContext(options))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                Repository         _repository        = new Repository(context, _logger);
                BusinessLogicClass businessLogicClass = new BusinessLogicClass(_repository, _mapperClass, _logger);
                var user = new User
                {
                    UserName  = "******",
                    Password  = "******",
                    FirstName = "Johnny",
                    LastName  = "Test",
                    Email     = "*****@*****.**"
                };

                await _repository.SaveNewUser(user);

                User u = await businessLogicClass.SaveUserToDb(user);

                Assert.NotNull(u);
            }
        }
Exemplo n.º 4
0
        public HygienistHomeForm(String strUserName, String strPassword)
        {
            InitializeComponent();
            UserClass ucDoctorUser = BusinessLogicClass.QueryDatabaseForUser(strUserName, strPassword);

            DoctorHomeFormWelcomeLabel.Text = $"Welcome {ucDoctorUser.m_strFirstName} {ucDoctorUser.m_strLastName}";

            List <AppointmentClass> lstAppointments = DataAccessClass.getAppointmentsWithDentistName(strUserName);

            int i = 1;

            foreach (AppointmentClass appointment in lstAppointments)
            {
                ListViewItem item = new ListViewItem("Appointment " + i);
                item.SubItems.Add(appointment.m_dtDateTime.Date.ToShortDateString());
                item.SubItems.Add(appointment.m_dtDateTime.TimeOfDay.ToString());
                item.SubItems.Add(appointment.m_strPatientName);
                item.SubItems.Add(appointment.m_strDescription);
                item.ForeColor = Color.LightSkyBlue;
                if (appointment.m_chrStatus[0] == 'C')
                {
                    item.Font = new Font("Arial", 9F, FontStyle.Strikeout, GraphicsUnit.Point, ((byte)(0)));
                }
                else
                {
                    item.Font = new Font("Arial", 9F, FontStyle.Bold, GraphicsUnit.Point, ((byte)(0)));
                }
                DoctorAppointmentListView.Items.Add(item);
                i++;
            }
        }
Exemplo n.º 5
0
        public async Task IncrementNumPlaysTest()
        {
            System.Threading.Thread.Sleep(TimeSpan.FromSeconds(4));

            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "InHarmonyTestLogicDB")
                          .Options;

            using (var context = new ApplicationDbContext(options))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                Repository         _repository        = new Repository(context, _logger);
                BusinessLogicClass businessLogicClass = new BusinessLogicClass(_repository, _mapperClass, _logger);

                var song = new Song();

                _repository.songs.Add(song);
                context.SaveChanges();

                await businessLogicClass.IncrementNUmPlays(song.Id);

                Assert.Equal(1, song.NumberOfPlays);
            }
        }
Exemplo n.º 6
0
        public void AcceptFriend()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "InHarmonyTestLogicDB3")
                          .Options;

            using (var context = new ApplicationDbContext(options))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                Repository         _repository        = new Repository(context, _logger);
                BusinessLogicClass businessLogicClass = new BusinessLogicClass(_repository, _mapperClass, _logger);

                var user1 = new User {
                    UserName = "******"
                };
                var user2 = new User {
                    UserName = "******"
                };

                _repository.users.Add(user1);
                _repository.users.Add(user2);

                var fl = new FriendList {
                    FromUsername = user1.UserName, ToUsername = user2.UserName
                };
                _repository.friendList.Add(fl);
                context.SaveChanges();

                Assert.NotNull(businessLogicClass.AcceptFriend(fl));
                // Assert below is necessary to actually check if this is passing. Needs to be fixed in logic layer.
                // Assert.Equal("accept", fl.status);
            }
        }
        private void AdminCreateButton_Click(object sender, EventArgs e)
        {
            if (AdminCreateUserTextbox.Text == String.Empty || AdminCreateUserTextbox.Text == "Create a Username" ||
                AdminCreatePassTextBox.Text == String.Empty || AdminCreatePassTextBox.Text == "Create a password" ||
                AdminCreateFirstTextbox.Text == String.Empty || AdminCreateFirstTextbox.Text == "Enter the first name" ||
                AdminCreateLastTextbox.Text == String.Empty || AdminCreateLastTextbox.Text == "Enter the last name" ||
                AdminCreateTypeCombobox.Text == String.Empty)
            {
                return;
            }

            Boolean blnWasAccountCreated = BusinessLogicClass.registerNewUser(AdminCreateFirstTextbox.Text,
                                                                              AdminCreateLastTextbox.Text,
                                                                              AdminCreateUserTextbox.Text,
                                                                              AdminCreatePassTextBox.Text,
                                                                              AdminCreateTypeCombobox.Text);

            if (blnWasAccountCreated)
            {
                AdminCreateValidLabel.Visible = true;
                AdminCreateErrorLabel.Visible = false;
            }
            else
            {
                AdminCreateValidLabel.Visible = false;
                AdminCreateErrorLabel.Visible = true;
            }
        }
Exemplo n.º 8
0
        public async Task LoginUserTest()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "InHarmonyTestLogicDB")
                          .Options;

            await Task.Run(() =>
            {
                using (var context = new ApplicationDbContext(options))
                {
                    context.Database.EnsureDeleted();
                    context.Database.EnsureCreated();

                    Repository _repository = new Repository(context, _logger);
                    BusinessLogicClass businessLogicClass = new BusinessLogicClass(_repository, _mapperClass, _logger);
                    var user = new User
                    {
                        UserName  = "******",
                        Password  = "******",
                        FirstName = "Johnny",
                        LastName  = "Test",
                        Email     = "*****@*****.**"
                    };

                    _repository.users.Add(user);
                    Task <User> loggedInUser = businessLogicClass.LoginUser(user.UserName, user.Password);
                    Assert.NotNull(loggedInUser);
                }
            });
        }
Exemplo n.º 9
0
        public async Task ConvertFileToBitArrayTest()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "InHarmonyTestLogicDB4")
                          .Options;

            using (var context = new ApplicationDbContext(options))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                Repository         _repository        = new Repository(context, _logger);
                BusinessLogicClass businessLogicClass = new BusinessLogicClass(_repository, _mapperClass, _logger);

                var song = new Song
                {
                    ArtistName    = "Bad Posture",
                    Genre         = "Pop Punk",
                    Title         = "Yellow",
                    Duration      = TimeSpan.MaxValue,
                    NumberOfPlays = 0,
                    isOriginal    = true
                };

                _repository.songs.Add(song);
                context.SaveChanges();
                Assert.NotNull(businessLogicClass.ConvertFileToBitArray(song));
            }
        }
Exemplo n.º 10
0
        public async Task GetAllFriendRequestsOUserIdTest()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "InHarmonyTestLogicDB3")
                          .Options;

            using (var context = new ApplicationDbContext(options))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                Repository         _repository        = new Repository(context, _logger);
                BusinessLogicClass businessLogicClass = new BusinessLogicClass(_repository, _mapperClass, _logger);

                var user1 = new User();
                var user2 = new User();

                _repository.users.Add(user1);
                _repository.users.Add(user2);
                context.SaveChanges();

                var fl = new FriendList(user1.Id, user2.Id, user1.UserName, user2.UserName);
                _repository.friendList.Add(fl);
                context.SaveChanges();

                var list = await businessLogicClass.GetAllFriendRequestsOUserId(user2.Id);

                Assert.NotEmpty(list);
            }
        }
        public void UploadSongTest()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "InHarmonyTestControllerDB")
                          .Options;

            using (var context = new ApplicationDbContext(options))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                Repository         repository     = new Repository(context, _repositoryLogger);
                BusinessLogicClass logic          = new BusinessLogicClass(repository, _mapperClass, _repositoryLogger);
                SongController     songController = new SongController(logic, _songControllerLogger);
                // create a song
                var song = new Song();

                repository.songs.Add(song);
                context.SaveChanges();

                var s = songController.UploadSong(song);

                Assert.NotNull(s);
            }
        }
Exemplo n.º 12
0
        public async Task GetUserProfileViewModelAsyncTest()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "InHarmonyTestLogicDB")
                          .Options;

            await Task.Run(() =>
            {
                using (var context = new ApplicationDbContext(options))
                {
                    context.Database.EnsureDeleted();
                    context.Database.EnsureCreated();

                    Repository _repository = new Repository(context, _logger);
                    BusinessLogicClass businessLogicClass = new BusinessLogicClass(_repository, _mapperClass, _logger);
                    var user = new User
                    {
                        UserName  = "******",
                        Password  = "******",
                        FirstName = "Johnny",
                        LastName  = "Test",
                        Email     = "*****@*****.**"
                    };

                    _repository.SaveNewUser(user).Wait();
                    var upvm = businessLogicClass.GetUserProfileViewModel(user.Id);
                    Assert.NotNull(upvm);
                }
            });
        }
        public void AddSongToFavoritesTest()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "InHarmonyTestControllerDB")
                          .Options;

            using (var context = new ApplicationDbContext(options))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                Repository         repository     = new Repository(context, _repositoryLogger);
                BusinessLogicClass logic          = new BusinessLogicClass(repository, _mapperClass, _repositoryLogger);
                SongController     songController = new SongController(logic, _songControllerLogger);
                // create a user
                var user = new User();

                // create a song
                var song = new Song();

                // create a favorite
                var fave = new FavoriteList {
                    UserId = user.Id, SongId = song.Id
                };

                repository.songs.Add(song);
                repository.users.Add(user);
                repository.favoriteLists.Add(fave);
                context.SaveChanges();

                var s = songController.addSongToFavorites(song.Id, user.Id);

                Assert.NotNull(s);
            }
        }
        public void GetUserToEditTest()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "InHarmonyTestControllerDB")
                          .Options;

            using (var context = new ApplicationDbContext(options))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                Repository         repository     = new Repository(context, _repositoryLogger);
                BusinessLogicClass logic          = new BusinessLogicClass(repository, _mapperClass, _repositoryLogger);
                UserController     userController = new UserController(logic, _userControllerLogger);
                var user = new User
                {
                    UserName  = "******",
                    Password  = "******",
                    FirstName = "Johnny",
                    LastName  = "Test",
                    Email     = "*****@*****.**"
                };

                repository.SaveNewUser(user).Wait();

                Task <User> u = userController.GetUserToEdit(user.Id);
                Assert.NotNull(u);
            }
        }
Exemplo n.º 15
0
        public async Task GetListOfFriendsByUserIdTest()
        {
            System.Threading.Thread.Sleep(TimeSpan.FromSeconds(2));

            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "InHarmonyTestLogicDB3")
                          .Options;

            using (var context = new ApplicationDbContext(options))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                Repository         _repository        = new Repository(context, _logger);
                BusinessLogicClass businessLogicClass = new BusinessLogicClass(_repository, _mapperClass, _logger);

                var user1 = new User();
                var user2 = new User();

                _repository.users.Add(user1);
                _repository.users.Add(user2);
                context.SaveChanges();

                var fl = new FriendList {
                    FriendId = user1.Id, RequestedFriendId = user2.Id, status = "accept"
                };
                _repository.friendList.Add(fl);
                context.SaveChanges();

                var list = await businessLogicClass.GetListOfFriendsByUserId(user2.Id);

                Assert.NotEmpty(list);
            }
        }
        public void GetUserByIdAsyncTest()
        {
            System.Threading.Thread.Sleep(TimeSpan.FromSeconds(6));

            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "InHarmonyTestControllerDB")
                          .Options;

            using (var context = new ApplicationDbContext(options))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                Repository         repository     = new Repository(context, _repositoryLogger);
                BusinessLogicClass logic          = new BusinessLogicClass(repository, _mapperClass, _repositoryLogger);
                UserController     userController = new UserController(logic, _userControllerLogger);
                // create a user
                var user = new User
                {
                    UserName  = "******",
                    Password  = "******",
                    FirstName = "Johnny",
                    LastName  = "Test",
                    Email     = "*****@*****.**"
                };

                repository.SaveNewUser(user).Wait();

                Assert.NotNull(userController.GetUserByIdAsync(user.Id));
            }
        }
        public void LoginTest()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "InHarmonyTestControllerDB")
                          .Options;

            using (var context = new ApplicationDbContext(options))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                Repository         repository     = new Repository(context, _repositoryLogger);
                BusinessLogicClass logic          = new BusinessLogicClass(repository, _mapperClass, _repositoryLogger);
                UserController     userController = new UserController(logic, _userControllerLogger);
                var user = new User
                {
                    Id        = int.MaxValue,
                    UserName  = "******",
                    Password  = "******",
                    FirstName = "Johnny",
                    LastName  = "Test",
                    Email     = "*****@*****.**"
                };

                Task <User> upvm  = userController.CreateUser(user);
                Task <User> upvm2 = userController.login(user.UserName, user.Password);
                Assert.NotNull(upvm2);
            }
        }
Exemplo n.º 18
0
        public async Task GetAllMessageAsyncTest()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "InHarmonyTestLogicDB")
                          .Options;

            using (var context = new ApplicationDbContext(options))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                Repository         _repository        = new Repository(context, _logger);
                BusinessLogicClass businessLogicClass = new BusinessLogicClass(_repository, _mapperClass, _logger);
                var user = new User
                {
                    Id        = int.MaxValue,
                    UserName  = "******",
                    Password  = "******",
                    FirstName = "Johnny",
                    LastName  = "Test",
                    Email     = "*****@*****.**"
                };

                IEnumerable <Message> messages = await businessLogicClass.GetAllMessagesAsync();

                Assert.NotNull(messages);
            }
        }
        public void GetAllSongsByACertainUserTest()
        {
            System.Threading.Thread.Sleep(TimeSpan.FromSeconds(2));

            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "InHarmonyTestControllerDB")
                          .Options;

            using (var context = new ApplicationDbContext(options))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                Repository         repository     = new Repository(context, _repositoryLogger);
                BusinessLogicClass logic          = new BusinessLogicClass(repository, _mapperClass, _repositoryLogger);
                SongController     songController = new SongController(logic, _songControllerLogger);
                // create a user -- generates with null as username
                var user = new User();

                // create a song -- generates with null as artist name
                var song = new Song();

                repository.songs.Add(song);
                repository.users.Add(user);
                context.SaveChanges();

                // gets list where artist name matches username
                var s = songController.GetAllSongsByACertainUser(user.Id);

                // list is not empty because we create song and user with null
                Assert.NotEmpty(s.Result);
            }
        }
Exemplo n.º 20
0
        public async Task GetSongByIdTest()
        {
            const string lyrics = "lorem ips subsciat boom bap da ting go skrrrrra ka ka pa pa pa";

            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "InHarmonyTestLogicDB")
                          .Options;

            await Task.Run(() =>
            {
                using (var context = new ApplicationDbContext(options))
                {
                    context.Database.EnsureDeleted();
                    context.Database.EnsureCreated();

                    Repository _repository = new Repository(context, _logger);
                    BusinessLogicClass businessLogicClass = new BusinessLogicClass(_repository, _mapperClass, _logger);

                    var song = new Song
                    {
                        ArtistName    = "Bad Posture",
                        Genre         = "Pop Punk",
                        Title         = "Yellow",
                        Duration      = TimeSpan.MaxValue,
                        NumberOfPlays = int.MaxValue,
                        Lyrics        = lyrics,
                        isOriginal    = true
                    };

                    _repository.songs.Add(song);
                    context.SaveChanges();
                    Assert.NotNull(businessLogicClass.GetSongById(song.Id));
                }
            });
        }
        public void GetOriginalSongSearchByGenreTest()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "InHarmonyTestControllerDB")
                          .Options;

            using (var context = new ApplicationDbContext(options))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                Repository         repository     = new Repository(context, _repositoryLogger);
                BusinessLogicClass logic          = new BusinessLogicClass(repository, _mapperClass, _repositoryLogger);
                SongController     songController = new SongController(logic, _songControllerLogger);

                // create a song with pop as genre
                var song = new Song {
                    Genre = "Pop"
                };

                repository.songs.Add(song);
                context.SaveChanges();

                // search for null
                var s = songController.GetOriginalSongSearchByGenre("Pop");

                Assert.NotEmpty(s.Result);
            }
        }
Exemplo n.º 22
0
        public async Task GetNumOfFriendsByUserIdTest()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "InHarmonyTestLogicDB")
                          .Options;

            using (var context = new ApplicationDbContext(options))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                Repository         _repository        = new Repository(context, _logger);
                BusinessLogicClass businessLogicClass = new BusinessLogicClass(_repository, _mapperClass, _logger);
                // create a user
                var user = new User
                {
                    UserName  = "******",
                    Password  = "******",
                    FirstName = "Johnny",
                    LastName  = "Test",
                    Email     = "*****@*****.**"
                };

                var x = await businessLogicClass.GetNumOfFriendsByUserId(user.Id);

                Assert.Equal(0, x);
            }
        }
Exemplo n.º 23
0
        public async Task SearchForUsersByPartialN()
        {
            const string username = "******";

            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "InHarmonyTestLogicDB")
                          .Options;

            await Task.Run(() =>
            {
                using (var context = new ApplicationDbContext(options))
                {
                    context.Database.EnsureDeleted();
                    context.Database.EnsureCreated();

                    Repository _repository = new Repository(context, _logger);
                    BusinessLogicClass businessLogicClass = new BusinessLogicClass(_repository, _mapperClass, _logger);
                    var user = new User
                    {
                        UserName  = username,
                        Password  = "******",
                        FirstName = "Johnny",
                        LastName  = "Test",
                        Email     = "*****@*****.**"
                    };

                    _repository.users.Add(user);
                    context.SaveChanges();
                    Task <List <User> > listOfUsers = businessLogicClass.SearchForUsersByPartialN(username);
                    Assert.NotNull(listOfUsers);
                }
            });
        }
 public LoginModel(BusinessLogicClass businessLogicClass, SignInManager <AppUser> signInManager,
                   ILogger <LoginModel> logger,
                   UserManager <AppUser> userManager)
 {
     _userManager        = userManager;
     _signInManager      = signInManager;
     _logger             = logger;
     _businessLogicClass = businessLogicClass;
 }
        public void AreWeFriendsTest()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "InHarmonyTestControllerDB")
                          .Options;

            using (var context = new ApplicationDbContext(options))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                Repository         repository     = new Repository(context, _repositoryLogger);
                BusinessLogicClass logic          = new BusinessLogicClass(repository, _mapperClass, _repositoryLogger);
                UserController     userController = new UserController(logic, _userControllerLogger);
                // create a user
                var user = new User
                {
                    UserName  = "******",
                    Password  = "******",
                    FirstName = "Johnny",
                    LastName  = "Test",
                    Email     = "*****@*****.**"
                };

                // create a second user
                var user2 = new User
                {
                    UserName  = "******",
                    Password  = "******",
                    FirstName = "Greg",
                    LastName  = "Smeg",
                    Email     = "*****@*****.**"
                };

                repository.SaveNewUser(user).Wait();
                repository.SaveNewUser(user2).Wait();

                var fl = new FriendList {
                    FriendId = user.Id, RequestedFriendId = user2.Id
                };
                repository.friendList.Add(fl);
                context.SaveChanges();

                Assert.False(userController.AreWeFriends(user.Id, user2.Id).Result);

                var fl2 = new FriendList {
                    FriendId = user.Id, RequestedFriendId = user2.Id, status = "accept"
                };
                repository.friendList.Add(fl2);
                context.SaveChanges();

                Assert.True(userController.AreWeFriends(user.Id, user2.Id).Result);
            }
        }
Exemplo n.º 26
0
 public RegisterModel(
     BusinessLogicClass businessLogicClass,
     UserManager <AppUser> userManager,
     SignInManager <AppUser> signInManager,
     ILogger <RegisterModel> logger,
     IEmailSender emailSender)
 {
     _userManager        = userManager;
     _signInManager      = signInManager;
     _logger             = logger;
     _emailSender        = emailSender;
     _businessLogicClass = businessLogicClass;
 }
        public void SearchForUsersTest()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "InHarmonyTestControllerDB")
                          .Options;

            using (var context = new ApplicationDbContext(options))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                Repository         repository     = new Repository(context, _repositoryLogger);
                BusinessLogicClass logic          = new BusinessLogicClass(repository, _mapperClass, _repositoryLogger);
                UserController     userController = new UserController(logic, _userControllerLogger);

                var userList = new List <User>();
                // create some dummy users
                for (int i = 0; i < 10; i++)
                {
                    // j0, j2, j4 ... j8
                    var user = new User
                    {
                        Id        = int.MaxValue - i,
                        UserName  = "******" + i,
                        Password  = "******",
                        FirstName = "Johnny" + i,
                        LastName  = "Test",
                        Email     = "johnnytest123" + i + "@email.com"
                    };

                    // g1, g3, g5 ... g9
                    var user2 = new User
                    {
                        Id        = int.MaxValue - ++i,
                        UserName  = "******" + i,
                        Password  = "******",
                        FirstName = "Greg" + i,
                        LastName  = "Smeg",
                        Email     = "johnnytest123" + i + "@zmail.com"
                    };

                    repository.SaveNewUser(user).Wait();
                    repository.SaveNewUser(user2).Wait();
                }

                // with user populated db, let's search for the letter g
                var userList2 = userController.SearchForUsers("g");
                // we expect 5 users to return in the list
                Assert.Equal(5, userList2.Result.Count);
            }
        }
        public void GetMessagesBetween2UsersTest()
        {
            System.Threading.Thread.Sleep(TimeSpan.FromSeconds(3));

            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "InHarmonyTestControllerDB")
                          .Options;

            using (var context = new ApplicationDbContext(options))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                Repository         repository     = new Repository(context, _repositoryLogger);
                BusinessLogicClass logic          = new BusinessLogicClass(repository, _mapperClass, _repositoryLogger);
                UserController     userController = new UserController(logic, _userControllerLogger);
                // create a user
                var user = new User
                {
                    UserName  = "******",
                    Password  = "******",
                    FirstName = "Johnny",
                    LastName  = "Test",
                    Email     = "*****@*****.**"
                };

                // create a second user
                var user2 = new User
                {
                    UserName  = "******",
                    Password  = "******",
                    FirstName = "Greg",
                    LastName  = "Smeg",
                    Email     = "*****@*****.**"
                };

                repository.SaveNewUser(user).Wait();
                repository.SaveNewUser(user2).Wait();

                var message = new Message {
                    ToUserId = user.Id, FromUserId = user2.Id, FromUserName = user2.UserName, Content = "Thicc dummy data"
                };

                repository.messages.Add(message);
                context.SaveChanges();

                var messagesBetween2Users = userController.GetMessagesBetween2Users(user.Id, user2.Id);

                Assert.NotNull(messagesBetween2Users);
            }
        }
Exemplo n.º 29
0
        public async Task DeleteFriendTest()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "InHarmonyTestLogicDB")
                          .Options;

            await Task.Run(() =>
            {
                using (var context = new ApplicationDbContext(options))
                {
                    context.Database.EnsureDeleted();
                    context.Database.EnsureCreated();

                    Repository _repository = new Repository(context, _logger);
                    BusinessLogicClass businessLogicClass = new BusinessLogicClass(_repository, _mapperClass, _logger);
                    // Create a user
                    var user1 = new User
                    {
                        UserName  = "******",
                        Password  = "******",
                        FirstName = "Johnny",
                        LastName  = "Test",
                        Email     = "*****@*****.**"
                    };

                    // Create a second user
                    var user2 = new User
                    {
                        UserName  = "******",
                        Password  = "******",
                        FirstName = "Johnny",
                        LastName  = "Test",
                        Email     = "*****@*****.**"
                    };

                    // instantiate friend list
                    FriendList fl = new FriendList(user1.Id, user2.Id, user2.UserName, user1.UserName);
                    _repository.friendList.Add(fl);
                    context.SaveChanges();

                    // make sure they're friends
                    Assert.Contains <FriendList>(fl, _repository.friendList);

                    // revoke friendship
                    businessLogicClass.DeleteFriend(user1.Id, user2.Id).Wait();
                    Assert.DoesNotContain <FriendList>(fl, _repository.friendList);
                }
            });
        }
Exemplo n.º 30
0
        public async Task GetMessages2UsersTest()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "InHarmonyTestLogicDB3")
                          .Options;

            using (var context = new ApplicationDbContext(options))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                Repository         _repository        = new Repository(context, _logger);
                BusinessLogicClass businessLogicClass = new BusinessLogicClass(_repository, _mapperClass, _logger);
                // Create a user
                var user1 = new User
                {
                    Id        = int.MaxValue,
                    UserName  = "******",
                    Password  = "******",
                    FirstName = "Johnny",
                    LastName  = "Test",
                    Email     = "*****@*****.**"
                };

                // Create a second user
                var user2 = new User
                {
                    Id        = int.MaxValue - 1,
                    UserName  = "******",
                    Password  = "******",
                    FirstName = "Johnny",
                    LastName  = "Test",
                    Email     = "*****@*****.**"
                };

                // Create a message
                var message = new Message {
                };
                _repository.users.Add(user1);
                _repository.users.Add(user2);
                _repository.messages.Add(message);
                context.SaveChanges();

                // It's about sending a message
                List <Message> mvm = await businessLogicClass.GetMessages2users(user1.Id, user2.Id);

                Assert.NotNull(mvm);
            }
        }