public void InsertDeviceCommand(Guid deviceGuid, JObject command) { if (deviceGuid == Guid.Empty) { throw new WebSocketRequestException("Please specify valid deviceGuid"); } if (command == null) { throw new WebSocketRequestException("Please specify command"); } var device = DataContext.Device.Get(deviceGuid); if (device == null || !IsNetworkAccessible(device.NetworkID)) { throw new WebSocketRequestException("Device not found"); } var commandEntity = CommandMapper.Map(command); commandEntity.Device = device; commandEntity.UserID = CurrentUser.ID; Validate(commandEntity); DataContext.DeviceCommand.Save(commandEntity); _commandSubscriptionManager.Subscribe(Connection, commandEntity.ID); _messageBus.Notify(new DeviceCommandAddedMessage(device.ID, commandEntity.ID)); command = CommandMapper.Map(commandEntity); SendResponse(new JProperty("command", command)); }
public void UpdateDeviceCommand(int commandId, JObject command) { if (commandId == 0) { throw new WebSocketRequestException("Please specify valid commandId"); } if (command == null) { throw new WebSocketRequestException("Please specify command"); } var commandEntity = DataContext.DeviceCommand.Get(commandId); if (commandEntity == null || commandEntity.DeviceID != CurrentDevice.ID) { throw new WebSocketRequestException("Device command not found"); } CommandMapper.Apply(commandEntity, command); commandEntity.Device = CurrentDevice; Validate(commandEntity); DataContext.DeviceCommand.Save(commandEntity); _messageBus.Notify(new DeviceCommandUpdatedMessage(CurrentDevice.ID, commandEntity.ID)); command = CommandMapper.Map(commandEntity); SendResponse(new JProperty("command", command)); }
public void HandleCommandUpdate(int commandId) { var command = DataContext.DeviceCommand.Get(commandId); var connections = _commandSubscriptionManager.GetConnections(commandId); foreach (var connection in connections) { connection.SendResponse("command/update", new JProperty("command", CommandMapper.Map(command))); } }
public void GivenValidSetPlateuSizeCommand_MapShouldReturnCorrectSizeAndCorrectCommandType (string commandText, int expectedWidth, int expectedHeight, [Frozen] Mock <ICommandTypeInterpreter> interpreter, [Frozen] Mock <ICommandFactory> factory, [Frozen] Mock <ISetPlateuSizeCommand> expectedCommand, CommandMapper sut) { expectedCommand.Setup(x => x.Size).Returns(new Size(expectedWidth, expectedHeight)); interpreter.Setup(x => x.GetCommandType(It.IsAny <string>())).Returns(CommandType.SetPlateauSize); factory.Setup(x => x.CreateSetPlateuSizeCommand(It.Is <Size>(p => p.Height == expectedHeight && p.Width == expectedWidth))) .Returns(expectedCommand.Object); ISetPlateuSizeCommand actual = (ISetPlateuSizeCommand)sut.Map(commandText).First(); actual.Should().BeEquivalentTo(expectedCommand.Object); }
public void GivenValidMovementCommand_MapShouldReturnExpectedCommand (string commandText, IList <Movement> expectedMovements, [Frozen] Mock <ICommandTypeInterpreter> interpreter, [Frozen] Mock <ICommandFactory> factory, [Frozen] Mock <IMovementCommand> expectedCommand, CommandMapper sut) { expectedCommand.Setup(x => x.Movements).Returns(expectedMovements); expectedCommand.Setup(x => x.CommandType).Returns(CommandType.Move); interpreter.Setup(x => x.GetCommandType(It.IsAny <string>())).Returns(CommandType.Move); factory.Setup(x => x.CreateMovementCommand(It.Is <IList <Movement> >(p => p.SequenceEqual(expectedMovements)))).Returns(expectedCommand.Object); var actual = (IMovementCommand)sut.Map(commandText).First(); actual.Should().BeEquivalentTo(expectedCommand.Object); }
public void GivenValidLandingCommand_MapShouldReturnCorrectCommand (string commandText, int expectedXCoordinate, int expectedYCoordinate, Direction expectedDirection, [Frozen] Mock <ICommandTypeInterpreter> interpreter, [Frozen] Mock <ICommandFactory> factory, [Frozen] Mock <ILandingCommand> expectedCommand, CommandMapper sut) { expectedCommand.Setup(x => x.Location).Returns(new Location(expectedXCoordinate, expectedYCoordinate)); expectedCommand.Setup(x => x.Direction).Returns(expectedDirection); interpreter.Setup(x => x.GetCommandType(It.IsAny <string>())).Returns(CommandType.Land); factory.Setup(x => x.CreateLandingCommand(It.Is <Location>(p => p.X == expectedXCoordinate && p.Y == expectedYCoordinate), It.Is <Direction>(p => p == expectedDirection))) .Returns(expectedCommand.Object); var actual = (ILandingCommand)sut.Map(commandText).First(); actual.Should().BeEquivalentTo(expectedCommand.Object); }
public async Task <ActionResult> Post(AddProductToOrderViewModel model) { var productsResponse = await GetAsync(HttpClients.ProductApi, "products"); var products = await productsResponse.ResultAsync <IEnumerable <ProductViewModel> >(); var command = CommandMapper.Map <AddProductToOrder>(model); command.Price = products.First(p => p.Sku == command.Sku).Price; command.UserId = Constants.DefaultUserId; await Bus.Send(command); return(Accepted()); }
public void EnsureCommandIsMappedCorrectlyEvenIfNoNameIsSpecified() { var applicationArgs = new CommandsWithoutName(); var dictionary = new Dictionary <string, CommandLineArgument> { { "Execute", new CommandLineArgument { Name = "Execute" } }, }; var commandMapper = new CommandMapper <CommandsWithoutName>(Setup.EngineFactory().Done()); var result = commandMapper.Map(dictionary, applicationArgs); result.Execute.Should().NotBeNull(); }
public void EnsureCommandIsParsedCorrectly() { var applicationArgs = new ApplicationArgs(); var dictionary = new Dictionary <string, CommandLineArgument> { { "execute", new CommandLineArgument { Name = "execute" } }, { "path", new CommandLineArgument { Name = "path", Value = "C:\\temp" } } }; var commandMapper = new CommandMapper <ApplicationArgs>(Setup.EngineFactory().Done()); var result = commandMapper.Map(dictionary, applicationArgs); result.Execute.Should().NotBeNull(); }
public void EnsureEventIsRaisedWhenHelpCommandIsMapped() { var applicationArgs = new CommandsWithName(); var commandLineArgument = new CommandLineArgument { Name = "?" }; var dictionary = new Dictionary <string, CommandLineArgument> { { "?", commandLineArgument } }; var commandMapper = new CommandMapper <CommandsWithName>(Setup.EngineFactory().Done()); commandMapper.MonitorEvents(); var result = commandMapper.Map(dictionary, applicationArgs); result.Help.Should().NotBeNull(); commandMapper.ShouldRaise(nameof(CommandMapper <CommandsWithName> .MappedCommandLineArgument)) .WithArgs <MapperEventArgs>(args => args.Argument == commandLineArgument); }
public void MappingTest(string commandLineArguments, ResultState expectedResult, string firstArgumentValue, ParserNotation notation) { // Setup var parser = new CommandParser(notation); var args = parser.Parse(commandLineArguments); var configuration = new CommandConfiguration(); configuration.CommandAssemblies.Add(Assembly.GetExecutingAssembly()); var lookup = new CommandLookup(configuration); var command = lookup.GetCommand(args.First().Key); Assert.NotNull(args); Assert.NotNull(command); // Test var target = new CommandMapper(); var result = target.Map(args.Skip(1), command.Arguments); // Assert Assert.NotNull(result); Assert.True(result.State == expectedResult); Assert.True(firstArgumentValue == null || firstArgumentValue == result?.ResultArguments?.First().ToString()); }
public void EnsureEventIsRaisedWhenCommandIsMapped() { var applicationArgs = new CommandsWithName(); var commandLineArgument = new CommandLineArgument { Name = "name" }; var property = typeof(CommandsWithName).GetProperty(nameof(CommandsWithName.Execute)); var dictionary = new Dictionary <string, CommandLineArgument> { { commandLineArgument.Name, commandLineArgument } }; var commandMapper = new CommandMapper <CommandsWithName>(Setup.EngineFactory().Done()); commandMapper.MonitorEvents(); var result = commandMapper.Map(dictionary, applicationArgs); result.Execute.Should().NotBeNull(); commandMapper.ShouldRaise(nameof(CommandMapper <CommandsWithName> .MappedCommandLineArgument)) .WithArgs <MapperEventArgs>(args => args.Argument == commandLineArgument) .WithArgs <MapperEventArgs>(args => args.PropertyInfo == property); }
[InlineData("dummysearch -take=10 -language=de", ResultState.MissingArguments, null, ParserNotation.Unix)] // check required arguments public void MappingTest(string commandLineArguments, ResultState expectedResult, string firstArgumentValue, ParserNotation notation) { // Setup var parser = new CommandParser(notation); var args = parser.Parse(commandLineArguments); var configuration = new CommandConfiguration(); configuration.CommandAssemblies.Add(Assembly.GetExecutingAssembly()); var lookup = new CommandLookup(configuration); var command = lookup.GetCommand(args.First().Key); Assert.NotNull(args); Assert.NotNull(command); // Test var target = new CommandMapper(); var result = target.Map(args.Skip(1), command.Arguments); // Assert Assert.NotNull(result); Assert.True(result.State == expectedResult); Assert.True(firstArgumentValue == null || firstArgumentValue == result?.ResultArguments?.First().ToString()); }
static void Main(string[] args) { if (args.Length == 0) { PrintUsage(); return; } var mapper = new CommandMapper(Console.Out); var action = mapper.Map(args); try { var task = action.Invoke(); task.Wait(); } catch (AggregateException ex) { Console.WriteLine(ex.Message); foreach (var exi in ex.InnerExceptions) { Console.WriteLine("- " + exi.Message); #if DEBUG Console.WriteLine("- " + exi.StackTrace); #endif } } catch (Exception ex) { Console.WriteLine(ex.Message); } #if DEBUG Console.ReadKey(); #endif }
public List <CommandDTO> FindByName(string Name) { return(this.FindByNameEntity(Name).Select(obj => CommandMapper.Map(obj)).ToList()); }
public List <CommandDTO> FindByCountry(string Country) { return(this.FindByCountryEntity(Country).Select(obj => CommandMapper.Map(obj)).ToList()); }
private void Notify(WebSocketConnectionBase connection, Device device, DeviceCommand command) { connection.SendResponse("command/insert", new JProperty("deviceGuid", device.GUID), new JProperty("command", CommandMapper.Map(command))); }
public CommandDTO Get(int CommandID) { return(CommandMapper.Map(this.GetEntity(CommandID))); }
public List <CommandDTO> List() { return(this.ListEntities().Select(obj => CommandMapper.Map(obj)).ToList()); }