本文整理汇总了C#中RandomObjectGenerator.Generate方法的典型用法代码示例。如果您正苦于以下问题:C# RandomObjectGenerator.Generate方法的具体用法?C# RandomObjectGenerator.Generate怎么用?C# RandomObjectGenerator.Generate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RandomObjectGenerator
的用法示例。
在下文中一共展示了RandomObjectGenerator.Generate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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));
}));
}
示例2: 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));
}
}
示例3: 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();
}
示例4: 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));
}
}
示例5: ExecuteWhenCurrentUserDidNotCreatePoll
public void ExecuteWhenCurrentUserDidNotCreatePoll()
{
var generator = new RandomObjectGenerator();
var userId = generator.Generate<int>();
var pollUserId = generator.Generate<int>();
var poll = new Mock<IPoll>(MockBehavior.Strict);
poll.Setup(_ => _.UserID).Returns(pollUserId);
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.IsFalse(context.HasPermission, context.GetPropertyName(_ => _.HasPermission));
}
principal.VerifyAll();
identity.VerifyAll();
poll.VerifyAll();
}
示例6: 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));
}
}
示例7: 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();
}
示例8: 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>();
entities.Setup(_ => _.MVPollSubmissions)
.Returns(new InMemoryDbSet<MVPollSubmission> { entity });
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);
}
}
示例9: 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
示例10: 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
示例11: MarkCleanSetDataTwiceAndMarkCleanAgainWithReferenceType
public void MarkCleanSetDataTwiceAndMarkCleanAgainWithReferenceType()
{
var data = new FieldDataUsingOriginalValueViaHashCode<string>("name");
data.MarkClean();
var generator = new RandomObjectGenerator();
data.Value = generator.Generate<string>();
data.Value = generator.Generate<string>();
data.MarkClean();
Assert.IsFalse(data.IsDirty);
}
开发者ID:transformersprimeabcxyz,项目名称:cslacontrib-MarimerLLC,代码行数:10,代码来源:FieldDataUsingOriginalValueViaHashCodeTests.cs
示例12: GetPollDefault
public void GetPollDefault()
{
var generator = new RandomObjectGenerator();
var category = generator.Generate<string>();
var id = generator.Generate<int>();
var imageLink = generator.Generate<string>();
var question = generator.Generate<string>();
var submissionCount = generator.Generate<int>();
var pollSearchResult = new Mock<IPollSearchResult>(MockBehavior.Strict);
pollSearchResult.SetupGet(_ => _.Id).Returns(id);
pollSearchResult.SetupGet(_ => _.ImageLink).Returns(imageLink);
pollSearchResult.SetupGet(_ => _.Question).Returns(question);
pollSearchResult.SetupGet(_ => _.SubmissionCount).Returns(submissionCount);
var searchResults = new Mock<IReadOnlyListBaseCore<IPollSearchResult>>(MockBehavior.Strict);
searchResults.Setup(_ => _.GetEnumerator()).Returns(new List<IPollSearchResult> { pollSearchResult.Object }.GetEnumerator());
var pollSearchResultsByCategory = new Mock<IPollSearchResultsByCategory>(MockBehavior.Strict);
pollSearchResultsByCategory.SetupGet(_ => _.SearchResults).Returns(searchResults.Object);
pollSearchResultsByCategory.SetupGet(_ => _.Category).Returns(category);
var searchResultsByCategory = new Mock<IReadOnlyListBaseCore<IPollSearchResultsByCategory>>(MockBehavior.Strict);
searchResultsByCategory.Setup(_ => _.GetEnumerator()).Returns(new List<IPollSearchResultsByCategory> { pollSearchResultsByCategory.Object }.GetEnumerator());
var pollSearchResults = new Mock<IPollSearchResults>(MockBehavior.Strict);
pollSearchResults.SetupGet(_ => _.SearchResultsByCategory).Returns(searchResultsByCategory.Object);
var pollSearchResultsFactory = new Mock<IObjectFactory<IPollSearchResults>>(MockBehavior.Strict);
pollSearchResultsFactory.Setup(_ => _.Fetch(PollSearchResultsQueryType.MostPopular)).Returns(pollSearchResults.Object);
var controller = new PollController();
controller.PollSearchResultsFactory = new Lazy<IObjectFactory<IPollSearchResults>>(() => pollSearchResultsFactory.Object);
var polls = controller.Get();
Assert.AreEqual(1, polls.Count());
var poll = polls.First();
Assert.AreEqual(category, poll.Category);
Assert.AreEqual(id, poll.Id);
Assert.AreEqual(imageLink, poll.ImageLink);
Assert.AreEqual(question, poll.Question);
Assert.AreEqual(submissionCount, poll.SubmissionCount);
pollSearchResultsFactory.VerifyAll();
pollSearchResults.VerifyAll();
searchResultsByCategory.VerifyAll();
pollSearchResultsByCategory.VerifyAll();
searchResults.VerifyAll();
pollSearchResult.VerifyAll();
}
示例13: FetchNotOwnedByUser
public void FetchNotOwnedByUser()
{
var generator = new RandomObjectGenerator();
var pollId = generator.Generate<int>();
var userId = generator.Generate<int>();
var pollDataResults = Mock.Of<IPollDataResults>();
var pollDataResultsFactory = new Mock<IObjectFactory<IPollDataResults>>(MockBehavior.Strict);
pollDataResultsFactory.Setup(_ => _.FetchChild(pollId)).Returns(pollDataResults);
var pollComments = Mock.Of<IPollComments>();
var pollCommentsFactory = new Mock<IObjectFactory<IPollComments>>(MockBehavior.Strict);
pollCommentsFactory.Setup(_ => _.FetchChild(pollId)).Returns(pollComments);
var poll = EntityCreator.Create<MVPoll>(_ =>
{
_.PollID = pollId;
_.UserID = userId + 1;
_.PollDeletedFlag = null;
_.PollStartDate = DateTime.UtcNow.AddDays(-1);
_.PollEndDate = DateTime.UtcNow.AddDays(1);
});
var entities = new Mock<IEntities>();
entities.Setup(_ => _.MVPolls).Returns(new InMemoryDbSet<MVPoll>
{
poll
});
var builder = new ContainerBuilder();
builder.Register<IObjectFactory<IPollDataResults>>(_ => pollDataResultsFactory.Object);
builder.Register<IObjectFactory<IPollComments>>(_ => pollCommentsFactory.Object);
builder.Register<IEntities>(_ => entities.Object);
using (new ObjectActivator(builder.Build()).Bind(() => ApplicationContext.DataPortalActivator))
{
var pollResults = DataPortal.Fetch<PollResults>(new PollResultsCriteria(userId, pollId));
Assert.AreEqual(pollId, pollResults.PollID, pollResults.GetPropertyName(_ => _.PollID));
Assert.AreEqual(poll.PollImageLink, pollResults.PollImageLink, pollResults.GetPropertyName(_ => _.PollImageLink));
Assert.AreSame(pollDataResults, pollResults.PollDataResults, pollResults.GetPropertyName(_ => _.PollDataResults));
Assert.AreSame(pollComments, pollResults.PollComments, pollResults.GetPropertyName(_ => _.PollComments));
Assert.IsFalse(pollResults.IsPollOwnedByUser, pollResults.GetPropertyName(_ => _.IsPollOwnedByUser));
Assert.IsTrue(pollResults.IsActive, pollResults.GetPropertyName(_ => _.IsActive));
}
pollDataResultsFactory.VerifyAll();
pollCommentsFactory.VerifyAll();
}
示例14: 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);
}
}
示例15: 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();
}