public void Cannot_Retrieve_Sample_Thumbnail_Data_For_Invalid_ID()
        {
            // Arrange - create a Sample with image (thumbnail) data
            Sample sample = new Sample
            {
                Id = 1,
                Thumbnail = new byte[] { }
            };

            // Arrange - create the mock repository
            Mock<IRepository<Sample>> mock = new Mock<IRepository<Sample>>();
            mock.Setup(m => m.Get(1)).Returns(sample);

            // Arrange - create the controller
            SampleController target = new SampleController(mock.Object);

            // Act - call the Thumbnail method
            HttpResponseMessage result = target.Thumbnail(100);

            // Assert
            Assert.IsInstanceOfType(result, typeof(HttpResponseMessage));
            Assert.AreEqual(result.StatusCode, HttpStatusCode.BadRequest);
        }
        private void tsbtnCopyModelToSample_Click(object sender, EventArgs e)
        {
            CurrencyManager cm = (CurrencyManager)this.BindingContext[dgvModels.DataSource, dgvModels.DataMember];

            Model model = (Model)cm.Current;

            Sample sample = new Sample();
            sample.Items = new List<SampleItem>();

            sample.ContentType = model.ContentType;
            sample.Image = model.Image;
            sample.ImageWidth = model.ImageWidth;
            sample.ImageHeight = model.ImageHeight;

            Bitmap bmpThumbnail = Utilities.Utils.ResizeImage(Utils.ByteArrayToBitmap(model.Image), 360, 270);
            sample.Thumbnail = Utilities.Utils.BitmapToByteArray(bmpThumbnail);

            foreach (ModelItem modelItem in model.Items)
            {
                SampleItem sampleItem = new SampleItem();

                sampleItem.ItemType = modelItem.ItemType;
                sampleItem.PositionTop = modelItem.PositionTop;
                sampleItem.PositionLeft = modelItem.PositionLeft;
                sampleItem.Text = modelItem.Text;
                sampleItem.TemplateId = modelItem.TemplateId;
                sampleItem.FontSize = modelItem.FontSize;
                sampleItem.FontColor = modelItem.FontColor;
                sampleItem.Rotation = modelItem.Rotation;

                sample.Items.Add(sampleItem);
            }

            _sampleRepository.Add(sample);
            _sampleRepository.Save();
        }
        public void Can_Retrieve_Sample_Thumbnail_Data()
        {
            // Arrange - create a Sample with image (thumbnail) data
            Sample sample = new Sample
            {
                Id = 1,
                Thumbnail = new byte[] { }
            };

            // Arrange - create the mock repository
            Mock<IRepository<Sample>> mock = new Mock<IRepository<Sample>>();
            mock.Setup(m => m.Get(1)).Returns(sample);

            // Arrange - create the controller
            SampleController target = new SampleController(mock.Object);

            // Act - call the Thumbnail method
            HttpResponseMessage result = target.Thumbnail(1);

            // Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(HttpResponseMessage));
            Assert.AreEqual(result.Content.Headers.ContentType.MediaType, "image/png");
        }
        private void tsbtnToSample_Click(object sender, EventArgs e)
        {
            string fontPath = @"E:\xWork\Apps\Work\AddTextToImage\AddTextToImage.WebUI\fonts\";
            Bitmap bmpResult;

            if (model != null)
            {
                ImageConverter ic = new ImageConverter();
                Image img = (Image)ic.ConvertFrom(model.Image);
                bmpResult = new Bitmap(img);

                Graphics graphics = Graphics.FromImage(bmpResult);

                foreach (var modelItem in model.Items)
                {
                    TemplateBase template = null;

                    if (modelItem.ItemType == 0)
                    {
                        template =
                            (from t in _textTemplateRepository.GetAllWithInclude("Font")
                             where t.Id == modelItem.TemplateId
                             select t).FirstOrDefault();
                    }
                    else
                    {
                        template =
                            (from t in _clipartTemplateRepository.GetAllWithInclude("Font")
                             where t.Id == modelItem.TemplateId
                             select t).FirstOrDefault();

                    }

                    OutlineTextProcessor outlineTextProcessor = new OutlineTextProcessor(modelItem, template, fontPath);
                    Bitmap image = outlineTextProcessor.GetImage();

                    graphics.DrawImage((Image)image, new Point(modelItem.PositionLeft, modelItem.PositionTop));
                }

                resultImage = bmpResult;

                graphics.Flush();
                graphics.Dispose();
            }

            Sample sample = new Sample();
            sample.Items = new List<SampleItem>();

            sample.ContentType = model.ContentType;
            sample.Image = model.Image;
            sample.ImageWidth = model.ImageWidth;
            sample.ImageHeight = model.ImageHeight;

            Bitmap bmpThumbnail = Utilities.Utils.ResizeImage(resultImage, 360, 270);
            sample.Thumbnail = Utilities.Utils.BitmapToByteArray(bmpThumbnail);

            foreach (ModelItem modelItem in model.Items)
            {
                SampleItem sampleItem = new SampleItem();

                sampleItem.ItemType = modelItem.ItemType;
                sampleItem.PositionTop = modelItem.PositionTop;
                sampleItem.PositionLeft = modelItem.PositionLeft;
                sampleItem.Text = modelItem.Text;
                sampleItem.TemplateId = modelItem.TemplateId;
                sampleItem.FontSize = modelItem.FontSize;
                sampleItem.FontColor = modelItem.FontColor;
                sampleItem.Rotation = modelItem.Rotation;

                sample.Items.Add(sampleItem);
            }

            _sampleRepository.Add(sample);
            _sampleRepository.Save();
        }