Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Completed the four user stories #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions ContentConsole.Test.Unit/ContentConsole.Test.Unit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,19 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ContentManagerTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TextAnalyserTests.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ContentConsole\ContentConsole.csproj">
<Project>{70da2b36-ebf3-4438-9f95-ecc828a64527}</Project>
<Name>ContentConsole</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
81 changes: 81 additions & 0 deletions ContentConsole.Test.Unit/ContentManagerTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using System;
using System.CodeDom;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using Moq;
using NUnit.Framework;

namespace ContentConsole.Test.Unit
{
[TestFixture]
public class ContentManagerTests
{
[Category("Story 1")]
[TestCase("text", 0)]
[TestCase("The weather in Manchester in winter is bad. It rains all the time - it must be horrible for people visiting.", 2)]
public void ScanText_Test(string text, int numberOfNegativeWords)
{
var ta = new TextAnalyser(new List<string>() {"swine", "bad", "nasty", "horrible"});
var cm = new ContentManager(ta, text);

string expected = String.Format("Scanned the text:{0}{1}{0}Total Number of negative words: {2}",
Environment.NewLine, text, numberOfNegativeWords);
string returned = cm.ScanText();

Assert.AreEqual(expected, returned);
}

[Category("Story 2")]
[TestCase("text people", 0, 1)]
[TestCase("The weather in Manchester in winter is bad. It rains all the time - it must be horrible for people visiting.", 2, 3)]
public void ScanText_Test(string text, int originalNumberOfNegativeWords, int newNumberOfNegativeWords)
{
var ta = new TextAnalyser(new List<string>() { "swine", "bad", "nasty", "horrible" });
var cm = new ContentManager(ta, text);

string expected = String.Format("Scanned the text:{0}{1}{0}Total Number of negative words: {2}",
Environment.NewLine, text, originalNumberOfNegativeWords);
string returned = cm.ScanText();
Assert.AreEqual(expected, returned);

//administrator doesn't like people and adds the word to the negative list
cm.TextAnalyser.AddBadWord("people");

expected = String.Format("Scanned the text:{0}{1}{0}Total Number of negative words: {2}",
Environment.NewLine, text, newNumberOfNegativeWords);
returned = cm.ScanText();
Assert.AreEqual(expected, returned);
}

[Category("Story 3")]
[TestCase("Horrible", "H######e")]
[TestCase("The weather in Manchester in winter is bad. It rains all the time - it must be horrible for people visiting.",
"The weather in Manchester in winter is b#d. It rains all the time - it must be h######e for people visiting.")]
public void ReadText_Returns_Filtered_Text(string text, string expectedFilteredText)
{
var ta = new TextAnalyser(new List<string>() { "swine", "bad", "nasty", "horrible" });
var cm = new ContentManager(ta, text);

string actualFilteredText = cm.ReadText();
Assert.AreEqual(expectedFilteredText, actualFilteredText);
}

[Category("Story 4")]
[TestCase("Horrible", "Horrible")]
[TestCase("The weather in Manchester in winter is bad. It rains all the time - it must be horrible for people visiting.",
"The weather in Manchester in winter is bad. It rains all the time - it must be horrible for people visiting.")]
public void ReadText_Returns_Unfiltered_Text_When_Parameter_Is_Passed(string text, string expectedFilteredText)
{
var ta = new TextAnalyser(new List<string>() { "swine", "bad", "nasty", "horrible" });
var cm = new ContentManager(ta, text);

string actualFilteredText = cm.ReadText(filter:false);
Assert.AreEqual(expectedFilteredText, actualFilteredText);
}
}


}
83 changes: 83 additions & 0 deletions ContentConsole.Test.Unit/TextAnalyserTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework;

