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(); }
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)); } }
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(), new ActivatorCallContext()) .Bind(() => ApplicationContext.DataPortalActivator)) { var response = DataPortal.CreateChild <PollSubmissionResponse>(option.Object); Assert.AreEqual(optionId, response.PollOptionID, nameof(response.PollOptionID)); Assert.AreEqual(optionPosition, response.OptionPosition, nameof(response.OptionPosition)); Assert.AreEqual(optionText, response.OptionText, nameof(response.OptionText)); Assert.IsFalse(response.IsOptionSelected, nameof(response.IsOptionSelected)); Assert.IsNull(response.PollResponseID, nameof(response.PollResponseID)); } option.VerifyAll(); }
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(); }
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(); }
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)); } }
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, nameof(context.HasPermission)); } principal.VerifyAll(); identity.VerifyAll(); poll.VerifyAll(); }
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)); } }
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(), new ActivatorCallContext()) .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(); }
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)); })); }
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); } }
public void ChangePollStartDateBeforeEndDate() { var generator = new RandomObjectGenerator(); var userId = generator.Generate <int>(); var startDate = generator.Generate <DateTime>(); var endDate = startDate.AddDays(2); var builder = new ContainerBuilder(); builder.Register <IEntities>(_ => Mock.Of <IEntities>()); builder.Register <IObjectFactory <BusinessList <IPollOption> > >(_ => Mock.Of <IObjectFactory <BusinessList <IPollOption> > >()); builder.Register <IObjectFactory <IPollOption> >(_ => Mock.Of <IObjectFactory <IPollOption> >()); using (new ObjectActivator(builder.Build(), new ActivatorCallContext()) .Bind(() => ApplicationContext.DataPortalActivator)) { var poll = DataPortal.Create <Poll>(userId); poll.PollStartDate = startDate; poll.PollEndDate = endDate; poll.BrokenRulesCollection.AssertBusinessRuleExists <StartAndEndDateRule>( Poll.PollStartDateProperty, false); poll.BrokenRulesCollection.AssertBusinessRuleExists <StartAndEndDateRule>( Poll.PollEndDateProperty, false); } }
private Mock <IPollComment> BuildMockPollComment(RandomObjectGenerator generator, IPollComment childComment) { var commentID = generator.Generate <int>(); var commentDate = generator.Generate <DateTime>(); var commentText = generator.Generate <string>(); var userName = generator.Generate <string>(); var pollCommentList = new List <IPollComment>(); if (childComment != null) { pollCommentList.Add(childComment); } var pollCommentCollection = new Mock <IPollCommentCollection>(MockBehavior.Strict); pollCommentCollection.Setup(_ => _.GetEnumerator()).Returns(pollCommentList.GetEnumerator()); var pollComment = new Mock <IPollComment>(MockBehavior.Strict); pollComment.SetupGet(_ => _.PollCommentID).Returns(commentID); pollComment.SetupGet(_ => _.CommentDate).Returns(commentDate); pollComment.SetupGet(_ => _.Comments).Returns(pollCommentCollection.Object); pollComment.SetupGet(_ => _.CommentText).Returns(commentText); pollComment.SetupGet(_ => _.UserName).Returns(userName); return(pollComment); }
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); }
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); }
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); }
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>(MockBehavior.Strict); entities.Setup(_ => _.MVPolls).Returns(new InMemoryDbSet <MVPoll> { poll }); entities.Setup(_ => _.Dispose()); 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(), new ActivatorCallContext()) .Bind(() => ApplicationContext.DataPortalActivator)) { var pollResults = DataPortal.Fetch <PollResults>(new PollResultsCriteria(userId, pollId)); Assert.AreEqual(pollId, pollResults.PollID, nameof(pollResults.PollID)); Assert.AreEqual(poll.PollImageLink, pollResults.PollImageLink, nameof(pollResults.PollImageLink)); Assert.AreSame(pollDataResults, pollResults.PollDataResults, nameof(pollResults.PollDataResults)); Assert.AreSame(pollComments, pollResults.PollComments, nameof(pollResults.PollComments)); Assert.IsFalse(pollResults.IsPollOwnedByUser, nameof(pollResults.IsPollOwnedByUser)); Assert.IsTrue(pollResults.IsActive, nameof(pollResults.IsActive)); } pollDataResultsFactory.VerifyAll(); pollCommentsFactory.VerifyAll(); entities.VerifyAll(); }
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); }
public void Create() { var generator = new RandomObjectGenerator(); var value = generator.Generate <Guid>(); var fitness = generator.Generate <double>(); var chromosome = new Chromosome <Guid>(value, fitness); Assert.AreEqual(value, chromosome.Value); Assert.AreEqual(fitness, chromosome.Fitness); }
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); }
public void CreateWithException() { var generator = new RandomObjectGenerator(); var parameter = generator.Generate <double>(); var exception = generator.Generate <ArithmeticException>(); var evolverResult = new ExpressionEvolverResult(parameter, exception); Assert.AreEqual(parameter, evolverResult.Parameter); Assert.AreSame(exception, evolverResult.Exception); }
public void CreateWithResult() { var generator = new RandomObjectGenerator(); var parameter = generator.Generate <double>(); var result = generator.Generate <double>(); var evolverResult = new ExpressionEvolverResult(parameter, result); Assert.AreEqual(parameter, evolverResult.Parameter); Assert.AreEqual(result, evolverResult.Result); Assert.IsNull(evolverResult.Exception); }
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); }
public void ChangeValue() { var generator = new RandomObjectGenerator(); var value = generator.Generate <Guid>(); var fitness = generator.Generate <double>(); var chromosome = new Chromosome <Guid>( generator.Generate <Guid>(), fitness); chromosome.Value = value; Assert.AreEqual(value, chromosome.Value); }
public void Fetch() { var generator = new RandomObjectGenerator(); var referenceType = generator.Generate <string>(); var valueType = generator.Generate <bool>(); var referenceTypeNotAStringId = generator.Generate <Guid>(); var parent = RootObject.Fetch(referenceType, valueType, new ReferenceTypeNotAString(referenceTypeNotAStringId)); Assert.IsFalse(parent.IsDirty); Assert.IsFalse(parent.Child.IsDirty); }
public void SetDataBackToOriginalValueWithValueType() { var data = new FieldDataUsingOriginalValueViaHashCode <int>("name"); data.MarkClean(); var generator = new RandomObjectGenerator(); var originalValue = generator.Generate <int>(); data.Value = originalValue; data.Value = generator.Generate <int>(); data.Value = originalValue; Assert.IsFalse(data.IsDirty); }
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(); }
public void GetUser() { var generator = new RandomObjectGenerator(); var userId = generator.Generate <int>(); var profileId = generator.Generate <string>(); var emailAddress = generator.Generate <string>(); var firstName = generator.Generate <string>(); var lastName = generator.Generate <string>(); var gender = generator.Generate <string>(); var birthDate = generator.Generate <DateTime>(); var postalCode = generator.Generate <string>(); var userName = generator.Generate <string>(); var user = new Mock <IUser>(MockBehavior.Strict); user.SetupGet(_ => _.UserID).Returns(userId); user.SetupGet(_ => _.ProfileID).Returns(profileId); user.SetupGet(_ => _.EmailAddress).Returns(emailAddress); user.SetupGet(_ => _.FirstName).Returns(firstName); user.SetupGet(_ => _.LastName).Returns(lastName); user.SetupGet(_ => _.Gender).Returns(gender); user.SetupGet(_ => _.BirthDate).Returns(birthDate); user.SetupGet(_ => _.PostalCode).Returns(postalCode); user.SetupGet(_ => _.UserName).Returns(userName); var userFactory = new Mock <IObjectFactory <IUser> >(MockBehavior.Strict); userFactory.Setup(_ => _.Fetch(profileId)).Returns(user.Object); var auth = new Mock <IMyVoteAuthentication>(MockBehavior.Strict); auth.Setup(_ => _.GetCurrentUserID()).Returns(userId); var controller = new UserController(); controller.UserFactory = userFactory.Object; controller.MyVoteAuthentication = auth.Object; var result = controller.Get(profileId); Assert.IsFalse(string.IsNullOrWhiteSpace(result.UserName)); Assert.AreEqual(userId, result.UserID); Assert.AreEqual(profileId, result.ProfileID); Assert.AreEqual(emailAddress, result.EmailAddress); Assert.AreEqual(firstName, result.FirstName); Assert.AreEqual(lastName, result.LastName); Assert.AreEqual(gender, result.Gender); Assert.AreEqual(birthDate, result.BirthDate); Assert.AreEqual(postalCode, result.PostalCode); Assert.AreEqual(userName, result.UserName); userFactory.VerifyAll(); user.VerifyAll(); }
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(); }
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(), new ActivatorCallContext()) .Bind(() => ApplicationContext.DataPortalActivator)) { var user = new DataPortal <User>().Create(profileId); Assert.IsNull(user.BirthDate, nameof(user.BirthDate)); Assert.AreEqual(string.Empty, user.EmailAddress, nameof(user.EmailAddress)); Assert.AreEqual(string.Empty, user.FirstName, nameof(user.FirstName)); Assert.AreEqual(string.Empty, user.Gender, nameof(user.Gender)); Assert.AreEqual(string.Empty, user.LastName, nameof(user.LastName)); Assert.AreEqual(string.Empty, user.PostalCode, nameof(user.PostalCode)); Assert.AreEqual(string.Empty, user.ProfileAuthToken, nameof(user.ProfileAuthToken)); Assert.AreEqual(profileId, user.ProfileID, nameof(user.ProfileID)); Assert.IsNull(user.UserID, nameof(user.UserID)); Assert.AreEqual(string.Empty, user.UserName, nameof(user.UserName)); Assert.IsNull(user.UserRoleID, nameof(user.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); } }
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(), new ActivatorCallContext()) .Bind(() => ApplicationContext.DataPortalActivator)) { var identity = DataPortal.Fetch <UserIdentity>(profileId); Assert.AreEqual(string.Empty, identity.ProfileID, nameof(identity.ProfileID)); Assert.IsNull(identity.UserID, nameof(identity.UserID)); Assert.AreEqual(string.Empty, identity.UserName, nameof(identity.UserName)); Assert.IsFalse(identity.IsAuthenticated, nameof(identity.IsAuthenticated)); } entities.VerifyAll(); }
public void ChangePollOptionsToValidValue() { var generator = new RandomObjectGenerator(); var userId = generator.Generate <int>(); var pollOptions = new Mock <IObjectFactory <BusinessList <IPollOption> > >(); pollOptions.Setup(_ => _.CreateChild()).Returns(new BusinessList <IPollOption>()); var builder = new ContainerBuilder(); builder.Register <IEntities>(_ => Mock.Of <IEntities>()); builder.Register <IObjectFactory <BusinessList <IPollOption> > >(_ => pollOptions.Object); builder.Register <IObjectFactory <IPollOption> >(_ => Mock.Of <IObjectFactory <IPollOption> >()); using (new ObjectActivator(builder.Build(), new ActivatorCallContext()) .Bind(() => ApplicationContext.DataPortalActivator)) { var poll = DataPortal.Create <Poll>(userId); poll.PollOptions.Add(DataPortal.CreateChild <PollOption>()); poll.PollOptions.Add(DataPortal.CreateChild <PollOption>()); poll.BrokenRulesCollection.AssertRuleCount(Poll.PollOptionsProperty, 0); } }
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(); }
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(); }
public void BindToInternalInstanceProperty() { var generator = new RandomObjectGenerator(); var original = generator.Generate<string>(); var newValue = generator.Generate<string>(); var binded = new Binded { InternalInstanceProperty = original }; Assert.AreEqual(original, binded.InternalInstanceProperty); using (newValue.Bind(() => binded.InternalInstanceProperty)) { Assert.AreEqual(newValue, binded.InternalInstanceProperty); } Assert.AreEqual(original, binded.InternalInstanceProperty); }
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); } }
public void ChangeReferenceTypeThatIsNotAStringAndUndo() { var generator = new RandomObjectGenerator(); var parent = RootObject.Fetch(generator.Generate <string>(), generator.Generate <bool>(), new ReferenceTypeNotAString(generator.Generate <Guid>())); var oldValue = parent.ReferenceTypeNotAString.Value; var newValue = generator.Generate <Guid>(); parent.ReferenceTypeNotAString = new ReferenceTypeNotAString(newValue); parent.ReferenceTypeNotAString = new ReferenceTypeNotAString(oldValue); Assert.AreEqual(oldValue, parent.ReferenceTypeNotAString.Value); Assert.IsFalse(parent.IsDirty); Assert.IsFalse(parent.Child.IsDirty); }
public void BindToInternalStaticProperty() { var generator = new RandomObjectGenerator(); var original = generator.Generate<string>(); var newValue = generator.Generate<string>(); Binded.InternalStaticProperty = original; Assert.AreEqual(original, Binded.InternalStaticProperty); using (newValue.Bind(() => Binded.InternalStaticProperty)) { Assert.AreEqual(newValue, Binded.InternalStaticProperty); } Assert.AreEqual(original, Binded.InternalStaticProperty); }
public void ChangeUserNameToValidValue() { var generator = new RandomObjectGenerator(); var profileId = generator.Generate<string>(); var userName = generator.Generate<string>(); var builder = new ContainerBuilder(); builder.Register<IEntities>(_ => Mock.Of<IEntities>()); using (new ObjectActivator(builder.Build()).Bind(() => ApplicationContext.DataPortalActivator)) { var user = DataPortal.Create<User>(profileId); user.UserName = userName; user.BrokenRulesCollection.AssertRuleCount(User.UserNameProperty, 0); } }
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(); }
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(); }
public void Respond() { var generator = new RandomObjectGenerator(); var userId = generator.Generate <int>(); var response = EntityCreator.Create <Models.PollResponse>(); var pollSubmission = new Mock <IPollSubmission>(MockBehavior.Strict); pollSubmission.Setup(_ => _.Save()).Returns(null); var pollSubmissionFactory = new Mock <IObjectFactory <IPollSubmission> >(MockBehavior.Strict); pollSubmissionFactory.Setup(_ => _.Create(It.IsAny <object>())).Returns(pollSubmission.Object); var auth = new Mock <IMyVoteAuthentication>(MockBehavior.Strict); auth.Setup(_ => _.GetCurrentUserID()).Returns(userId); var controller = new RespondController(); controller.PollSubmissionFactory = pollSubmissionFactory.Object; controller.MyVoteAuthentication = auth.Object; controller.Put(response); pollSubmissionFactory.VerifyAll(); pollSubmission.VerifyAll(); auth.VerifyAll(); }
public void ChangePollCategoryIdToValidValue() { var generator = new RandomObjectGenerator(); var userId = generator.Generate<int>(); var pollCategoryId = generator.Generate<int>(); var builder = new ContainerBuilder(); builder.Register<IEntities>(_ => Mock.Of<IEntities>()); using (new ObjectActivator(builder.Build()).Bind(() => ApplicationContext.DataPortalActivator)) { var poll = DataPortal.Create<Poll>(userId); poll.PollCategoryID = pollCategoryId; poll.BrokenRulesCollection.AssertRuleCount(Poll.PollCategoryIDProperty, 0); } }
public void CreateViaResultsAndNullRandom() { var generator = new RandomObjectGenerator(); var results = generator.Generate <ReadOnlyCollection <ExpressionEvolverResult> >(); using (var parameters = new ExpressionEvolverGeneticAlgorithmParameters( results, null)) { } }
public void UpdateUser() { var generator = new RandomObjectGenerator(); var profileId = generator.Generate <string>(); var userId = generator.Generate <int>(); var value = new Models.User(); var user = new Mock <IUser>(MockBehavior.Strict); user.SetupSet(_ => _.BirthDate = value.BirthDate); user.SetupSet(_ => _.EmailAddress = value.EmailAddress); user.SetupSet(_ => _.FirstName = value.FirstName); user.SetupSet(_ => _.Gender = value.Gender); user.SetupSet(_ => _.LastName = value.LastName); user.SetupSet(_ => _.PostalCode = value.PostalCode); user.SetupSet(_ => _.UserName = value.UserName); user.SetupGet(_ => _.UserID).Returns(userId); user.SetupGet(_ => _.UserName).Returns(default(string)); user.SetupGet(_ => _.BirthDate).Returns(default(DateTime)); user.SetupGet(_ => _.EmailAddress).Returns(default(string)); user.SetupGet(_ => _.FirstName).Returns(default(string)); user.SetupGet(_ => _.Gender).Returns(default(string)); user.SetupGet(_ => _.LastName).Returns(default(string)); user.SetupGet(_ => _.PostalCode).Returns(default(string)); user.Setup(_ => _.Save()).Returns(null); var userFactory = new Mock <IObjectFactory <IUser> >(MockBehavior.Strict); userFactory.Setup(_ => _.Fetch(profileId)).Returns(user.Object); var auth = new Mock <IMyVoteAuthentication>(MockBehavior.Strict); auth.Setup(_ => _.GetCurrentUserID()).Returns(userId); var controller = new UserController(); controller.UserFactory = userFactory.Object; controller.MyVoteAuthentication = auth.Object; controller.Put(profileId, value); auth.VerifyAll(); userFactory.VerifyAll(); user.VerifyAll(); }
public void GetUser() { var generator = new RandomObjectGenerator(); var userId = generator.Generate<int>(); var profileId = generator.Generate<string>(); var emailAddress = generator.Generate<string>(); var firstName = generator.Generate<string>(); var lastName = generator.Generate<string>(); var gender = generator.Generate<string>(); var birthDate = generator.Generate<DateTime>(); var postalCode = generator.Generate<string>(); var userName = generator.Generate<string>(); var user = new Mock<IUser>(MockBehavior.Strict); user.SetupGet(_ => _.UserID).Returns(userId); user.SetupGet(_ => _.ProfileID).Returns(profileId); user.SetupGet(_ => _.EmailAddress).Returns(emailAddress); user.SetupGet(_ => _.FirstName).Returns(firstName); user.SetupGet(_ => _.LastName).Returns(lastName); user.SetupGet(_ => _.Gender).Returns(gender); user.SetupGet(_ => _.BirthDate).Returns(birthDate); user.SetupGet(_ => _.PostalCode).Returns(postalCode); user.SetupGet(_ => _.UserName).Returns(userName); var userFactory = new Mock<IObjectFactory<IUser>>(MockBehavior.Strict); userFactory.Setup(_ => _.Fetch(profileId)).Returns(user.Object); var auth = new Mock<IMyVoteAuthentication>(MockBehavior.Strict); auth.Setup(_ => _.GetCurrentUserID()).Returns(userId); var controller = new UserController(); controller.UserFactory = userFactory.Object; controller.MyVoteAuthentication = auth.Object; var result = controller.Get(profileId); Assert.IsFalse(string.IsNullOrWhiteSpace(result.UserName)); Assert.AreEqual(userId, result.UserID); Assert.AreEqual(profileId, result.ProfileID); Assert.AreEqual(emailAddress, result.EmailAddress); Assert.AreEqual(firstName, result.FirstName); Assert.AreEqual(lastName, result.LastName); Assert.AreEqual(gender, result.Gender); Assert.AreEqual(birthDate, result.BirthDate); Assert.AreEqual(postalCode, result.PostalCode); Assert.AreEqual(userName, result.UserName); userFactory.VerifyAll(); user.VerifyAll(); }
public void ChangePollEndDateToValidValue() { var generator = new RandomObjectGenerator(); var userId = generator.Generate<int>(); var endDate = generator.Generate<DateTime>(); var builder = new ContainerBuilder(); builder.Register<IEntities>(_ => Mock.Of<IEntities>()); using (new ObjectActivator(builder.Build()).Bind(() => ApplicationContext.DataPortalActivator)) { var poll = DataPortal.Create<Poll>(userId); poll.PollEndDate = endDate; poll.BrokenRulesCollection.AssertValidationRuleExists<RequiredAttribute>( Poll.PollEndDateProperty, false); } }
private static BusinessList<IPollOption> CreateOptions() { 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.Loose); option.Setup(_ => _.IsChild).Returns(true); option.Setup(_ => _.PollOptionID).Returns(optionId); option.Setup(_ => _.OptionPosition).Returns(optionPosition); option.Setup(_ => _.OptionText).Returns(optionText); var options = new BusinessList<IPollOption>(); options.Add(option.Object); return options; }
public void ChangeUserNameToValidValue() { var generator = new RandomObjectGenerator(); var profileId = generator.Generate <string>(); var userName = generator.Generate <string>(); var builder = new ContainerBuilder(); builder.Register <IEntities>(_ => Mock.Of <IEntities>()); using (new ObjectActivator(builder.Build(), new ActivatorCallContext()) .Bind(() => ApplicationContext.DataPortalActivator)) { var user = DataPortal.Create <User>(profileId); user.UserName = userName; user.BrokenRulesCollection.AssertRuleCount(User.UserNameProperty, 0); } }
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>(MockBehavior.Strict); poll.Setup(_ => _.PollID).Returns(pollId); var pollOptions = new InMemoryDbSet <MVPollOption>(); var entities = new Mock <IEntities>(MockBehavior.Strict); entities.Setup(_ => _.MVPollOptions) .Returns(pollOptions); entities.Setup(_ => _.SaveChanges()) .Callback(() => pollOptions.Local[0].PollOptionID = pollOptionId) .Returns(1); entities.Setup(_ => _.Dispose()); var builder = new ContainerBuilder(); builder.Register <IEntities>(_ => entities.Object); using (new ObjectActivator(builder.Build(), new ActivatorCallContext()) .Bind(() => ApplicationContext.DataPortalActivator)) { var pollOption = DataPortal.CreateChild <PollOption>(); pollOption.OptionPosition = optionPosition; pollOption.OptionText = optionText; DataPortal.UpdateChild(pollOption, poll.Object); Assert.AreEqual(pollId, pollOption.PollID, nameof(pollOption.PollID)); Assert.AreEqual(pollOptionId, pollOption.PollOptionID, nameof(pollOption.PollOptionID)); Assert.AreEqual(optionPosition, pollOption.OptionPosition, nameof(pollOption.OptionPosition)); Assert.AreEqual(optionText, pollOption.OptionText, nameof(pollOption.OptionText)); } entities.VerifyAll(); poll.VerifyAll(); }
public void CreateViaResults() { var generator = new RandomObjectGenerator(); var results = generator.Generate <ReadOnlyCollection <ExpressionEvolverResult> >(); using (var parameters = new ExpressionEvolverGeneticAlgorithmParameters(results)) { CollectionAssert.AreEquivalent(results, parameters.Results); } }
public void ChangePollQuestionToInvalidValue() { var generator = new RandomObjectGenerator(); var userId = generator.Generate<int>(); var pollQuestion = new string(generator.Generate<string>()[0], 1001); var builder = new ContainerBuilder(); builder.Register<IEntities>(_ => Mock.Of<IEntities>()); using (new ObjectActivator(builder.Build()).Bind(() => ApplicationContext.DataPortalActivator)) { var poll = DataPortal.Create<Poll>(userId); poll.PollQuestion = pollQuestion; poll.BrokenRulesCollection.AssertRuleCount(Poll.PollQuestionProperty, 1); poll.BrokenRulesCollection.AssertValidationRuleExists<StringLengthAttribute>( Poll.PollQuestionProperty, true); } }
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 }); entities.Setup(_ => _.Dispose()); var pollFactory = new Mock <IObjectFactory <IPoll> >(); pollFactory.Setup(_ => _.Fetch(pollId)).Returns <int>(_ => DataPortal.Fetch <Poll>(_)); var pollSubmissionResponsesFactory = new Mock <IObjectFactory <IPollSubmissionResponseCollection> >(); pollSubmissionResponsesFactory.Setup(_ => _.CreateChild(It.IsAny <object[]>())) .Returns <object[]>(_ => DataPortal.CreateChild <PollSubmissionResponseCollection>(_[0] as BusinessList <IPollOption>)); var builder = new ContainerBuilder(); builder.Register <IEntities>(_ => entities.Object); builder.Register <IObjectFactory <IPoll> >(_ => pollFactory.Object); builder.Register <IObjectFactory <IPollSubmissionResponseCollection> >(_ => pollSubmissionResponsesFactory.Object); using (new ObjectActivator(builder.Build(), Mock.Of <ICallContext>()) .Bind(() => ApplicationContext.DataPortalActivator)) { var criteria = new PollSubmissionCriteria(pollId, userId); new DataPortal <PollSubmission>().Create(criteria); } }
private static BusinessList <IPollOption> CreateOptions() { 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.Loose); option.Setup(_ => _.IsChild).Returns(true); option.Setup(_ => _.PollOptionID).Returns(optionId); option.Setup(_ => _.OptionPosition).Returns(optionPosition); option.Setup(_ => _.OptionText).Returns(optionText); var options = new BusinessList <IPollOption>(); options.Add(option.Object); return(options); }
public void ChangePollQuestionToValidValue() { var generator = new RandomObjectGenerator(); var userId = generator.Generate <int>(); var pollQuestion = new string(generator.Generate <string>()[0], 1); var builder = new ContainerBuilder(); builder.Register <IEntities>(_ => Mock.Of <IEntities>()); builder.Register <IObjectFactory <BusinessList <IPollOption> > >(_ => Mock.Of <IObjectFactory <BusinessList <IPollOption> > >()); builder.Register <IObjectFactory <IPollOption> >(_ => Mock.Of <IObjectFactory <IPollOption> >()); using (new ObjectActivator(builder.Build(), new ActivatorCallContext()) .Bind(() => ApplicationContext.DataPortalActivator)) { var poll = DataPortal.Create <Poll>(userId); poll.PollQuestion = pollQuestion; poll.BrokenRulesCollection.AssertRuleCount(Poll.PollQuestionProperty, 0); } }
public void Create() { var generator = new RandomObjectGenerator(); var userId = generator.Generate<int>(); var builder = new ContainerBuilder(); builder.Register<IEntities>(_ => Mock.Of<IEntities>()); using (new ObjectActivator(builder.Build()).Bind(() => ApplicationContext.DataPortalActivator)) { var poll = new DataPortal<Poll>().Create(userId); Assert.IsNull(poll.PollAdminRemovedFlag, poll.GetPropertyName(_ => _.PollAdminRemovedFlag)); Assert.IsNull(poll.PollCategoryID, poll.GetPropertyName(_ => _.PollCategoryID)); Assert.IsNull(poll.PollDateRemoved, poll.GetPropertyName(_ => _.PollDateRemoved)); Assert.IsNull(poll.PollDeletedDate, poll.GetPropertyName(_ => _.PollDeletedDate)); Assert.IsNull(poll.PollDeletedFlag, poll.GetPropertyName(_ => _.PollDeletedFlag)); Assert.AreEqual(string.Empty, poll.PollDescription, poll.GetPropertyName(_ => _.PollDescription)); Assert.IsNull(poll.PollEndDate, poll.GetPropertyName(_ => _.PollEndDate)); Assert.IsNull(poll.PollID, poll.GetPropertyName(_ => _.PollID)); Assert.AreEqual(string.Empty, poll.PollImageLink, poll.GetPropertyName(_ => _.PollImageLink)); Assert.IsNull(poll.PollMaxAnswers, poll.GetPropertyName(_ => _.PollMaxAnswers)); Assert.IsNull(poll.PollMinAnswers, poll.GetPropertyName(_ => _.PollMinAnswers)); Assert.AreEqual(string.Empty, poll.PollQuestion, poll.GetPropertyName(_ => _.PollQuestion)); Assert.IsNull(poll.PollStartDate, poll.GetPropertyName(_ => _.PollStartDate)); Assert.AreEqual(userId, poll.UserID, poll.GetPropertyName(_ => _.UserID)); Assert.AreEqual(0, poll.PollOptions.Count, poll.GetPropertyName(_ => _.PollOptions)); poll.BrokenRulesCollection.AssertRuleCount(7); poll.BrokenRulesCollection.AssertRuleCount(Poll.PollStartDateProperty, 1); poll.BrokenRulesCollection.AssertValidationRuleExists<RequiredAttribute>( Poll.PollStartDateProperty, true); poll.BrokenRulesCollection.AssertRuleCount(Poll.PollEndDateProperty, 1); poll.BrokenRulesCollection.AssertValidationRuleExists<RequiredAttribute>( Poll.PollEndDateProperty, true); poll.BrokenRulesCollection.AssertRuleCount(Poll.PollCategoryIDProperty, 1); poll.BrokenRulesCollection.AssertValidationRuleExists<RequiredAttribute>( Poll.PollCategoryIDProperty, true); poll.BrokenRulesCollection.AssertRuleCount(Poll.PollQuestionProperty, 1); poll.BrokenRulesCollection.AssertValidationRuleExists<RequiredAttribute>( Poll.PollQuestionProperty, true); poll.BrokenRulesCollection.AssertRuleCount(Poll.PollMinAnswersProperty, 1); poll.BrokenRulesCollection.AssertValidationRuleExists<RequiredAttribute>( Poll.PollMinAnswersProperty, true); poll.BrokenRulesCollection.AssertRuleCount(Poll.PollMaxAnswersProperty, 1); poll.BrokenRulesCollection.AssertValidationRuleExists<RequiredAttribute>( Poll.PollMaxAnswersProperty, true); poll.BrokenRulesCollection.AssertRuleCount(Poll.PollOptionsProperty, 1); poll.BrokenRulesCollection.AssertBusinessRuleExists<PollOptionsRule>( Poll.PollOptionsProperty, true); } }
public void ChildFetchWithOutMiddleName() { // Arrange var generator = new RandomObjectGenerator(); var expected = new E.Person { Id = generator.Generate<int>(), FirstName = generator.Generate<string>(), MiddleName = string.Empty, LastName = generator.Generate<string>(), Gender = generator.Generate<string>() }; var expectedFullname = string.Format("{0} {1}", expected.FirstName, expected.LastName); // Act var actual = AssemblyTests.DoChildOperation(() => DataPortal.FetchChild<PersonView>(expected)); // Assert Assert.IsNotNull(actual); Assert.AreEqual(expected.Id, actual.Id, actual.GetPropertyName(_ => _.Id)); Assert.AreEqual(expectedFullname, actual.FullName, actual.GetPropertyName(_ => _.FullName)); Assert.AreEqual(expected.Gender, actual.Gender, actual.GetPropertyName(_ => _.Gender)); }
public void ChangeOptionTextToValidValue() { var builder = new ContainerBuilder(); builder.Register<IEntities>(_ => Mock.Of<IEntities>()); using (new ObjectActivator(builder.Build()).Bind(() => ApplicationContext.DataPortalActivator)) { var generator = new RandomObjectGenerator(); var optionPosition = new string(generator.Generate<string>()[0], 1); var pollOption = DataPortal.CreateChild<PollOption>(); pollOption.OptionText = optionPosition; pollOption.BrokenRulesCollection.AssertRuleCount(PollOption.OptionTextProperty, 0); } }
public void FetchById() { var generator = new RandomObjectGenerator(); var id = generator.Generate<int>(); var products = new InMemoryDbSet<E.Product> { EntityCreator.Create<E.Product>(_ => { _.Id = id; }) }; var context = new Mock<IEntityContext>(MockBehavior.Strict); context.Setup(_ => _.Products).Returns(products); context.Setup(_ => _.Dispose()); var container = new ContainerBuilder(); container.Register<IEntityContext>(_ => context.Object); using (container.Build().Bind(() => IoC.Container)) { var actual = DataPortal.Fetch<Product>(id); Assert.AreEqual(id, actual.Id, actual.GetPropertyName(_ => _.Id)); context.VerifyAll(); } }
public void Edit() { using (var target = new PeopleController()) { var generator = new RandomObjectGenerator(); var id = generator.Generate<int>(); var person = new Mock<IPerson>(MockBehavior.Strict); person.Setup(_ => _.Id).Returns(id); var personFactory = new Mock<IObjectFactory<IPerson>>(MockBehavior.Strict); personFactory.Setup(_ => _.Fetch(It.Is<int>(__ => __ == id))).Returns(person.Object); target.PersonFactory = personFactory.Object; var actual = target.Edit(id) as ViewResult; Assert.AreEqual(string.Empty, actual.ViewName, "ViewName"); Assert.AreSame(person.Object, (actual.Model as PersonModel).ModelObject, "Model"); personFactory.VerifyAll(); } }