当前位置: 首页>>代码示例>>C#>>正文


C# RandomObjectGenerator类代码示例

本文整理汇总了C#中RandomObjectGenerator的典型用法代码示例。如果您正苦于以下问题:C# RandomObjectGenerator类的具体用法?C# RandomObjectGenerator怎么用?C# RandomObjectGenerator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


RandomObjectGenerator类属于命名空间,在下文中一共展示了RandomObjectGenerator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Create

		public void Create()
		{
			var generator = new RandomObjectGenerator();
			var optionId = generator.Generate<int>();
			var optionPosition = generator.Generate<short>();
			var optionText = generator.Generate<string>();

			var option = new Mock<IPollOption>(MockBehavior.Strict);
			option.Setup(_ => _.PollOptionID).Returns(optionId);
			option.Setup(_ => _.OptionPosition).Returns(optionPosition);
			option.Setup(_ => _.OptionText).Returns(optionText);

			var builder = new ContainerBuilder();
			builder.Register<IEntities>(_ => Mock.Of<IEntities>());

			using (new ObjectActivator(builder.Build()).Bind(() => ApplicationContext.DataPortalActivator))
			{
				var response = DataPortal.CreateChild<PollSubmissionResponse>(option.Object);

				Assert.AreEqual(optionId, response.PollOptionID, response.GetPropertyName(_ => _.PollOptionID));
				Assert.AreEqual(optionPosition, response.OptionPosition, response.GetPropertyName(_ => _.OptionPosition));
				Assert.AreEqual(optionText, response.OptionText, response.GetPropertyName(_ => _.OptionText));
				Assert.IsFalse(response.IsOptionSelected, response.GetPropertyName(_ => _.IsOptionSelected));
				Assert.IsNull(response.PollResponseID, response.GetPropertyName(_ => _.PollResponseID));
			}

			option.VerifyAll();
		}
开发者ID:JacobAtchley,项目名称:MyVote,代码行数:28,代码来源:PollSubmissionResponseTests.cs

示例2: Create

		public void Create()
		{
			var now = DateTime.UtcNow;
			var generator = new RandomObjectGenerator();
			var userId = generator.Generate<int>();

			var poll = EntityCreator.Create<MVPoll>(_ =>
			{
				_.PollDeletedFlag = false;
				_.PollStartDate = now.AddDays(-2);
				_.PollEndDate = now.AddDays(2);
				_.PollMinAnswers = 2;
				_.PollMaxAnswers = 3;
			});

			poll.MVPollOptions = new List<MVPollOption> 
			{ 
				EntityCreator.Create<MVPollOption>(),
				EntityCreator.Create<MVPollOption>(),
				EntityCreator.Create<MVPollOption>(),
				EntityCreator.Create<MVPollOption>()
			};

			var category = EntityCreator.Create<MVCategory>(_ => _.CategoryID = poll.PollCategoryID);

			var entities = new Mock<IEntities>(MockBehavior.Strict);
			entities.Setup(_ => _.MVPolls)
				.Returns(new InMemoryDbSet<MVPoll> { poll });
			entities.Setup(_ => _.MVPollSubmissions)
				.Returns(new InMemoryDbSet<MVPollSubmission>());
			entities.Setup(_ => _.MVCategories)
				.Returns(new InMemoryDbSet<MVCategory> { category });
			entities.Setup(_ => _.Dispose());

			var builder = new ContainerBuilder();
			builder.Register<IEntities>(_ => entities.Object);

			using (new ObjectActivator(builder.Build()).Bind(() => ApplicationContext.DataPortalActivator))
			{
				var criteria = new PollSubmissionCriteria(poll.PollID, userId);
				var submission = DataPortal.Create<PollSubmission>(criteria);

				Assert.AreEqual(poll.PollID, submission.PollID, submission.GetPropertyName(_ => _.PollID));
				Assert.AreEqual(poll.PollImageLink, submission.PollImageLink, submission.GetPropertyName(_ => _.PollImageLink));
				Assert.AreEqual(userId, submission.UserID, submission.GetPropertyName(_ => _.UserID));
				Assert.AreEqual(poll.PollQuestion, submission.PollQuestion, submission.GetPropertyName(_ => _.PollQuestion));
				Assert.AreEqual(category.CategoryName, submission.CategoryName, submission.GetPropertyName(_ => _.CategoryName));
				Assert.AreEqual(poll.PollDescription, submission.PollDescription, submission.GetPropertyName(_ => _.PollDescription));
				Assert.AreEqual(poll.PollMaxAnswers.Value, submission.PollMaxAnswers, submission.GetPropertyName(_ => _.PollMaxAnswers));
				Assert.AreEqual(poll.PollMinAnswers.Value, submission.PollMinAnswers, submission.GetPropertyName(_ => _.PollMinAnswers));
				Assert.AreEqual(4, submission.Responses.Count, submission.GetPropertyName(_ => _.Responses));

				submission.BrokenRulesCollection.AssertRuleCount(1);
				submission.BrokenRulesCollection.AssertRuleCount(PollSubmission.ResponsesProperty, 1);
				submission.BrokenRulesCollection.AssertBusinessRuleExists<MinimumAndMaximumPollSubmissionResponsesRule>(
					PollSubmission.ResponsesProperty, true);
			}

			entities.VerifyAll();
		}
