-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Deserializer tests * Extensions tests * Commands tests * Generator tests
- Loading branch information
Showing
51 changed files
with
1,125 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using client_generator.App; | ||
using Xunit; | ||
|
||
namespace client_generator_tests.App | ||
{ | ||
public class BackFileEntryTest | ||
{ | ||
|
||
[Fact] | ||
public void CorrectPath() | ||
{ | ||
// Arrange | ||
var paths = new List<string> | ||
{ | ||
"/path/a/b", | ||
"/a/b/c/d", | ||
"/a/b/c/d/../t/s", | ||
}; | ||
|
||
// Act | ||
var backPaths = paths.Select(x => new BackFileEntry(x).ParentDirectory); | ||
|
||
// Arrange | ||
Assert.Equal(paths.Select(x => Directory.GetParent(x).FullName), backPaths); | ||
} | ||
|
||
[Fact] | ||
public void SlashPath() | ||
{ | ||
// Arrange | ||
var paths = new List<string> | ||
{ | ||
"/", | ||
"//" | ||
}; | ||
|
||
// Act | ||
var backPaths = paths.Select(x => new BackFileEntry(x).ParentDirectory); | ||
|
||
// Arrange | ||
Assert.Equal(paths.Select(x => x), backPaths); | ||
} | ||
|
||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
client-generator-tests/App/Commands/ChangeWindowCommandTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using client_generator.App; | ||
using client_generator.App.Commands; | ||
using Moq; | ||
using Terminal.Gui; | ||
using Xunit; | ||
|
||
namespace client_generator_tests.App.Commands | ||
{ | ||
public class ChangeWindowCommandTest | ||
{ | ||
|
||
[Fact] | ||
public void ChangeWindow() | ||
{ | ||
// Arrange | ||
var window = new Mock<Window>(null); | ||
var appController = new Mock<IAppController>(); | ||
appController.Setup(x => x.ChangeWindow(window.Object)).Verifiable(); | ||
var command = new ChangeWindowCommand(appController.Object, window.Object); | ||
|
||
// Act | ||
command.Execute(); | ||
|
||
// Assert | ||
appController.Verify(x => x.ChangeWindow(It.IsAny<Window>()), Times.Once); | ||
appController.Verify(x => x.ChangeWindow(window.Object), Times.Once); | ||
} | ||
|
||
[Fact] | ||
public void ConstructionShouldBeEffectless() | ||
{ | ||
// Arrange | ||
var window = new Mock<Window>(null); | ||
var appController = new Mock<IAppController>(); | ||
appController.Setup(x => x.ChangeWindow(window.Object)).Verifiable(); | ||
|
||
// Act | ||
var command = new ChangeWindowCommand(appController.Object, window.Object); | ||
|
||
appController.Verify(x => x.ChangeWindow(It.IsAny<Window>()), Times.Never); | ||
|
||
} | ||
|
||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
client-generator-tests/App/Commands/CommandWithConnectedWindow.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using System; | ||
using client_generator.App; | ||
using client_generator.App.Commands; | ||
using client_generator.App.Windows; | ||
using client_generator.Generators; | ||
using Moq; | ||
using Newtonsoft.Json; | ||
using Terminal.Gui; | ||
using Xunit; | ||
|
||
namespace client_generator_tests.App.Commands | ||
{ | ||
public class CommandWithConnectedWindow | ||
{ | ||
|
||
[Fact] | ||
public void OnExecuteShouldChangeWindow() | ||
{ | ||
// Arrange | ||
var window = new Mock<Window>(null); | ||
var appController = new Mock<IAppController>(); | ||
appController.Setup(x => x.GetCurrentWindow()).Returns(window.Object); | ||
appController.Setup(x => x.ChangeWindow(It.IsAny<Window>())).Verifiable(); | ||
|
||
var commands = new (Type type, ICommand command)[] | ||
{ | ||
(typeof(GeneratorSettingsWindow), | ||
new EditGeneratorSettingsCommand(appController.Object, new GeneratorSettings())), | ||
|
||
(typeof(JsonSettingsWindow), | ||
new EditJsonDeserializationSettingsCommand(appController.Object, new JsonSerializerSettings())), | ||
|
||
(typeof(FileSelectorWindow), | ||
new SelectFileCommand(appController.Object, entry => {} )) | ||
}; | ||
|
||
// Act | ||
foreach (var (_, command) in commands) | ||
{ | ||
command.Execute(); | ||
} | ||
|
||
// Assert | ||
foreach (var (type, _) in commands) | ||
{ | ||
appController.Verify( | ||
x => x.ChangeWindow(It.Is<Window>(changedWindow => | ||
changedWindow.GetType() == type)), Times.Once); | ||
} | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using client_generator.App; | ||
using client_generator.App.Commands; | ||
using Moq; | ||
using Terminal.Gui; | ||
using Xunit; | ||
|
||
namespace client_generator_tests.App.Commands | ||
{ | ||
public class ExitCommandTest | ||
{ | ||
|
||
[Fact] | ||
public void Exit() | ||
{ | ||
// Arrange | ||
var appController = new Mock<IAppController>(); | ||
appController.Setup(x => x.ExitApp()).Verifiable(); | ||
var command = new ExitAppCommand(appController.Object); | ||
|
||
// Act | ||
command.Execute(); | ||
|
||
// Assert | ||
appController.Verify(x => x.ExitApp(), Times.Once); | ||
} | ||
|
||
[Fact] | ||
public void ConstructionShouldBeEffectless() | ||
{ | ||
// Arrange | ||
var appController = new Mock<IAppController>(); | ||
appController.Setup(x => x.ExitApp()).Verifiable(); | ||
|
||
// Act | ||
var command = new ExitAppCommand(appController.Object); | ||
|
||
// Assert | ||
appController.Verify(x => x.ExitApp(), Times.Never); | ||
} | ||
|
||
} | ||
} |
104 changes: 104 additions & 0 deletions
104
client-generator-tests/Deserializer/Builders/SuspendBuildsManagerTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using client_generator.Deserializer.Helpers.Builders; | ||
using client_generator_tests.Helpers; | ||
using Xunit; | ||
|
||
namespace client_generator_tests.Deserializer.Builders | ||
{ | ||
public class SuspendBuildsManagerTest | ||
{ | ||
|
||
[Fact] | ||
public void SimpleBuild() | ||
{ | ||
// Arrange | ||
var builds = new Dictionary<string, BuildableObject> | ||
{ | ||
{"1", new BuildableObject {Id = "1", RequiredIds = new string[0]}} | ||
}; | ||
var builder = new SuspendBuildsManager<BuildableObject, string>(builds, BuildableObject.BuildMethod); | ||
|
||
// Act | ||
var resultStatus = builder.Build(); | ||
var result = builder.GetResult(); | ||
|
||
// Assert | ||
Assert.True(resultStatus, "Build should be possible"); | ||
Assert.Single(result.Values); | ||
Assert.Equal("1", result["1"]); | ||
} | ||
|
||
[Fact] | ||
public void MultiTaskBuild() | ||
{ | ||
// Arrange | ||
var builds = new Dictionary<string, BuildableObject> | ||
{ | ||
{"1", new BuildableObject {Id = "a", RequiredIds = new string[0]}}, | ||
{"2", new BuildableObject {Id = "b", RequiredIds = new string[0]}}, | ||
{"3", new BuildableObject {Id = "c", RequiredIds = new string[0]}} | ||
}; | ||
var builder = new SuspendBuildsManager<BuildableObject, string>(builds, BuildableObject.BuildMethod); | ||
|
||
// Act | ||
var resultStatus = builder.Build(); | ||
var result = builder.GetResult(); | ||
|
||
// Assert | ||
Assert.True(resultStatus, "Build should be possible"); | ||
Assert.Equal(builds.Keys.Count, result.Keys.Count); | ||
Assert.Equal(builds.Select(x => x.Value.Id), result.Select(x => x.Value)); | ||
} | ||
|
||
[Fact] | ||
public void MultiDependentTaskBuild() | ||
{ | ||
// Arrange | ||
var builds = new Dictionary<string, BuildableObject> | ||
{ | ||
{"1", new BuildableObject {Id = "a", RequiredIds = new[] {"2"}}}, | ||
{"2", new BuildableObject {Id = "b", RequiredIds = new string[0]}}, | ||
{"3", new BuildableObject {Id = "c", RequiredIds = new[] {"4"}}}, | ||
{"4", new BuildableObject {Id = "d", RequiredIds = new string[0]}}, | ||
{"5", new BuildableObject {Id = "e", RequiredIds = new[] {"4"}}} | ||
}; | ||
var builder = new SuspendBuildsManager<BuildableObject, string>(builds, BuildableObject.BuildMethod); | ||
|
||
// Act | ||
var resultStatus = builder.Build(); | ||
var result = builder.GetResult(); | ||
|
||
// Assert | ||
Assert.True(resultStatus, "Build should be possible"); | ||
Assert.Equal(builds.Keys.Count, result.Keys.Count); | ||
Assert.Equal(builds.Select(x => x.Value.Id).OrderBy(x => x), | ||
result.Select(x => x.Value).OrderBy(x => x)); | ||
} | ||
|
||
|
||
[Fact] | ||
public void ImpossibleBuild() | ||
{ | ||
// Arrange | ||
var builds = new Dictionary<string, BuildableObject> | ||
{ | ||
{"1", new BuildableObject {Id = "a", RequiredIds = new[] {"2"}}}, | ||
{"2", new BuildableObject {Id = "b", RequiredIds = new[] {"2"}}}, | ||
{"3", new BuildableObject {Id = "c", RequiredIds = new[] {"4"}}}, | ||
{"4", new BuildableObject {Id = "d", RequiredIds = new string[0]}}, | ||
{"5", new BuildableObject {Id = "e", RequiredIds = new[] {"4"}}} | ||
}; | ||
var builder = new SuspendBuildsManager<BuildableObject, string>(builds, BuildableObject.BuildMethod); | ||
|
||
// Act | ||
var resultStatus = builder.Build(); | ||
var result = builder.GetResult(); | ||
|
||
// Assert | ||
Assert.False(resultStatus, "Build should be possible"); | ||
Assert.Equal(3, result.Keys.Count); | ||
} | ||
|
||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
client-generator-tests/Deserializer/Helpers/OpenApiDeserializerAssemblyIteratorTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using client_generator.Deserializer.Helpers; | ||
using client_generator_tests.Helpers; | ||
using Xunit; | ||
|
||
namespace client_generator_tests.Deserializer.Helpers | ||
{ | ||
public class OpenApiDeserializerAssemblyIteratorTest | ||
{ | ||
|
||
[Fact] | ||
public void ReturnsCorrectTypes() | ||
{ | ||
// Arrange | ||
var typesArray = new[] | ||
{ | ||
typeof(string), | ||
typeof(FakeDeserializer), | ||
typeof(char), | ||
typeof(FakeDeserializer) | ||
}; | ||
var iterator = new OpenApiDeserializerAssemblyIterator(typesArray); | ||
|
||
// Act | ||
var counter = typesArray.Count(type => type == typeof(FakeDeserializer)); | ||
var getTypes = new List<Type>(); | ||
while (iterator.MoveNext()) | ||
{ | ||
getTypes.Add(iterator.Current); | ||
counter--; | ||
} | ||
|
||
// Assert | ||
Assert.Equal(0, counter); | ||
Assert.True(getTypes.All(type => type == typeof(FakeDeserializer)), "Iterator returns incorrect type."); | ||
} | ||
|
||
[Fact] | ||
public void ReturnsNothingOnEmptyCollection() | ||
{ | ||
// Arrange | ||
var typeArray = new Type[0]; | ||
|
||
// Act | ||
var iterator = new OpenApiDeserializerAssemblyIterator(typeArray); | ||
|
||
// Assert | ||
Assert.False(iterator.MoveNext(), "Collection should be empty"); | ||
} | ||
|
||
|
||
[Fact] | ||
public void ReturnsNothingOnNullCollection() | ||
{ | ||
// Act | ||
var iterator = new OpenApiDeserializerAssemblyIterator(null); | ||
|
||
// Assert | ||
Assert.False(iterator.MoveNext(), "Collection should be empty"); | ||
} | ||
} | ||
} |
Oops, something went wrong.