示例#1
0
        public void ForgotPassword_NormalEmail_True()
        {
            Mock<IUserEntityRepository> repository = new Mock<IUserEntityRepository>();
            Mock<IPasswordService> passwordService = new Mock<IPasswordService>();
            Mock<IMailService> mailService = new Mock<IMailService>();
            Mock<ILoggerService> loggerService = new Mock<ILoggerService>();

            mailService.Setup(o => o.SendMessage(It.IsAny<List<string>>(),It.IsAny<string>(),It.IsAny<string>(),It.IsAny<string>(),It.IsAny<bool>())).Returns(true);

            UserEntity user = new UserEntity();
            user.ID = Guid.NewGuid();
            user.FirstName = "Test";

            repository.Setup(o => o.GetByEmail(It.IsAny<string>())).Returns(user);
            loggerService.Setup(o => o.Log(It.IsAny<Log>()));

            LoginService service = new LoginService(
                                  repository.Object,
                                  passwordService.Object,
                                  mailService.Object,
                                  loggerService.Object);

            bool flag = service.ForgotPassword("*****@*****.**");
            Assert.IsTrue(flag);
        }
示例#2
0
        public void GenerateCredentials_EmptyPassword_ReturnsNull()
        {
            UserEntity user = new UserEntity();
            user.ID = Guid.NewGuid();
            user.FirstName = "Test";
            user.UserPassword = string.Empty;

            PasswordService service = new PasswordService();
            UserEntity retrieved = service.GenerateCredentials(user);
            Assert.IsNull(retrieved);
        }
示例#3
0
        public void AddUser_ValidUser_True()
        {
            UserEntity user = new UserEntity();
            user.ID = Guid.NewGuid();
            user.FirstName = "test";

            Mock<IUserEntityRepository> repository = new Mock<IUserEntityRepository>();
            Mock<IFileService> service = new Mock<IFileService>();
            Mock<ILoggerService> logger = new Mock<ILoggerService>();

            UserService userService = new UserService(repository.Object, service.Object, logger.Object);

            bool flag = userService.AddUser(user);

            Assert.IsTrue(flag);
        }
示例#4
0
        public void GenerateCredentials_ValidUserEntity_ReturnedWithFields()
        {
            string plaintext = "Password123456789";

            UserEntity user = new UserEntity();
            user.ID = Guid.NewGuid();
            user.FirstName = "Test";
            user.UserPassword = "******";

            PasswordService service = new PasswordService();
            UserEntity retrieved = service.GenerateCredentials(user);

            StringAssert.DoesNotMatch(plaintext, retrieved.UserPassword);
            Assert.NotNull(user.Registered);
            Assert.NotNull(user.Salt);
            Assert.NotNull(user.UserPassword);
        }
示例#5
0
        public void AddProfilePicture_NonExisting_EmptyPath()
        {
            UserEntity Entity = new UserEntity()
            {
                ID = Guid.NewGuid(),
                FirstName = "Kiran"
            };

            Mock<IUserEntityRepository> Repository = new Mock<IUserEntityRepository>();
            Repository.Setup(o => o.Update(Entity, false));
            Repository.SetupSequence(o => o.GetByID(Entity.ID)).Returns(null);

            Mock<IFileService> FileService = new Mock<IFileService>();
            FileService.Setup(o => o.SaveMedia(It.IsAny<string>(), It.IsAny<byte[]>())).Returns(true);

            Mock<ILoggerService> LoggerService = new Mock<ILoggerService>();

            UserService Service = new UserService(Repository.Object, FileService.Object, LoggerService.Object);
            string path = Service.AddProfilePicture(Entity.ID, Environment.CurrentDirectory, new byte[1]);

            Assert.AreEqual(string.Empty, path);
        }
