Пример #1
0
 public InputData(Guid diff, InputPosition position, string data)
 {
     DiffId    = diff;
     Position  = position;
     Data      = data;
     Timestamp = DateTime.UtcNow;
 }
Пример #2
0
            public static AnyValue Convert(IEnumerable <Notification> notifications)
            {
                IList <AnyValue> @out = new List <AnyValue>();

                foreach (Notification notification in notifications)
                {
                    InputPosition   pos             = notification.Position;                // position is optional
                    bool            includePosition = !pos.Equals(InputPosition.empty);
                    int             size            = includePosition ? 5 : 4;
                    MapValueBuilder builder         = new MapValueBuilder(size);

                    builder.Add("code", stringValue(notification.Code));
                    builder.Add("title", stringValue(notification.Title));
                    builder.Add("description", stringValue(notification.Description));
                    builder.Add("severity", stringValue(notification.Severity.ToString()));

                    if (includePosition)
                    {
                        // only add the position if it is not empty
                        builder.Add("position", VirtualValues.map(new string[] { "offset", "line", "column" }, new AnyValue[] { intValue(pos.Offset), intValue(pos.Line), intValue(pos.Column) }));
                    }

                    @out.Add(builder.Build());
                }
                return(VirtualValues.fromList(@out));
            }
Пример #3
0
 /// <summary>
 /// Gets the hash code
 /// </summary>
 /// <returns>Hash code</returns>
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         var hashCode = 41;
         // Suitable nullity checks etc, of course :)
         if (Id != null)
         {
             hashCode = hashCode * 59 + Id.GetHashCode();
         }
         if (Name != null)
         {
             hashCode = hashCode * 59 + Name.GetHashCode();
         }
         if (InputPosition != null)
         {
             hashCode = hashCode * 59 + InputPosition.GetHashCode();
         }
         if (OutputPosition != null)
         {
             hashCode = hashCode * 59 + OutputPosition.GetHashCode();
         }
         if (Zone != null)
         {
             hashCode = hashCode * 59 + Zone.GetHashCode();
         }
         return(hashCode);
     }
 }
Пример #4
0
        private void AssertInputCreatedOnPosition(
            IActionResult response,
            Guid expectedDiffId,
            string data,
            InputPosition expectedPosition,
            Mock <IInputRepository> inputRepository
            )
        {
            // AssertAssert
            var createdResult = Assert.IsType <CreatedResult>(response);
            var result        = Assert.IsType <InputViewModel>(createdResult.Value);

            Assert.NotNull(result);
            Assert.Equal(expectedDiffId, result.DiffId);
            Assert.Equal(Enum.GetName(typeof(InputPosition), expectedPosition), result.Position);

            inputRepository.Verify(v =>
                                   v.AddOneAsync(
                                       It.Is <InputData>(i =>
                                                         i.DiffId == expectedDiffId &&
                                                         i.Data == data
                                                         )
                                       )
                                   );
        }
Пример #5
0
    public void RemoveUpListener(InputPosition toRemove)
    {
        if (_upListeners == null)
		{
            return;
		}
        _upListeners -= toRemove;
    }
Пример #6
0
 public TestNotification(string code, string title, string description, SeverityLevel severityLevel, InputPosition position)
 {
     this._code          = code;
     this._title         = title;
     this._description   = description;
     this._severityLevel = severityLevel;
     this._position      = position != null ? position : InputPosition.empty;
 }
Пример #7
0
    public void RemoveDoubleTapListener(InputPosition toRemove)
    {
        if (_doubleTapListeners == null)
		{
            return;
		}
        _doubleTapListeners -= toRemove;
    }
Пример #8
0
 public void RemoveDragListener(IDragListener listener)
 {
     if(_dragStartListeners != null)
         _dragStartListeners -= listener.OnDragStart;
     if(_dragUpdateListeners != null)
         _dragUpdateListeners -= listener.OnDragUpdate;
     if (_dragEndListeners != null)
         _dragEndListeners -= listener.OnDragEnd;
 }
Пример #9
0
        public void GetOpposingPosition_returns_expected_opposing_position_for_given_position(
            InputPosition position,
            InputPosition expectedOpposingPosition
            )
        {
            var result = _logic.GetOpposingPosition(position);

            Assert.Equal(result, expectedOpposingPosition);
        }
Пример #10
0
 internal InputGroup(object inputIds, InputPosition position, object width, object height, int?rows, int?columns, string layer)
 {
     InputIds = inputIds;
     Position = position;
     Width    = width;
     Height   = height;
     Rows     = rows;
     Columns  = columns;
     Layer    = layer;
 }
