Ejemplo n.º 1
0
        public ActionResult Edit(long id)
        {
            var model = TreeService.Get(id);

            ConvertViewModel(model);
            return(View(model));
        }
Ejemplo n.º 2
0
        public ActionResult TreeLabel(long id)
        {
            var tree = TreeService.Get(id);
            var data = TreeTagPainter.Paint(tree, HttpContext.Request.Url.Host);

            return(File(data, "image/jpeg"));
        }
Ejemplo n.º 3
0
        public ActionResult View(long id)
        {
            var tree = TreeService.Get(id);

            tree = ConvertViewModel(tree);
            return(View(tree));
        }
Ejemplo n.º 4
0
 public override int Run(string[] remainingArguments)
 {
     try
     {
         var service = TreeService.Get <int>();
         Console.WriteLine();
         Console.WriteLine($"Reading a tree from '{FileName}");
         using (var stream = File.OpenRead(FileName))
         {
             Helpers.ShowTree(service.Load(stream));
         }
         return(0);
     }
     catch
     {
         return(1);
     }
 }
Ejemplo n.º 5
0
        public ActionResult DownloadLabel(string ids)
        {
            var          id     = ids.Split(',').Select(c => long.Parse(c));
            MemoryStream memory = new MemoryStream();

            using (var output = new ZipOutputStream(memory))
            {
                foreach (var i in id)
                {
                    var tree = TreeService.Get(i);
                    var data = TreeTagPainter.Paint(tree, HttpContext.Request.Url.Host);

                    ZipEntry entry = new ZipEntry(tree.Name + "-" + tree.ID + ".png");
                    entry.DateTime = DateTime.Now;
                    output.PutNextEntry(entry);
                    output.Write(data, 0, data.Length);
                }
                output.Finish();
                output.Close();
            }

            return(File(memory.ToArray(), "application/x-zip-compressed", "tree-label.zip"));
        }
Ejemplo n.º 6
0
 public IEnumerable <Tree> RetrieveAll()
 {
     return(_service.Get());
 }
Ejemplo n.º 7
0
 public void Setup()
 {
     Service = TreeService.Get <int>();
 }
Ejemplo n.º 8
0
 public ActionResult <List <Tree> > Get() =>
 _treeService.Get();
        public void TreeService_Get_ByPage_Overload_Returns_PagedList_Of_Trees()
        {
            //Arrange
            var mockRepository = new Mock<IRepository<Tree>>();
            mockRepository.Setup(r => r.GetAll()).Returns(GetTrees(TestConstants.PAGE_TotalCount));
            _mockUnitOfWork.Setup(d => d.GetRepository<Tree>()).Returns(mockRepository.Object);

            _service = new TreeService(_mockUnitOfWork.Object);

            //Act
            var trees = _service.Get(t => true, 0, TestConstants.PAGE_RecordCount);

            //Assert
            Assert.IsInstanceOf<IPagedList<Tree>>(trees);
            Assert.AreEqual(TestConstants.PAGE_TotalCount, trees.TotalCount);
            Assert.AreEqual(TestConstants.PAGE_RecordCount, trees.PageSize);
        }
        public void TreeService_Get_ByPage_Overload_Calls_Repository_GetAll()
        {
            //Arrange
            var mockRepository = new Mock<IRepository<Tree>>();
            _mockUnitOfWork.Setup(d => d.GetRepository<Tree>()).Returns(mockRepository.Object);

            _service = new TreeService(_mockUnitOfWork.Object);

            //Act
            _service.Get(t => true, 0, 5);

            //Assert
            mockRepository.Verify(r => r.GetAll());
        }
        public void TreeService_Get_Returns_Null_On_InValid_Id()
        {
            //Arrange
            var mockRepository = new Mock<IRepository<Tree>>();
            mockRepository.Setup(r => r.GetAll()).Returns(GetTrees(TestConstants.PAGE_TotalCount));
            _mockUnitOfWork.Setup(d => d.GetRepository<Tree>()).Returns(mockRepository.Object);

            _service = new TreeService(_mockUnitOfWork.Object);
            const int id = TestConstants.ID_NotFound;

            //Act
            var tree = _service.Get(id);

            //Assert
            Assert.IsNull(tree);
        }
        public void TreeService_Get_Calls_Repository_GetAll()
        {
            //Arrange
            var mockRepository = new Mock<IRepository<Tree>>();
            mockRepository.Setup(r => r.GetAll()).Returns(GetTrees(TestConstants.PAGE_TotalCount));
            _mockUnitOfWork.Setup(d => d.GetRepository<Tree>()).Returns(mockRepository.Object);

            _service = new TreeService(_mockUnitOfWork.Object);
            const int id = TestConstants.ID_Exists;

            //Act
            _service.Get(id);

            //Assert
            mockRepository.Verify(r => r.GetAll());
        }
        public void TreeService_Get_Throws_On_Negative_Id()
        {
            //Arrange
            _service = new TreeService(_mockUnitOfWork.Object);

            //Assert
            Assert.Throws<IndexOutOfRangeException>(() => _service.Get(-1));
        }