Exemplo n.º 1
0
        public void UpdateTest()
        {
            var UserService = GetService();
            int CreatedId   = UserService.Create(MockAddUser, "testcom01", "");

            MockUpdateUser.Id = CreatedId;
            UserService.Update(MockUpdateUser);

            using (var CdDb = new CDSEntities())
            {
                var DbUser = CdDb.Users.SingleOrDefault(x => x.Id == CreatedId);
                Assert.IsNotNull(DbUser);

                Assert.AreEqual(DbUser.Adress, MockUpdateUser.Adress);
                Assert.AreEqual(DbUser.BirthDate, MockUpdateUser.BirthDate);
                Assert.AreEqual(DbUser.Cellphone, MockUpdateUser.Cellphone);
                Assert.AreEqual(DbUser.CEP, MockUpdateUser.CEP);
                Assert.AreEqual(DbUser.Gender, MockUpdateUser.Gender);
                Assert.AreEqual(DbUser.IdGroup, MockUpdateUser.IdGroup);
                Assert.AreEqual(DbUser.Name, MockUpdateUser.Name);
                Assert.AreEqual(DbUser.Phone, MockUpdateUser.Phone);
                Assert.AreEqual(DbUser.State, MockUpdateUser.State);

                CdDb.Users.Remove(DbUser);
                CdDb.SaveChanges();
            }
        }
Exemplo n.º 2
0
 internal ContentService(CDSEntities DbEntities, ITokenService TokenService, AuthResponse Response, string UploadsFolder)
 {
     this.TokenService      = TokenService;
     this.CdDb              = DbEntities;
     this.AuthResult        = Response;
     this.UploadsFolderPath = UploadsFolder;
 }
Exemplo n.º 3
0
        public void CreteTest()
        {
            string Code = string.Empty;

            using (var TokenService = ServiceFinder.GetTokenService())
            {
                Code = TokenService.CreateToken(TokenType.WebAuth, 1);
            }

            var GroupService = ServiceFinder.GetGroupService(Code, TokenType.WebAuth);

            using (var CdDb = new CDSEntities())
            {
                var LastGroupId = CdDb.Groups.Max(x => x.Id);

                try
                {
                    GroupService.Create("default");
                    Assert.Fail("Exception should by raised");
                }
                catch { }

                var CreatedID = GroupService.Create("TEST" + LastGroupId);
                Assert.IsTrue(CreatedID != 0);
                Assert.IsTrue(LastGroupId < CreatedID);
            }
        }
Exemplo n.º 4
0
        public void DeleteTestFailWithUsers()
        {
            string Code = string.Empty;

            using (var TokenService = ServiceFinder.GetTokenService())
            {
                Code = TokenService.CreateToken(TokenType.WebAuth, 1);
            }

            var GroupService = ServiceFinder.GetGroupService(Code, TokenType.WebAuth);

            var CreatedId = GroupService.Create("DeleteTestGroup");

            using (var CdDb = new CDSEntities())
            {
                var User = CdDb.Users.SingleOrDefault(x => x.Id == 1);
                User.IdGroup = CreatedId;
                CdDb.SaveChanges();

                try
                {
                    GroupService.Delete(CreatedId);
                }
                catch (Exception)
                {
                    User.IdGroup = null;
                    CdDb.SaveChanges();
                    CdDb.Groups.Remove(CdDb.Groups.SingleOrDefault(x => x.Id == CreatedId));
                    CdDb.SaveChanges();
                    throw;
                }
            }
        }
