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

Change Credits module to Credit #212 #229

Merged
merged 2 commits into from
Nov 12, 2024
Merged
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
26 changes: 13 additions & 13 deletions app-test/CommandLineParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class CommandLineParserTests
[Fact]
public void TestParseNoun()
{
Assert.Equal(Noun.Credits, parser.ParseNoun("credits"));
Assert.Equal(Noun.Credit, parser.ParseNoun("credit"));
}

[Fact]
Expand All @@ -19,7 +19,7 @@ public void TestParseNounWithBlock()
[Fact]
public void TestParseVerb()
{
Assert.Equal(Verb.List, parser.ParseVerb("list", Noun.Credits));
Assert.Equal(Verb.List, parser.ParseVerb("list", Noun.Credit));
}

[Fact]
Expand All @@ -31,15 +31,15 @@ public void TestParseVerbInvalidNoun()
[Fact]
public void TestParseVerbInvalidVerb()
{
Assert.Equal(Verb.Invalid, parser.ParseVerb("abc", Noun.Credits));
Assert.Equal(Verb.Invalid, parser.ParseVerb("abc", Noun.Credit));
}

[Fact]
public void TestParseCredits()
public void TestParseCredit()
{
string[] args = { "credits", "list" };
((Noun noun, Verb verb), string[] commandArgs) = parser.ParseWithArgs(args);
Assert.Equal(Noun.Credits, noun);
string[] args = { "credit", "list" };
(Noun noun, Verb verb) = parser.Parse(args);
Assert.Equal(Noun.Credit, noun);
Assert.Equal(Verb.List, verb);
}

Expand All @@ -64,36 +64,36 @@ public void TestParseBlock()
[Fact]
public void TestCommandLineArgs()
{
string[] args = { "credits", "list" };
string[] args = { "credit", "list" };
string[] commandLineArgs = parser.GetCommandLineArgs(args);
Assert.Equal(new string[] {}, commandLineArgs);
}

[Fact]
public void TestCommandLineArgsMultiple()
{
string[] args = { "credits", "list", "abc" };
string[] args = { "credit", "list", "abc" };
string[] commandLineArgs = parser.GetCommandLineArgs(args);
Assert.Equal(new string[] { "abc" }, commandLineArgs);
}

[Fact]
public void TestCommandLineArgsInvalid()
{
string[] args = { "credits" };
string[] args = { "credit" };
string[] commandLineArgs = parser.GetCommandLineArgs(args);
Assert.Equal(new string[] {}, commandLineArgs);
}