示例#6
0
        public void AddProfilePicture_ExistingUser_PathAdded()
        {
            UserEntity Entity = new UserEntity()
            {
                ID = Guid.NewGuid(),
                FirstName = "Kiran"
            };

            Mock<IUserEntityRepository> Repository = new Mock<IUserEntityRepository>();
            Repository.Setup(o => o.Update(Entity, false));
            Repository.Setup(o => o.GetByID(Entity.ID)).Returns(Entity);

            Mock<IFileService> FileService = new Mock<IFileService>();
            FileService.Setup(o => o.SaveMedia(It.IsAny<string>(), It.IsAny<byte[]>())).Returns(true);

            Mock<ILoggerService> LoggerService = new Mock<ILoggerService>();

            UserService Service = new UserService(Repository.Object, FileService.Object, LoggerService.Object);
            string path = Service.AddProfilePicture(Entity.ID, Environment.CurrentDirectory, new byte[1]);

            string expected = string.Format("{0}/Profile{1}.jpg", Environment.CurrentDirectory, Entity.ID.ToString());
            Assert.AreEqual(expected, path);
        }
        public void Login_EmptyCredentials_ReturnsLoginView()
        {
            Mock<ILoggerService> loggerService = new Mock<ILoggerService>();
            Mock<ILoginService> loginService = new Mock<ILoginService>();
            Mock<IUserService> userService = new Mock<IUserService>();
            Mock<IPasswordService> passwordService = new Mock<IPasswordService>();

            AccountController controller = new AccountController(
                loggerService.Object,
                loginService.Object,
                userService.Object,
                passwordService.Object);

            UserViewModel model = new UserViewModel();

            UserEntity user = new UserEntity();
            user.ID = Guid.NewGuid();
            user.Email = string.Empty;
            user.UserPassword = string.Empty;

            model.User = user;

            ActionResult actionResult = controller.Login(model);
        }
示例#8
0
        public void RemoveProfilePicture_NullPath_False()
        {
            UserEntity Entity = new UserEntity()
            {
                ID = Guid.NewGuid(),
                FirstName = "Kiran",
                ProfilePicture = string.Empty
            };

            Mock<IUserEntityRepository> Repository = new Mock<IUserEntityRepository>();
            Repository.SetupSequence(o => o.GetByID(Entity.ID)).Returns(Entity);
            Repository.Setup(o => o.Update(Entity, false));

            Mock<IFileService> FileService = new Mock<IFileService>();
            FileService.Setup(o => o.DeleteMedia(It.IsAny<string>())).Returns(true);
            Mock<ILoggerService> LoggerService = new Mock<ILoggerService>();

            bool flag = new UserService(Repository.Object, FileService.Object, LoggerService.Object).RemoveProfilePicture(Entity.ID);

            Assert.IsFalse(flag);
        }
示例#9
0
        public void GetUser_ExistingUser_Retrieved()
        {
            UserEntity User = new UserEntity()
            {
                ID = Guid.NewGuid(),
                FirstName = "Kiran",
                LastName = "Patel"
            };

            Mock<IUserEntityRepository> Repository = new Mock<IUserEntityRepository>();
            Repository.SetupSequence(o => o.GetByID(User.ID)).Returns(User);

            Mock<IFileService> FileService = new Mock<IFileService>();
            Mock<ILoggerService> LoggerService = new Mock<ILoggerService>();

            UserService Service = new UserService(Repository.Object, FileService.Object, LoggerService.Object);
            UserEntity Retrieved = Service.GetUser(User.ID);
            Assert.AreEqual(User, Retrieved);
        }
示例#10
0
        public void EditProfilePicture_NullProfilePicture_False()
        {
            UserEntity Entity = new UserEntity()
            {
                ID = Guid.NewGuid(),
                FirstName = "Kiran",
                ProfilePicture = null
            };

            Mock<IUserEntityRepository> Repository = new Mock<IUserEntityRepository>();
            Repository.SetupSequence(o => o.GetByID(Entity.ID)).Returns(Entity);
            Repository.Setup(o => o.Update(Entity, false));

            Mock<IFileService> FileService = new Mock<IFileService>();
            FileService.SetupSequence(o => o.SaveMedia(It.IsAny<string>(), It.IsAny<byte[]>())).Returns(true);

            Mock<ILoggerService> LoggerService = new Mock<ILoggerService>();

            UserService Service = new UserService(Repository.Object, FileService.Object, LoggerService.Object);
            bool flag = Service.EditProfilePicture(Entity.ID, new byte[2]);

            Assert.IsFalse(flag);
        }