开发者ID:JacobAtchley,项目名称:MyVote,代码行数:60,代码来源:PollSubmissionLifecycleTests.cs

示例3: Insert

		public void Insert()
		{
			var generator = new RandomObjectGenerator();
			var optionPosition = generator.Generate<short>();
			var optionText = generator.Generate<string>();
			var pollId = generator.Generate<int>();
			var pollOptionId = generator.Generate<int>();

			var poll = new Mock<IPoll>();
			poll.Setup(_ => _.PollID).Returns(pollId);

			var pollOptions = new InMemoryDbSet<MVPollOption>();
			var entities = new Mock<IEntities>();
			entities.Setup(_ => _.MVPollOptions)
				.Returns(pollOptions);
			entities.Setup(_ => _.SaveChanges()).Callback(() => pollOptions.Local[0].PollOptionID = pollOptionId);
			var builder = new ContainerBuilder();
			builder.Register<IEntities>(_ => entities.Object);

			using (new ObjectActivator(builder.Build()).Bind(() => ApplicationContext.DataPortalActivator))
			{
				var pollOption = DataPortal.CreateChild<PollOption>();
				pollOption.OptionPosition = optionPosition;
				pollOption.OptionText = optionText;

				DataPortal.UpdateChild(pollOption, poll.Object);

				Assert.AreEqual(pollId, pollOption.PollID, pollOption.GetPropertyName(_ => _.PollID));
				Assert.AreEqual(pollOptionId, pollOption.PollOptionID, pollOption.GetPropertyName(_ => _.PollOptionID));
				Assert.AreEqual(optionPosition, pollOption.OptionPosition, pollOption.GetPropertyName(_ => _.OptionPosition));
				Assert.AreEqual(optionText, pollOption.OptionText, pollOption.GetPropertyName(_ => _.OptionText));
			}
		}
开发者ID:kamilkk,项目名称:MyVote,代码行数:33,代码来源:PollOptionLifecycleTests.cs

示例4: Create

		public void Create()
		{
			var generator = new RandomObjectGenerator();
			var userId = generator.Generate<int>();
			var userName = generator.Generate<string>();

			var pollComments = Mock.Of<IPollCommentCollection>();
			var pollCommentsFactory = new Mock<IObjectFactory<IPollCommentCollection>>(MockBehavior.Strict);
			pollCommentsFactory.Setup(_ => _.CreateChild()).Returns(pollComments);

			var pollCommentFactory = Mock.Of<IObjectFactory<IPollComment>>();

			var builder = new ContainerBuilder();
			builder.Register<IObjectFactory<IPollComment>>(_ => pollCommentFactory);
			builder.Register<IObjectFactory<IPollCommentCollection>>(_ => pollCommentsFactory.Object);
			builder.Register<IEntities>(_ => Mock.Of<IEntities>());

			using (new ObjectActivator(builder.Build()).Bind(() => ApplicationContext.DataPortalActivator))
			{
				var result = DataPortal.CreateChild<PollComment>(userId, userName);
				Assert.IsNotNull(result.CommentDate);
				Assert.AreSame(pollComments, result.Comments);
				Assert.AreEqual(string.Empty, result.CommentText);
				Assert.IsNull(result.PollCommentID);
				Assert.AreEqual(userId, result.UserID);
				Assert.AreEqual(userName, result.UserName);
			}

			pollCommentsFactory.VerifyAll();
		}
开发者ID:kamilkk,项目名称:MyVote,代码行数:30,代码来源:PollCommentTests.cs

