public void ANoteWithAnEmptyContentIsInvalid()
        {
            // Arrange
            var user = new User() { PartitionKey = "windowsliveid", RowKey = "user.test-windowsliveid" };
            var taskList = new TaskList("Test title", user) { PartitionKey = "user.test-windowsliveid", RowKey = ShortGuid.NewGuid().ToString() };
            const string validTitle = "Test title";
            string invalidContent = string.Empty;
            var note = new Note(validTitle, invalidContent, user, taskList) { PartitionKey = taskList.RowKey, RowKey = ShortGuid.NewGuid().ToString() };

            // Act
            var validationResult = note.IsValid();

            // Assert
            Assert.IsFalse(validationResult);
        }
        public void ANoteWithAllValidPropertiesIsValid()
        {
            // Arrange
            var user = new User() { PartitionKey = "windowsliveid", RowKey = "user.test-windowsliveid" };
            var taskList = new TaskList("Test title", user) { PartitionKey = "user.test-windowsliveid", RowKey = ShortGuid.NewGuid().ToString() };
            const string validTitle = "Test title";
            const string validContent = "Test content";
            var note = new Note(validTitle, validContent, user, taskList) { PartitionKey = taskList.RowKey, RowKey = ShortGuid.NewGuid().ToString() };

            // Act
            var validationResult = note.IsValid();

            // Assert
            Assert.IsTrue(validationResult);
        }
        public void ANoteWithANullContainerListIsInvalid()
        {
            // Arrange
            var user = new User() { PartitionKey = "windowsliveid", RowKey = "user.test-windowsliveid" };
            const string validTitle = "Test title";
            const string validContent = "Test content";
            var note = new Note(validTitle, validContent, user, null) { PartitionKey = string.Empty, RowKey = Guid.NewGuid().ToString() };

            // Act
            var validationResult = note.IsValid();

            // Assert
            Assert.IsFalse(validationResult);
        }
        public void ANoteWithATittleLongerThan10CharactersIsInvalid()
        {
            // Arrange
            var user = new User() { PartitionKey = "windowsliveid", RowKey = "user.test-windowsliveid" };
            var taskList = new TaskList("Test title", user) { PartitionKey = "user.test-windowsliveid", RowKey = ShortGuid.NewGuid().ToString() };
            const string invalidTitle = "A very long invalid title";
            const string validContent = "Test content";
            var note = new Note(invalidTitle, validContent, user, taskList) { PartitionKey = taskList.RowKey, RowKey = ShortGuid.NewGuid().ToString() };

            // Act
            var validationResult = note.IsValid();

            // Assert
            Assert.IsFalse(validationResult);
        }
        public ActionResult CreatePost(string taskListOwnerId, string taskListId)
        {
            var currentUser = (User) Session["CurrentUser"];
            var container = _taskListsService.Get(t => t.PartitionKey == taskListOwnerId && t.RowKey == taskListId);
            var note = new Note { Owner = currentUser, Container = container };

            // Only a user in the note's containing tasklist share list can create a new note.
            if (!_taskListsService.HasPermissionToEdit(currentUser, container))
            {
                return View("Info", "_Layout", string.Format("The user '{0}' doesn't have permission to create a note in the tasklist '{1}'.", currentUser.Name, container.Title));
            }

            try
            {
                TryUpdateModel(note);

                // Check if a note with the same title already exists.
                var noteWithSameTitleExists = _notesService.NoteWithTitleExists(note.Title, container);

                if (noteWithSameTitleExists)
                {
                    ViewBag.ValidationErrors = new List<ValidationResult> { new ValidationResult(string.Format("The note with the title '{0}' already exists.", note.Title)) };
                    return View(note);
                }

                if (note.IsValid())
                {
                    _notesService.Create(note);
                    return RedirectToAction("Index", new { taskListOwnerId = container.PartitionKey, taskListId = container.RowKey });
                }
                else
                {
                    ViewBag.ValidationErrors = note.GetValidationErrors();
                }
            }
            catch (Exception ex)
            {
                ViewBag.ValidationErrors = new List<ValidationResult> { new ValidationResult(string.Format("Create Note exception: {0}", ex.Message)) };
            }

            return View(note);
        }