Example #1
0
        public void GenerateReturnsErrorIfReadAllImageFilesReturnsError()
        {
            var id    = ObjectId.GenerateNewId().ToString();
            var model = new GenerateMosaicModel();

            var projectResponse = new ProjectResponse()
            {
                Project = new ProjectStructure()
                {
                    Id = id, LargeFileId = ObjectId.GenerateNewId().ToString()
                }
            };

            projectResponse.Project.SmallFileIds.Add("1");

            MockMakerClient.Setup(x => x.ReadProject(It.Is <string>(y => y.Equals(id)))).Returns(projectResponse);
            MockMakerClient.Setup(x => x.ReadAllImageFiles(It.IsAny <IList <string> >())).Returns(new ImageFileIndexResponse()
            {
                Error = "Error"
            });
            MockMakerClient.Setup(x => x.ReadImageFile(It.IsAny <string>())).Returns(new ImageFileResponse()
            {
            });

            var response = model.Generate(MockMakerClient.Object, id);

            Assert.IsFalse(String.IsNullOrEmpty(response.Error));
        }
Example #2
0
        public void GenerateReturnsErrorIfIdNullOrEmpty()
        {
            var id       = ObjectId.GenerateNewId().ToString();
            var model    = new GenerateMosaicModel();
            var response = model.Generate(MockMakerClient.Object, null);

            Assert.IsFalse(String.IsNullOrEmpty(response.Error));
        }
Example #3
0
        public void GenerateReturnsErrorIfReadProjectReturnsError()
        {
            var id              = ObjectId.GenerateNewId().ToString();
            var model           = new GenerateMosaicModel();
            var projectResponse = new ProjectResponse()
            {
                Error = "Error"
            };

            MockMakerClient.Setup(x => x.ReadProject(It.Is <string>(y => y.Equals(id)))).Returns(projectResponse);

            var response = model.Generate(MockMakerClient.Object, id);

            Assert.IsFalse(String.IsNullOrEmpty(response.Error));
        }
Example #4
0
        public void GenerateReturnsErrorIfProjectDoesNotContainAnySmallFiles()
        {
            var id              = ObjectId.GenerateNewId().ToString();
            var model           = new GenerateMosaicModel();
            var projectResponse = new ProjectResponse()
            {
                Project = new ProjectStructure()
                {
                    Id = id, LargeFileId = ObjectId.GenerateNewId().ToString()
                }
            };

            MockMakerClient.Setup(x => x.ReadProject(It.Is <string>(y => y.Equals(id)))).Returns(projectResponse);

            var response = model.Generate(MockMakerClient.Object, id);

            Assert.IsFalse(String.IsNullOrEmpty(response.Error));
        }
Example #5
0
        public void GenerateReturnErrorIfEnhancedAndEdgeDetectionBothTrue()
        {
            var id    = ObjectId.GenerateNewId().ToString();
            var model = new GenerateMosaicModel();

            var projectResponse = new ProjectResponse()
            {
                Project = new ProjectStructure()
                {
                    Id = id, LargeFileId = ObjectId.GenerateNewId().ToString()
                }
            };

            projectResponse.Project.SmallFileIds.Add("1");

            MockMakerClient.Setup(x => x.ReadProject(It.Is <string>(y => y.Equals(id)))).Returns(projectResponse);

            var response = model.Generate(MockMakerClient.Object, id, enhanced: true, edgeDetection: true, threshold: 0);

            Assert.IsFalse(String.IsNullOrEmpty(response.Error));
        }
        public ActionResult GenerateMosaic(string id, bool random, int tileWidth, int tileHeight, bool colourBlended, bool enhanced, int enhancedThreshold, bool edgeDetection, int edgeDetectionThreshold)
        {
            // Generate the mosaic passing the project id and whether to randomise tile selection
            var model    = new GenerateMosaicModel();
            var response = model.Generate(client, id, random, tileWidth, tileHeight, colourBlended, enhanced, enhancedThreshold, edgeDetection, edgeDetectionThreshold);

            if (String.IsNullOrEmpty(response.Error))
            {
                // copy generated image to root directory to allow it display
                var image = new ViewImageModel();
                image.CopyImage(response.Location);
                // update project status and store location
                var insertResponse = new MosaicFileModel().InsertMosaicFile(client, id, image.ImagePath);
                if (String.IsNullOrEmpty(insertResponse.Error))
                {
                    Response.StatusCode = (int)HttpStatusCode.OK;
                    return(Json(image.ImagePath));
                }
            }
            Response.StatusCode = (int)HttpStatusCode.BadRequest;
            return(Json(response.Error));
        }