namespace ContentConsole.Test.Unit
{
[TestFixture]
public class TextAnalyserTests
{
[TestCase("This contains one bad word", 1)]
[TestCase("This contains one Bad word", 1)]
[TestCase("This contains one Bad. word", 1)]
public void Analyse_Given_Text_With_One_Bad_Word_Returns_One(string text, int badWordsExpected)
{
var badWords = new List<String>() {"bad"};
var textAnalyser = new TextAnalyser(badWords);
var badWordsFound = textAnalyser.Analyse(text);

Assert.AreEqual(badWordsExpected, badWordsFound);
}

[TestCase("This contains zero superbad words", 0)]
public void Analyse_Given_Bad_Word_As_Substring_Of_Good_Word_Returns_Zero(string text, int badWordsExpected)
{
var badWords = new List<String>() { "bad" };
var textAnalyser = new TextAnalyser(badWords);
var badWordsFound = textAnalyser.Analyse(text);

Assert.AreEqual(badWordsExpected, badWordsFound);
}

[TestCase("bad", 1)]
[TestCase("Bad", 1)]
public void AddBadWord_Given_Existing_Word_Does_Nothing(string badWord, int expectedBadWordsCount)
{
var badWords = new List<String>() { "bad" };
var textAnalyser = new TextAnalyser(badWords);
textAnalyser.AddBadWord(badWord);
var badWordsCount = textAnalyser.CountBadWords();

Assert.AreEqual(expectedBadWordsCount, badWordsCount);
}

[TestCase("worse", 1)]
public void RemoveBadWord_Given_Unknown_Word_Does_Nothing(string badWord, int expectedBadWordsCount)
{
var badWords = new List<String>() { "bad" };
var textAnalyser = new TextAnalyser(badWords);
textAnalyser.RemoveBadWord(badWord);
var badWordsCount = textAnalyser.CountBadWords();

Assert.AreEqual(expectedBadWordsCount, badWordsCount);
}

[TestCase("bad", 0)]
[TestCase("Bad", 0)]
public void RemoveBadWord_Given_Existing_Word_Removes_It(string badWord, int expectedBadWordsCount)
{
var badWords = new List<String>() { "bad" };
var textAnalyser = new TextAnalyser(badWords);
textAnalyser.RemoveBadWord(badWord);
var badWordsCount = textAnalyser.CountBadWords();

Assert.AreEqual(expectedBadWordsCount, badWordsCount);
}

[TestCase("bad", "b#d")]
[TestCase("Bad", "B#d")]
[TestCase("Horrible", "H######e")]
public void Filter_Given_Existing_Word_Returns_Filtered_Version(string badWord, string expectedFilteredBadWord)
{
var badWords = new List<String>() { "bad", "horrible" };
var textAnalyser = new TextAnalyser(badWords);
var actualFilteredBadWord = textAnalyser.Filter(badWord);

Assert.AreEqual(expectedFilteredBadWord, actualFilteredBadWord);
}
}
}
2 changes: 2 additions & 0 deletions ContentConsole/ContentConsole.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ContentManager.cs" />
<Compile Include="TextAnalyser.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
Expand Down
35 changes: 35 additions & 0 deletions ContentConsole/ContentManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ContentConsole
{
public class ContentManager
{
public readonly TextAnalyser TextAnalyser;
private readonly String text;

public ContentManager(TextAnalyser textAnalyser, string text)
{
this.TextAnalyser = textAnalyser;
this.text = text;
}

public string ScanText()
{
int numberOfNegativeWords = TextAnalyser.Analyse(text);
return String.Format("Scanned the text:{0}{1}{0}Total Number of negative words: {2}",
Environment.NewLine, text, numberOfNegativeWords);
}

public string ReadText(bool filter = true)
{
if (filter)
return TextAnalyser.Filter(text);
else
return text;
}
}
}
71 changes: 42 additions & 29 deletions ContentConsole/Program.cs
Original file line number Diff line number Diff line change
@@ -1,44 +1,57 @@
using System;
using System.Collections.Generic;

namespace ContentConsole
{
public static class Program
{
public static void Main(string[] args)
{
string bannedWord1 = "swine";
string bannedWord2 = "bad";
string bannedWord3 = "nasty";
string bannedWord4 = "horrible";

string content =
"The weather in Manchester in winter is bad. It rains all the time - it must be horrible for people visiting.";

int badWords = 0;
if (content.Contains(bannedWord1))
{
badWords = badWords + 1;
}
if (content.Contains(bannedWord2))
{
badWords = badWords + 1;
}
if (content.Contains(bannedWord3))
{
badWords = badWords + 1;
}
if (content.Contains(bannedWord4))
{
badWords = badWords + 1;
}

Console.WriteLine("Scanned the text:");
Console.WriteLine(content);
Console.WriteLine("Total Number of negative words: " + badWords);
List<string> badWords = new List<string>() {"swine", "bad", "nasty", "horrible"};
string content = "The weather in Manchester in winter is bad. It rains all the time - it must be horrible for people visiting.";

var textAnalyser = new TextAnalyser(badWords);
var contentManager = new ContentManager(textAnalyser, content);

//Story 1
Console.WriteLine("User can scan text");
Console.WriteLine(contentManager.ScanText());

Console.WriteLine();

//Story 2
Console.WriteLine("Administrator doesn't like 'people' and adds them to the bad words list");
contentManager.TextAnalyser.AddBadWord("people");
Console.WriteLine(contentManager.ScanText());

Console.WriteLine();

//Story 3
Console.WriteLine("When reading, readers should see the filtered bad words instead of the actual ones");
Console.WriteLine(contentManager.ReadText());

Console.WriteLine();
Console.WriteLine("Readers convinced the administrator that 'people' are not that bad so he removed them from the list");
contentManager.TextAnalyser.RemoveBadWord("people");

Console.WriteLine();

Console.WriteLine("Now readers should see the word 'people' not filtered");
Console.WriteLine(contentManager.ReadText());

Console.WriteLine();

//Story 4
Console.WriteLine("Content Curators wish to see the original text");
Console.WriteLine(contentManager.ReadText(filter:false));

Console.WriteLine();

Console.WriteLine("Press ANY key to exit.");
Console.ReadKey();
}


}

}
Loading