示例5: FetchByPersonId

		public void FetchByPersonId()
		{
			// Arrange
			var generator = new RandomObjectGenerator();
			var expected = new E.Person
			{
				Id = generator.Generate<int>(),
				FirstName = generator.Generate<string>(),
				MiddleName = generator.Generate<string>(),
				LastName = generator.Generate<string>(),
				Gender = generator.Generate<string>()
			};

			var dbSet = new InMemoryDbSet<E.Person> { expected };

			PersonTests.Arrange(mockedContext =>
			{
				mockedContext.Setup(_ => _.People).Returns(dbSet);
				mockedContext.Setup(_ => _.Dispose());
			}, (() =>
			{
				// Act
				var expectedId = expected.Id;
				var actual = DataPortal.Fetch<Person>(expectedId);

				// Assert
				Assert.IsNotNull(actual);
				Assert.IsFalse(actual.IsNew, actual.GetPropertyName(_ => _.IsNew));
				Assert.AreEqual(expectedId, actual.Id, actual.GetPropertyName(_ => _.Id));
				Assert.AreEqual(expected.FirstName, actual.FirstName, actual.GetPropertyName(_ => _.FirstName));
				Assert.AreEqual(expected.MiddleName, actual.MiddleName, actual.GetPropertyName(_ => _.MiddleName));
				Assert.AreEqual(expected.LastName, actual.LastName, actual.GetPropertyName(_ => _.LastName));
				Assert.AreEqual(expected.Gender, actual.Gender, actual.GetPropertyName(_ => _.Gender));
			}));
		}
开发者ID:rbocobo,项目名称:MagenicManila.BrownBag,代码行数:35,代码来源:PersonTests.cs

示例6: CreateUser

		public void CreateUser()
		{
			var generator = new RandomObjectGenerator();
			var profileId = generator.Generate<string>();
			var entity = EntityCreator.Create<Models.User>(_ => _.ProfileID = profileId);

			var user = new Mock<IUser>(MockBehavior.Strict);
			user.SetupSet(_ => _.BirthDate = entity.BirthDate);
			user.SetupSet(_ => _.EmailAddress = entity.EmailAddress);
			user.SetupSet(_ => _.FirstName = entity.FirstName);
			user.SetupSet(_ => _.Gender = entity.Gender);
			user.SetupSet(_ => _.LastName = entity.LastName);
			user.SetupSet(_ => _.PostalCode = entity.PostalCode);
			user.SetupSet(_ => _.UserName = entity.UserName);
			user.Setup(_ => _.Save()).Returns(null);

			var userFactory = new Mock<IObjectFactory<IUser>>(MockBehavior.Strict);
			userFactory.Setup(_ => _.Create(profileId)).Returns(user.Object);

			var controller = new UserController();
			controller.UserFactory = userFactory.Object;
			controller.Put(entity);

			userFactory.VerifyAll();
			user.VerifyAll(); 
		}
开发者ID:JacobAtchley,项目名称:MyVote,代码行数:26,代码来源:UserControllerTests.cs

示例7: ExecuteWhenUserHasNotSubmittedAnswersForThePoll

		public void ExecuteWhenUserHasNotSubmittedAnswersForThePoll()
		{
			var generator = new RandomObjectGenerator();
			var pollId = generator.Generate<int>();
			var userId = generator.Generate<int>();

			var entities = new Mock<IEntities>();
			entities.Setup(_ => _.MVPollSubmissions).Returns(
				new InMemoryDbSet<MVPollSubmission>());

			var factory = new Mock<IObjectFactory<IPollSubmission>>();
			factory.Setup(_ => _.Create(It.IsAny<PollSubmissionCriteria>()))
				.Returns(new Mock<IPollSubmission>().Object);

			var builder = new ContainerBuilder();
			builder.Register<IEntities>(_ => entities.Object);
			builder.Register<IObjectFactory<IPollSubmission>>(_ => factory.Object);

			using (new ObjectActivator(builder.Build()).Bind(() => ApplicationContext.DataPortalActivator))
			{
				var command = DataPortal.Execute<PollSubmissionCommand>(
					new PollSubmissionCommand
					{
						PollID = pollId,
						UserID = userId
					});

				Assert.AreEqual(pollId, command.PollID, command.GetPropertyName(_ => _.PollID));
				Assert.AreEqual(userId, command.UserID, command.GetPropertyName(_ => _.UserID));
				Assert.IsNotNull(command.Submission, command.GetPropertyName(_ => _.Submission));
			}
		}
开发者ID:kamilkk,项目名称:MyVote,代码行数:32,代码来源:PollSubmissionCommandTests.cs

