Exemple #1
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);
        }
Exemple #2
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);
        }
Exemple #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);
        }
Exemple #4
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);
        }
Exemple #5
0
        public void GetUser_NonExistingUser_NullRetrieved()
        {
            Guid ID = Guid.NewGuid();
            Mock<IUserEntityRepository> Repository = new Mock<IUserEntityRepository>();
            Repository.SetupSequence(o => o.GetByID(ID)).Returns(null);

            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(ID);
            Assert.IsNull(Retrieved);
        }
Exemple #6
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);
        }
Exemple #7
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);
        }
Exemple #8
0
        public void Constructor_RepositoryNull_ExceptionThrown()
        {
            Mock<IFileService> FileService = new Mock<IFileService>();
            Mock<ILoggerService> LoggerService = new Mock<ILoggerService>();

            UserService Service = new UserService(null, FileService.Object, LoggerService.Object);
        }
Exemple #9
0
        public void Constructor_RepositoryInjected_PropertySet()
        {
            Mock<IUserEntityRepository> Repository = new Mock<IUserEntityRepository>();
            Mock<IFileService> FileService = new Mock<IFileService>();
            Mock<ILoggerService> LoggerService = new Mock<ILoggerService>();

            UserService Service = new UserService(Repository.Object, FileService.Object, LoggerService.Object);
            Assert.IsTrue(Service.isRepositorySet());
        }
Exemple #10
0
        public void Constructor_LoggerNull_ExceptionThrown()
        {
            Mock<IUserEntityRepository> Repository = new Mock<IUserEntityRepository>();
            Mock<IFileService> FileService = new Mock<IFileService>();

            UserService Service = new UserService(null, FileService.Object, null);
        }
Exemple #11
0
        public void Constructor_FileServiceNull_ExceptionThrown()
        {
            Mock<IUserEntityRepository> Repository = new Mock<IUserEntityRepository>();
            Mock<ILoggerService> LoggerService = new Mock<ILoggerService>();

            UserService Service = new UserService(Repository.Object, null, LoggerService.Object);
        }