Пример #11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotifyWhenUsingCreateUniqueWhenCypherVersionIs3_5()
        public virtual void ShouldNotifyWhenUsingCreateUniqueWhenCypherVersionIs3_5()
        {
            // when
            Result        result   = Db().execute("CYPHER 3.5 MATCH (b) WITH b LIMIT 1 CREATE UNIQUE (b)-[:REL]->()");
            InputPosition position = new InputPosition(36, 1, 37);

            // then
            assertThat(result.Notifications, ContainsItem(_deprecatedCreateUnique));
            result.Close();
        }
Пример #12
0
 public Task <InputData> GetLastInputBeforeAsync(Guid diffId, InputPosition position, DateTime timestamp)
 {
     return(collection
            .Find(input =>
                  input.DiffId == diffId &&
                  input.Position == position &&
                  input.Timestamp <= timestamp
                  )
            .SortByDescending(input => input.Timestamp)
            .FirstOrDefaultAsync());
 }
Пример #13
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotifyWhenUsingCreateUniqueWhenCypherVersionIsDefault()
        public virtual void ShouldNotifyWhenUsingCreateUniqueWhenCypherVersionIsDefault()
        {
            // when
            Result        result   = Db().execute("EXPLAIN MATCH (b) WITH b LIMIT 1 CREATE UNIQUE (b)-[:REL]->()");
            InputPosition position = new InputPosition(33, 1, 34);

            // then
            assertThat(result.Notifications, ContainsNotification(CREATE_UNIQUE_UNAVAILABLE_FALLBACK.notification(position)));
            IDictionary <string, object> arguments = result.ExecutionPlanDescription.Arguments;

            assertThat(arguments["version"], equalTo("CYPHER 3.1"));
            result.Close();
        }
Пример #14
0
        internal virtual void ShouldNotifyInStream(string version, string query, InputPosition pos, NotificationCode code)
        {
            //when
            Result result = Db().execute(version + query);

            //then
            NotificationCode.Notification notification = code.notification(pos);
            assertThat(Iterables.asList(result.Notifications), Matchers.hasItems(notification));
            IDictionary <string, object> arguments = result.ExecutionPlanDescription.Arguments;

            assertThat(arguments["version"], equalTo(version));
            result.Close();
        }
Пример #15
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotifyWhenUsingCypher3_1ForTheRulePlannerWhenCypherVersionIsTheDefault()
        public virtual void ShouldNotifyWhenUsingCypher3_1ForTheRulePlannerWhenCypherVersionIsTheDefault()
        {
            // when
            Result        result   = Db().execute("CYPHER planner=rule RETURN 1");
            InputPosition position = InputPosition.empty;

            // then
            assertThat(result.Notifications, ContainsItem(RulePlannerUnavailable));
            IDictionary <string, object> arguments = result.ExecutionPlanDescription.Arguments;

            assertThat(arguments["version"], equalTo("CYPHER 3.1"));
            assertThat(arguments["planner"], equalTo("RULE"));
            result.Close();
        }
        private static INotification CollectNotification(IDictionary <string, object> notificationDict)
        {
            var code        = notificationDict.GetValue("code", string.Empty);
            var title       = notificationDict.GetValue("title", string.Empty);
            var description = notificationDict.GetValue("description", string.Empty);
            var posValue    = notificationDict.GetValue("position", new Dictionary <string, object>());
            var position    = new InputPosition(
                (int)posValue.GetValue("offset", 0L),
                (int)posValue.GetValue("line", 0L),
                (int)posValue.GetValue("column", 0L));
            var severity = notificationDict.GetValue("severity", string.Empty);

            return(new Notification(code, title, description, position, severity));
        }
Пример #17
0
 private static object[] NewExpectedResult(
     string inputData,
     string opposingData,
     ResultType expectedResult,
     IDictionary <int, int> expectedDifferences = null,
     InputPosition inputPosition    = InputPosition.Left,
     InputPosition opposingPosition = InputPosition.Right
     )
 => new object[]
 {
     new InputData(inputPosition, inputData),
     new InputData(opposingPosition, opposingData),
     new DiffResult(expectedResult, expectedDifferences)
 };
Пример #18
0
        public void CompareData_returns_expected_result_no_matter_input_position(
            InputPosition largerInputPosition,
            InputPosition smallerInputPosition,
            ResultType expectedResult)
        {
            var input = new InputData()
            {
                Data = "aaa", Position = largerInputPosition
            };
            var opposingInput = new InputData {
                Data = "a", Position = smallerInputPosition
            };

            var result = _logic.CompareData(input, opposingInput);

            Assert.Equal(result.Result, expectedResult);
        }
