mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2025-07-08 20:46:29 +02:00
Version 3.0.381
This commit is contained in:
parent
f963c0a219
commit
3a363acf3a
1525 changed files with 60589 additions and 125098 deletions
|
@ -0,0 +1,204 @@
|
|||
using System;
|
||||
using NSubstitute;
|
||||
using NUnit.Framework;
|
||||
using ShareeBike;
|
||||
using ShareeBike.Model.Bikes.BikeInfoNS.CopriLock;
|
||||
using ShareeBike.Model.Bikes.BikeInfoNS.DriveNS.BatteryNS;
|
||||
using ShareeBike.Model.Connector;
|
||||
using ShareeBike.Model.Device;
|
||||
using ShareeBike.Model.User;
|
||||
using ShareeBike.View;
|
||||
using ShareeBike.ViewModel;
|
||||
using ShareeBike.ViewModel.Bikes;
|
||||
using ShareeBike.ViewModel.Bikes.Bike.CopriLock.RequestHandler;
|
||||
|
||||
namespace SharedBusinessLogic.Tests.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
|
||||
(isConnected) => connector,
|
||||
() => pollingManager,
|
||||
Substitute.For<ISmartDevice>(),
|
||||
viewService,
|
||||
bikesViewModel,
|
||||
activeUser);
|
||||
|
||||
connector.Command.DoSubmitFeedback(
|
||||
Arg.Any<ShareeBike.Model.Connector.IUserFeedback>(),
|
||||
Arg.Any<Uri>()).Returns(x => throw new Exception("Context info", new Exception("Tst")));
|
||||
|
||||
|
||||
var subsequent = handler.HandleRequestOption2().Result;
|
||||
|
||||
// Verify behavior
|
||||
Received.InOrder(() =>
|
||||
{
|
||||
bikesViewModel.Received(1).IsIdle = false; // GUI must be locked
|
||||
bikesViewModel.ActionText = "One moment please...";
|
||||
pollingManager.StopAsync(); // Polling must be stopped before any COPR and lock service action
|
||||
viewService.DisplayUserFeedbackPopup(Arg.Any<IBatteryMutable>());
|
||||
bikesViewModel.ActionText = "Submitting feedback...";
|
||||
connector.Command.DoSubmitFeedback(Arg.Any<ShareeBike.Model.Connector.IUserFeedback>(), Arg.Any<Uri>()); // Booking must be performed
|
||||
bikesViewModel.ActionText = string.Empty;
|
||||
viewService.DisplayAlert(
|
||||
"Submitting feedback failed!",
|
||||
"A stable Internet connection is required. Connect to WIFI or to mobile network and activate mobile data. Try again.",
|
||||
"OK");
|
||||
bikesViewModel.ActionText = "Updating...";
|
||||
pollingManager.StartAsync(); // 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
|
||||
(isConnected) => connector,
|
||||
() => pollingManager,
|
||||
Substitute.For<ISmartDevice>(),
|
||||
viewService,
|
||||
bikesViewModel,
|
||||
activeUser);
|
||||
|
||||
var subsequent = handler.HandleRequestOption2().Result;
|
||||
|
||||
// Verify behavior
|
||||
Received.InOrder(() =>
|
||||
{
|
||||
bikesViewModel.Received(1).IsIdle = false; // GUI must be locked
|
||||
bikesViewModel.ActionText = "One moment please...";
|
||||
pollingManager.StopAsync(); // Polling must be stopped before any COPR and lock service action
|
||||
viewService.DisplayUserFeedbackPopup(Arg.Any<IBatteryMutable>());
|
||||
bikesViewModel.ActionText = "Submitting feedback...";
|
||||
connector.Command.DoSubmitFeedback(Arg.Any<ShareeBike.Model.Connector.IUserFeedback>(), Arg.Any<Uri>()); // Booking must be performed
|
||||
bikesViewModel.ActionText = "Updating...";
|
||||
pollingManager.StartAsync(); // 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
|
||||
(isConnected) => connector,
|
||||
() => pollingManager,
|
||||
Substitute.For<ISmartDevice>(),
|
||||
viewService,
|
||||
bikesViewModel,
|
||||
activeUser);
|
||||
|
||||
bike.BookingFinishedModel.MiniSurvey.Questions.Count.Returns(1);
|
||||
|
||||
var subsequent = handler.HandleRequestOption2().Result;
|
||||
|
||||
// Verify behavior
|
||||
Received.InOrder(() =>
|
||||
{
|
||||
bikesViewModel.Received(1).IsIdle = false; // GUI must be locked
|
||||
bikesViewModel.ActionText = "One moment please...";
|
||||
pollingManager.StopAsync(); // Polling must be stopped before any COPR and lock service action
|
||||
viewService.DisplayUserFeedbackPopup(Arg.Any<IBatteryMutable>());
|
||||
bikesViewModel.ActionText = "Submitting feedback...";
|
||||
connector.Command.DoSubmitFeedback(Arg.Any<ShareeBike.Model.Connector.IUserFeedback>(), Arg.Any<Uri>()); // Booking must be performed
|
||||
viewService.PushModalAsync(ViewTypes.MiniSurvey);
|
||||
bikesViewModel.ActionText = "Updating...";
|
||||
pollingManager.StartAsync(); // 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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue