public void MarkRange_NonZeroItem_Works() { _collection.MarkRange(new Range(1, 7), _markupDescriptor, null); _collection.Should().HaveCount(1); DidYouKnow.That(Ranges).Should().HaveElementAt(0, new Range(1, 7)); }
public void ExtractParameterOrderDoesNotMatter(int insertionIndex) { var caret = Content.CursorFromGraphemeIndex(insertionIndex); var originalText = Content.AsText(); var content = new TextBlockContent(); content.Insert(content.GetCaretAtStart(), "ABCDEFGHIJ"); var newPosition = Content.Insert(caret, content); // make sure the inserted text is correct by comparing the text we get by simply inserted the // same text into a string. var expectedFinalText = originalText.Insert(insertionIndex, content.AsText()); DidYouKnow.That(Content.AsText()).Should().Be(expectedFinalText); // make sure the caret returned is correct by comparing it to the text that should come after // the caret. var expectedAfterText = originalText.Substring(0, insertionIndex) + "ABCDEFGHIJ"; DidYouKnow.That(Content.CloneContent(Content.GetCaretAtStart(), newPosition).AsText()) .Should().Be(expectedAfterText); }
public void GetNextContainerBlock_Works(TestData data) { var nextBlock = BlockTreeWalker.GetNextNonContainerBlock(data.GetCurrent(this)); DidYouKnow.That(GetNameOf(nextBlock)).Should().Be(GetNameOf(data.GetExpected(this))); DidYouKnow.That(nextBlock).Should().Be(data.GetExpected(this)); }
protected void Page_Load(object sender, EventArgs e) { AuthenticateUser(); intProfile = Int32.Parse(Request.Cookies["profileid"].Value); oDidYouKnow = new DidYouKnow(intProfile, dsn); DataSet ds = oDidYouKnow.Gets(); if (ds.Tables[0].Rows.Count == 0) { strKnow = "<p><div align=\"center\"><br/><img src=\"/images/alert.gif\" border=\"0\" align=\"absmiddle\"/> "Did You Know" has not been configured.</div></p>"; lblTip.Text = "Tip # 0 / 0"; } else { if (Request.QueryString["id"] != null && Request.QueryString["id"] != "") { int intId = Int32.Parse(Request.QueryString["id"]); lblTip.Text = "Tip # " + intId.ToString() + " / " + ds.Tables[0].Rows.Count; intId = intId - 1; strKnow = ds.Tables[0].Rows[intId]["description"].ToString(); } else { Random oRandom = new Random(DateTime.Now.Millisecond); int intId = oRandom.Next(1, ds.Tables[0].Rows.Count); Response.Redirect(Request.Path + "?id=" + intId.ToString()); } } }
public void MarkRange_ReturnsInstance_ThatsValidAfterOperation() { var instance = _collection.MarkRange(new Range(0, 10), _markupDescriptor, null); _collection.UpdateFromEvent(new RangeModification(4, 4, true)); DidYouKnow.That(_collection).Should().HaveElementAt(0, instance); }
public void MarkRange_InMiddleWorks() { _collection.MarkRange(new Range(0, 8), _markupDescriptor, null); _collection.MarkRange(new Range(1, 7), _markupDescriptor, null); DidYouKnow.That(Ranges).Should().HaveElementAt(0, new Range(0, 8)); DidYouKnow.That(Ranges).Should().HaveElementAt(1, new Range(1, 7)); }
public void MarkRange_ActuallyAdds() { _collection.MarkRange(new Range(0, 3), _markupDescriptor, null); var first = _collection.First(); DidYouKnow.That(first.GetRange()).Should().Be(new Range(0, 3)); }
public void VerifyGraphemeHelperLength(int index, int expectedLength) { var text = "a\u0304\u0308bc\u0327"; int length = GraphemeHelper.GetGraphemeLength(text, index); DidYouKnow.That(length).Should().Be(expectedLength); }
public void MarkRange_OutOfOrderMaintainsSortedOrder() { _collection.MarkRange(new Range(3, 4), _markupDescriptor, null); _collection.MarkRange(new Range(1, 7), _markupDescriptor, null); _collection.MarkRange(new Range(0, 8), _markupDescriptor, null); DidYouKnow.That(Ranges).Should().HaveElementAt(0, new Range(0, 8)); DidYouKnow.That(Ranges).Should().HaveElementAt(1, new Range(1, 7)); DidYouKnow.That(Ranges).Should().HaveElementAt(2, new Range(3, 4)); }
public void Break_AtBeginning_HasNewBlock() { Initialize("abc|123"); var nextBlock = (TextBlock)TextBlockHelperMethods.TryBreakBlock(_caret).Block; DidYouKnow.That(nextBlock).Should().NotBeNull(); DidYouKnow.That(_block.Content.GetText()).Should().Be("abc"); DidYouKnow.That(nextBlock.Content.GetText()).Should().Be("123"); }
public void MoveBackward_ReportsStartAndEndCorrectly(MovementTestData testData) { var content = CreateContent("123456789"); var cursor = content.GetCaretAtEnd().MoveCursorBackwardBy(testData.AmountToMove); DidYouKnow.That(cursor.IsAtBlockStart) .Should().Be(testData.IsAtBlockStart); DidYouKnow.That(cursor.IsAtBlockEnd) .Should().Be(testData.IsAtBlockEnd); }
public void MarkRange_MultipleItemsAddsThemAll() { _collection.MarkRange(new Range(0, 3), _markupDescriptor, null); _collection.MarkRange(new Range(0, 5), _markupDescriptor, null); _collection.MarkRange(new Range(0, 7), _markupDescriptor, null); DidYouKnow.That(_collection).Should() .HaveCount(3) .And.Contain(it => it.GetRange().Equals(new Range(0, 3))) .And.Contain(it => it.GetRange().Equals(new Range(0, 5))) .And.Contain(it => it.GetRange().Equals(new Range(0, 7))); }
public void VerifyCloneContentEverywhere(int start, int end) { var originalText = Content.AsText(); var extracted = Content.CloneContent(Content.CursorFromGraphemeIndex(start), Content.CursorFromGraphemeIndex(end)); var extractedText = originalText.Substring(start, end - start); DidYouKnow.That(Content.AsText()).Should().Be(originalText); DidYouKnow.That(extracted.AsText()).Should().Be(extractedText); }
public void VerifyExtractionEverywhere(int start, int end) { var originalText = Content.AsText(); var extracted = Content.ExtractContent(Content.CursorFromGraphemeIndex(start), Content.CursorFromGraphemeIndex(end)); var removedText = originalText.Substring(start, end - start); var modifiedText = originalText.Remove(start, end - start); DidYouKnow.That(Content.AsText()).Should().Be(modifiedText); DidYouKnow.That(extracted.AsText()).Should().Be(removedText); }
public void BreakAtEnd_MakesNewNextEmptyBlock() { var cursor = (TextCaret)_collection.NthBlock(0).EndCaret(); var newBlock = TextBlockHelperMethods.TryBreakBlock(cursor).Block; DidYouKnow.That(_collection.ChildCount).Should().Be(3); DidYouKnow.That(_collection.NthBlock(0).AsText()).Should().Be("This is line #1"); DidYouKnow.That(_collection.NthBlock(1).AsText()).Should().Be(""); DidYouKnow.That(_collection.NthBlock(2).AsText()).Should().Be("This is line #2"); DidYouKnow.That(newBlock).Should().Be(_collection.NthBlock(1)); }
public BlockCollectionTests() { _collection = new AddableBlockCollection() { new ParagraphBlock() .WithText("This is line #1"), new ParagraphBlock() .WithText("This is line #2") } .RemoveFirstChilds(); DidYouKnow.That(_collection.ChildCount).Should().Be(2); }
public void CharactersAreReportedCorrectly_AfterMoving10() { var text = "0123456789"; var content = CreateContent(text); var cursor = content.GetCaretAtStart().MoveCursorForwardBy(10); DidYouKnow.That(cursor).Should().Be(content.GetCaretAtEnd()); DidYouKnow.That(cursor.Offset.GraphemeOffset).Should().Be(10); DidYouKnow.That(cursor.CharacterAfter.Text).Should().Be(null); TextUnit tempQualifier = cursor.GetCharacterBefore(); DidYouKnow.That(tempQualifier.Text).Should().Be("9"); }
public void MoveBackwardWorks(MovementTestData testData) { var content = CreateContent("123456789"); var cursor = content.GetCaretAtEnd().MoveCursorBackwardBy(testData.AmountToMove); DidYouKnow.That(cursor.CharacterAfter.Text) .Should().Be(testData.ExpectedAfterChar); TextUnit tempQualifier = cursor.GetCharacterBefore(); DidYouKnow.That(tempQualifier.Text) .Should().Be(testData.ExpectedBeforeChar); }
public void VerifyBreakInMiddleOfParagraph_SplitsIntoTwo() { var cursor = (TextCaret)_collection.NthBlock(0).BeginCaret(); cursor = cursor.MoveCursorForwardBy(7); // should be after "is" var newBlock = TextBlockHelperMethods.TryBreakBlock(cursor).Block; DidYouKnow.That(_collection.ChildCount).Should().Be(3); DidYouKnow.That(_collection.NthBlock(0).AsText()).Should().Be("This is"); DidYouKnow.That(_collection.NthBlock(1).AsText()).Should().Be(" line #1"); DidYouKnow.That(_collection.NthBlock(2).AsText()).Should().Be("This is line #2"); DidYouKnow.That(newBlock).Should().Be(_collection.NthBlock(1)); }
public void CharactersAreReportedCorrectly_ForMiddleIndices(int index) { var text = "0123456789"; var expectedRightCharacter = text[index].ToString(); var expectedLeftCharacter = text[index - 1].ToString(); var content = CreateContent(text); var cursor = content.GetCaretAtStart().MoveCursorForwardBy(index); DidYouKnow.That(cursor.Offset.GraphemeOffset).Should().Be(index); DidYouKnow.That(cursor.CharacterAfter.Text).Should().Be(expectedRightCharacter); TextUnit tempQualifier = cursor.GetCharacterBefore(); DidYouKnow.That(tempQualifier.Text).Should().Be(expectedLeftCharacter); }
public void MoveForwardWorks(MovementTestData testData) { _testOutputHelper.WriteLine(testData.ToString()); var content = CreateContent("123456789"); var cursor = content.GetCaretAtStart().MoveCursorForwardBy(testData.AmountToMove); DidYouKnow.That(cursor.CharacterAfter.Text) .Should().Be(testData.ExpectedAfterChar); TextUnit tempQualifier = cursor.GetCharacterBefore(); DidYouKnow.That(tempQualifier.Text) .Should().Be(testData.ExpectedBeforeChar); }
public void CharactersAreReportedCorrectly_AtEnd() { var text = "0123456789"; var content = CreateContent(text); var cursor = content.GetCaretAtEnd(); DidYouKnow.That(cursor.IsAtBlockStart).Should().BeFalse(); DidYouKnow.That(cursor.IsAtBlockEnd).Should().BeTrue(); DidYouKnow.That(cursor.Offset.GraphemeOffset).Should().Be(10); DidYouKnow.That(cursor.CharacterAfter.Text).Should().Be(null); TextUnit tempQualifier = cursor.GetCharacterBefore(); DidYouKnow.That(tempQualifier.Text).Should().Be("9"); }
private void VerifyCorrectness(RangeModification modification) { AddAllRangesToCollection(_allValidTextRanges.Value); _collection.UpdateFromEvent(modification); var rangesOriginal = _allValidTextRanges.Value; var actualRanges = Ranges; for (var i = 0; i < Ranges.Length; i++) { var type = modification.WasAdded ? "insert" : "deletion"; var msg = $"'operation {type} @{modification.Index} of @{modification.NumberOfItems} characters'. Original was {rangesOriginal[i]}"; var expected = Transform(rangesOriginal[i], modification); DidYouKnow.That(Ranges).Should().HaveElementAt(i, expected, because: msg); // msg } }
public void DeleteText_TryMany() { /* * 012345678901234 * #### * ####__#### * ### * ###### * ####### * #### */ var originalRanges = new[] { new Range(0, 4), new Range(2, 12), new Range(7, 10), new Range(8, 14), new Range(8, TextLength), new Range(9, 13), }; /* * 012345678901234 * #### * ######## * ## * ###### * ####### * #### */ var newRanges = new[] { new Range(0, 4), new Range(2, 10), new Range(6, 8), new Range(6, 12), new Range(6, 13), new Range(7, 11), }; originalRanges.ToList() .ForEach(r => _collection.MarkRange(r, _markupDescriptor, null)); _collection.UpdateFromEvent(new RangeModification(6, 2, false)); DidYouKnow.That(Ranges).Should().HaveElementAt(0, newRanges[0]); DidYouKnow.That(Ranges).Should().HaveElementAt(1, newRanges[1]); // note that technically the api doesn't guarantee that just be cause we added #3 after #2 that // the order was maintained so this could fail the test in the future if that changes. DidYouKnow.That(Ranges).Should().HaveElementAt(2, newRanges[2]); DidYouKnow.That(Ranges).Should().HaveElementAt(3, newRanges[3]); }
public void MarkRange_TryMany() { /* * 01234567890123456 * #### * ######## * ###### * ######## */ var originalRanges = new[] { new Range(0, 4), new Range(2, 10), new Range(6, 12), new Range(7, 14), }; AddAllRangesToCollection(originalRanges); for (var i = 0; i < originalRanges.Length; i++) { DidYouKnow.That(Ranges).Should().HaveElementAt(i, originalRanges[i]); } }
protected void Page_Load(object sender, EventArgs e) { Response.Cookies["loginreferrer"].Value = "/admin/did_you_know.aspx"; Response.Cookies["loginreferrer"].Expires = DateTime.Now.AddDays(30); if (Request.Cookies["adminid"] != null && Request.Cookies["adminid"].Value != "") { intProfile = Int32.Parse(Request.Cookies["adminid"].Value); } else { Response.Redirect("/admin/login.aspx"); } oDidYouKnow = new DidYouKnow(intProfile, dsn); if (Request.QueryString["id"] != null && Request.QueryString["id"] != "") { int intID = Int32.Parse(Request.QueryString["id"]); lblId.Text = intID.ToString(); if (!IsPostBack) { if (intID > 0) { panEdit.Visible = true; DataSet ds = oDidYouKnow.Get(intID); txtDescription.Text = ds.Tables[0].Rows[0]["description"].ToString(); btnAdd.Text = "Update"; } else { panEdit.Visible = true; btnDelete.Enabled = false; } } } else { panView.Visible = true; LoopRepeater(); } }
public void InsertText_TryMany() { /* * 0123456789012345 * #### * ######## * ###### * ######## */ var originalRanges = new[] { new Range(0, 4), new Range(2, 10), new Range(6, 12), new Range(6, 14), }; /* * 01234567890123456 * #### * ####__#### * ###### * ######## */ var newRanges = new[] { new Range(0, 4), new Range(2, 12), new Range(8, 14), new Range(8, 16), }; AddAllRangesToCollection(originalRanges); _collection.UpdateFromEvent(new RangeModification(6, 2, true)); DidYouKnow.That(Ranges).Should().HaveElementAt(0, newRanges[0]); DidYouKnow.That(Ranges).Should().HaveElementAt(0, newRanges[0]); DidYouKnow.That(Ranges).Should().HaveElementAt(1, newRanges[1]); // note that technically the api doesn't guarantee that just be cause we added #3 after #2 that // the order was maintained so this could fail the test in the future if that changes. DidYouKnow.That(Ranges).Should().HaveElementAt(2, newRanges[2]); DidYouKnow.That(Ranges).Should().HaveElementAt(3, newRanges[3]); }
public void MarkRange_Works() { var markup = _collection.MarkRange(new Range(0, 3), _markupDescriptor, null); DidYouKnow.That(markup).Should().NotBeNull(); }