-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Issue2104.cs
129 lines (109 loc) · 3.25 KB
/
Issue2104.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
using System;
using System.Collections.Generic;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
using System.Threading.Tasks;
#if UITEST
using Xamarin.Forms.Core.UITests;
using NUnit.Framework;
using System.Linq;
#endif
namespace Xamarin.Forms.Controls.Issues
{
#if UITEST
[NUnit.Framework.Category(Core.UITests.UITestCategories.Github5000)]
[Category(UITestCategories.Editor)]
#endif
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Github, 2104, "Ensure Multiple Calls to Save Properties Doesn't Cause a Crash")]
public class Issue2104 : TestContentPage
{
const string ErrorMessage = "ErrorMessage";
protected override void Init()
{
var errorMessage = new Label() { AutomationId = ErrorMessage, HeightRequest = 100 };
Log.Listeners.Add(
new DelegateLogListener((c, m) => Device.BeginInvokeOnMainThread(() =>
{
errorMessage.Text = m;
})));
Dictionary<int, object> expectedValues = new Dictionary<int, object>();
for (int i = 0; i < 40; i++)
{
expectedValues.Add(i, DateTime.Now);
}
Button AddData = new Button()
{
Text = "Click Me To call Properties Save a bunch of times",
Command = new Command(() =>
{
Xamarin.Forms.Application.Current.Properties.Clear();
Xamarin.Forms.Application.Current.SendSleep();
for (int i = 0; i < 20; i++)
{
Xamarin.Forms.Application.Current.Properties[i.ToString()] = expectedValues[i];
Xamarin.Forms.Application.Current.SendSleep();
}
for (int i = 20; i < 40; i++)
{
Xamarin.Forms.Application.Current.Properties[i.ToString()] = expectedValues[i];
Task.Run(() =>
{
Xamarin.Forms.Application.Current.SendSleep();
});
}
}),
AutomationId = "FillUp"
};
Button ClearData = new Button()
{
Text = "Click to clear properties",
AutomationId = "Clear",
Command = new Command(() =>
{
Xamarin.Forms.Application.Current.Properties.Clear();
Xamarin.Forms.Application.Current.SendSleep();
}),
};
var deserializer = DependencyService.Get<IDeserializer>();
Button TestData = new Button()
{
Text = "Click to test for properties",
AutomationId = "Test",
Command = new Command(async () =>
{
IDictionary<string, object> properties = await deserializer.DeserializePropertiesAsync();
if (40 != properties.Count)
{
errorMessage.Text = "Invalid Property Count";
}
for (int i = 0; i < 40; i++)
{
if (!properties[i.ToString()].Equals(expectedValues[i]))
{
errorMessage.Text = $"Property Serialized Incorrectly: {properties[i.ToString()]} {expectedValues[i]}";
}
}
}),
};
var layout = new StackLayout();
layout.Children.Add(AddData);
layout.Children.Add(ClearData);
layout.Children.Add(TestData);
layout.Children.Add(errorMessage);
Content = layout;
}
#if UITEST
[Test]
public void Issue2104Test()
{
RunningApp.WaitForElement(q => q.Marked("Clear"));
RunningApp.Tap(q => q.Marked("Clear"));
RunningApp.Tap(q => q.Marked("FillUp"));
RunningApp.Tap(q => q.Marked("Test"));
var errorMessage = RunningApp.Query(x => x.Marked(ErrorMessage)).First().Text;
Assert.IsTrue(String.IsNullOrWhiteSpace(errorMessage), errorMessage);
}
#endif
}
}