示例#11
0
 /// <summary>
 /// Updates the given user
 /// </summary>
 /// <param name="user">User to update</param>
 /// <returns>Flag to indicate if successfull</returns>
 public bool UpdateUser(UserEntity user)
 {
     try
     {
         this._repository.Update(user, false);
         return true;
     }
     catch (Exception e)
     {
         this._loggerservice.Log(new Log(e.Message, true));
         return false;
     }
 }
        public void Update_NonExistingEntity_Successfull()
        {
            UserEntity user = new UserEntity()
            {
                ID = Guid.NewGuid(),
                FirstName = "NonExisting",
                LastName = "NonExisting",
                DateOfBirth = DateTime.Now,
                Email = "NonExisting",
                UserPassword = "******",
                Registered = DateTime.Now,
                LastLogin = DateTime.Now,
                InvalidPasswordDate = DateTime.Now
            };

            UserEntityRepository Repository = new UserEntityRepository(helper);
            Repository.Update(user, true);

            Assert.AreEqual(user.ID, Repository.GetByID(user.ID).ID);
        }
示例#13
0
        public void SignIn_WrongCredentails_False()
        {
            Mock<IUserEntityRepository> repository = new Mock<IUserEntityRepository>();
            Mock<IPasswordService> passwordService = new Mock<IPasswordService>();
            Mock<IMailService> mailService = new Mock<IMailService>();
            Mock<ILoggerService> loggerService = new Mock<ILoggerService>();

            string Role;
            Guid ID;
            repository.Setup(o => o.Authenticate(It.IsAny<string>(), It.IsAny<string>(), out Role, out ID)).Returns(false);
            repository.Setup(o => o.Update(It.IsAny<UserEntity>(), false));

            UserEntity user = new UserEntity();
            user.ID = Guid.NewGuid();
            user.FirstName = "Test";

            repository.Setup(o => o.GetByEmail(It.IsAny<string>())).Returns(user);

            LoginService service = new LoginService(
                                      repository.Object,
                                      passwordService.Object,
                                      mailService.Object,
                                      loggerService.Object);

            bool flag = service.SignIn("*****@*****.**", "123", out Role, out ID);

            Assert.IsFalse(flag);
        }
示例#14
0
        public void RegisterUser_ValidUser_Registered()
        {
            UserEntity entity = new UserEntity();
            entity.ID = Guid.NewGuid();
            entity.FirstName = "Test";
            entity.UserPassword = "******";
            entity.Email = "*****@*****.**";

            Mock<IUserEntityRepository> repository = new Mock<IUserEntityRepository>();
            Mock<IPasswordService> passwordService = new Mock<IPasswordService>();
            Mock<IMailService> mailService = new Mock<IMailService>();
            Mock<ILoggerService> loggerService = new Mock<ILoggerService>();

            repository.Setup(o => o.Insert(It.IsAny<UserEntity>()));
            repository.Setup(o => o.isEmailInUse(It.IsAny<string>())).Returns(false);
            passwordService.SetupSequence(o => o.GenerateCredentials(entity)).Returns(entity);
            mailService.SetupSequence(o => o.SendMessage(
                It.IsAny<System.Collections.Generic.List<string>>(),
                It.IsAny<string>(),
                It.IsAny<string>(),
                It.IsAny<string>(),
                It.IsAny<bool>()))
                .Returns(true);

            LoginService service = new LoginService(
                                        repository.Object,
                                        passwordService.Object,
                                        mailService.Object,
                                        loggerService.Object);

            entity = service.RegisterUser(entity);

            Assert.IsNotNull(entity);
        }