Пример #19
0
        public void Handle_consider_input_larger_if_no_opposing_input_found(InputPosition position, ResultType expectedResultType)
        {
            // Arrange
            var input          = new InputData(position, "test");
            var expectedResult = new DiffResult(expectedResultType, null);
            var resultEvent    = new NewResultIntegrationEvent(input, string.Empty, expectedResult);
            var newInputEvent  = new NewInputIntegrationEvent()
            {
                Position = input.Position
            };

            var eventBus = new Mock <IRabbitMQEventBus>();

            var logic = new Mock <IDiffLogic>();

            logic.Setup(s => s.CompareData(It.IsAny <InputData>(), It.IsAny <InputData>()))
            .Returns(expectedResult);

            var repository = new Mock <IInputRepository>();

            repository
            .Setup(s => s.FindAsync(It.IsAny <string>()))
            .ReturnsAsync(() => input);

            repository
            .Setup(s => s.GetLastInputBeforeAsync(It.IsAny <Guid>(), It.IsAny <InputPosition>(), It.IsAny <DateTime>()))
            .ReturnsAsync(() => null);

            var handler = GetHandler(
                eventBus: eventBus,
                repository: repository,
                logic: logic.Object
                );

            // Act
            handler.Handle(newInputEvent);

            // Assert
            eventBus.Verify(
                eb => eb.Publish(
                    It.Is <NewResultIntegrationEvent>(e => e.Result == expectedResult.Result)
                    )
                );
        }
Пример #20
0
        private void AssertNewInputIntegrationEventPublished(
            IActionResult response,
            Guid expectedDiffId,
            InputPosition expectedPosition,
            Mock <IRabbitMQEventBus> eventBus
            )
        {
            var createdResult = Assert.IsType <CreatedResult>(response);
            var result        = Assert.IsType <InputViewModel>(createdResult.Value);

            eventBus.Verify(eb =>
                            eb.Publish(It.Is <NewInputIntegrationEvent>(ie =>
                                                                        ie.DiffId == expectedDiffId.ToString() &&
                                                                        ie.Position == expectedPosition &&
                                                                        ie.InputId == result.Id &&
                                                                        ie.Timestamp == result.Timestamp
                                                                        ))
                            );
        }
Пример #21
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") public static org.neo4j.graphdb.Notification fromMap(java.util.Map<String,Object> notification)
        public static Notification FromMap(IDictionary <string, object> notification)
        {
            assertThat(notification, hasKey("code"));
            assertThat(notification, hasKey("title"));
            assertThat(notification, hasKey("description"));
            assertThat(notification, hasKey("severity"));
            InputPosition position = null;

            if (notification.ContainsKey("position"))
            {
                IDictionary <string, long> pos = (IDictionary <string, long>)notification["position"];
                assertThat(pos, hasKey("offset"));
                assertThat(pos, hasKey("line"));
                assertThat(pos, hasKey("column"));
                position = new InputPosition(pos["offset"].intValue(), pos["line"].intValue(), pos["column"].intValue());
            }

            return(new TestNotification(( string )notification["code"], ( string )notification["title"], ( string )notification["description"], Enum.Parse(typeof(SeverityLevel), ( string )notification["severity"]), position));
        }
Пример #22
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void writePosition(org.neo4j.graphdb.InputPosition position) throws java.io.IOException
        private void WritePosition(InputPosition position)
        {
            //do not add position if empty
            if (position == InputPosition.empty)
            {
                return;
            }

            @out.writeObjectFieldStart("position");
            try
            {
                @out.writeNumberField("offset", position.Offset);
                @out.writeNumberField("line", position.Line);
                @out.writeNumberField("column", position.Column);
            }
            finally
            {
                @out.writeEndObject();
            }
        }
Пример #23
0
        /// <summary>
        /// Returns true if TemperatureZone instances are equal
        /// </summary>
        /// <param name="other">Instance of TemperatureZone to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(TemperatureZone other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Id == other.Id ||
                     Id != null &&
                     Id.Equals(other.Id)
                     ) &&
                 (
                     Name == other.Name ||
                     Name != null &&
                     Name.Equals(other.Name)
                 ) &&
                 (
                     InputPosition == other.InputPosition ||
                     InputPosition != null &&
                     InputPosition.Equals(other.InputPosition)
                 ) &&
                 (
                     OutputPosition == other.OutputPosition ||
                     OutputPosition != null &&
                     OutputPosition.Equals(other.OutputPosition)
                 ) &&
                 (
                     Zone == other.Zone ||
                     Zone != null &&
                     Zone.Equals(other.Zone)
                 ));
        }
