예제 #1
0
        public void Character_can_be_spawned_if_it_has_no_location()
        {
            // Arrange
            var characterId = Guid.NewGuid();
            var characterLocationRepository = new Mock <ICharacterLocationRepository>();

            characterLocationRepository
            .Setup(r => r.GetByCharacterIdAsync(
                       It.Is <Guid>(id => id == characterId),
                       It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <CharacterLocation>(null));

            var singleLocationPerCharacterChecker = new SingleLocationPerCharacterChecker(characterLocationRepository.Object);

            // Act
            var character = CharacterLocation.Create(
                characterId,
                0,
                0,
                singleLocationPerCharacterChecker
                );

            // Assert
            AssertPublishedDomainEvent <CharacterMovedEvent>(character);
        }
예제 #2
0
 /// <summary>
 ///		Creates a new Token Pair
 /// </summary>
 public TokenPair(IComparable type,
                  CharacterLocation tokenLocation,
                  IMorestachioExpression expression,
                  EmbeddedInstructionOrigin isEmbeddedToken = EmbeddedInstructionOrigin.Self)
     : this(type, null, tokenLocation, expression, null, isEmbeddedToken)
 {
 }
예제 #3
0
        private static CharacterLocation HumanizeCharacterLocation(string content, int characterIndex, ref int[] lines)
        {
            if (lines == null)
            {
                lines = _newlineFinder.Matches(content).OfType <Match>().Select(k => k.Index).ToArray();
            }
            var line = Array.BinarySearch(lines, characterIndex);

            line = line < 0 ? ~line : line;

            var charIdx = characterIndex;

            //in both of these cases, we want to increment the char index by one to account for the '\n' that is skipped in the indexes.
            if (line < lines.Length && line > 0)
            {
                charIdx = characterIndex - (lines[line - 1] + 1);
            }
            else if (line > 0)
            {
                charIdx = characterIndex - (lines.LastOrDefault() + 1);
            }

            var retval = new CharacterLocation
            {
                //Humans count from 1, so let's do that, too (hence the "++" on these).
                Line      = line + 1,
                Character = charIdx + 1
            };

            return(retval);
        }
 /// <inheritdoc />
 public BlockDocumentItem(CharacterLocation location,
                          BlockDocumentProviderFunction action,
                          string value,
                          IEnumerable <ITokenOption> tagCreationOptions) : base(location, value, tagCreationOptions)
 {
     _action = action;
 }
예제 #5
0
        public void Character_cannot_be_spawned_if_it_has_a_location()
        {
            // Arrange
            var characterId = Guid.NewGuid();
            var characterLocationRepository       = new Mock <ICharacterLocationRepository>();
            var singleLocationPerCharacterChecker = new SingleLocationPerCharacterChecker(characterLocationRepository.Object);

            var existingCharacterLocation = CharacterLocation.Create(
                characterId,
                0,
                0,
                singleLocationPerCharacterChecker
                );

            characterLocationRepository
            .Setup(r => r.GetByCharacterIdAsync(
                       It.Is <Guid>(id => id == characterId),
                       It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(existingCharacterLocation));

            // Assert
            AssertBrokenRule <CharacterCanOnlyHaveOneLocation>(() =>
            {
                // Act
                CharacterLocation.Create(
                    characterId,
                    0,
                    0,
                    singleLocationPerCharacterChecker);
            });
        }
예제 #6
0
 /// <summary>
 /// </summary>
 /// <param name="info"></param>
 /// <param name="context"></param>
 protected ExpressionArgument(SerializationInfo info, StreamingContext context)
 {
     Name = info.GetString(nameof(Name));
     MorestachioExpression =
         info.GetValue(nameof(MorestachioExpression), typeof(IMorestachioExpression)) as IMorestachioExpression;
     Location = CharacterLocation.FromFormatString(info.GetString(nameof(Location)));
 }
예제 #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PartialDocumentItem"/> class.
 /// </summary>
 /// <param name="partialName">The partial name.</param>
 public PartialDocumentItem(CharacterLocation location,
                            string partialName,
                            IEnumerable <ITokenOption> tagCreationOptions)
     : base(location, tagCreationOptions)
 {
     PartialName = partialName;
 }
예제 #8
0
 /// <summary>
 ///		Creates a new Token Pair
 /// </summary>
 public TokenPair(IComparable type,
                  string value,
                  CharacterLocation tokenLocation,
                  EmbeddedInstructionOrigin isEmbeddedToken = EmbeddedInstructionOrigin.Self)
     : this(type, value, tokenLocation, null, null, isEmbeddedToken)
 {
 }
예제 #9
0
 public StringToken(string value, char delimiter, CharacterLocation location)
 {
     TokenType = ExpressionTokenType.String;
     Value     = value;
     Delimiter = delimiter;
     Location  = location;
 }
        public async Task <IActionResult> Edit(int id, [Bind("Id,CharacterId,MapId,PositionX,PositionY")] CharacterLocation characterLocation)
        {
            if (id != characterLocation.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(characterLocation);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CharacterLocationExists(characterLocation.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CharacterId"] = new SelectList(_context.Characters, "Id", "Name", characterLocation.CharacterId);
            ViewData["MapId"]       = new SelectList(_context.Maps, "Id", "Name", characterLocation.MapId);
            return(View(characterLocation));
        }
예제 #11
0
 /// <inheritdoc />
 public IsolationScopeDocumentItem(CharacterLocation location, IsolationOptions isolationOptions,
                                   IMorestachioExpression morestachioExpression,
                                   IEnumerable <ITokenOption> tagCreationOptions) : base(location, tagCreationOptions)
 {
     Isolation = isolationOptions;
     ScopeIsolationExpression = morestachioExpression;
 }
예제 #12
0
 /// <summary>
 ///		Creates a new Alias DocumentItem
 /// </summary>
 /// <param name="value">The name of the Alias</param>
 /// <param name="variableScope">The Scope id generated by the parser to determinate when to clean this variable</param>
 public AliasDocumentItem(CharacterLocation location,
                          string value,
                          int variableScope,
                          IEnumerable <ITokenOption> tagCreationOptions) : base(location, value, tagCreationOptions)
 {
     IdVariableScope = variableScope;
 }
 /// <summary>
 ///		Creates a new global Variable
 /// </summary>
 /// <param name="value"></param>
 /// <param name="morestachioExpression"></param>
 public EvaluateVariableDocumentItem(CharacterLocation location, string value, IMorestachioExpression morestachioExpression,
                                     IEnumerable <ITokenOption> tagCreationOptions)
     : base(location, morestachioExpression, tagCreationOptions)
 {
     Value           = value;
     IdVariableScope = 0;
 }
예제 #14
0
 /// <inheritdoc />
 public IfExpressionScopeDocumentItem(CharacterLocation location, IMorestachioExpression value,
                                      IEnumerable <ITokenOption> tagCreationOptions,
                                      bool inverted)
     : base(location, value, tagCreationOptions)
 {
     Inverted = inverted;
 }
 /// <summary>
 ///		Creates an new Variable that expires when its enclosing scope (<see cref="IdVariableScope"/>) is closed
 /// </summary>
 /// <param name="value"></param>
 /// <param name="morestachioExpression"></param>
 /// <param name="idVariableScope"></param>
 public EvaluateLetVariableDocumentItem(CharacterLocation location,
                                        string value,
                                        IMorestachioExpression morestachioExpression,
                                        int idVariableScope,
                                        IEnumerable <ITokenOption> tagCreationOptions)
     : base(location, value, morestachioExpression, idVariableScope, tagCreationOptions)
 {
 }
예제 #16
0
 /// <inheritdoc />
 public MorestachioLocalizationDocumentItem(CharacterLocation location,
                                            IMorestachioExpression value,
                                            IMorestachioExpression explicitCulture,
                                            IEnumerable <ITokenOption> tagCreationOptions) : base(location, tagCreationOptions)
 {
     ExplicitCulture       = explicitCulture;
     MorestachioExpression = value;
 }
 /// <inheritdoc />
 public ImportPartialDocumentItem(CharacterLocation location,
                                  IMorestachioExpression value,
                                  IMorestachioExpression context,
                                  IEnumerable <ITokenOption> tagCreationOptions)
     : base(location, value, tagCreationOptions)
 {
     Context = context;
 }
예제 #18
0
 /// <inheritdoc />
 public SwitchDocumentItem(CharacterLocation location,
                           IMorestachioExpression value,
                           bool shouldScopeToValue,
                           IEnumerable <ITokenOption> tagCreationOptions)
     : base(location, value, tagCreationOptions)
 {
     ScopeToValue = shouldScopeToValue;
 }
예제 #19
0
 /// <summary>
 ///		Serialization constructor
 /// </summary>
 /// <param name="info"></param>
 /// <param name="context"></param>
 protected MorestachioExpression(SerializationInfo info, StreamingContext context)
 {
     PathParts = new Traversable(info.GetValue(nameof(PathParts), typeof(KeyValuePair <string, PathType>[])) as KeyValuePair <string, PathType>[]);
     Formats   = info.GetValue(nameof(Formats), typeof(IList <ExpressionArgument>))
                 as IList <ExpressionArgument>;
     FormatterName     = info.GetString(nameof(FormatterName));
     Location          = CharacterLocation.FromFormatString(info.GetString(nameof(Location)));
     EndsWithDelimiter = info.GetBoolean(nameof(EndsWithDelimiter));
 }
예제 #20
0
 protected MorestachioExpression(SerializationInfo info, StreamingContext context)
 {
     PathParts = info.GetValue(nameof(PathParts), typeof(IList <KeyValuePair <string, PathType> >))
                 as IList <KeyValuePair <string, PathType> >;
     Formats = info.GetValue(nameof(Formats), typeof(IList <ExpressionArgument>))
               as IList <ExpressionArgument>;
     FormatterName = info.GetString(nameof(FormatterName));
     Location      = CharacterLocation.FromFormatString(info.GetString(nameof(Location)));
 }
예제 #21
0
 /// <summary>
 ///		Creates a new Token Pair
 /// </summary>
 public TokenPair(IComparable type, string value, CharacterLocation tokenLocation,
                  IMorestachioExpression expression, ScopingBehavior?noScope = null)
 {
     Type = type;
     MorestachioExpression = expression;
     TokenLocation         = tokenLocation;
     ScopeBehavior         = noScope;
     Value = value;
 }
예제 #22
0
 public static CharacterLocationDto FromCharacterLocation([NotNull] CharacterLocation characterLocation)
 {
     return(new()
     {
         CharacterId = characterLocation.CharacterId,
         X = characterLocation.X,
         Y = characterLocation.Y
     });
 }
예제 #23
0
        /// <inheritdoc />
        public void ReadXml(XmlReader reader)
        {
            Location          = CharacterLocation.FromFormatString(reader.GetAttribute(nameof(Location)));
            EndsWithDelimiter = reader.GetAttribute(nameof(EndsWithDelimiter)) == bool.TrueString;
            var pathParts = new List <KeyValuePair <string, PathType> >();

            reader.ReadStartElement();            //Path

            if (reader.Name == "Path")
            {
                reader.ReadStartElement();                //Any SubPath

                while (reader.Name != "Path" && reader.NodeType != XmlNodeType.EndElement)
                {
                    var    partName  = reader.Name;
                    string partValue = null;
                    if (reader.IsEmptyElement)
                    {
                        reader.ReadStartElement();
                    }
                    else
                    {
                        partValue = reader.ReadElementContentAsString();
                    }
                    pathParts.Add(new KeyValuePair <string, PathType>(partValue, (PathType)Enum.Parse(typeof(PathType), partName)));
                }
                reader.ReadEndElement();                //</Path>
            }
            PathParts = new Traversable(pathParts);
            if (reader.Name == "Format" && reader.NodeType == XmlNodeType.Element)
            {
                FormatterName = reader.GetAttribute(nameof(FormatterName));
                if (reader.IsEmptyElement)
                {
                    reader.ReadStartElement();
                }
                else
                {
                    reader.ReadStartElement();                     //<Argument>
                    while (reader.Name == "Argument" && reader.NodeType != XmlNodeType.EndElement)
                    {
                        var formatSubTree = reader.ReadSubtree();
                        formatSubTree.Read();

                        var expressionArgument = new ExpressionArgument();
                        Formats.Add(expressionArgument);

                        expressionArgument.ReadXml(formatSubTree);

                        reader.Skip();
                        reader.ReadEndElement();
                    }
                    reader.ReadEndElement();                    //</Format>
                }
            }
            reader.ReadEndElement();
        }
예제 #24
0
 /// <summary>
 ///
 /// </summary>
 public TextEditDocumentItem(CharacterLocation location,
                             ITextOperation operation,
                             EmbeddedInstructionOrigin embeddedInstructionOrigin,
                             IEnumerable <ITokenOption> tagCreationOptions)
     : base(location, tagCreationOptions)
 {
     Operation = operation ?? throw new ArgumentNullException(nameof(operation));
     EmbeddedInstructionOrigin = embeddedInstructionOrigin;
 }
예제 #25
0
 /// <inheritdoc />
 public TagDocumentItem(CharacterLocation location,
                        TagDocumentProviderFunction action,
                        string tagKeyword,
                        string value,
                        IEnumerable <ITokenOption> tagCreationOptions) : base(location, value, tagCreationOptions)
 {
     _action    = action;
     TagKeyword = tagKeyword;
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="info"></param>
        /// <param name="context"></param>
        protected MorestachioOperatorExpression(SerializationInfo info, StreamingContext context)
        {
            Location = CharacterLocation.FromFormatString(info.GetString(nameof(Location)));
            var opText = info.GetString(nameof(Operator));

            Operator       = MorestachioOperator.Yield().First(f => f.OperatorText.Equals(opText));
            LeftExpression =
                info.GetValue(nameof(LeftExpression), typeof(IMorestachioExpression)) as IMorestachioExpression;
            RightExpression =
                info.GetValue(nameof(RightExpression), typeof(IMorestachioExpression)) as IMorestachioExpression;
        }
        public async Task <CharacterLocationDto> Handle(SpawnCharacterCommand request, CancellationToken cancellationToken)
        {
            var random            = new Random(SystemClock.Now.Millisecond);
            var characterLocation = CharacterLocation.Create(request.CharacterId, random.Next(-2, 2), random.Next(-2, 2), _singleLocationPerCharacterChecker);

            await _characterLocationRepository.AddAsync(characterLocation, cancellationToken);

            await _unitOfWork.CommitAsync(cancellationToken);

            return(CharacterLocationDto.FromCharacterLocation(characterLocation));
        }
예제 #28
0
        /// <inheritdoc />
        public void ReadXml(XmlReader reader)
        {
            Location = CharacterLocation.FromFormatString(reader.GetAttribute(nameof(Location)));
            Name     = reader.GetAttribute(nameof(Name));
            reader.ReadStartElement();

            var expSubtree = reader.ReadSubtree();

            expSubtree.Read();
            MorestachioExpression = expSubtree.ParseExpressionFromKind();
        }
예제 #29
0
        protected DocumentItemBase(SerializationInfo info, StreamingContext c)
        {
            var documentItemBases = info.GetValue(nameof(Children), typeof(IDocumentItem[])) as IDocumentItem[];

            Children = new List <IDocumentItem>(documentItemBases ?? throw new InvalidOperationException());
            var expStartLocation = info.GetString(nameof(ExpressionStart));

            if (!string.IsNullOrWhiteSpace(expStartLocation))
            {
                ExpressionStart = CharacterLocation.FromFormatString(expStartLocation);
            }
        }
예제 #30
0
        protected DocumentItemBase(SerializationInfo info, StreamingContext c)
        {
            var expStartLocation = info.GetString(nameof(ExpressionStart));

            if (!string.IsNullOrWhiteSpace(expStartLocation))
            {
                ExpressionStart = CharacterLocation.FromFormatString(expStartLocation);
            }

            TagCreationOptions =
                info.GetValue(nameof(TagCreationOptions), typeof(IEnumerable <ITokenOption>)) as IEnumerable <ITokenOption>;
        }
예제 #31
0
        private static CharacterLocation HumanizeCharacterLocation(string content, int characterIndex, ref int[] lines)
        {
            if (lines == null)
            {
                lines = _newlineFinder.Matches(content).OfType<Match>().Select(k => k.Index).ToArray();
            }
            var line = Array.BinarySearch(lines, characterIndex);
            line = line < 0 ? ~line : line;

            var charIdx = characterIndex;
            //in both of these cases, we want to increment the char index by one to account for the '\n' that is skipped in the indexes.
            if (line < lines.Length && line > 0)
            {
                charIdx = characterIndex - (lines[line - 1] + 1);
            }
            else if (line > 0)
            {
                charIdx = characterIndex - (lines.LastOrDefault() + 1);
            }

            var retval = new CharacterLocation
            {
                //Humans count from 1, so let's do that, too (hence the "++" on these).
                Line = line + 1,
                Character = charIdx + 1
            };
            return retval;
        }