示例#15
0
        public void RegisterUser_EmptyPassword_NotRegistered()
        {
            Mock<IUserEntityRepository> repository = new Mock<IUserEntityRepository>();
            Mock<IPasswordService> passwordService = new Mock<IPasswordService>();
            Mock<IMailService> mailService = new Mock<IMailService>();
            Mock<ILoggerService> loggerService = new Mock<ILoggerService>();

            repository.Setup(o => o.isEmailInUse(It.IsAny<string>())).Returns(false);
            passwordService.SetupSequence(o => o.GenerateCredentials(It.IsAny<UserEntity>())).Returns(null);

            LoginService service = new LoginService(
                                       repository.Object,
                                       passwordService.Object,
                                       mailService.Object,
                                       loggerService.Object);

            UserEntity user = new UserEntity();
            user.ID = Guid.NewGuid();
            user.FirstName = "Test";
            user.UserPassword = string.Empty;
            user.Email = "*****@*****.**";

            UserEntity retuser = service.RegisterUser(user);
            Assert.IsNull(retuser);
        }
示例#16
0
        public void RegisterUser_EmailInUse_NotRegistered()
        {
            Mock<IUserEntityRepository> repository = new Mock<IUserEntityRepository>();
            Mock<IPasswordService> passwordService = new Mock<IPasswordService>();
            Mock<IMailService> mailService = new Mock<IMailService>();
            Mock<ILoggerService> loggerService = new Mock<ILoggerService>();

            repository.Setup(o => o.isEmailInUse(It.IsAny<string>())).Returns(true);

            LoginService service = new LoginService(
                                      repository.Object,
                                      passwordService.Object,
                                      mailService.Object,
                                      loggerService.Object);

            UserEntity user = new UserEntity();
            user.ID = Guid.NewGuid();
            user.FirstName = "Test";
            user.UserPassword = "******";
            user.Email = "*****@*****.**";

            user = service.RegisterUser(user);
            Assert.IsNull(user);
        }
        public void Delete_NonExistingEntity_NothingDeleted()
        {
            UserEntity Entity = new UserEntity()
            {
                ID = Guid.NewGuid(),
                FirstName = "NonExisting",
                LastName = "NonExisting",
                Email = "NonExisting",
                UserPassword = "******"
            };

            UserEntityRepository Repository = new UserEntityRepository(helper);
            Repository.Delete(Entity);
        }
        public void SetUp()
        {
            Configuration config = new Configuration();
            config.DataBaseIntegration(db =>
            {
                db.Dialect<MsSql2012Dialect>();
                db.Driver<SqlClientDriver>();
                db.ConnectionString = "Data Source=DESKTOP-0II3UCP\\MAINSERVER;Initial Catalog=travelme;Integrated Security=True";
            });

            var mapper = new ModelMapper();
            mapper.AddMappings(Assembly.GetExecutingAssembly().GetExportedTypes());
            HbmMapping mapping = mapper.CompileMappingForAllExplicitlyAddedEntities();
            config.AddMapping(mapping);

            MockConfig = new Mock<IDatabaseConfig>();
            MockConfig.SetupSequence(o => o.GetConfig()).Returns(config);

            helper = new NhibernateHelper(MockConfig.Object);

            TestUser = new UserEntity()
            {
                ID = Guid.Parse("9fc0b724-d55f-441d-a1ae-ec726d7737f7"),
                FirstName = "Kiran",
                LastName = "Patel",
                DateOfBirth = new DateTime(1994, 08, 05, 10, 0, 0),
                Email = "*****@*****.**",
                UserPassword = "******",
                Registered = DateTime.Now,
                LastLogin = DateTime.Now,
                InvalidPasswordDate = DateTime.Now
            };

            TestTrip = new Trip()
            {
                ID = Guid.Parse("209F9526-3611-4F30-A79C-55557FFBECF5"),
                TripName = "Australia",
                TripDescription = "Aussies",
                TripLocation = "Backpacking",
                RelationID = Guid.Parse("9fc0b724-d55f-441d-a1ae-ec726d7737f7")
            };

            TestTrip2 = new Trip()
            {
                ID = Guid.Parse("6D8BCE5C-5681-472E-A1DC-97C5EA0C23FA"),
                TripName = "Thailand",
                TripDescription = "Thai!",
                TripLocation = "Backpacking",
                RelationID = Guid.Parse("9fc0b724-d55f-441d-a1ae-ec726d7737f7")
            };

            TestPost = new Post()
            {
                ID = Guid.Parse("832B97D6-F958-497A-952D-0224F27C4E1A"),
                PostData = "PostName",
                PostLat = "Lat",
                PostLong = "Long",
                PostDate = new DateTime(2012,08,09,10,0,0),
                RelationID = Guid.Parse("209F9526-3611-4F30-A79C-55557FFBECF5")
            };

            TestTrip.Posts.Add(TestPost);
            TestUser.Trips.Add(TestTrip);
            TestUser.Trips.Add(TestTrip2);

            toDeleteUser = new UserEntity()
            {
                ID = Guid.NewGuid(),
                FirstName = "Deleted",
                LastName = "Deleted",
                DateOfBirth = new DateTime(1994, 08, 05, 10, 0, 0),
                Email = "*****@*****.**",
                UserPassword = "******",
                InvalidPasswordDate = DateTime.Now,
                LastLogin = DateTime.Now,
                Registered = DateTime.Now
            };

            UserEntityRepository ForDelete = new UserEntityRepository(helper);
            ForDelete.Insert(toDeleteUser);
            ForDelete = null;
        }
        public void Update_InvalidEntity_ExceptionThrown()
        {
            UserEntity user = new UserEntity()
            {
                ID = Guid.NewGuid(),
                FirstName = "NonExistingNonExistingNonExistingNonExistingNonExistingNonExistingNonExistingNonExistingNonExistingNonExistingNonExisting",
                LastName = "NonExisting",
                DateOfBirth = DateTime.Now,
                Email = "NonExisting",
                UserPassword = "******",
                Registered = DateTime.Now,
                LastLogin = DateTime.Now,
                InvalidPasswordDate = DateTime.Now
            };

            UserEntityRepository Repository = new UserEntityRepository(helper);
            Repository.Update(user, true);
        }