Exemplo n.º 5
0
        public void UpdateTest()
        {
            int LastContentId  = 0;
            var ContentService = GetAdminService();

            using (CDSEntities CdDb = new CDSEntities())
            {
                if (CdDb.Contents.Any())
                {
                    LastContentId = CdDb.Contents.Max(x => x.Id);
                }
                FileName = FileName + LastContentId;
                var CreatedId = ContentService.CreateContent(GroupIds, IdsGenre, IdType, FileName, Description, UploadedFiles, BeginDate, EndDate, false);

                ContentService.UpdateContent(CreatedId, GroupIds, IdsGenre, FileName + "D", Description + "D", UploadedFiles, DateTime.Today, DateTime.Today.AddDays(1), true);

                var DbContent = CdDb.Contents.SingleOrDefault(x => x.Id == CreatedId);

                Assert.IsTrue(DbContent.Name == FileName + "D");
                Assert.IsTrue(DbContent.Description == Description + "D");
                Assert.IsTrue(DbContent.BeginDeliveryDate == DateTime.Today);
                Assert.IsTrue(DbContent.EndDeliveryDate == DateTime.Today.AddDays(1));
                Assert.IsTrue(DbContent.IsBroadcast == true);


                CdDb.GroupContents.RemoveRange(CdDb.GroupContents.Where(x => x.IdContent == CreatedId));
                CdDb.SaveChanges();
                DbContent.Genres.Clear();
                CdDb.Contents.Remove(CdDb.Contents.SingleOrDefault(x => x.Id == CreatedId));
                CdDb.SaveChanges();
            }
        }
Exemplo n.º 6
0
 internal UserService(CDSEntities CdDb, AuthResponse AuthResult, BatchMail SmtpHelper, IAuthServiceInternal AuthService)
 {
     this.CdDb        = CdDb;
     this.AuthService = AuthService;
     this.SmtpService = SmtpHelper;
     this.AuthResult  = AuthResult;
 }
Exemplo n.º 7
0
 internal AuthService(CDSEntities DbEntities, ITokenService TokenService)
 {
     CdDb = DbEntities;
     this.TokenService = TokenService;
     ErrorResponse     = new AuthResponse()
     {
         IsSuccess = false
     };
 }
Exemplo n.º 8
0
 internal static IContentService Create(CDSEntities DbEntities, ITokenService TokenService, AuthResponse Response, string UploadsFolder)
 {
     if (Response.IsAdmin)
     {
         return(new AdminContentService(DbEntities, TokenService, Response, UploadsFolder));
     }
     else
     {
         return(new CommonContentService(DbEntities, TokenService, Response, UploadsFolder));
     }
 }
Exemplo n.º 9
0
 public void SetUp()
 {
     tokenType = TokenType.WebAuth;
     cdDb      = new CDSEntities();
     using (var TokenService = ServiceFinder.GetTokenService())
     {
         tokenCode = TokenService.CreateToken(tokenType, 1);
     }
     genreService = ServiceFinder.GetGenreService(tokenCode, tokenType);
     testName     = "TESTENAME";
 }
Exemplo n.º 10
0
        internal GenreService(CDSEntities cdDb, IAuthService authService, string tokenCode, TokenType type)
        {
            this.authService = authService;
            var authResult = authService.GetAuthResponse(tokenCode, type);

            if (!authResult.IsSuccess || !authResult.IsAdmin)
            {
                throw new InvalidTokenException();
            }

            this.cdDb   = cdDb;
            this.genres = cdDb.Genres;
        }
Exemplo n.º 11
0
        public void DeleteTest()
        {
            var UserService = GetService();
            int CreatedId   = UserService.Create(MockAddUser, "testcom01", "");

            using (CDSEntities CdDb = new CDSEntities())
            {
                var DbUser = CdDb.Users.SingleOrDefault(x => x.Id == CreatedId);
                Assert.IsNotNull(DbUser);

                UserService.Delete(CreatedId);
                Assert.IsFalse(CdDb.Users.Any(x => x.Id == CreatedId));
            }
        }
Exemplo n.º 12
0
        public void CreateTest()
        {
            var UserService = GetService();
            int CreatedId   = UserService.Create(MockAddUser, mockPwd, "");

            using (CDSEntities CdDb = new CDSEntities())
            {
                var DbUser = CdDb.Users.SingleOrDefault(x => x.Id == CreatedId);
                Assert.IsNotNull(DbUser);
                Assert.IsTrue(DbUser.IdType != 1);
                CdDb.Users.Remove(DbUser);
                CdDb.SaveChanges();
            }
        }
