public void AddTwoComments() { var profile = (ProfileDTO)profiles[0].Tag; var profile1 = (ProfileDTO)profiles[1].Tag; SessionData data = CreateNewSession(profile, ClientInformation); TrainingDayDTO day = new TrainingDayDTO(DateTime.Now); day.ProfileId = profile.GlobalId; BlogEntryDTO blogEntry = new BlogEntryDTO(); blogEntry.Comment = "jakis tekst"; day.AllowComments = true; day.AddEntry(blogEntry); SaveTrainingDayResult result = null; RunServiceMethod(delegate(InternalBodyArchitectService Service) { result = Service.SaveTrainingDay(data.Token, day); day = result.TrainingDay; }); TrainingDayCommentDTO comment = new TrainingDayCommentDTO(); comment.Profile = profile; comment.Comment = "msg"; DateTime time = DateTime.UtcNow; RunServiceMethod(delegate(InternalBodyArchitectService Service) { TimerService.UtcNow = time; TrainingDayCommentOperationParam arg = new TrainingDayCommentOperationParam(); arg.TrainingDayId = day.GlobalId; arg.Comment = comment; arg.OperationType = TrainingDayOperationType.Add; Service.TrainingDayCommentOperation(data.Token, arg); }); data = CreateNewSession(profile1, ClientInformation); comment = new TrainingDayCommentDTO(); comment.Profile = profile1; comment.Comment = "msg1"; time = DateTime.UtcNow.AddHours(2); RunServiceMethod(delegate(InternalBodyArchitectService Service) { TimerService.UtcNow = time; TrainingDayCommentOperationParam arg = new TrainingDayCommentOperationParam(); arg.TrainingDayId = day.GlobalId; arg.Comment = comment; arg.OperationType = TrainingDayOperationType.Add; Service.TrainingDayCommentOperation(data.Token, arg); }); var dbDay = Session.QueryOver <TrainingDay>().SingleOrDefault(); Assert.IsNotNull(dbDay); Assert.AreEqual(2, dbDay.CommentsCount); Assert.IsTrue(dbDay.LastCommentDate.Value.CompareDateTime(time)); }
string getBlogMessage(BlogEntryDTO blog) { StringBuilder builder = new StringBuilder(); builder.AppendLine("FINISH"); return(builder.ToString()); }
public async Task BlogEntriesApi_Post_ReturnBlogEntryDTO() { // Arrange var blogEntryDTO = new BlogEntryDTO() { Id = 0, Title = "Title", Content = "Content", EntryUpdates = new List <BlogEntryUpdateDTO>(), Status = BlogEntryStatus.Public, CreationDate = DateTime.MinValue, LastUpdated = DateTime.MinValue, Deleted = false, Blog = new BlogDTO() { Id = 1, Name = "Test blog", CreationDate = DateTime.Now, Entries = null, Deleted = false, Owner = null } }; string stringData = JsonConvert.SerializeObject(blogEntryDTO); var contentData = new StringContent(stringData, Encoding.UTF8, "application/json"); //Act var response = await client.PostAsync("api/blogentries/", contentData); // Assert response.EnsureSuccessStatusCode(); response.StatusCode.Should().Be(HttpStatusCode.OK); var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false); var blogs = JsonConvert.DeserializeObject <BlogEntryDTO>(responseContent); blogs.Should().BeAssignableTo <BlogEntryDTO>(); }
public async Task <IActionResult> Post([CustomizeValidator(RuleSet = "BlogEntryAddOrUpdate")] BlogEntryDTO blogEntryDTO) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var blog = await blogService.GetAsync(blogEntryDTO.Blog.Id); if (blog.OwnerId != LoggedInUserId) { return(StatusCode((int)HttpStatusCode.Forbidden, "The user is not the owner of the blog.")); } var blogEntry = mapper.Map <BlogEntry>(blogEntryDTO); blogEntry = await blogEntryService.AddOrUpdateAsync(blogEntry); blogEntryDTO = mapper.Map <BlogEntryDTO>(blogEntry); } catch { throw new BlogSystemException("There's been an error while trying to add the blog entry"); } return(Ok(blogEntryDTO)); }
public static PagedResult <BlogCommentDTO> GetBlogComments(BlogEntryDTO entry, PartialRetrievingInfo info) { return(exceptionHandling(delegate { info.PageSize = GetPageSize(info.PageSize); return Instance.GetBlogComments(Token, entry, info); })); }
public async Task Put_WhenException_ThrowsBlogSystemException() { // Arrange var blogEntryDTO = new BlogEntryDTO() { Id = 1, Title = "Title", Content = "Content", EntryUpdates = new List <BlogEntryUpdateDTO>(), Status = BlogEntryStatus.Public, CreationDate = DateTime.Now, LastUpdated = DateTime.Now, Deleted = false, Blog = new BlogDTO() { Id = 1, Name = "Test blog", CreationDate = DateTime.Now, Entries = null, Deleted = false, Owner = null } }; var blogEntry = new BlogEntry() { Id = 1, Title = "Title", Content = "Content", EntryUpdates = new List <BlogEntryUpdate>(), Status = BlogEntryStatus.Public, CreationDate = blogEntryDTO.CreationDate, LastUpdated = blogEntryDTO.LastUpdated, Deleted = false, BlogId = 1, Blog = new Blog() { Id = 1, Name = "Test blog", CreationDate = DateTime.Now, Entries = null, Deleted = false, OwnerId = 1, Owner = null } }; blogEntryServiceMock .Setup(m => m.GetAsync(It.IsAny <int>(), It.IsAny <Expression <Func <BlogEntry, object> > >())) .ReturnsAsync(blogEntry); blogEntryServiceMock .Setup(m => m.AddOrUpdateAsync(It.IsAny <BlogEntry>())) .Throws <Exception>(); var controller = GetController(mapper); controller.ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext { User = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.Name, "jdoe"), new Claim(ClaimTypes.Sid, "1") }, "jwt")) } }; var message = "There's been an error while trying to add the blog entry"; // Act var exception = await Record.ExceptionAsync(() => controller.Put(1, blogEntryDTO)); // Assert Assert.NotNull(exception); Assert.IsType <BlogSystemException>(exception); Assert.Equal(message, exception.Message); blogEntryServiceMock.Verify(m => m.GetAsync(It.IsAny <int>(), It.IsAny <Expression <Func <BlogEntry, object> > >()), Times.Once); blogEntryServiceMock.Verify(m => m.AddOrUpdateAsync(It.IsAny <BlogEntry>()), Times.Once); }
public async Task Put_WhenUserNotOwner_ReturnsForbidden() { // Arrange var blogEntryDTO = new BlogEntryDTO() { Id = 1, Title = "Title", Content = "Content", EntryUpdates = new List <BlogEntryUpdateDTO>(), Status = BlogEntryStatus.Public, CreationDate = DateTime.Now, LastUpdated = DateTime.Now, Deleted = false, Blog = new BlogDTO() { Id = 1, Name = "Test blog", CreationDate = DateTime.Now, Entries = null, Deleted = false, Owner = null } }; var blogEntry = new BlogEntry() { Id = 1, Title = "Title", Content = "Content", EntryUpdates = new List <BlogEntryUpdate>(), Status = BlogEntryStatus.Public, CreationDate = blogEntryDTO.CreationDate, LastUpdated = blogEntryDTO.LastUpdated, Deleted = false, BlogId = 1, Blog = new Blog() { Id = 1, Name = "Test blog", CreationDate = DateTime.Now, Entries = null, Deleted = false, OwnerId = 1, Owner = null } }; blogEntryServiceMock .Setup(m => m.GetAsync(It.IsAny <int>(), It.IsAny <Expression <Func <BlogEntry, object> > >())) .ReturnsAsync(blogEntry); blogEntryServiceMock .Setup(m => m.AddOrUpdateAsync(It.IsAny <BlogEntry>())) .ReturnsAsync(blogEntry); var controller = GetController(mapper); controller.ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext { User = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.Name, "jdoe"), new Claim(ClaimTypes.Sid, "2") }, "jwt")) } }; // Act var result = await controller.Put(1, blogEntryDTO); // Assert Assert.NotNull(result); var forbidResult = Assert.IsType <ObjectResult>(result); Assert.Equal(403, forbidResult.StatusCode); blogEntryServiceMock.Verify(m => m.GetAsync(It.IsAny <int>(), It.IsAny <Expression <Func <BlogEntry, object> > >()), Times.Once); blogEntryServiceMock.Verify(m => m.AddOrUpdateAsync(It.IsAny <BlogEntry>()), Times.Never); }
public void Fill(BlogEntryDTO blogEntry) { this.blogEntry = blogEntry; if (blogEntry == null || blogEntry.Id == Constants.UnsavedObjectId) { return; } blogCommentsList1.Fill(blogEntry); }
public void Fill(EntryObjectDTO entry) { filling = true; usrHtmlEditor1.ClearContent(); blogEntry = (BlogEntryDTO)entry; usrBlogComments1.Fill(blogEntry); usrHtmlEditor1.SetHtml(blogEntry.Comment); cmbAllowComments.SelectedIndex = blogEntry.AllowComments ? 0 : 1; updateReadOnly(); filling = false; }
public void AddComment_SetLoginData() { var profile = (ProfileDTO)profiles[0].Tag; var profile1 = (ProfileDTO)profiles[1].Tag; SessionData data = CreateNewSession(profile, ClientInformation); TrainingDayDTO day = new TrainingDayDTO(DateTime.Now); day.ProfileId = profile.GlobalId; BlogEntryDTO blogEntry = new BlogEntryDTO(); blogEntry.Comment = "jakis tekst"; day.AllowComments = true; day.AddEntry(blogEntry); SaveTrainingDayResult result = null; RunServiceMethod(delegate(InternalBodyArchitectService Service) { result = Service.SaveTrainingDay(data.Token, day); day = result.TrainingDay; }); LoginData loginData = new LoginData(); loginData.ApiKey = apiKey; loginData.ApplicationVersion = "1.0.0"; loginData.LoginDateTime = DateTime.UtcNow; loginData.ApplicationLanguage = "en"; loginData.PlatformVersion = "NUnit"; insertToDatabase(loginData); data = CreateNewSession(profile1, ClientInformation, loginData); TrainingDayCommentDTO comment = new TrainingDayCommentDTO(); comment.Profile = profile1; comment.Comment = "msg"; DateTime time = DateTime.UtcNow; RunServiceMethod(delegate(InternalBodyArchitectService Service) { TimerService.UtcNow = time; TrainingDayCommentOperationParam arg = new TrainingDayCommentOperationParam(); arg.TrainingDayId = day.GlobalId; arg.Comment = comment; arg.OperationType = TrainingDayOperationType.Add; Service.TrainingDayCommentOperation(data.Token, arg); }); var dbDay = Session.QueryOver <TrainingDay>().SingleOrDefault(); Assert.AreEqual(loginData.ApiKey.ApiKey, dbDay.Comments.First().LoginData.ApiKey.ApiKey); }
public void AddComment_SendEMailAndMessage() { var profile = (ProfileDTO)profiles[0].Tag; var profile1 = (ProfileDTO)profiles[1].Tag; profiles[0].Settings.NotificationBlogCommentAdded = ProfileNotification.Message | ProfileNotification.Email; insertToDatabase(profiles[0]); SessionData data = CreateNewSession(profile, ClientInformation); TrainingDayDTO day = new TrainingDayDTO(DateTime.Now); day.ProfileId = profile.GlobalId; BlogEntryDTO blogEntry = new BlogEntryDTO(); blogEntry.Comment = "jakis tekst"; day.AllowComments = true; day.AddEntry(blogEntry); SaveTrainingDayResult result = null; RunServiceMethod(delegate(InternalBodyArchitectService Service) { result = Service.SaveTrainingDay(data.Token, day); day = result.TrainingDay; }); data = CreateNewSession(profile1, ClientInformation); TrainingDayCommentDTO comment = new TrainingDayCommentDTO(); comment.Profile = profile1; comment.Comment = "msg"; DateTime time = DateTime.UtcNow; RunServiceMethod(delegate(InternalBodyArchitectService Service) { TimerService.UtcNow = time; TrainingDayCommentOperationParam arg = new TrainingDayCommentOperationParam(); arg.TrainingDayId = day.GlobalId; arg.Comment = comment; arg.OperationType = TrainingDayOperationType.Add; Service.TrainingDayCommentOperation(data.Token, arg); Assert.True(((MockEmailService)Service.EMailService).EMailSent); }); var messages = Session.QueryOver <Message>().Where(x => x.Receiver == profiles[0]).SingleOrDefault(); Assert.IsNotNull(messages); Assert.IsNotNull(messages.Content); Assert.AreEqual(MessagePriority.System, messages.Priority); }
public Color GetBackColor(IEnumerable <EntryObjectDTO> entryObjects) { BlogEntryDTO blog = (BlogEntryDTO)entryObjects.Single(); DateTime lastVisit = BlogSettings.Default.GetVisitDate(blog.TrainingDay.TrainingDate, UserContext.CurrentProfile.Id, blog.TrainingDay.ProfileId); if (blog.LastCommentDate.HasValue && lastVisit < blog.LastCommentDate) { return(Color.DarkOrange); } else { return(Color.DarkKhaki); } }
public void AddComment_AnotherProfile() { var profile = (ProfileDTO)profiles[0].Tag; var profile1 = (ProfileDTO)profiles[1].Tag; SessionData data = CreateNewSession(profile, ClientInformation); TrainingDayDTO day = new TrainingDayDTO(DateTime.Now); day.ProfileId = profile.GlobalId; BlogEntryDTO blogEntry = new BlogEntryDTO(); blogEntry.Comment = "jakis tekst"; day.AllowComments = true; day.AddEntry(blogEntry); SaveTrainingDayResult result = null; RunServiceMethod(delegate(InternalBodyArchitectService Service) { result = Service.SaveTrainingDay(data.Token, day); day = result.TrainingDay; }); data = CreateNewSession(profile1, ClientInformation); TrainingDayCommentDTO comment = new TrainingDayCommentDTO(); comment.Profile = profile; comment.Comment = "msg"; DateTime time = DateTime.UtcNow; RunServiceMethod(delegate(InternalBodyArchitectService Service) { TimerService.UtcNow = time; TrainingDayCommentOperationParam arg = new TrainingDayCommentOperationParam(); arg.TrainingDayId = day.GlobalId; arg.Comment = comment; arg.OperationType = TrainingDayOperationType.Add; Service.TrainingDayCommentOperation(data.Token, arg); }); }
public async Task BlogEntriesApi_Post_BadParameters_ReturnBadRequest() { // Arrange var blogEntryDTO = new BlogEntryDTO() { Id = 0, Title = "", Content = "", EntryUpdates = new List <BlogEntryUpdateDTO>(), Status = BlogEntryStatus.Public, CreationDate = DateTime.MinValue, LastUpdated = DateTime.MinValue, Deleted = false, Blog = new BlogDTO() { Id = 1, Name = "Test blog", CreationDate = DateTime.Now, Entries = null, Deleted = false, Owner = null } }; string stringData = JsonConvert.SerializeObject(blogEntryDTO); var contentData = new StringContent(stringData, Encoding.UTF8, "application/json"); //Act var response = await client.PostAsync("api/blogentries/", contentData); // Assert response.StatusCode.Should().Be(HttpStatusCode.BadRequest); }
public void Fill(BlogEntryDTO entry) { this.entry = entry; fillPage(0); }
public PagedResult <BlogCommentDTO> GetBlogComments(Token token, BlogEntryDTO entry, PartialRetrievingInfo info) { throw new NotImplementedException(); }
public BlogViewModel(BlogEntryDTO blogEntryDTO) { this.entry = blogEntryDTO; }
public async Task Post_WhenSuccessful_ReturnsBlogEntryDTO() { // Arrange var blogEntryDTO = new BlogEntryDTO() { Id = 0, Title = "Title", Content = "Content", EntryUpdates = new List <BlogEntryUpdateDTO>(), Status = BlogEntryStatus.Public, CreationDate = DateTime.MinValue, LastUpdated = DateTime.MinValue, Deleted = false, Blog = new BlogDTO() { Id = 1, Name = "Test blog", CreationDate = DateTime.Now, Entries = null, Deleted = false, Owner = null } }; var blogEntry = new BlogEntry() { Id = 1, Title = "Title", Content = "Content", EntryUpdates = new List <BlogEntryUpdate>(), Status = BlogEntryStatus.Public, CreationDate = DateTime.Now, LastUpdated = DateTime.Now, Deleted = false, BlogId = 1 }; blogServiceMock .Setup(m => m.GetAsync(It.IsAny <int>())) .ReturnsAsync(new Blog() { Id = 1, Name = "Test blog", CreationDate = DateTime.Now, Entries = null, Deleted = false, OwnerId = 1, Owner = null }); blogEntryServiceMock .Setup(m => m.AddOrUpdateAsync(It.IsAny <BlogEntry>())) .ReturnsAsync(blogEntry); var controller = GetController(mapper); controller.ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext { User = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.Name, "jdoe"), new Claim(ClaimTypes.Sid, "1") }, "jwt")) } }; // Act var result = await controller.Post(blogEntryDTO); // Assert Assert.NotNull(result); var okResult = Assert.IsType <OkObjectResult>(result); var returnBlogEntry = Assert.IsAssignableFrom <BlogEntryDTO>(okResult.Value); Assert.NotEqual(blogEntryDTO.Id, returnBlogEntry.Id); Assert.Equal(blogEntryDTO.Title, returnBlogEntry.Title); Assert.Equal(blogEntryDTO.Content, returnBlogEntry.Content); Assert.NotEqual(blogEntryDTO.CreationDate, returnBlogEntry.CreationDate); Assert.NotEqual(blogEntryDTO.LastUpdated, returnBlogEntry.LastUpdated); Assert.Equal(blogEntryDTO.Status, returnBlogEntry.Status); Assert.Equal(blogEntryDTO.Deleted, returnBlogEntry.Deleted); blogServiceMock.Verify(m => m.GetAsync(It.IsAny <int>()), Times.Once); blogEntryServiceMock.Verify(m => m.AddOrUpdateAsync(It.IsAny <BlogEntry>()), Times.Once); }
public Task <bool> Save(BlogEntryDTO blogEntry) { throw new NotImplementedException(); }