예제 #1
0
        public void Register_ValidData_RegisteredUser()
        {
            // Arrange
            IOptions <AppSettings> mockOptions = Options.Create <AppSettings>(new AppSettings()
            {
                Secret = "SECRET FOR TESTING"
            });
            IUserService  userService = new UserService(MockHelper.MockUserRepository(), mockOptions);
            RegisterModel model       = new RegisterModel()
            {
                FirstName       = "Greg",
                LastName        = "Gregsky",
                Password        = "******",
                ConfirmPassword = "******",
                Username        = "******"
            };

            // Act
            userService.Register(model);

            // Assert
            UserModel newUser = userService.Authenticate(model.Username, model.Password);

            Assert.AreEqual(model.FirstName, newUser.FirstName);
            Assert.AreEqual(model.LastName, newUser.LastName);
        }
예제 #2
0
        public void GetNote_InvalidUserId_Exception()
        {
            // Arrange
            INoteService noteService = new NoteService(MockHelper.MockUserRepository(), MockHelper.MockNoteRepository());
            int          userId      = 1;
            int          noteId      = 9;

            // Act / Assert
            Assert.ThrowsException <NullReferenceException>(() => noteService.GetNote(noteId, userId));
        }
예제 #3
0
        public void GetUserNotes_InvalidUserId_null()
        {
            // Arrange
            INoteService noteService    = new NoteService(MockHelper.MockUserRepository(), MockHelper.MockNoteRepository());
            int          expectedResult = 0;
            int          userId         = 3;
            // Act
            IEnumerable <NoteModel> result = noteService.GetUserNotes(userId);

            // Assert
            Assert.AreEqual(expectedResult, result.ToList().Count);
        }
예제 #4
0
        public void GetNote_ValidUserId_Note()
        {
            // Arrange
            INoteService noteService    = new NoteService(MockHelper.MockUserRepository(), MockHelper.MockNoteRepository());
            int          userId         = 1;
            int          noteId         = 1;
            int          expectedResult = 1;
            // Act
            NoteModel result = noteService.GetNote(noteId, userId);

            // Assert
            Assert.AreEqual(expectedResult, result.Id);
        }
예제 #5
0
        public void DeleteNote_ValidNote_NoteDeleted()
        {
            // Arrange
            INoteService noteService    = new NoteService(MockHelper.MockUserRepository(), MockHelper.MockNoteRepository());
            int          expectedResult = 1;
            int          userId         = 1;
            int          noteId         = 1;

            // Act
            noteService.DeleteItem(noteId, userId);
            // Assert
            IEnumerable <NoteModel> resultNotes = noteService.GetUserNotes(userId);

            Assert.AreEqual(expectedResult, resultNotes.ToList().Count);
        }
예제 #6
0
        public void Authenticate_InvalidUsernamePassword_UserModel()
        {
            // Arrange
            IOptions <AppSettings> mockOptions = Options.Create <AppSettings>(new AppSettings()
            {
                Secret = "SECRET FOR TESTING"
            });
            IUserService userService = new UserService(MockHelper.MockUserRepository(), mockOptions);
            string       username    = "******";
            string       password    = "******";

            // Act
            UserModel result = userService.Authenticate(username, password);

            // Assert
            Assert.IsNull(result);
        }
예제 #7
0
        public void Authenticate_ValidUsernamePassword_ValidToken()
        {
            // Arrange
            IOptions <AppSettings> mockOptions = Options.Create <AppSettings>(new AppSettings()
            {
                Secret = "SECRET FOR TESTING"
            });
            IUserService userService = new UserService(MockHelper.MockUserRepository(), mockOptions);
            string       username    = "******";
            string       password    = "******";

            // Act
            UserModel result = userService.Authenticate(username, password);

            // Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Token != string.Empty && result.Token != null);
        }
예제 #8
0
        public void AddNote_ValidNote_NoteAdded()
        {
            // Arrange
            INoteService noteService    = new NoteService(MockHelper.MockUserRepository(), MockHelper.MockNoteRepository());
            int          expectedResult = 3;
            NoteModel    model          = new NoteModel()
            {
                Id     = 4,
                Text   = "Test the app",
                Color  = "red",
                Tag    = TagType.Work,
                UserId = 1
            };

            // Act
            noteService.AddNote(model);
            // Assert
            IEnumerable <NoteModel> resultNotes = noteService.GetUserNotes(model.UserId);

            Assert.AreEqual(expectedResult, resultNotes.ToList().Count);
        }