[Fact]
public void TestParseWithArgs()
{
string[] args = { "credits", "list", "abc" };
string[] args = { "credit", "list", "abc" };
((Noun noun, Verb verb), string[] commandLineArgs) = parser.ParseWithArgs(args);
Assert.Equal(Noun.Credits, noun);
Assert.Equal(Noun.Credit, noun);
Assert.Equal(Verb.List, verb);
Assert.Equal(new string[] { "abc" }, commandLineArgs);
}


}
}
68 changes: 34 additions & 34 deletions app-test/CreditsTests.cs → app-test/CreditTests.cs
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
namespace credits_tests;
public class CreditsTests
{
Credits credits = new Credits();
[Fact]
public void TestGetCreditsType()
{
Assert.True(typeof(string[]) == credits.GetCredits().GetType());
}
[Fact]
public void TestGetCreditsLength()
{
Assert.Equal(12, credits.GetCredits().Length);
}
[Fact]
public void TestGetCreditsContent()
{
Assert.Equal("Emil Harvey", credits.GetCredits()[0]);
Assert.Equal("Parth Gajjar", credits.GetCredits()[1]);
Assert.Equal("Boa Im", credits.GetCredits()[2]);
Assert.Equal("Nimeshkumar Chaudhari", credits.GetCredits()[3]);
Assert.Equal("Daphne Duong", credits.GetCredits()[4]);
Assert.Equal("Shaik Mathar Syed", credits.GetCredits()[5]);
Assert.Equal("Bharat Chauhan", credits.GetCredits()[6]);
Assert.Equal("Prabhdeep Singh", credits.GetCredits()[7]);
Assert.Equal("Tao Boyce", credits.GetCredits()[8]);
Assert.Equal("Zumhliansang Lung Ler", credits.GetCredits()[9]);
Assert.Equal("Daeseong Yu", credits.GetCredits()[10]);
Assert.Equal("Tian Yang", credits.GetCredits()[11]);
}
namespace credit_tests;

public class CreditTests
{
Credit credits = new Credit();

[Fact]
public void TestGetCreditsType()
{
Assert.True(typeof(string[]) == credits.GetCredits().GetType());
}

[Fact]
public void TestGetCreditsLength()
{
Assert.Equal(12, credits.GetCredits().Length);
}

[Fact]
public void TestGetCreditsContent()
{
Assert.Equal("Emil Harvey", credits.GetCredits()[0]);
Assert.Equal("Parth Gajjar", credits.GetCredits()[1]);
Assert.Equal("Boa Im", credits.GetCredits()[2]);
Assert.Equal("Nimeshkumar Chaudhari", credits.GetCredits()[3]);
Assert.Equal("Daphne Duong", credits.GetCredits()[4]);
Assert.Equal("Shaik Mathar Syed", credits.GetCredits()[5]);
Assert.Equal("Bharat Chauhan", credits.GetCredits()[6]);
Assert.Equal("Prabhdeep Singh", credits.GetCredits()[7]);
Assert.Equal("Tao Boyce", credits.GetCredits()[8]);
Assert.Equal("Zumhliansang Lung Ler", credits.GetCredits()[9]);
Assert.Equal("Daeseong Yu", credits.GetCredits()[10]);
Assert.Equal("Tian Yang", credits.GetCredits()[11]);
}
}
5 changes: 3 additions & 2 deletions app/CommandLineParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/// </summary>
enum Noun
{
Credits, // Represents the "credits" noun.
Credit, // Represents the "credit" noun.
WorkItem, // Represents work item
Block, // Represents the "block" noun.
Progress, // Represents Progerss item
Expand Down Expand Up @@ -69,7 +69,8 @@ class CommandLineParser : ICommandLineParser
{
private readonly Dictionary<Noun, HashSet<Verb>> ValidVerbs = new Dictionary<Noun, HashSet<Verb>>
{
{ Noun.Credits, new HashSet<Verb> { Verb.List } },
// Credit supports just the List verb.
{ Noun.Credit, new HashSet<Verb> { Verb.List } },
{ Noun.WorkItem, new HashSet<Verb> { Verb.List, Verb.Create, Verb.Edit, Verb.Delete } },
{ Noun.Block, new HashSet<Verb> { Verb.List, Verb.Create, Verb.Edit, Verb.Delete } },
{ Noun.Progress, new HashSet<Verb> { Verb.Edit, Verb.Delete} },
Expand Down
6 changes: 3 additions & 3 deletions app/Credits.cs → app/Credit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ It was created to fulfill #16

using Lms;

class Credits : ICommand {
class Credit : ICommand {
private LmsDbContext? db;

public Credits() {
public Credit() {
this.db = null;
}

public Credits(LmsDbContext db) {
public Credit(LmsDbContext db) {
this.db = db;
}

Expand Down
9 changes: 4 additions & 5 deletions app/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,13 @@
case Noun.Invalid:
Console.WriteLine("Invalid noun.");
return 400; // 400 Bad Request
case Noun.Credits:
Credits credits = new Credits(dbContext); // initialize here to avoid unnecessary instantiation
credits.Execute(verb, commandArgs);
return 200; // 200 OK
case Noun.Credit:
Credit credits = new Credit(dbContext); // initialize here to avoid unnecessary instantiation
credits.Execute(verb);
return 200;
case Noun.Block:
Blockers blockers = new Blockers(dbContext);
blockers.Execute(verb, commandArgs);

return 200; // 200 OK
case Noun.WorkItem:
WorkItem work_item = new WorkItem(dbContext);
Expand Down
2 changes: 1 addition & 1 deletion app/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"profiles": {
"showCredits": {
"commandName": "Project",
"commandLineArgs": "Credits List"
"commandLineArgs": "Credit List"
}
}
}
2 changes: 1 addition & 1 deletion wiki/announcements/Iteration 2 starting soon.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ As an overview:
## CLI
I completed #48. This adds super basic CLI (command-line interface) functionality for this project. At a super high level, the app works with a `noun verb` pattern. For example:
```
$ dotnet run credits list
$ dotnet run credit list
Credits
-------
Emil Harvey
Expand Down
8 changes: 4 additions & 4 deletions wiki/development/CLI Standards.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ Our CLI should adopt a "noun" "verb" pattern. This means that the first argument
# Architecture
The `CommandLineParser` class handles command line parsing. The `parse` function receives command line arguments (via the magic `args` variable). It has several functions that help you along.
- `Parse` is a simple function that receives command line `args` and returns both the `Noun` and the `Verb`
- E.g., `credits list` -> `(Credits, List)`
- E.g., `credit list` -> `(Credit, List)`
- `GetCommandLineArgs` returns the arguments *after* the `Noun` and `Verb`
- E.g., `credits list` -> `[]`
- E.g., `credits list abc` -> `["abc"]`
- E.g., `credit list` -> `[]`
- E.g., `credit list abc` -> `["abc"]`
- `ParseWithArgs` is a combination of both `Parse` and `GetCommandLineArgs`
- E.g., `credits list abc` -> `((Credits, List), ["abc"]`
- E.g., `credit list abc` -> `((Credit, List), ["abc"]`
Loading