Fix filling in comments.

- VERBESSERT: Fehler bei der Kommentaraufforderung wurden behoben.
This commit is contained in:
Daniel Kraus 2015-09-07 21:17:27 +02:00
parent 3ce046a238
commit 2f60c2c5d1
5 changed files with 42 additions and 3 deletions

View File

@ -30,6 +30,7 @@ namespace Tests.Controller.Comments
[Test]
public void CreateCommentIfDoesNotExist()
{
CommentPool.Default.Reset();
int n = CommentPool.Default.Count;
ItemComment i = CommentPool.Default.GetCommentFor("item \"<>\"");
Assert.AreEqual(n + 1, CommentPool.Default.Count);

View File

@ -38,5 +38,39 @@ namespace Tests.ViewModels
Assert.AreEqual(comment.Suffix, vm.Suffix);
Assert.AreEqual(comment.Value, vm.Value);
}
[Test]
public void EnterComment()
{
ItemComment comment = new ItemComment("TAC", "(Ziel-Talspiegel: ", "", "µg/l)");
ItemCommentViewModel vm = new ItemCommentViewModel(comment);
vm.Value = "8-10";
bool eventRaised = false;
vm.RequestCloseView += (sender, args) =>
{
eventRaised = true;
};
vm.SaveCommand.Execute(null);
Assert.IsTrue(eventRaised, "Event was not raised.");
Assert.IsFalse(comment.IsCancelled, "Comment.IsCancelled should be false");
Assert.AreEqual("8-10", comment.Value);
}
[Test]
public void CancelComment()
{
ItemComment comment = new ItemComment("TAC", "(Ziel-Talspiegel: ", "default", "µg/l)");
ItemCommentViewModel vm = new ItemCommentViewModel(comment);
vm.Value = "blabla";
bool eventRaised = false;
vm.RequestCloseView += (sender, args) =>
{
eventRaised = true;
};
vm.CloseViewCommand.Execute(null);
Assert.IsTrue(eventRaised, "Event was not raised.");
Assert.IsTrue(comment.IsCancelled, "Comment.IsCancelled should be true");
Assert.AreEqual("default", comment.Value);
}
}
}

View File

@ -197,9 +197,12 @@ namespace zaaReloaded2.Controller.Comments
/// </summary>
protected virtual void OnFillInComment()
{
if (_isFilledIn) return;
EventHandler<ItemCommentEventArgs> h = FillInComment;
if (h != null)
{
_isFilledIn = true;
h(this, new ItemCommentEventArgs(this));
}
}
@ -208,6 +211,7 @@ namespace zaaReloaded2.Controller.Comments
#region Fields
bool _isFilledIn;
static readonly Regex _definition =
new Regex(@"(?<item>[^""]+)""(?<prefix>[^<]+)?<(?<value>[^>]*)>(?<suffix>[^""]+)?""");

View File

@ -41,7 +41,7 @@ namespace zaaReloaded2.ViewModels
{
get
{
return _itemComment.Value;
return _value;
}
set
{
@ -56,7 +56,7 @@ namespace zaaReloaded2.ViewModels
#region Commands
DelegatingCommand SaveCommand
public DelegatingCommand SaveCommand
{
get
{

View File

@ -42,7 +42,7 @@
<DockPanel Margin="0 10 0 10">
<TextBlock DockPanel.Dock="Left" Text="{Binding Prefix}" VerticalAlignment="Center" />
<TextBlock DockPanel.Dock="Right" Text="{Binding Suffix}" VerticalAlignment="Center" />
<TextBox Text="{Binding Value,Mode=TwoWay,UpdateSourceTrigger=LostFocus}"
<TextBox Text="{Binding Value,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
MinWidth="120" MaxWidth="240" VerticalAlignment="Center"
x:Name="ValueTextBox" Margin="5 0 5 0" />
</DockPanel>