mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2024-11-15 06:36:38 +01:00
204 lines
6.8 KiB
C#
204 lines
6.8 KiB
C#
using System;
|
|
using NSubstitute;
|
|
using NUnit.Framework;
|
|
using TINK;
|
|
using TINK.Model.Bikes.BikeInfoNS.CopriLock;
|
|
using TINK.Model.Bikes.BikeInfoNS.DriveNS.BatteryNS;
|
|
using TINK.Model.Connector;
|
|
using TINK.Model.Device;
|
|
using TINK.Model.User;
|
|
using TINK.View;
|
|
using TINK.ViewModel;
|
|
using TINK.ViewModel.Bikes;
|
|
using TINK.ViewModel.Bikes.Bike.CopriLock.RequestHandler;
|
|
|
|
namespace TestShareeLib.ViewModel.Bikes.Bike.CopriLock.RequestHandler
|
|
{
|
|
[TestFixture]
|
|
public class TestFeedbackPending
|
|
{
|
|
/// <summary>
|
|
/// Use case: Give feedback but submission fails.
|
|
/// Final state: Feedback is pending.
|
|
/// </summary>
|
|
[Test]
|
|
public void TestGiveFeedbackDoSubmitFeedbackFailsException()
|
|
{
|
|
var bike = Substitute.For<IBikeInfoMutable>();
|
|
var connector = Substitute.For<IConnector>();
|
|
var command = Substitute.For<ICommand>();
|
|
var pollingManager = Substitute.For<IPollingUpdateTaskManager>();
|
|
var viewService = Substitute.For<IViewService>();
|
|
var bikesViewModel = Substitute.For<IBikesViewModel>();
|
|
var activeUser = Substitute.For<IUser>();
|
|
|
|
var handler = new FeedbackPending(
|
|
bike,
|
|
() => true, // isConnectedDelegate
|
|
(isConnexted) => connector,
|
|
() => pollingManager,
|
|
Substitute.For<ISmartDevice>(),
|
|
viewService,
|
|
bikesViewModel,
|
|
activeUser);
|
|
|
|
connector.Command.DoSubmitFeedback(
|
|
Arg.Any<TINK.Model.Connector.IUserFeedback>(),
|
|
Arg.Any<Uri>()).Returns(x => throw new Exception("Context info", new Exception("Tst")));
|
|
|
|
|
|
var subsequent = handler.HandleRequestOption2().Result;
|
|
|
|
// Verify behaviour
|
|
Received.InOrder(() =>
|
|
{
|
|
bikesViewModel.Received(1).IsIdle = false; // GUI must be locked
|
|
bikesViewModel.ActionText = "One moment please...";
|
|
pollingManager.StopUpdatePeridically(); // Polling must be stopped before any COPR and lock service action
|
|
viewService.DisplayUserFeedbackPopup(Arg.Any<IBattery>(), Arg.Any<string>());
|
|
bikesViewModel.ActionText = "Submitting feedback...";
|
|
connector.Command.DoSubmitFeedback(Arg.Any<TINK.Model.Connector.IUserFeedback>(), Arg.Any<Uri>()); // Booking must be performed
|
|
bikesViewModel.ActionText = string.Empty;
|
|
viewService.DisplayAlert(
|
|
"Submitting feedback failed!",
|
|
"Your feedback could not be send to server successfully.",
|
|
"OK");
|
|
bikesViewModel.ActionText = "Updating...";
|
|
pollingManager.StartUpdateAyncPeridically(); // polling must be restarted again
|
|
bikesViewModel.ActionText = string.Empty;
|
|
bikesViewModel.Received(1).IsIdle = true; // GUI must be unlocked
|
|
});
|
|
|
|
// Verify state after action
|
|
Assert.That(
|
|
subsequent.ButtonText,
|
|
Is.EqualTo("FeedbackPending"));
|
|
Assert.That(
|
|
subsequent.IsButtonVisible,
|
|
Is.False);
|
|
Assert.That(
|
|
subsequent.LockitButtonText,
|
|
Is.EqualTo("Give Feedback"));
|
|
Assert.That(
|
|
subsequent.IsLockitButtonVisible,
|
|
Is.True);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Use case: Give feedback.
|
|
/// Final state: Feedback is pending.
|
|
/// </summary>
|
|
[Test]
|
|
public void TestGiveFeedback()
|
|
{
|
|
var bike = Substitute.For<IBikeInfoMutable>();
|
|
var connector = Substitute.For<IConnector>();
|
|
var command = Substitute.For<ICommand>();
|
|
var pollingManager = Substitute.For<IPollingUpdateTaskManager>();
|
|
var viewService = Substitute.For<IViewService>();
|
|
var bikesViewModel = Substitute.For<IBikesViewModel>();
|
|
var activeUser = Substitute.For<IUser>();
|
|
|
|
var handler = new FeedbackPending(
|
|
bike,
|
|
() => true, // isConnectedDelegate
|
|
(isConnexted) => connector,
|
|
() => pollingManager,
|
|
Substitute.For<ISmartDevice>(),
|
|
viewService,
|
|
bikesViewModel,
|
|
activeUser);
|
|
|
|
var subsequent = handler.HandleRequestOption2().Result;
|
|
|
|
// Verify behaviour
|
|
Received.InOrder(() =>
|
|
{
|
|
bikesViewModel.Received(1).IsIdle = false; // GUI must be locked
|
|
bikesViewModel.ActionText = "One moment please...";
|
|
pollingManager.StopUpdatePeridically(); // Polling must be stopped before any COPR and lock service action
|
|
viewService.DisplayUserFeedbackPopup(Arg.Any<IBattery>(), Arg.Any<string>());
|
|
bikesViewModel.ActionText = "Submitting feedback...";
|
|
connector.Command.DoSubmitFeedback(Arg.Any<TINK.Model.Connector.IUserFeedback>(), Arg.Any<Uri>()); // Booking must be performed
|
|
bikesViewModel.ActionText = "Updating...";
|
|
pollingManager.StartUpdateAyncPeridically(); // polling must be restarted again
|
|
bikesViewModel.ActionText = string.Empty;
|
|
bikesViewModel.Received(1).IsIdle = true; // GUI must be unlocked
|
|
});
|
|
|
|
// Verify state after action
|
|
Assert.That(
|
|
subsequent.ButtonText,
|
|
Is.EqualTo("FeedbackPending"));
|
|
Assert.That(
|
|
subsequent.IsButtonVisible,
|
|
Is.False);
|
|
Assert.That(
|
|
subsequent.LockitButtonText,
|
|
Is.EqualTo("Give Feedback"));
|
|
Assert.That(
|
|
subsequent.IsLockitButtonVisible,
|
|
Is.True);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Use case: Give feedback.
|
|
/// Final state: Feedback is pending.
|
|
/// </summary>
|
|
[Test]
|
|
public void TestGiveFeedbackAndQuerry()
|
|
{
|
|
var bike = Substitute.For<IBikeInfoMutable>();
|
|
var connector = Substitute.For<IConnector>();
|
|
var command = Substitute.For<ICommand>();
|
|
var pollingManager = Substitute.For<IPollingUpdateTaskManager>();
|
|
var viewService = Substitute.For<IViewService>();
|
|
var bikesViewModel = Substitute.For<IBikesViewModel>();
|
|
var activeUser = Substitute.For<IUser>();
|
|
|
|
var handler = new FeedbackPending(
|
|
bike,
|
|
() => true, // isConnectedDelegate
|
|
(isConnexted) => connector,
|
|
() => pollingManager,
|
|
Substitute.For<ISmartDevice>(),
|
|
viewService,
|
|
bikesViewModel,
|
|
activeUser);
|
|
|
|
bike.BookingFinishedModel.MiniSurvey.Questions.Count.Returns(1);
|
|
|
|
var subsequent = handler.HandleRequestOption2().Result;
|
|
|
|
// Verify behaviour
|
|
Received.InOrder(() =>
|
|
{
|
|
bikesViewModel.Received(1).IsIdle = false; // GUI must be locked
|
|
bikesViewModel.ActionText = "One moment please...";
|
|
pollingManager.StopUpdatePeridically(); // Polling must be stopped before any COPR and lock service action
|
|
viewService.DisplayUserFeedbackPopup(Arg.Any<IBattery>(), Arg.Any<string>());
|
|
bikesViewModel.ActionText = "Submitting feedback...";
|
|
connector.Command.DoSubmitFeedback(Arg.Any<TINK.Model.Connector.IUserFeedback>(), Arg.Any<Uri>()); // Booking must be performed
|
|
viewService.PushModalAsync(ViewTypes.MiniSurvey);
|
|
bikesViewModel.ActionText = "Updating...";
|
|
pollingManager.StartUpdateAyncPeridically(); // polling must be restarted again
|
|
bikesViewModel.ActionText = string.Empty;
|
|
bikesViewModel.Received(1).IsIdle = true; // GUI must be unlocked
|
|
});
|
|
|
|
// Verify state after action
|
|
Assert.That(
|
|
subsequent.ButtonText,
|
|
Is.EqualTo("FeedbackPending"));
|
|
Assert.That(
|
|
subsequent.IsButtonVisible,
|
|
Is.False);
|
|
Assert.That(
|
|
subsequent.LockitButtonText,
|
|
Is.EqualTo("Give Feedback"));
|
|
Assert.That(
|
|
subsequent.IsLockitButtonVisible,
|
|
Is.True);
|
|
}
|
|
}
|
|
}
|