Пример #24
0
        public override bool Equals(object o)
        {
            if (this == o)
            {
                return(true);
            }
            if (o == null || this.GetType() != o.GetType())
            {
                return(false);
            }

            InputPosition that = ( InputPosition )o;

            if (_offset != that._offset)
            {
                return(false);
            }
            if (_line != that._line)
            {
                return(false);
            }
            return(_column == that._column);
        }
Пример #25
0
 public InputData(InputPosition position, string data)
 {
     Position = position;
     Data     = data;
 }
Пример #26
0
 public void AddDragListener(IDragListener listener)
 {
     _dragStartListeners += listener.OnDragStart;
     _dragUpdateListeners += listener.OnDragUpdate;
     _dragEndListeners += listener.OnDragEnd;
 }
Пример #27
0
        internal static InputGroup DeserializeInputGroup(JsonElement element)
        {
            object inputIds = default;
            Optional <InputPosition> position = default;
            Optional <object>        width    = default;
            Optional <object>        height   = default;
            Optional <int>           rows     = default;
            Optional <int>           columns  = default;
            Optional <string>        layer    = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("inputIds"))
                {
                    inputIds = property.Value.GetObject();
                    continue;
                }
                if (property.NameEquals("position"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    position = InputPosition.DeserializeInputPosition(property.Value);
                    continue;
                }
                if (property.NameEquals("width"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    width = property.Value.GetObject();
                    continue;
                }
                if (property.NameEquals("height"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    height = property.Value.GetObject();
                    continue;
                }
                if (property.NameEquals("rows"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    rows = property.Value.GetInt32();
                    continue;
                }
                if (property.NameEquals("columns"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    columns = property.Value.GetInt32();
                    continue;
                }
                if (property.NameEquals("layer"))
                {
                    layer = property.Value.GetString();
                    continue;
                }
            }
            return(new InputGroup(inputIds, position.Value, width.Value, height.Value, Optional.ToNullable(rows), Optional.ToNullable(columns), layer.Value));
        }
Пример #28
0
 public override int GetHashCode() =>
 Production.GetHashCode() + DotPosition.GetHashCode() * 17 + InputPosition.GetHashCode() * 31;
Пример #29
0
        private async Task <IActionResult> HandlePostInputRequest(Guid diffId, NewInputViewModel input, InputPosition position)
        {
            if (!ModelState.IsValid)
            {
                _logger.LogWarning($"Post{Enum.GetName(typeof(InputPosition), position)}({diffId}) failed validation");

                return(BadRequest(ModelState));
            }

            _logger.LogInformation($"Find({diffId}): retrieving item on repository");

            var diff = await _diffRepository.FindAsync(_ => _.UUID == diffId);

            if (diff == null)
            {
                _logger.LogWarning($"Find({diffId}): item not found on repository");

                return(NotFound(new ResourceNotFoundForIdResultMessage <Diff>(diffId)));
            }

            var newInput = new InputData(diffId, position, input.Data);

            _logger.LogInformation($"Save({diffId}, Diff obj): saving item on repository");

            await _inputRepository.AddOneAsync(newInput);

            _logger.LogInformation($"Save({diffId}, Diff obj): saving item on repository");

            var eventMessage = new NewInputIntegrationEvent(newInput);

            _logger.LogInformation($"Input registered, sending integration event ({eventMessage.Id})");

            _eventBus.Publish(eventMessage);

            _logger.LogInformation($"Integration event ({eventMessage.Id}) sent!");

            var viewModel = _mapper.Map <InputViewModel>(newInput);

            return(Created(newInput.Id, viewModel));
        }
        private async Task AssertInputCreatedOnDiffPosition(HttpResponseMessage response, Guid diffId, InputPosition position)
        {
            var strInputContent = await response.Content.ReadAsStringAsync();

            var inputResult = JsonConvert.DeserializeObject <InputViewModel>(strInputContent);

            // Assert
            Assert.Equal(HttpStatusCode.Created, response.StatusCode);
            Assert.NotNull(inputResult);
            Assert.Equal(diffId, inputResult.DiffId);
            Assert.Equal(Enum.GetName(typeof(InputPosition), position), inputResult.Position);
            Assert.NotEqual(default(DateTime), inputResult.Timestamp);
        }