Skip to content

Commit

Permalink
Merge pull request #24 from hughesjs/method-args
Browse files Browse the repository at this point in the history
Added the ability to add args to your methods
  • Loading branch information
hughesjs authored Jun 15, 2023
2 parents 574efc0 + 27adfa2 commit 9feb062
Show file tree
Hide file tree
Showing 14 changed files with 229 additions and 188 deletions.
18 changes: 0 additions & 18 deletions src/DemoProject/DemoProject.csproj

This file was deleted.

62 changes: 0 additions & 62 deletions src/DemoProject/Program.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ Methods:
- "Lock"
- "Enter"
- Name: "Start"
Arguments:
- Name: "speed"
Type: "int"
- Name: "direction"
Type: "string"
CanTransitionTo:
- "Stop"
- "Build"
Expand All @@ -29,5 +34,8 @@ Methods:
- "Start"
- "Exit"
- Name: "Build"
Arguments:
- Name: "color"
Type: "string"
CanTransitionTo: []
ReturnType: "string"
203 changes: 108 additions & 95 deletions src/SuperFluid.Tests/Parsers/FluidApiDefinitionParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,86 +6,97 @@ namespace SuperFluid.Tests.Parsers;

public class FluidApiDefinitionParserTests
{
private readonly FluidApiMethodDefinition _init = new()
{
Name = "Initialize",
CanTransitionTo = new()
{
"Unlock"
}
};
private readonly FluidApiMethodDefinition _initSimple = new()
{
Name = "Initialize",
CanTransitionTo = new()
{
"DropDead"
}
};

private readonly FluidApiMethodDefinition _unlock = new()
{
Name = "Unlock",
CanTransitionTo = new()
private static readonly FluidApiArgumentDefinition Speed = new()
{
Name = "speed",
Type = "int"
};

private static readonly FluidApiMethodDefinition Init = new()
{
Name = "Initialize",
CanTransitionTo = new()
{
"Unlock"
}
};

private static readonly FluidApiMethodDefinition InitSimple = new()
{
Name = "Initialize",
CanTransitionTo = new()
{
"DropDead"
}
};

private static readonly FluidApiMethodDefinition Unlock = new()
{
Name = "Unlock",
CanTransitionTo = new()
{
"Enter",
"Lock"
}
};

private static readonly FluidApiMethodDefinition Lock = new()
{
Name = "Lock",
CanTransitionTo = new()
{
"Unlock"
}
};

private static readonly FluidApiMethodDefinition Enter = new()
{
Name = "Enter",
CanTransitionTo = new()
{
"Start",
"Exit"
}
};

private static readonly FluidApiMethodDefinition Exit = new()
{
Name = "Exit",
CanTransitionTo = new()
{
"Lock",
"Enter"
}
};

private static readonly FluidApiMethodDefinition Start = new()
{
Name = "Start",
CanTransitionTo = new()
{
"Stop"
},
Arguments = new()
{
"Enter",
"Lock"
Speed
}
};

private readonly FluidApiMethodDefinition _lock = new()
{
Name = "Lock",
CanTransitionTo = new()
{
"Unlock"
}
};

private readonly FluidApiMethodDefinition _enter = new()
{
Name = "Enter",
CanTransitionTo = new()
{
"Start",
"Exit"
}
};

private readonly FluidApiMethodDefinition _exit = new()
{
Name = "Exit",
CanTransitionTo = new()
{
"Lock",
"Enter"
}
};

private readonly FluidApiMethodDefinition _start = new()
{
Name = "Start",
CanTransitionTo = new()
{
"Stop"
}
};

private readonly FluidApiMethodDefinition _stop = new()
{
Name = "Stop",
CanTransitionTo = new()
{
"Start",
"Exit"
}
};

private readonly FluidApiMethodDefinition _dropDead = new()
{
Name = "DropDead",
CanTransitionTo = new()
};
};

private static readonly FluidApiMethodDefinition Stop = new()
{
Name = "Stop",
CanTransitionTo = new()
{
"Start",
"Exit"
}
};

private static readonly FluidApiMethodDefinition DropDead = new()
{
Name = "DropDead",
CanTransitionTo = new()
};

[Fact]
public void CanDeserializeSimpleCase()
Expand All @@ -94,10 +105,10 @@ public void CanDeserializeSimpleCase()
{
Name = "Simple",
Namespace = "Simple.Test",
InitialState = _initSimple,
InitialState = InitSimple,
Methods = new()
{
_dropDead
DropDead
}
};

Expand All @@ -122,30 +133,30 @@ public void CanDeserializeComplexCase()
{
Name = "Simple",
Namespace = "Simple.Test",
InitialState = _init,
InitialState = Init,
Methods = new()
{
_lock,
_unlock,
_enter,
_exit,
_start,
_stop
Lock,
Unlock,
Enter,
Exit,
Start,
Stop
}
};

FluidApiDefinitionParser parser = new();
FluidApiModel model = parser.Parse(definition);

FluidApiMethod lockMethod = model.Methods.Single(s => s.Name == _lock.Name);
FluidApiMethod unlockMethod = model.Methods.Single(s => s.Name == _unlock.Name);
FluidApiMethod enterMethod = model.Methods.Single(s => s.Name == _enter.Name);
FluidApiMethod exitMethod = model.Methods.Single(s => s.Name == _exit.Name);
FluidApiMethod startMethod = model.Methods.Single(s => s.Name == _start.Name);
FluidApiMethod stopMethod = model.Methods.Single(s => s.Name == _stop.Name);
FluidApiMethod lockMethod = model.Methods.Single(s => s.Name == Lock.Name);
FluidApiMethod unlockMethod = model.Methods.Single(s => s.Name == Unlock.Name);
FluidApiMethod enterMethod = model.Methods.Single(s => s.Name == Enter.Name);
FluidApiMethod exitMethod = model.Methods.Single(s => s.Name == Exit.Name);
FluidApiMethod startMethod = model.Methods.Single(s => s.Name == Start.Name);
FluidApiMethod stopMethod = model.Methods.Single(s => s.Name == Stop.Name);

FluidApiMethod initMethod = model.InitialMethod;
initMethod.Name.ShouldBe(_init.Name);
initMethod.Name.ShouldBe(Init.Name);
model.Methods.ShouldContain(initMethod);

initMethod.CanTransitionTo.ShouldBeEquivalentTo(new HashSet<FluidApiMethod> {unlockMethod});
Expand All @@ -155,6 +166,8 @@ public void CanDeserializeComplexCase()
exitMethod.CanTransitionTo.ShouldBeEquivalentTo(new HashSet<FluidApiMethod> {enterMethod, lockMethod});
startMethod.CanTransitionTo.ShouldBeEquivalentTo(new HashSet<FluidApiMethod> {stopMethod});
stopMethod.CanTransitionTo.ShouldBeEquivalentTo(new HashSet<FluidApiMethod> {startMethod, exitMethod});
}

startMethod.Arguments.First().Name.ShouldBe("speed");
startMethod.Arguments.First().Type.ShouldBe("int");
}
}
Loading

0 comments on commit 9feb062

Please sign in to comment.