示例8: Create

		public void Create()
		{
			var generator = new RandomObjectGenerator();
			var profileId = generator.Generate<string>();

			var builder = new ContainerBuilder();
			builder.Register<IEntities>(_ => Mock.Of<IEntities>());

			using (new ObjectActivator(builder.Build()).Bind(() => ApplicationContext.DataPortalActivator))
			{
				var user = new DataPortal<User>().Create(profileId);

				Assert.IsNull(user.BirthDate, user.GetPropertyName(_ => _.BirthDate));
				Assert.AreEqual(string.Empty, user.EmailAddress, user.GetPropertyName(_ => _.EmailAddress));
				Assert.AreEqual(string.Empty, user.FirstName, user.GetPropertyName(_ => _.FirstName));
				Assert.AreEqual(string.Empty, user.Gender, user.GetPropertyName(_ => _.Gender));
				Assert.AreEqual(string.Empty, user.LastName, user.GetPropertyName(_ => _.LastName));
				Assert.AreEqual(string.Empty, user.PostalCode, user.GetPropertyName(_ => _.PostalCode));
				Assert.AreEqual(string.Empty, user.ProfileAuthToken, user.GetPropertyName(_ => _.ProfileAuthToken));
				Assert.AreEqual(profileId, user.ProfileID, user.GetPropertyName(_ => _.ProfileID));
				Assert.IsNull(user.UserID, user.GetPropertyName(_ => _.UserID));
				Assert.AreEqual(string.Empty, user.UserName, user.GetPropertyName(_ => _.UserName));
				Assert.IsNull(user.UserRoleID, user.GetPropertyName(_ => _.UserRoleID));

				user.BrokenRulesCollection.AssertRuleCount(2);
				user.BrokenRulesCollection.AssertRuleCount(User.EmailAddressProperty, 1);
				user.BrokenRulesCollection.AssertValidationRuleExists<RequiredAttribute>(
					User.EmailAddressProperty, true);
				user.BrokenRulesCollection.AssertRuleCount(User.UserNameProperty, 1);
				user.BrokenRulesCollection.AssertValidationRuleExists<RequiredAttribute>(
					User.UserNameProperty, true);
			}
		}
开发者ID:kamilkk,项目名称:MyVote,代码行数:33,代码来源:UserLifecycleTests.cs

示例9: ExecuteWhenCurrentUserCreatedPoll

		public void ExecuteWhenCurrentUserCreatedPoll()
		{
			var generator = new RandomObjectGenerator();
			var userId = generator.Generate<int>();

			var poll = new Mock<IPoll>(MockBehavior.Strict);
			poll.Setup(_ => _.UserID).Returns(userId);

			var identity = new Mock<IUserIdentity>(MockBehavior.Strict);
			identity.Setup(_ => _.UserID).Returns(userId);
			identity.Setup(_ => _.IsInRole(UserRoles.Admin)).Returns(false);

			var principal = new Mock<IPrincipal>(MockBehavior.Strict);
			principal.Setup(_ => _.Identity).Returns(identity.Object);

			using (principal.Object.Bind(() => ApplicationContext.User))
			{
				var rule = new CanDeletePollRule();
				var context = new AuthorizationContext(rule, poll.Object, typeof(IPoll));
				(rule as IAuthorizationRule).Execute(context);

				Assert.IsTrue(context.HasPermission, context.GetPropertyName(_ => _.HasPermission));
			}

			principal.VerifyAll();
			identity.VerifyAll();
			poll.VerifyAll();
		}
开发者ID:JacobAtchley,项目名称:MyVote,代码行数:28,代码来源:CanDeletePollRuleTests.cs

示例10: CreateWhenUserHasSubmittedAnswersBefore

		public void CreateWhenUserHasSubmittedAnswersBefore()
		{
			var generator = new RandomObjectGenerator();
			var userId = generator.Generate<int>();
			var pollId = generator.Generate<int>();

			var entity = EntityCreator.Create<MVPollSubmission>(_ =>
			{
				_.UserID = userId;
				_.PollID = pollId;
			});

			var entities = new Mock<IEntities>(MockBehavior.Strict);
			entities.Setup(_ => _.MVPollSubmissions)
				.Returns(new InMemoryDbSet<MVPollSubmission> { entity });
			entities.Setup(_ => _.Dispose());

			var builder = new ContainerBuilder();
			builder.Register<IEntities>(_ => entities.Object);

			using (new ObjectActivator(builder.Build()).Bind(() => ApplicationContext.DataPortalActivator))
			{
				var criteria = new PollSubmissionCriteria(pollId, userId);
				new DataPortal<PollSubmission>().Create(criteria);
			}

			entities.VerifyAll();
		}
