public void Serializes_Null_Message_To_Null_Element() { // Arrange var txt = new SensorText(null); // Act var element = txt.ToXElement(); // Assert element.Should().BeNull(); }
public void When_Message_Is_Over_Max_Length_Then_Message_Should_Be_Truncated_With_Elipsis() { // Arrange var messageMoreThanMax = string.Concat(Enumerable.Repeat("x", 2001)); // Act var txt = new SensorText(messageMoreThanMax); // Assert txt.Message.Should().EndWith("x…").And.HaveLength(2000); }
public void When_Message_Is_Max_Length_Then_Message_Should_Be_What_Was_Passed_In() { // Arrange var messageAtMax = string.Concat(Enumerable.Repeat("x", 2000)); // Act var txt = new SensorText(messageAtMax); // Assert txt.Message.Should().EndWith("x").And.HaveLength(2000); }
public void Serializes_Too_Long_Message_To_Text_Element() { // Arrange var txt = new SensorText(string.Concat(Enumerable.Repeat("x", 2001))); // Act var element = txt.ToXElement(); // Assert element.Name.LocalName.Should().Be("text"); element.Value.Should().Be(string.Concat(Enumerable.Repeat("x", 1999)) + "…"); }
public void Serializes_Message_To_Text_Element() { // Arrange var txt = new SensorText("This is my sensor message."); // Act var element = txt.ToXElement(); // Assert element.Name.LocalName.Should().Be("text"); element.Value.Should().Be("This is my sensor message."); }
public void Serializes_Whitespace_Message_To_Matching_Element() { // Arrange var txt = new SensorText(" "); // Act var element = txt.ToXElement(); // Assert element.Name.LocalName.Should().Be("text"); element.Value.Should().Be(" "); }
public void Serializes_Message_Needing_Ecoding_To_Text_Element() { // Arrange var txt = new SensorText("This is my <sensor> & message."); // Act var element = txt.ToXElement(); // Assert element.Name.LocalName.Should().Be("text"); element.Value.Should().Be("This is my <sensor> & message."); element.ToString().Should().Be("<text>This is my <sensor> & message.</text>"); }
public MainPageXaml() { InitializeComponent(); SizeChanged += MainPageXaml_SizeChanged; //Viewのサイズが決まった時のイベント // Motion処理 motion.Start(MotionSensorType.Accelerometer, MotionSensorDelay.Ui); if (motion.IsActive(MotionSensorType.Accelerometer)) { // 現在の位置を取得 nowX = SensorText.X; nowY = SensorText.Y; motion.SensorValueChanged += (object sender, SensorValueChangedEventArgs e) => { Device.BeginInvokeOnMainThread(() => { SensorText.Text = string.Format("X: {0:N4}\nY: {1:N4}", ((MotionVector)e.Value).X, ((MotionVector)e.Value).Y); }); if (Device.OS == TargetPlatform.Android) { moveX = ((MotionVector)e.Value).X * -10; moveY = ((MotionVector)e.Value).Y * 10; } else { moveX = ((MotionVector)e.Value).X * 10; moveY = ((MotionVector)e.Value).Y * -10; } //Debug.WriteLine($"layoutW: {layoutW}, layoutH: {layoutH}"); //Debug.WriteLine($"nowX: {nowX}, nowY: {nowY}"); //Debug.WriteLine($"moveX: {moveX}, moveY: {moveY}"); Device.BeginInvokeOnMainThread(() => { if (nowX + moveX > ((layoutW - textW) / 2) * -1 && nowX + moveX < (layoutW - textW) / 2 && nowY + moveY > ((layoutH - textH) / 2) * -1 && nowY + moveY < (layoutH - textH) / 2) { SensorText.TranslateTo(nowX + moveX, nowY + moveY); nowX = nowX + moveX; nowY = nowY + moveY; } }); }; } }