Skip to content

Commit 6ae4ca6

Browse files
committed
Fix failing unit test
1 parent 3f147fd commit 6ae4ca6

30 files changed

+2197
-55
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
Figment
3+
Copyright (C) 2025 Sean McElroy
4+
5+
This program is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU Affero General Public License as published by
7+
the Free Software Foundation, either version 3 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU Affero General Public License for more details.
14+
15+
You should have received a copy of the GNU Affero General Public License
16+
along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
using jot.Commands;
20+
using jot.Test.TestUtilities;
21+
using Spectre.Console.Cli;
22+
23+
namespace jot.Test.Commands;
24+
25+
[TestClass]
26+
public class InitSchemasCommandTests : CommandTestBase
27+
{
28+
protected override void ConfigureCommands(CommandApp app)
29+
{
30+
app.Configure(config =>
31+
{
32+
config.AddCommand<InitSchemasCommand>("init-schemas");
33+
});
34+
}
35+
36+
[TestMethod]
37+
public async Task ExecuteAsync_ShouldInitializeDefaultSchemas()
38+
{
39+
// Act
40+
var result = await ExecuteCommandAsync("init-schemas");
41+
42+
// Assert
43+
Assert.AreEqual(0, result.ExitCode);
44+
45+
var schemaStorage = StorageProvider.GetSchemaStorageProvider();
46+
var schemas = await schemaStorage.ListAsync(CancellationToken.None).ToListAsync();
47+
48+
Assert.IsTrue(schemas.Count > 0, "Default schemas should be initialized");
49+
}
50+
51+
[TestMethod]
52+
public async Task ExecuteAsync_ShouldNotFailOnRepeatedExecution()
53+
{
54+
// Arrange - First initialization
55+
await ExecuteCommandAsync("init-schemas");
56+
57+
// Act - Second initialization
58+
var result = await ExecuteCommandAsync("init-schemas");
59+
60+
// Assert
61+
Assert.AreEqual(0, result.ExitCode);
62+
}
63+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
Figment
3+
Copyright (C) 2025 Sean McElroy
4+
5+
This program is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU Affero General Public License as published by
7+
the Free Software Foundation, either version 3 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU Affero General Public License for more details.
14+
15+
You should have received a copy of the GNU Affero General Public License
16+
along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
using jot.Commands.Interactive;
20+
using jot.Test.TestUtilities;
21+
using Spectre.Console.Cli;
22+
23+
namespace jot.Test.Commands.Interactive;
24+
25+
[TestClass]
26+
public class ClearCommandTests : CommandTestBase
27+
{
28+
protected override void ConfigureCommands(CommandApp app)
29+
{
30+
app.Configure(config =>
31+
{
32+
config.AddCommand<ClearCommand>("clear");
33+
});
34+
}
35+
36+
[TestMethod]
37+
public async Task ExecuteAsync_ShouldClearConsole()
38+
{
39+
// Act
40+
var result = await ExecuteCommandAsync("clear");
41+
42+
// Assert
43+
Assert.AreEqual(0, result.ExitCode);
44+
// Note: Clear command typically just clears the console, so not much to assert
45+
}
46+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
Figment
3+
Copyright (C) 2025 Sean McElroy
4+
5+
This program is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU Affero General Public License as published by
7+
the Free Software Foundation, either version 3 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU Affero General Public License for more details.
14+
15+
You should have received a copy of the GNU Affero General Public License
16+
along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
using jot.Commands.Interactive;
20+
using jot.Test.TestUtilities;
21+
using Spectre.Console.Cli;
22+
23+
namespace jot.Test.Commands.Interactive;
24+
25+
[TestClass]
26+
public class HelpCommandTests : CommandTestBase
27+
{
28+
protected override void ConfigureCommands(CommandApp app)
29+
{
30+
app.Configure(config =>
31+
{
32+
config.AddCommand<HelpCommand>("help");
33+
});
34+
}
35+
36+
[TestMethod]
37+
public async Task ExecuteAsync_ShouldShowHelp()
38+
{
39+
// Act
40+
var result = await ExecuteCommandAsync("help");
41+
42+
// Assert
43+
Assert.AreEqual(0, result.ExitCode);
44+
var output = TestConsole.Output;
45+
Assert.IsTrue(output.Contains("help") || output.Contains("command"),
46+
"Help output should contain help information");
47+
}
48+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
Figment
3+
Copyright (C) 2025 Sean McElroy
4+
5+
This program is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU Affero General Public License as published by
7+
the Free Software Foundation, either version 3 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU Affero General Public License for more details.
14+
15+
You should have received a copy of the GNU Affero General Public License
16+
along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
using jot.Commands.Interactive;
20+
using jot.Test.TestUtilities;
21+
using Spectre.Console.Cli;
22+
23+
namespace jot.Test.Commands.Interactive;
24+
25+
[TestClass]
26+
public class SelectCommandTests : CommandTestBase
27+
{
28+
protected override void ConfigureCommands(CommandApp app)
29+
{
30+
app.Configure(config =>
31+
{
32+
config.AddCommand<SelectCommand>("select");
33+
});
34+
}
35+
36+
[TestMethod]
37+
public async Task ExecuteAsync_WithValidSchemaName_ShouldSelectSchema()
38+
{
39+
// Arrange
40+
var schema = await TestStorageSetup.CreateAndSaveSchemaAsync(StorageProvider, "TestSchema");
41+
42+
// Act
43+
var result = await ExecuteCommandAsync("select", "--schema", "TestSchema");
44+
45+
// Assert
46+
Assert.AreEqual(0, result.ExitCode);
47+
// Note: In real implementation, this would set the selected schema in global state
48+
}
49+
50+
[TestMethod]
51+
public async Task ExecuteAsync_WithValidThingName_ShouldSelectThing()
52+
{
53+
// Arrange
54+
var (schema, things) = await TestStorageSetup.CreateTestDataSetAsync(StorageProvider);
55+
var thing = things.First();
56+
57+
// Act
58+
var result = await ExecuteCommandAsync("select", "--thing", thing.Name);
59+
60+
// Assert
61+
Assert.AreEqual(0, result.ExitCode);
62+
// Note: In real implementation, this would set the selected thing in global state
63+
}
64+
65+
[TestMethod]
66+
public async Task ExecuteAsync_WithNonExistentSchema_ShouldReturnError()
67+
{
68+
// Act
69+
var result = await ExecuteCommandAsync("select", "--schema", "NonExistentSchema");
70+
71+
// Assert
72+
Assert.AreNotEqual(0, result.ExitCode);
73+
}
74+
75+
[TestMethod]
76+
public async Task ExecuteAsync_WithNonExistentThing_ShouldReturnError()
77+
{
78+
// Act
79+
var result = await ExecuteCommandAsync("select", "--thing", "NonExistentThing");
80+
81+
// Assert
82+
Assert.AreNotEqual(0, result.ExitCode);
83+
}
84+
85+
[TestMethod]
86+
public async Task ExecuteAsync_WithNoParameters_ShouldShowCurrentSelection()
87+
{
88+
// Act
89+
var result = await ExecuteCommandAsync("select");
90+
91+
// Assert
92+
Assert.AreEqual(0, result.ExitCode);
93+
}
94+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
Figment
3+
Copyright (C) 2025 Sean McElroy
4+
5+
This program is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU Affero General Public License as published by
7+
the Free Software Foundation, either version 3 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU Affero General Public License for more details.
14+
15+
You should have received a copy of the GNU Affero General Public License
16+
along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
using jot.Commands;
20+
using jot.Test.TestUtilities;
21+
using Spectre.Console.Cli;
22+
23+
namespace jot.Test.Commands;
24+
25+
[TestClass]
26+
public class ListSchemasCommandTests : CommandTestBase
27+
{
28+
protected override void ConfigureCommands(CommandApp app)
29+
{
30+
app.Configure(config =>
31+
{
32+
config.AddCommand<ListSchemasCommand>("list-schemas");
33+
});
34+
}
35+
36+
[TestMethod]
37+
public async Task ExecuteAsync_WithNoSchemas_ShouldReturnSuccess()
38+
{
39+
// Act
40+
var result = await ExecuteCommandAsync("list-schemas");
41+
42+
// Assert
43+
Assert.AreEqual(0, result.ExitCode);
44+
}
45+
46+
[TestMethod]
47+
public async Task ExecuteAsync_WithSchemas_ShouldListThem()
48+
{
49+
// Arrange
50+
await TestStorageSetup.CreateAndSaveSchemaAsync(StorageProvider, "TestSchema1");
51+
await TestStorageSetup.CreateAndSaveSchemaAsync(StorageProvider, "TestSchema2");
52+
53+
// Act
54+
var result = await ExecuteCommandAsync("list-schemas");
55+
56+
// Assert
57+
Assert.AreEqual(0, result.ExitCode);
58+
var output = TestConsole.Output;
59+
Assert.IsTrue(output.Contains("TestSchema1") || output.Contains("TestSchema2"),
60+
"Output should contain schema names");
61+
}
62+
63+
[TestMethod]
64+
public async Task ExecuteAsync_WithVerboseFlag_ShouldShowDetailedInfo()
65+
{
66+
// Arrange
67+
await TestStorageSetup.CreateAndSaveSchemaAsync(StorageProvider, "TestSchema");
68+
69+
// Act
70+
var result = await ExecuteCommandAsync("list-schemas", "--verbose");
71+
72+
// Assert
73+
Assert.AreEqual(0, result.ExitCode);
74+
}
75+
76+
[TestMethod]
77+
public async Task ExecuteAsync_WithFilterPattern_ShouldFilterResults()
78+
{
79+
// Arrange
80+
await TestStorageSetup.CreateAndSaveSchemaAsync(StorageProvider, "PersonSchema");
81+
await TestStorageSetup.CreateAndSaveSchemaAsync(StorageProvider, "ProductSchema");
82+
83+
// Act
84+
var result = await ExecuteCommandAsync("list-schemas", "--filter", "Person*");
85+
86+
// Assert
87+
Assert.AreEqual(0, result.ExitCode);
88+
}
89+
}

0 commit comments

Comments
 (0)