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(); } }
internal ContentService(CDSEntities DbEntities, ITokenService TokenService, AuthResponse Response, string UploadsFolder) { this.TokenService = TokenService; this.CdDb = DbEntities; this.AuthResult = Response; this.UploadsFolderPath = UploadsFolder; }
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); } }
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; } } }
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(); } }
internal UserService(CDSEntities CdDb, AuthResponse AuthResult, BatchMail SmtpHelper, IAuthServiceInternal AuthService) { this.CdDb = CdDb; this.AuthService = AuthService; this.SmtpService = SmtpHelper; this.AuthResult = AuthResult; }
internal AuthService(CDSEntities DbEntities, ITokenService TokenService) { CdDb = DbEntities; this.TokenService = TokenService; ErrorResponse = new AuthResponse() { IsSuccess = false }; }
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)); } }
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"; }
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; }
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)); } }
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(); } }
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))); } }
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); } } }
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))); } }
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); }
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)); } }
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)); } }
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); } }
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); }
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; } } }
internal GroupService(CDSEntities DbEntities, IAuthService AuthService, string Token, TokenType tokenType) { CdDb = DbEntities; this.AuthService = AuthService; this.AuthResult = AuthService.GetAuthResponse(Token, tokenType); }
internal CommonContentService(CDSEntities DbEntities, ITokenService TokenService, AuthResponse Response, string UploadsFolder) : base(DbEntities, TokenService, Response, UploadsFolder) { }
public TokenService(CDSEntities DbEntities) { CdDb = DbEntities; }