示例#20
0
 /// <summary>
 /// Adds a user
 /// </summary>
 /// <param name="user">User to add</param>
 /// <returns>Flag indicating if the user is added</returns>
 public bool AddUser(UserEntity user)
 {
     try
     {
         this._repository.Insert(user);
         this._loggerservice.Log(new Log("User Added", false));
         return true;
     }
     catch(Exception e)
     {
         this._loggerservice.Log(new Log(e.Message, true));
         return false;
     }
 }
        public void InsertSubList_ExistingEntity_Successfull()
        {
            UserEntity Entity = new UserEntity()
            {
                ID = Guid.Parse("B42B1A1E-9DD5-4904-B7CE-9D55FD9A547A"),
                FirstName = "SecondEntity",
                LastName = "SecondEntity",
                DateOfBirth = new DateTime(1994, 08, 05, 10, 0, 0),
                Email = "SecondEntity",
                UserPassword = "******",
                Registered = DateTime.Now,
                LastLogin = DateTime.Now,
                InvalidPasswordDate = DateTime.Now
            };

            Trip trip = new Trip()
            {
                ID = Guid.Parse("053340CE-EE99-48B2-9687-693879933AFE"),
                TripName = "Trip",
                TripDescription = "Desc",
                TripLocation = "Location",
                RelationID = this.TestUser.ID
            };

            UserEntityRepository Repository = new UserEntityRepository(helper);
            Entity.Trips.Add(trip);
            Repository.Update(Entity, true);

            IList<Trip> trips = Repository.GetByID(this.TestUser.ID).Trips
                .Where(o => o.ID == trip.ID)
                .ToList();

            Assert.That(Entity.Trips.Any(o => o.ID == trip.ID));
            TripRepository RepositoryTrip = new TripRepository(helper);
            RepositoryTrip.Delete(trip);
        }