コード例 #1
0
		public async Task SharePoll()
		{
			// Arrange
			var viewModel = GetViewModel();

			var random = new Random();

			var pollId = random.Next();
			var pollDataResults = new PollDataResultsMock
				{
					PollID = pollId,
					Question = Guid.NewGuid().ToString()
				};
			pollDataResults.ResultsDelegate = () =>
				{
					return new ReadOnlyListBaseCoreMock<IPollDataResult>(new List<IPollDataResult>());
				};

			var pollResults = new PollResultsMock
			{
				PollID = pollId,
				PollDataResults = pollDataResults
			};

			Csla.ApplicationContext.User = new PrincipalMock
			{
				Identity = new UserIdentityMock
				{
					UserID = random.Next()
				}
			};

			int actualPollId = -1;
			ObjectFactory.FetchAsyncWithCriteriaDelegate = (criteria) =>
			{
				actualPollId = ((PollResultsCriteria)criteria).PollID;
				return pollResults;
			};

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

			viewModel.Parameter = Serializer.Serialize(
				new PollResultsPageNavigationCriteria { 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.AreEqual(pollId, actualPollId, "Actual Poll Id");
			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");
		}
コード例 #2
0
		public async Task UnpinPoll()
		{
			// Arrange
			var viewModel = GetViewModel();

			var random = new Random();

			var pollDataResults = new PollDataResultsMock
			{
				PollID = random.Next(),
				Question = Guid.NewGuid().ToString()
			};
			pollDataResults.ResultsDelegate = () =>
			{
				return new ReadOnlyListBaseCoreMock<IPollDataResult>(
					new List<IPollDataResult> 
						{
							new PollDataResultMock
							{
								ResponseCount = random.Next()
							}
						});
			};

			var pollResults = new PollResultsMock
			{
				PollID = pollDataResults.PollID,
				PollDataResults = pollDataResults
			};

			viewModel.PollResults = pollResults;

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

			// Act
			await viewModel.UnpinPoll(null);

			// Assert
			Assert.AreEqual(pollDataResults.PollID, actualPollId, "Poll Id");
			Assert.IsFalse(viewModel.IsPollPinned, "Is Poll Pinned");
		}