Exemplo n.º 1
0
		public async Task UnpinPoll()
		{
			// Arrange
			var viewModel = GetViewModel();

			var pollSubmission = new PollSubmissionMock
			{
				PollID = new Random().Next(),
				PollQuestion = Guid.NewGuid().ToString()
			};
			viewModel.PollSubmission = pollSubmission;

			int actualPollId = -1;
			SecondaryPinner.UnpinPollDelegate = (frameworkElement, pollId) =>
			{
				actualPollId = pollId;
				return true;
			};

			// Act
			await viewModel.UnpinPoll(null);

			// Assert
			Assert.AreEqual(pollSubmission.PollID, actualPollId, "Poll Id");
			Assert.IsFalse(viewModel.IsPollPinned, "Is Poll Pinned");
		}
Exemplo n.º 2
0
		public async Task LoadPollAsync()
		{
			// Arrange
			var viewModel = GetViewModel();

			var random = new Random();

			var principal = new PrincipalMock();

			var identity = new UserIdentityMock();
			identity.UserID = random.Next();
			principal.Identity = identity;

			Csla.ApplicationContext.User = principal;

			var pollId = random.Next();

			viewModel.Parameter = Serializer.Serialize(
				new ViewPollPageNavigationCriteria { PollId = pollId });

			var pollSubmission = new PollSubmissionMock();
			IPollSubmissionCommand actualCommand = null;
			ObjectFactory.CreateAsyncDelegate = () => new PollSubmissionCommandMock();
			ObjectFactory.ExecuteAsyncDelegate = (command) =>
				{
					actualCommand = command;
					return new PollSubmissionCommandMock { Submission = pollSubmission };
				};

			var didNavigate = false;
			Navigation.NavigateToViewModelWithParameterDelegate = ((type, param) =>
			{
				didNavigate = true;
			});

			// Act
			await viewModel.LoadPollAsync();

			// Assert
			Assert.IsFalse(didNavigate, "Did Navigate");
			Assert.AreEqual(identity.UserID, actualCommand.UserID, "UserID");
			Assert.AreEqual(pollId, actualCommand.PollID, "PollID");
		}
Exemplo n.º 3
0
		public void CanSubmitNotSavable()
		{
			// Arrange
			var viewModel = GetViewModel();

			var pollSubmission = new PollSubmissionMock();
			pollSubmission.IsActive = true;
			pollSubmission.IsSavable = false;

			viewModel.PollSubmission = pollSubmission;

			// Act

			// Assert
			Assert.IsFalse(viewModel.CanSubmit);
		}
Exemplo n.º 4
0
		public void PollSubmission()
		{
			// Arrange
			var viewModel = GetViewModel();

			var pollSubmission = new PollSubmissionMock();

			// Act
			viewModel.PropertyChanged += OnPropertyChanged;
			viewModel.PollSubmission = pollSubmission;
			viewModel.PropertyChanged -= OnPropertyChanged;

			// Assert
			Assert.AreSame(pollSubmission, viewModel.PollSubmission, "Poll Submission");
			Assert.IsTrue(PropertiesChanged.Contains("PollSubmission"), "Property Changed");
		}
Exemplo n.º 5
0
		public async Task SubmitWithError()
		{
			// Arrange
			var viewModel = GetViewModel();

			var random = new Random();

			var pollSubmission = new PollSubmissionMock { PollID = random.Next() };
			viewModel.PollSubmission = pollSubmission;
			pollSubmission.SaveAsyncDelegate = () =>
				{
					throw new DataPortalException(null, pollSubmission);
				};

			var wasMessageBoxShown = false;
			MessageBox.ShowAsyncWithTitleDelegate = (message, title, buttons) =>
			{
				wasMessageBoxShown = true;
				return true;
			};

			// Act
			await viewModel.Submit();

			// Assert
			Assert.IsTrue(wasMessageBoxShown, "Was Message Box Shown");
		}
Exemplo n.º 6
0
		public async Task Submit()
		{
			// Arrange
			var viewModel = GetViewModel();

			var random = new Random();

			var pollSubmission = new PollSubmissionMock { PollID = random.Next() };
			viewModel.PollSubmission = pollSubmission;

			Type actualType = null;
			PollResultsPageNavigationCriteria actualParam = null;
			Navigation.NavigateToViewModelAndRemoveCurrentWithParameterDelegate = ((type, param) =>
			{
				actualType = type;
				actualParam = (PollResultsPageNavigationCriteria)param;
			});

			// Act
			await viewModel.Submit();

			// Assert
			Assert.AreEqual(typeof(PollResultsPageViewModel), actualType, "Navigation Type");
			Assert.AreEqual(pollSubmission.PollID, actualParam.PollId, "Poll Id");
		}
Exemplo n.º 7
0
		public async Task SharePoll()
		{
			// Arrange
			var viewModel = GetViewModel();

			var random = new Random();

			var principal = new PrincipalMock();

			var identity = new UserIdentityMock();
			identity.UserID = random.Next();
			principal.Identity = identity;

			Csla.ApplicationContext.User = principal;

			var pollId = random.Next();
			var pollSubmission = new PollSubmissionMock
			{
				PollID = pollId
			};
			
			ObjectFactory.CreateAsyncDelegate = () => new PollSubmissionCommandMock();
			ObjectFactory.ExecuteAsyncDelegate = (command) =>
			{
				return new PollSubmissionCommandMock { Submission = pollSubmission };
			};

			var wasShareManagerInitialized = false;
			ShareManager.InitializeDelegate = () =>
				{
					wasShareManagerInitialized = true;
				};

			viewModel.Parameter = Serializer.Serialize(
				new ViewPollPageNavigationCriteria { PollId = pollId });

			await viewModel.LoadPollAsync();

			((IActivate)viewModel).Activate();

			var dataPackage = new DataPackage();
			var dataPackageView = dataPackage.GetView();

			// Act
			ShareManager.ExecuteShareRequested(dataPackage);

			// Assert
			Assert.IsTrue(wasShareManagerInitialized, "Was Share Manager Initialized");
			Assert.IsTrue(!string.IsNullOrEmpty(await dataPackageView.GetTextAsync()), "Text Exists");
			Assert.AreEqual(string.Format("myvote://poll/{0}", pollId), (await dataPackageView.GetApplicationLinkAsync()).ToString(), "Uri");
			Assert.IsTrue(!string.IsNullOrEmpty(await dataPackageView.GetHtmlFormatAsync()), "HTML Exists");
		}