Exemplo n.º 13
0
        public void GetAdminContents()
        {
            var ContentService = GetAdminService();
            var UserContents   = ContentService.GetContents("");

            using (CDSEntities CdDb = new CDSEntities())
            {
                var DbUserContents = CdDb.Contents.Where(x => x.BeginDeliveryDate <DateTime.Now &&
                                                                                   x.EndDeliveryDate> DateTime.Now);

                Assert.IsTrue(UserContents.Count == DbUserContents.Count());
                Assert.IsFalse(UserContents.Any(x => string.IsNullOrEmpty(x.DownloadLink)));
            }
        }
Exemplo n.º 14
0
 public void CreateTokenTest()
 {
     using (var TokenService = ServiceFinder.GetTokenService())
     {
         int IdResource = 1;
         var Code       = TokenService.CreateToken(MockType, IdResource);
         Assert.IsTrue(Code.Length == 32);
         var TokenTypeId = TokenService.GetTokenTypeId(MockType);
         using (var CdDb = new CDSEntities())
         {
             var Count = CdDb.Tokens.Count(x => x.IdUser == IdResource &&
                                           x.IdType == TokenTypeId);
             Assert.IsTrue(Count == 1);
         }
     }
 }
Exemplo n.º 15
0
        public void GetCommunContents()
        {
            var ContentService = GetCommonService();
            var UserContents   = ContentService.GetContents("");

            using (CDSEntities CdDb = new CDSEntities())
            {
                var User           = CdDb.Users.First(x => x.IdType == 2);
                var DbUserContents = CdDb.GroupContents.Where(x => x.IdGroup == User.IdGroup &&
                                                              x.Contents.BeginDeliveryDate <DateTime.Now &&
                                                                                            x.Contents.EndDeliveryDate> DateTime.Now).Select(x => x.Contents).ToList();
                DbUserContents.AddRange(CdDb.Contents.Where(x => x.IsBroadcast &&
                                                            x.BeginDeliveryDate <DateTime.Now && x.EndDeliveryDate> DateTime.Now));
                Assert.IsTrue(UserContents.Count == DbUserContents.Count());
                Assert.IsFalse(UserContents.Any(x => string.IsNullOrEmpty(x.DownloadLink)));
            }
        }
Exemplo n.º 16
0
        private IContentService GetCommonService()
        {
            int Id = 0;

            using (CDSEntities db = new CDSEntities()){
                Id = db.Users.First(x => x.IdType == 2).Id;
            }
            string CodeCommon = string.Empty;

            using (var TokenService = ServiceFinder.GetTokenService())
            {
                CodeCommon = TokenService.CreateToken(TokenType.WebAuth, Id);
            }
            var ContentService = ServiceFinder.GetContentService(CodeCommon, TokenType.WebAuth, BaseUploadPath);

            return(ContentService);
        }
Exemplo n.º 17
0
        public void DeleteTest()
        {
            string Code = string.Empty;

            using (var TokenService = ServiceFinder.GetTokenService())
            {
                Code = TokenService.CreateToken(TokenType.WebAuth, 1);
            }

            var GroupService = ServiceFinder.GetGroupService(Code, TokenType.WebAuth);

            var CreatedId = GroupService.Create("DeleteTestGroup");

            using (var CdDb = new CDSEntities())
            {
                Assert.IsTrue(GroupService.Delete(CreatedId));
                Assert.IsFalse(CdDb.Groups.Any(x => x.Id == CreatedId));
            }
        }
Exemplo n.º 18
0
        public void CreateTest()
        {
            int LastContentId  = 0;
            var ContentService = GetAdminService();

            using (CDSEntities CdDb = new CDSEntities())
            {
                if (CdDb.Contents.Any())
                {
                    LastContentId = CdDb.Contents.Max(x => x.Id);
                }
                FileName = FileName + LastContentId;


                var CreatedId = ContentService.CreateContent(GroupIds, IdsGenre, IdType, FileName, Description, UploadedFiles, BeginDate, EndDate, false, null);
                Assert.IsTrue(CreatedId > LastContentId);
                Assert.IsTrue(CreatedId > 1);
                Assert.IsTrue(CdDb.GroupContents.Count(x => x.IdContent == CreatedId) == GroupIds.Count());

                var ResultFileName = CdDb.Contents.SingleOrDefault(x => x.Id == CreatedId).FileName;
                Assert.IsTrue(File.Exists(BaseUploadPath + ResultFileName));
            }
        }
