Esempio n. 1
0
 public FolderManagement.Models.Folder Add(FolderManagement.Models.Folder folder)
 {
     //Guid guid = Guid.NewGuid();
     //Random random = new Random();
     //folder.FolderId = BitConverter.ToInt32(Guid.NewGuid().ToByteArray(), 0);
     folder.FolderId = Interlocked.Increment(ref nextId);
     _folders.Add(folder);
     return(folder);
 }
        public void Add_InvalidObjectPassed_ReturnBadRequest()
        {
            //Arrange
            var nameMissingFolder = new FolderManagement.Models.Folder()
            {
                ParentFolderId = null
            };

            _controller.ModelState.AddModelError("Name", "Required");

            //Act
            var badResponse = _controller.Create(nameMissingFolder);

            //Assert
            Assert.IsType <ViewResult>(badResponse);
        }
        public void Add_ValidObjectPassed_ReturnsCreatedResponseRedirected()
        {
            //Arrange
            FolderManagement.Models.Folder testFolder = new FolderManagement.Models.Folder()
            {
                ParentFolderId = 1,
                Name           = "TestFolder"
            };

            //Act
            var createdResponse = _controller.Create(testFolder);
            IEnumerable <FolderManagement.Models.Folder> totalFolders = _service.GetAllFolders();

            //Assert
            Assert.IsType <RedirectToActionResult>(createdResponse);
            Assert.Equal(6, totalFolders.Count());
        }