Ejemplo n.º 1
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");
		}
Ejemplo n.º 2
0
		public async Task SignInWithTwitter()
		{
			// Arrange
			var viewModel = GetViewModel();

			var userId = Guid.NewGuid().ToString();

			AuthenticationProvider? actualProvider = null;
			AuthenticationService.AuthenticateWithProviderDelegate = ((provider) =>
				{
					actualProvider = provider;
					return userId;
				});

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

			var identity = new UserIdentityMock { IsAuthenticated = false };
			this.ObjectFactory.FetchAsyncWithCriteriaDelegate = (profileId) =>
				{
					return identity;
				};

			// Act
			await viewModel.SignInWithTwitter();

			// Assert
			Assert.AreEqual(AuthenticationProvider.Twitter, actualProvider, "Provider");
			Assert.AreEqual(typeof(RegistrationPageViewModel), actualType, "Navigation Type");
			Assert.AreEqual(userId, actualParam.ProfileId, "Profile Id");
		}
Ejemplo n.º 3
0
		public void AutoSignInProfileDoesNotExist()
		{
			// Arrange
			var viewModel = GetViewModel();

			AppSettings.TryGetValueDelegate = (key, value) =>
			{
				return false;
			};

			Type actualType = null;
			Navigation.NavigateToViewModelDelegate = ((type) =>
			{
				actualType = type;
			});

			var identity = new UserIdentityMock { IsAuthenticated = true };
			this.ObjectFactory.FetchAsyncWithCriteriaDelegate = (profileIdParam) =>
			{
				return identity;
			};

			// Act
			((IActivate)viewModel).Activate();

			// Assert
			Assert.IsNull(actualType, "Type");
		}
Ejemplo n.º 4
0
		public void AutoSignInProfileExists()
		{
			// Arrange
			var viewModel = GetViewModel();

			var profileId = Guid.NewGuid().ToString();
			AppSettings.TryGetValueDelegate = (key, value) =>
				{
					value = profileId;
					return true;
				};

			Type actualType = null;
			Navigation.NavigateToViewModelDelegate = ((type) =>
			{
				actualType = type;
			});

			var identity = new UserIdentityMock { IsAuthenticated = true };
			this.ObjectFactory.FetchAsyncWithCriteriaDelegate = (profileIdParam) =>
			{
				return identity;
			};

			// Act
			((IActivate)viewModel).Activate();

			// Assert
			Assert.AreEqual(typeof(PollsPageViewModel), actualType, "Type");
		}
Ejemplo n.º 5
0
		public async Task SignInProfileExists()
		{
			// Arrange
			var viewModel = GetViewModel();

			var userId = Guid.NewGuid().ToString();

			AuthenticationProvider? actualProvider = null;
			AuthenticationService.AuthenticateWithProviderDelegate = ((provider) =>
			{
				actualProvider = provider;
				return userId;
			});

			Type actualType = null;
			Navigation.NavigateToViewModelDelegate = ((type) =>
			{
				actualType = type;
			});

			var identity = new UserIdentityMock { IsAuthenticated = true };
			this.ObjectFactory.FetchAsyncWithCriteriaDelegate = (profileId) =>
			{
				return identity;
			};

			// Act
			await viewModel.SignInWithGoogle();

			// Assert
			Assert.AreEqual(AuthenticationProvider.Google, actualProvider, "Provider");
			Assert.AreEqual(typeof(PollsPageViewModel), actualType, "Type");
		}
Ejemplo n.º 6
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");
		}
Ejemplo n.º 7
0
		public async Task LoadPollAsyncWithError()
		{
			// 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 });

			ObjectFactory.CreateAsyncDelegate = () => new PollSubmissionCommandMock();
			ObjectFactory.ExecuteAsyncDelegate = (command) =>
			{
				throw new DataPortalException(null, command);
			};

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

			// Act
			await viewModel.LoadPollAsync();

			// Assert
			Assert.IsTrue(wasMessageBoxShown, "Was Message Box Shown");
		}
Ejemplo n.º 8
0
		public async Task LoadPollAsyncAlreadyVoted()
		{
			// 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 });

			Type actualType = null;
			PollResultsPageNavigationCriteria actualParam = null;
			ObjectFactory.CreateAsyncDelegate = () => new PollSubmissionCommandMock();
			ObjectFactory.ExecuteAsyncDelegate = command => new PollSubmissionCommandMock();

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

			// Act
			await viewModel.LoadPollAsync();

			// Assert
			Assert.AreEqual(typeof(PollResultsPageViewModel), actualType, "Navigation Type");
			Assert.AreEqual(pollId, actualParam.PollId, "Navigated Poll Id");
		}