Exemplo n.º 19
0
        public int Create(Users User, string Password, string ActivateUrl)
        {
            //VerifyToken();

            if (!Validate(User))
            {
                return(0);
            }
            User.IdType = 2;
            using (var CdDb = new CDSEntities())
            {
                var Group = CdDb.Groups.SingleOrDefault(x => x.Id == User.IdGroup);

                if (Group == null)
                {
                    throw new ArgumentException("Invalid Id group");
                }
                if (!Group.Active)
                {
                    throw new ArgumentException("Id must be of a active group");
                }

                User.Password  = AuthService.CreateEncryptedPassword(Password);
                User.Active    = true;
                User.CreatedAt = DateTime.Now;
                CdDb.Users.Add(User);
                CdDb.SaveChanges();

                try
                {
                    SendActiveAccountEmail(User.Name, User.Email, User.Id, ActivateUrl);
                }
                catch { }

                return(User.Id);
            }
        }
Exemplo n.º 20
0
        public void UpdateTest()
        {
            string Code = string.Empty;

            using (var TokenService = ServiceFinder.GetTokenService())
            {
                Code = TokenService.CreateToken(TokenType.WebAuth, 1);
            }

            var GroupService = ServiceFinder.GetGroupService(Code, TokenType.WebAuth);
            var NewName      = "testname";
            var TestActive   = false;
            var TestId       = 1;

            GroupService.Update(TestId, NewName, TestActive);

            using (CDSEntities CdDb = new CDSEntities())
            {
                var DefaultGroup = CdDb.Groups.SingleOrDefault(x => x.Id == TestId);
                Assert.IsTrue(DefaultGroup.Name == NewName);
                Assert.IsTrue(DefaultGroup.Active == TestActive);
            }
            GroupService.Update(TestId, "default", true);
        }
Exemplo n.º 21
0
        public void DeleteTestFailWithContents()
        {
            string Code = string.Empty;

            using (var TokenService = ServiceFinder.GetTokenService())
            {
                Code = TokenService.CreateToken(TokenType.WebAuth, 1);
            }

            var GroupService = ServiceFinder.GetGroupService(Code, TokenType.WebAuth);

            var CreatedId = GroupService.Create("DeleteTestGroup");

            using (var CdDb = new CDSEntities())
            {
                CdDb.GroupContents.Add(new GroupContents()
                {
                    IdContent = 24,
                    IdGroup   = CreatedId,
                    CreatedAt = DateTime.Now
                });
                CdDb.SaveChanges();
                try
                {
                    GroupService.Delete(CreatedId);
                }
                catch (Exception)
                {
                    CdDb.GroupContents.RemoveRange(CdDb.GroupContents.Where(x => x.IdGroup == CreatedId));
                    CdDb.SaveChanges();
                    CdDb.Groups.Remove(CdDb.Groups.SingleOrDefault(x => x.Id == CreatedId));
                    CdDb.SaveChanges();
                    throw;
                }
            }
        }
Exemplo n.º 22
0
 internal GroupService(CDSEntities DbEntities, IAuthService AuthService, string Token, TokenType tokenType)
 {
     CdDb             = DbEntities;
     this.AuthService = AuthService;
     this.AuthResult  = AuthService.GetAuthResponse(Token, tokenType);
 }
Exemplo n.º 23
0
 internal CommonContentService(CDSEntities DbEntities, ITokenService TokenService, AuthResponse Response, string UploadsFolder) :
     base(DbEntities, TokenService, Response, UploadsFolder)
 {
 }
Exemplo n.º 24
0
 public TokenService(CDSEntities DbEntities)
 {
     CdDb = DbEntities;
 }