Ejemplo n.º 1
0
        public void CopiesTextCorrectly()
        {
            try
            {
                CodeSample           codeSampleNormal = (CodeSample)ControlsTestPage.Instance.FindName("CodeSampleNormal");
                ButtonAutomationPeer copyButton       = new ButtonAutomationPeer((Button)codeSampleNormal.FindName("CopyButton"));

                copyButton.Invoke();
                Assert.AreEqual("Code", GetClipBoardText());

                CodeSample codeSampleHighlightingEnabled = (CodeSample)ControlsTestPage.Instance.FindName("CodeSampleWithHighlighting");
                copyButton = new ButtonAutomationPeer((Button)codeSampleHighlightingEnabled.FindName("CopyButton"));

                copyButton.Invoke();

                Assert.AreEqual("<Code />", GetClipBoardText());
            }
            catch (UnauthorizedAccessException)
            {
                // Pasting to clipboard is not allowed while app is in background
#pragma warning disable CA1303 // Do not pass literals as localized parameters
                Console.WriteLine("Test CopiesTextCorrectly was not run as app is not in foreground");
#pragma warning restore CA1303 // Do not pass literals as localized parameters
            }
        }
        private async Task GetCodeFromGithub(CodeSample snippet)
        {
            string code = await PublicClient.GetFromGithubRepo(snippet.Code);

            MouseOverContent(snippet.Description);
            AppState.UpdateSnippet(code);
        }
Ejemplo n.º 3
0
		public CodeSampleGroup (string title, UIImage icon, CodeSample [] codeSamples)
		{

			Title = title;
			Icon = icon;
			CodeSamples = codeSamples;

		}
Ejemplo n.º 4
0
        public ActionResult DeleteConfirmed(int id)
        {
            CodeSample codeSample = db.CodeSamples.Find(id);

            db.CodeSamples.Remove(codeSample);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 5
0
        public ActionResult Create([Bind(Include = "Id,Title,Description,Url,Thumbnail,Image")] CodeSample codeSample, HttpPostedFileBase thumbnailUpload, HttpPostedFileBase imageUpload)
        {
            if (ModelState.IsValid)
            {
                /*
                 * if (thumbnailUpload != null && thumbnailUpload.ContentLength > 0)
                 * {
                 *  using (var reader = new BinaryReader(thumbnailUpload.InputStream))
                 *  {
                 *      codeSample.Thumbnail = reader.ReadBytes(thumbnailUpload.ContentLength);
                 *  }
                 * }
                 *
                 * if (imageUpload != null && imageUpload.ContentLength > 0)
                 * {
                 *  using (var reader = new BinaryReader(imageUpload.InputStream))
                 *  {
                 *      codeSample.Image = reader.ReadBytes(imageUpload.ContentLength);
                 *  }
                 * }
                 */

                string message = "";
                try
                {
                    db.CodeSamples.Add(codeSample);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                catch (DbEntityValidationException dbe)
                {
                    foreach (var eve in dbe.EntityValidationErrors)
                    {
                        string msg = String.Format("Entity of Type {0} in state {1} has the following validation errors:\n\r",
                                                   eve.Entry.Entity.GetType().Name, eve.Entry.State);

                        foreach (var ve in eve.ValidationErrors)
                        {
                            msg += String.Format("- Property: {0}, Error: {1}\n\r", ve.PropertyName, ve.ErrorMessage);
                        }

                        message += msg;
                    }

                    return(View("Error", message));
                }
            }

            return(View(codeSample));
        }
Ejemplo n.º 6
0
        // GET: Samples/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CodeSample codeSample = db.CodeSamples.Find(id);

            if (codeSample == null)
            {
                return(HttpNotFound());
            }
            return(View(codeSample));
        }
Ejemplo n.º 7
0
        public async Task <CodeSampleDto> CreateAsync(CodeSampleDto dto)
        {
            var link = new CodeSample
            {
                Name      = dto.Name,
                IsDeleted = false,
                Code      = dto.Code
            };

            _unitOfWork.CodeSamples.Create(link);
            await _unitOfWork.SaveChangesAsync();

            return(dto);
        }
Ejemplo n.º 8
0
        public void VerifyRenderedText()
        {
            CodeSample    codeSampleNormal = (CodeSample)ControlsTestPage.Instance.FindName("CodeSampleNormal");
            RichTextBlock codeText         = (RichTextBlock)codeSampleNormal.FindName("CodeBlock");

            codeText.SelectAll();

            Assert.AreEqual("Code", codeText.SelectedText);

            CodeSample codeSampleHighlightingEnabled = (CodeSample)ControlsTestPage.Instance.FindName("CodeSampleWithHighlighting");

            codeText = (RichTextBlock)codeSampleHighlightingEnabled.FindName("CodeBlock");
            codeText.SelectAll();

            Assert.AreEqual("<Code />", codeText.SelectedText);
        }
        private async Task AddNewCodeSample(string content, string fileName)
        {
            var codeSample = new CodeSample
            {
                Code     = content,
                Name     = fileName,
                Language = CodeLanguage,
                Custom   = true
            };

            CodeSamples.Add(codeSample);
            await CodeSampleRepository.AddCodeSampleAsync(codeSample);

            SelectedCodeSample = CodeSamples.Count - 1;
            StateHasChanged();
        }
 public string GetDisplayTitle(CodeSample codeSample)
 {
     return(Truncate(codeSample.DisplayTitle, 80));
 }
Ejemplo n.º 11
0
 public void Sample_code_is_compile_clean(CodeSample codeSample)
 {
     CodeSampleAssert.NoCompilationErrors(codeSample);
 }