开发者ID:JacobAtchley,项目名称:MyVote,代码行数:28,代码来源:PollSubmissionLifecycleTests.cs

示例11: Fetch

		public void Fetch()
		{
			var generator = new RandomObjectGenerator();
			var profileId = generator.Generate<string>();
			var userId = generator.Generate<int>();
			var userName = generator.Generate<string>();

			var entity = EntityCreator.Create<MVUser>(_ =>
				{
					_.ProfileID = profileId;
					_.UserID = userId;
					_.UserName = userName;
					_.MVUserRole = EntityCreator.Create<MVUserRole>();
				});

			var entities = new Mock<IEntities>();
			entities.Setup(_ => _.MVUsers)
				.Returns(new InMemoryDbSet<MVUser> { entity });

			var builder = new ContainerBuilder();
			builder.Register<IEntities>(_ => entities.Object);

			using (new ObjectActivator(builder.Build()).Bind(() => ApplicationContext.DataPortalActivator))
			{
				var identity = DataPortal.Fetch<UserIdentity>(profileId);

				Assert.AreEqual(profileId, identity.ProfileID, identity.GetPropertyName(_ => _.ProfileID));
				Assert.AreEqual(userId, identity.UserID, identity.GetPropertyName(_ => _.UserID));
				Assert.AreEqual(userName, identity.UserName, identity.GetPropertyName(_ => _.UserName));
				Assert.IsTrue(identity.IsAuthenticated, identity.GetPropertyName(_ => _.IsAuthenticated));
			}
		}
开发者ID:kamilkk,项目名称:MyVote,代码行数:32,代码来源:UserIdentityTests.cs

示例12: FetchWhenUserDoesNotExist

		public void FetchWhenUserDoesNotExist()
		{
			var generator = new RandomObjectGenerator();
			var profileId = generator.Generate<string>();

			var entities = new Mock<IEntities>(MockBehavior.Strict);
			entities.Setup(_ => _.MVUsers)
				.Returns(new InMemoryDbSet<MVUser>());
			entities.Setup(_ => _.Dispose());

			var builder = new ContainerBuilder();
			builder.Register<IEntities>(_ => entities.Object);

			using (new ObjectActivator(builder.Build()).Bind(() => ApplicationContext.DataPortalActivator))
			{
				var identity = DataPortal.Fetch<UserIdentity>(profileId);

				Assert.AreEqual(string.Empty, identity.ProfileID, identity.GetPropertyName(_ => _.ProfileID));
				Assert.IsNull(identity.UserID, identity.GetPropertyName(_ => _.UserID));
				Assert.AreEqual(string.Empty, identity.UserName, identity.GetPropertyName(_ => _.UserName));
				Assert.IsFalse(identity.IsAuthenticated, identity.GetPropertyName(_ => _.IsAuthenticated));
			}

			entities.VerifyAll();
		}
开发者ID:JacobAtchley,项目名称:MyVote,代码行数:25,代码来源:UserIdentityTests.cs

示例13: MockDataTest

 public MockDataTest()
 {
     //
     // TODO: Add constructor logic here
     //
     generator = new RandomObjectGenerator();
 }
开发者ID:rbocobo,项目名称:MagenicMasters.Csla,代码行数:7,代码来源:MockDataTest.cs

示例14: MarkCleanAndSetDataTwiceWithReferenceType

		public void MarkCleanAndSetDataTwiceWithReferenceType()
		{
			var data = new FieldDataUsingOriginalValueViaDuplicate<string>("name");
			data.MarkClean();
			var generator = new RandomObjectGenerator();
			data.Value = generator.Generate<string>();
			data.Value = generator.Generate<string>();
			Assert.IsTrue(data.IsDirty);			
		}
开发者ID:transformersprimeabcxyz,项目名称:cslacontrib-MarimerLLC,代码行数:9,代码来源:FieldDataUsingOriginalValueViaDuplicateTests.cs

示例15: MarkCleanAndSetDataTwiceWithValueType

		public void MarkCleanAndSetDataTwiceWithValueType()
		{
			var data = new FieldDataUsingOriginalValueViaHashCode<int>("name");
			data.MarkClean();
			var generator = new RandomObjectGenerator();
			data.Value = generator.Generate<int>();
			data.Value = generator.Generate<int>();
			Assert.IsTrue(data.IsDirty);
		}
开发者ID:transformersprimeabcxyz,项目名称:cslacontrib-MarimerLLC,代码行数:9,代码来源:FieldDataUsingOriginalValueViaHashCodeTests.cs


注:本文中的RandomObjectGenerator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。