/// <summary> /// CTOR - from builder /// </summary> /// <param name="builder">Builder</param> protected Member(MemberBuilder builder) { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } SourceFiles = builder.SourceFiles; Name = builder.Name; NameBase = builder.NameBase; MemberKind = builder.MemberKind; Root = builder.Root; Assembly = builder.Assembly; Namespace = builder.Namespace; Modifier = builder.Modifier; IsAbstract = builder.IsAbstract; IsExtern = builder.IsExtern; IsSealed = builder.IsSealed; IsStatic = builder.IsStatic; IsNew = builder.IsNew; IsOverride = builder.IsOverride; IsVirtual = builder.IsVirtual; Attributes = builder.Attributes; AttributeTypeRefs = builder.AttributeTypeRefs; DocumentationId = builder.DocumentationId; DocumentationXml = builder.DocumentationXml; Documentation = builder.Documentation; Symbol = builder.Symbol; Id = Base36(StableHash(DocumentationId ?? MemberKind + "_" + Name)); AllMembers = new List <Member>(); //To be filled in child classes }
public void MustNotHavePersonalDataIsNull() { // Then Assert.Throws <DomainException>(() => MemberBuilder.New().WithPersonalData(null).Build()) .WithMessage(MemberValidation.PersonalDataIsEmpty); }
public void MustNotHaveInvalidOccupation(string invalidOccupation) { // Then Assert.Throws <DomainException>(() => MemberBuilder.New().WithOccupation(invalidOccupation).Build()) .WithMessage(MemberValidation.OccupationIsEmpty, MemberValidation.OccupationIsInvalid); }
public void MustNotHaveInvalidChurch(string invalidChurch) { // Then Assert.Throws <DomainException>(() => MemberBuilder.New().WithChurch(invalidChurch).Build()) .WithMessage(MemberValidation.ChurchIsEmpty, MemberValidation.ChurchIsInvalid); }
public void SavingUpdatesNameAndEmail() { IMember sut; var provider = ScopeProvider; using (var scope = provider.CreateScope()) { var repository = CreateRepository(provider); var memberType = MemberTypeBuilder.CreateSimpleMemberType(); MemberTypeRepository.Save(memberType); var member = MemberBuilder.CreateSimpleMember(memberType, "Johnny Hefty", "*****@*****.**", "123", "hefty"); repository.Save(member); sut = repository.Get(member.Id); sut.Username = "******"; sut.Email = "*****@*****.**"; repository.Save(sut); sut = repository.Get(member.Id); Assert.That(sut.Email, Is.EqualTo("*****@*****.**")); Assert.That(sut.Username, Is.EqualTo("This is new")); } }
public void MemberHasBuiltinProperties() { var provider = ScopeProvider; using (var scope = provider.CreateScope()) { var repository = CreateRepository(provider); var memberType = MemberTypeBuilder.CreateSimpleMemberType(); MemberTypeRepository.Save(memberType); var member = MemberBuilder.CreateSimpleMember(memberType, "Johnny Hefty", "*****@*****.**", "123", "hefty"); repository.Save(member); var sut = repository.Get(member.Id); Assert.That(memberType.CompositionPropertyGroups.Count(), Is.EqualTo(2)); Assert.That(memberType.CompositionPropertyTypes.Count(), Is.EqualTo(3 + ConventionsHelper.GetStandardPropertyTypeStubs(ShortStringHelper).Count)); Assert.That(sut.Properties.Count(), Is.EqualTo(3 + ConventionsHelper.GetStandardPropertyTypeStubs(ShortStringHelper).Count)); var grp = memberType.CompositionPropertyGroups.FirstOrDefault(x => x.Name == Constants.Conventions.Member.StandardPropertiesGroupName); Assert.IsNotNull(grp); var aliases = ConventionsHelper.GetStandardPropertyTypeStubs(ShortStringHelper).Select(x => x.Key) .ToArray(); foreach (var p in memberType.CompositionPropertyTypes.Where(x => aliases.Contains(x.Alias))) { Assert.AreEqual(grp.Id, p.PropertyGroupId.Value); } } }
public void GivenProductsWithCurrentCampaignWithSomeThatApplyToTheMember_WhenQuerying_ThenReturnTheProductsThatApplyToTheMember() { var member = new MemberBuilder().InState(State.Wa).WithAge(10, _now).Build(); var products = Builder <ProductBuilder> .CreateListOfSize(3) .TheFirst(1).With(b => b.WithName("1").WithCampaign(_now, new CampaignBuilder() .ForAllMembers() .StartingAt(_now.AddDays(-1)) .EndingAt(_now.AddDays(1)) )) .TheNext(1).With(b => b.WithName("2").WithCampaign(_now, new CampaignBuilder() .ForState(State.Act) .StartingAt(_now.AddDays(-1)) .EndingAt(_now.AddDays(1)) )) .TheNext(1).With(b => b.WithName("3").WithCampaign(_now, new CampaignBuilder() .ForState(State.Wa) .WithMinimumAge(9) .WithMaximumAge(11) .StartingAt(_now.AddDays(-1)) .EndingAt(_now.AddDays(1)) )) .BuildList(); products.ToList().ForEach(p => Session.Save(p)); var result = Execute(new GetProductsForMember(_now, member)); Assert.That(result.Select(p => p.Name).ToArray(), Is.EqualTo(new[] { products[0].Name, products[2].Name })); }
public void SavingPreservesPassword() { IMember sut; var provider = ScopeProvider; using (var scope = provider.CreateScope()) { var repository = CreateRepository(provider); var memberType = MemberTypeBuilder.CreateSimpleMemberType(); MemberTypeRepository.Save(memberType); var member = MemberBuilder.CreateSimpleMember(memberType, "Johnny Hefty", "*****@*****.**", "123", "hefty"); repository.Save(member); sut = repository.Get(member.Id); // When the password is null it will not overwrite what is already there. sut.RawPasswordValue = null; repository.Save(sut); sut = repository.Get(member.Id); Assert.That(sut.RawPasswordValue, Is.EqualTo("123")); } }
public void GivenProductsWithCurrentCampaignWithSomeThatApplyToTheMember_WhenQuerying_ThenReturnTheProductsThatApplyToTheMember() { var member = new MemberBuilder().InState(State.Wa).WithAge(10, _now).Build(); var products = new[] { new ProductBuilder().WithName("1").WithCampaign(_now, new CampaignBuilder() .ForAllMembers() .StartingAt(_now.AddDays(-1)) .EndingAt(_now.AddDays(1)) ).Build(), new ProductBuilder().WithName("2").WithCampaign(_now, new CampaignBuilder() .ForState(State.Act) .StartingAt(_now.AddDays(-1)) .EndingAt(_now.AddDays(1)) ).Build(), new ProductBuilder().WithName("2").WithCampaign(_now, new CampaignBuilder() .ForState(State.Wa) .WithMinimumAge(9) .WithMaximumAge(11) .StartingAt(_now.AddDays(-1)) .EndingAt(_now.AddDays(1)) ).Build() }; products.ToList().ForEach(p => Session.Save(p)); var result = Execute(new GetProductsForMember(_now, member)); Assert.That(result.Select(p => p.Name).ToArray(), Is.EqualTo(new[]{products[0].Name, products[2].Name})); }
public void GivenProductsWithCurrentCampaignWithSomeThatApplyToTheMember_WhenQuerying_ThenReturnTheProductsThatApplyToTheMember() { var member = new MemberBuilder().InState(State.Wa).WithAge(10, _now).Build(); var products = Builder<ProductBuilder>.CreateListOfSize(3) .TheFirst(1).With(b => b.WithName("1").WithCampaign(_now, ObjectMother.Campaigns.Current(_now) .ForAllMembers() )) .TheNext(1).With(b => b.WithName("2").WithCampaign(_now, ObjectMother.Campaigns.Current(_now) .ForState(State.Act) )) .TheNext(1).With(b => b.WithName("3").WithCampaign(_now, ObjectMother.Campaigns.Current(_now) .ForState(State.Wa) .WithMinimumAge(9) .WithMaximumAge(11) )) .BuildList(); products.ToList().ForEach(p => Session.Save(p)); var result = Execute(new GetProductsForMember(_now, member)); Assert.That(result.Select(p => p.Name).ToArray(), Is.EqualTo(new[] { products[0].Name, products[2].Name })); }
bool exec(string name) { IMember member = new MemberBuilder() .AddMemberInfo(typeof(TestClass).GetMembers().Where(x => x.Name.ToLower() == name.ToLower()).First()) .Build(); return(new FactoryResultExistChecker(new AttributesFinder()) .Check(member)); }
public void GivenDemographicForAnyAgeAndSpecificState_WhenCheckingIfTheDemographicAppliesToAMember_ThenReturnTrueOnlyIfMemberIsInThatState([ValueSource("AllStates")] State memberState, [ValueSource("AllStates")] State demographicState) { var member = new MemberBuilder().InState(memberState).Build(); var demographic = new DemographicBuilder().ForState(demographicState).Build(); var applies = demographic.Contains(member, DateTime.UtcNow); Assert.That(applies, Is.EqualTo(memberState == demographicState)); }
public void GivenDemographicForAllMembers_WhenCheckingIfTheDemographicAppliesToAMember_ThenReturnTrue() { var member = new MemberBuilder().Build(); var demographic = new DemographicBuilder().ForAllMembers().Build(); var applies = demographic.Contains(member, DateTime.UtcNow); Assert.That(applies, Is.True); }
public void GivenDemographicForAnyStateWithMaximumAgeAndMemberOlderThanThatAge_WhenCheckingIfTheDemographicAppliesToAMember_ThenReturnTrueOnlyIfMemberIsThatAgeOrYounger([Range(1, 25)] int memberAge, [Range(1, 25)] int maximumAge) { var now = DateTime.UtcNow; var member = new MemberBuilder().WithAge(memberAge, now).Build(); var demographic = new DemographicBuilder().WithMaximumAge(maximumAge).Build(); var applies = demographic.Contains(member, now); Assert.That(applies, Is.EqualTo(memberAge <= maximumAge)); }
public void GivenDemographicForAnyAgeAndSpecificState_WhenCheckingIfTheDemographicAppliesToAMember_ThenReturnTrueOnlyIfMemberIsInThatState ([ValueSource("AllStates")] State memberState, [ValueSource("AllStates")] State demographicState) { var member = new MemberBuilder().InState(memberState).Build(); var demographic = new DemographicBuilder().ForState(demographicState).Build(); var applies = demographic.Contains(member, DateTime.UtcNow); Assert.That(applies, Is.EqualTo(memberState == demographicState)); }
public void GivenDemographicForAnyStateWithMinimumAge_WhenCheckingIfTheDemographicAppliesToAMember_ThenReturnTrueOnlyIfMemberIsThatAgeOrOlder([Range(1, 25)] int memberAge, [Range(1, 25)] int minimumAge) { var now = DateTime.UtcNow; var member = new MemberBuilder().WithDateOfBirth(now.AddYears(-(memberAge + 1)).AddSeconds(1)).Build(); var demographic = new DemographicBuilder().WithMinimumAge(minimumAge).Build(); var applies = demographic.Contains(member, now); Assert.That(applies, Is.EqualTo(memberAge >= minimumAge)); }
public void GivenDemographicForAnyStateWithMinimumAge_WhenCheckingIfTheDemographicAppliesToAMember_ThenReturnTrueOnlyIfMemberIsThatAgeOrOlder ([Range(1, 25)] int memberAge, [Range(1, 25)] int minimumAge) { var now = DateTime.UtcNow; var member = new MemberBuilder().WithDateOfBirth(now.AddYears(-(memberAge + 1)).AddSeconds(1)).Build(); var demographic = new DemographicBuilder().WithMinimumAge(minimumAge).Build(); var applies = demographic.Contains(member, now); Assert.That(applies, Is.EqualTo(memberAge >= minimumAge)); }
public void GivenDemographicForAnyStateWithMaximumAgeAndMemberOlderThanThatAge_WhenCheckingIfTheDemographicAppliesToAMember_ThenReturnTrueOnlyIfMemberIsThatAgeOrYounger ([Range(1, 25)] int memberAge, [Range(1, 25)] int maximumAge) { var now = DateTime.UtcNow; var member = new MemberBuilder().WithAge(memberAge, now).Build(); var demographic = new DemographicBuilder().WithMaximumAge(maximumAge).Build(); var applies = demographic.Contains(member, now); Assert.That(applies, Is.EqualTo(memberAge <= maximumAge)); }
private void CreateTestDataForPagingTests(out List <IContent> createdContent, out List <IMember> createdMembers, out List <IMedia> createdMedia) { // Create content createdContent = new List <IContent>(); ContentType contentType = ContentTypeBuilder.CreateBasicContentType("blah"); ContentTypeService.Save(contentType); for (int i = 0; i < 3; i++) { Content c1 = ContentBuilder.CreateBasicContent(contentType); ContentService.Save(c1); createdContent.Add(c1); } // Create media createdMedia = new List <IMedia>(); MediaType imageType = MediaTypeBuilder.CreateImageMediaType("myImage"); MediaTypeService.Save(imageType); for (int i = 0; i < 3; i++) { Media c1 = MediaBuilder.CreateMediaImage(imageType, -1); MediaService.Save(c1); createdMedia.Add(c1); } // Create members MemberType memberType = MemberTypeBuilder.CreateSimpleMemberType("simple"); MemberTypeService.Save(memberType); createdMembers = MemberBuilder.CreateSimpleMembers(memberType, 3).ToList(); GetMemberService().Save(createdMembers); IRelationType relType = RelationService.GetRelationTypeByAlias(Constants.Conventions.RelationTypes.RelatedMediaAlias); // Relate content to media foreach (IContent content in createdContent) { foreach (IMedia media in createdMedia) { RelationService.Relate(content.Id, media.Id, relType); } } // Relate members to media foreach (IMember member in createdMembers) { foreach (IMedia media in createdMedia) { RelationService.Relate(member.Id, media.Id, relType); } } }
public void CreateMembers() { AddressBuilder builderAddress = new AddressBuilder(); MemberBuilder builder = new MemberBuilder(); Pilot member = builder.WithDefaultValues(); //member.Contact.AddUpdateAddress(builderAddress.WithDefaultValues()); //member.Contact.AddUpdateEmail(new EMAIL() { Id = 1, EMail = "*****@*****.**" }); //member.Contact.AddUpdatePhone(new Phone() { Id = 1, PhoneNumber = "0549050750", Type = ContactType.HOME }); //club.AddMember(member); //Pilot p = new Pilot(); //p.Id = 1; //club.AddMember(p); }
protected override void BuildCore(TypePair typePair, BindingConfig bindingConfig) { var members = MemberBuilder.Build(typePair).Where(x => !x.Ignored).ToList(); var equalMembers = new List <MappingMember>(); var mappingMembers = new List <MappingMember>(); var refMembers = new List <MappingMember>(); var collectionMembers = new List <MappingMember>(); var expressionMembers = new List <MappingMember>(); foreach (var item in members) { if (item.IsExpressionMapping) { expressionMembers.Add(item); } else { var memberTypePair = TypePair.Create(item.Source.GetMemberType(), item.Target.GetMemberType()); if (memberTypePair.IsEqualTypes) { equalMembers.Add(item); } else if (memberTypePair.IsBaseTypes) { mappingMembers.Add(item); } else if (config.ReferencePropertyHandle != ReferencePropertyHandle.Ignore) { if (memberTypePair.IsEnumerableTypes) { collectionMembers.Add(item); } else { refMembers.Add(item); } } } } var func = CreateMapper(typePair, equalMembers, mappingMembers); MapperCache.Add(typePair, func); var action = CreateMapperRef(typePair, refMembers, collectionMembers, expressionMembers); if (action != null) { MapperRefCache.Add(typePair, action); } }
public string Serialize(Contract contract, string template, List <Contract> contracts) { var nodes = NodeHelper.GetMembers(contract).ToList(); if (!nodes.Any()) { return(template.Replace("{{Members}}", string.Empty)); } var builder = new MemberBuilder(nodes); template = template.Replace("{{Members}}", builder.Build()); return(template); }
protected override void OnModelCreating(ModelBuilder builder) { MessageBuilder.Build(builder); UserBuilder.Build(builder); ConversationBuilder.Build(builder); FriendsRequestBuilder.Build(builder); MessageBuilder.Build(builder); UserContactBuilder.Build(builder); ContactBuilder.Build(builder); NotificationBuilder.Build(builder); NotificationTypeBuilder.Build(builder); ParticipantBuilder.Build(builder); FileStorageBuilder.Build(builder); ReadReceiptBuilder.Build(builder); MemberBuilder.Build(builder); }
void IIdeProject.ClearMethodCompilerMessages(MemberBuilder member) { lock (_errorList.Tasks) { _errorList.SuspendRefresh(); try { ClearCompilerMessgesTasks(task => { var memberMsg = task.CompilerMessage as CompilerMessageForMethod; var result = memberMsg != null && memberMsg.Member == member; return(result); }); } finally { _errorList.ResumeRefresh(); } } }
public void GivenDemographicWithStateAndAgeRange_WhenCheckingIfTheDemographicAppliesToAMember_ThenReturnTrueOnlyIfTheMemberConformsToAllParameters([Range(1, 25)] int age, [ValueSource("AllStates")] State state) { var now = DateTime.UtcNow; var member = new MemberBuilder() .InState(state) .WithAge(age, now) .Build(); var demographic = new DemographicBuilder() .ForState(State.Wa) .WithMinimumAge(18) .WithMaximumAge(19) .Build(); var applies = demographic.Contains(member, now); Assert.That(applies, Is.EqualTo(state == State.Wa && (age >= 18 && age <= 19))); }
public void GivenDemographicWithStateAndAgeRange_WhenCheckingIfTheDemographicAppliesToAMember_ThenReturnTrueOnlyIfTheMemberConformsToAllParameters ([Range(1, 25)] int age, [ValueSource("AllStates")] State state) { var now = DateTime.UtcNow; var member = new MemberBuilder() .InState(state) .WithAge(age, now) .Build(); var demographic = new DemographicBuilder() .ForState(State.Wa) .WithMinimumAge(18) .WithMaximumAge(19) .Build(); var applies = demographic.Contains(member, now); Assert.That(applies, Is.EqualTo(state == State.Wa && (age >= 18 && age <= 19))); }
/// This method need only for debugging purpose. bool IsMemberVersionCorrect(MemberBuilder member) { var method = member as MethodBuilderEx; if (method == null) { Debug.Assert(false); return(false); } var treeVer = Engine.TypesTreeVersion; var methodVer = method.TypesTreeVersion; if (methodVer != treeVer) { //Trace.Assert(false, "This should not happen. We have problem with multithreading!"); return(false); } return(true); }
private IMember CreateTestMember(IMemberType memberType = null, string name = null, string email = null, string password = null, string username = null, Guid?key = null) { var provider = ScopeProvider; using (var scope = provider.CreateScope()) { var repository = CreateRepository(provider); if (memberType == null) { memberType = MemberTypeBuilder.CreateSimpleMemberType(); MemberTypeRepository.Save(memberType); } var member = MemberBuilder.CreateSimpleMember(memberType, name ?? "Johnny Hefty", email ?? "*****@*****.**", password ?? "123", username ?? "hefty", key); repository.Save(member); scope.Complete(); return(member); } }
public void Deleting_PropertyType_Removes_The_Property_From_Member() { IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType(); MemberTypeService.Save(memberType); IMember member = MemberBuilder.CreateSimpleMember(memberType, "test", "*****@*****.**", "pass", "test"); MemberService.Save(member); int initProps = member.Properties.Count; // remove a property (NOT ONE OF THE DEFAULTS) Dictionary <string, PropertyType> standardProps = ConventionsHelper.GetStandardPropertyTypeStubs(ShortStringHelper); memberType.RemovePropertyType(memberType.PropertyTypes.First(x => standardProps.ContainsKey(x.Alias) == false).Alias); MemberTypeService.Save(memberType); // re-load it from the db member = MemberService.GetById(member.Id); Assert.AreEqual(initProps - 1, member.Properties.Count); }
void IIdeProject.SetMethodCompilerMessages(MemberBuilder member, IEnumerable <CompilerMessage> messages) { if (!IsMemberVersionCorrect(member)) { return; } var count = _errorList.Tasks.Count; if (count > 100) { _delayedMethodCompilerMessages.Enqueue(messages); } else { SetCompilerMessages(messages, null /* messges related to member was deleted be ClearMethodCompilerMessages() */); } // Following for debugging purpose: //var res = _errorList.Tasks.OfType<NemerleErrorTask>().GroupBy(x => x.ToString()).Where(g => g.Count() > 1).ToArray(); //if (res.Length > 0) // Test(res, Engine.TypesTreeVersion); }
public void Is_Built_Correctly() { // Arrange const int testMemberTypeId = 99; const string testMemberTypeAlias = "memberType"; const string testMemberTypeName = "Member Type"; const string testMemberTypePropertyGroupName = "Content"; const int testId = 10; const string testName = "Fred"; const string testUsername = "******"; const string testRawPasswordValue = "raw pass"; const string testEmail = "*****@*****.**"; const int testCreatorId = 22; const int testLevel = 3; const string testPath = "-1, 4, 10"; const bool testIsApproved = true; const bool testIsLockedOut = true; const int testSortOrder = 5; const bool testTrashed = false; var testKey = Guid.NewGuid(); DateTime testCreateDate = DateTime.Now.AddHours(-1); DateTime testUpdateDate = DateTime.Now; const int testFailedPasswordAttempts = 22; DateTime testLastLockoutDate = DateTime.Now.AddHours(-2); DateTime testLastLoginDate = DateTime.Now.AddHours(-3); DateTime testLastPasswordChangeDate = DateTime.Now.AddHours(-4); var testPropertyType1 = new PropertyTypeDetail { Alias = "title", Name = "Title", SortOrder = 1, DataTypeId = -88 }; var testPropertyType2 = new PropertyTypeDetail { Alias = "bodyText", Name = "Body Text", SortOrder = 2, DataTypeId = -87 }; var testPropertyType3 = new PropertyTypeDetail { Alias = "author", Name = "Author", Description = "Writer of the article", SortOrder = 1, DataTypeId = -88 }; var testGroups = new string[] { "group1", "group2" }; var testPropertyData1 = new KeyValuePair <string, object>("title", "Name member"); var testPropertyData2 = new KeyValuePair <string, object>("bodyText", "This is a subpage"); var testPropertyData3 = new KeyValuePair <string, object>("author", "John Doe"); var testAdditionalData1 = new KeyValuePair <string, object>("test1", 123); var testAdditionalData2 = new KeyValuePair <string, object>("test2", "hello"); const int testPropertyIdsIncrementingFrom = 200; var builder = new MemberBuilder(); // Act Member member = builder .AddMemberType() .WithId(testMemberTypeId) .WithAlias(testMemberTypeAlias) .WithName(testMemberTypeName) .WithMembershipPropertyGroup() .AddPropertyGroup() .WithId(1) .WithName(testMemberTypePropertyGroupName) .WithSortOrder(1) .AddPropertyType() .WithAlias(testPropertyType1.Alias) .WithName(testPropertyType1.Name) .WithSortOrder(testPropertyType1.SortOrder) .WithDataTypeId(testPropertyType1.DataTypeId) .Done() .AddPropertyType() .WithValueStorageType(ValueStorageType.Ntext) .WithAlias(testPropertyType2.Alias) .WithName(testPropertyType2.Name) .WithSortOrder(testPropertyType2.SortOrder) .WithDataTypeId(testPropertyType2.DataTypeId) .Done() .AddPropertyType() .WithAlias(testPropertyType3.Alias) .WithName(testPropertyType3.Name) .WithDescription(testPropertyType3.Description) .WithSortOrder(testPropertyType3.SortOrder) .WithDataTypeId(testPropertyType3.DataTypeId) .Done() .Done() .Done() .WithId(testId) .WithKey(testKey) .WithName(testName) .WithLogin(testUsername, testRawPasswordValue) .WithEmail(testEmail) .WithCreatorId(testCreatorId) .WithCreateDate(testCreateDate) .WithUpdateDate(testUpdateDate) .WithLevel(testLevel) .WithPath(testPath) .WithFailedPasswordAttempts(testFailedPasswordAttempts) .WithIsApproved(testIsApproved) .WithIsLockedOut(testIsLockedOut, testLastLockoutDate) .WithLastLoginDate(testLastLoginDate) .WithLastPasswordChangeDate(testLastPasswordChangeDate) .WithSortOrder(testSortOrder) .WithTrashed(testTrashed) .AddMemberGroups() .WithValue(testGroups[0]) .WithValue(testGroups[1]) .Done() .AddAdditionalData() .WithKeyValue(testAdditionalData1.Key, testAdditionalData1.Value) .WithKeyValue(testAdditionalData2.Key, testAdditionalData2.Value) .Done() .WithPropertyIdsIncrementingFrom(200) .AddPropertyData() .WithKeyValue(testPropertyData1.Key, testPropertyData1.Value) .WithKeyValue(testPropertyData2.Key, testPropertyData2.Value) .WithKeyValue(testPropertyData3.Key, testPropertyData3.Value) .Done() .Build(); // Assert Assert.AreEqual(testMemberTypeId, member.ContentTypeId); Assert.AreEqual(testMemberTypeAlias, member.ContentType.Alias); Assert.AreEqual(testMemberTypeName, member.ContentType.Name); Assert.AreEqual(testId, member.Id); Assert.AreEqual(testKey, member.Key); Assert.AreEqual(testName, member.Name); Assert.AreEqual(testCreateDate, member.CreateDate); Assert.AreEqual(testUpdateDate, member.UpdateDate); Assert.AreEqual(testCreatorId, member.CreatorId); Assert.AreEqual(testFailedPasswordAttempts, member.FailedPasswordAttempts); Assert.AreEqual(testIsApproved, member.IsApproved); Assert.AreEqual(testIsLockedOut, member.IsLockedOut); Assert.AreEqual(testLastLockoutDate, member.LastLockoutDate); Assert.AreEqual(testLastLoginDate, member.LastLoginDate); Assert.AreEqual(testLastPasswordChangeDate, member.LastPasswordChangeDate); Assert.AreEqual(testGroups, member.Groups.ToArray()); Assert.AreEqual(4, member.Properties.Count); // 1 from membership properties group, 3 custom Assert.AreEqual(testPropertyData1.Value, member.GetValue <string>(testPropertyData1.Key)); Assert.AreEqual(testPropertyData2.Value, member.GetValue <string>(testPropertyData2.Key)); Assert.AreEqual(testPropertyData3.Value, member.GetValue <string>(testPropertyData3.Key)); IOrderedEnumerable <int> propertyIds = member.Properties.Select(x => x.Id).OrderBy(x => x); Assert.AreEqual(testPropertyIdsIncrementingFrom + 1, propertyIds.Min()); Assert.AreEqual(testPropertyIdsIncrementingFrom + 4, propertyIds.Max()); Assert.AreEqual(2, member.AdditionalData.Count); Assert.AreEqual(testAdditionalData1.Value, member.AdditionalData[testAdditionalData1.Key]); Assert.AreEqual(testAdditionalData2.Value, member.AdditionalData[testAdditionalData2.Key]); }
public void Get_Paged_Mixed_Entities_By_Ids() { // Create content IContentService contentService = GetRequiredService <IContentService>(); IContentTypeService contentTypeService = GetRequiredService <IContentTypeService>(); var createdContent = new List <IContent>(); ContentType contentType = ContentTypeBuilder.CreateBasicContentType("blah"); contentTypeService.Save(contentType); for (int i = 0; i < 10; i++) { Content c1 = ContentBuilder.CreateBasicContent(contentType); contentService.Save(c1); createdContent.Add(c1); } // Create media IMediaService mediaService = GetRequiredService <IMediaService>(); IMediaTypeService mediaTypeService = GetRequiredService <IMediaTypeService>(); var createdMedia = new List <IMedia>(); MediaType imageType = MediaTypeBuilder.CreateImageMediaType("myImage"); mediaTypeService.Save(imageType); for (int i = 0; i < 10; i++) { Media c1 = MediaBuilder.CreateMediaImage(imageType, -1); mediaService.Save(c1); createdMedia.Add(c1); } // Create members IMemberService memberService = GetRequiredService <IMemberService>(); IMemberTypeService memberTypeService = GetRequiredService <IMemberTypeService>(); MemberType memberType = MemberTypeBuilder.CreateSimpleMemberType("simple"); memberTypeService.Save(memberType); var createdMembers = MemberBuilder.CreateMultipleSimpleMembers(memberType, 10).ToList(); memberService.Save(createdMembers); IScopeProvider provider = ScopeProvider; using (provider.CreateScope()) { EntityRepository repo = CreateRepository((IScopeAccessor)provider); IEnumerable <int> ids = createdContent.Select(x => x.Id).Concat(createdMedia.Select(x => x.Id)).Concat(createdMembers.Select(x => x.Id)); System.Guid[] objectTypes = new[] { Constants.ObjectTypes.Document, Constants.ObjectTypes.Media, Constants.ObjectTypes.Member }; IQuery <IUmbracoEntity> query = provider.CreateQuery <IUmbracoEntity>() .WhereIn(e => e.Id, ids); var entities = repo.GetPagedResultsByQuery(query, objectTypes, 0, 20, out long totalRecords, null, null).ToList(); Assert.AreEqual(20, entities.Count); Assert.AreEqual(30, totalRecords); // add the next page entities.AddRange(repo.GetPagedResultsByQuery(query, objectTypes, 1, 20, out totalRecords, null, null)); Assert.AreEqual(30, entities.Count); Assert.AreEqual(30, totalRecords); var contentEntities = entities.OfType <IDocumentEntitySlim>().ToList(); var mediaEntities = entities.OfType <IMediaEntitySlim>().ToList(); var memberEntities = entities.OfType <IMemberEntitySlim>().ToList(); Assert.AreEqual(10, contentEntities.Count); Assert.AreEqual(10, mediaEntities.Count); Assert.AreEqual(10, memberEntities.Count); } }
/// <summary> /// Setup all standard member data for test /// </summary> private Member SetupMemberTestData( out MemberSave fakeMemberData, out MemberDisplay memberDisplay, ContentSaveAction contentAction) { // arrange var memberType = MemberTypeBuilder.CreateSimpleMemberType(); var member = MemberBuilder.CreateSimpleMember(memberType, "Test Member", "*****@*****.**", "123", "test"); var memberId = 123; member.Id = memberId; // TODO: replace with builder for MemberSave and MemberDisplay fakeMemberData = new MemberSave { Id = memberId, SortOrder = member.SortOrder, ContentTypeId = memberType.Id, Key = member.Key, Password = new ChangingPasswordModel { Id = 456, NewPassword = member.RawPasswordValue, OldPassword = null }, Name = member.Name, Email = member.Email, Username = member.Username, PersistedContent = member, PropertyCollectionDto = new ContentPropertyCollectionDto(), Groups = new List <string>(), // Alias = "fakeAlias", ContentTypeAlias = member.ContentTypeAlias, Action = contentAction, Icon = "icon-document", Path = member.Path, }; memberDisplay = new MemberDisplay { Id = memberId, SortOrder = member.SortOrder, ContentTypeId = memberType.Id, Key = member.Key, Name = member.Name, Email = member.Email, Username = member.Username, // Alias = "fakeAlias", ContentTypeAlias = member.ContentTypeAlias, ContentType = new ContentTypeBasic(), ContentTypeName = member.ContentType.Name, Icon = fakeMemberData.Icon, Path = member.Path, Tabs = new List <Tab <ContentPropertyDisplay> > { new() { Alias = "test", Id = 77, Properties = new List <ContentPropertyDisplay> { new() { Alias = $"{Constants.PropertyEditors.InternalGenericPropertiesPrefix}login" }, new() { Alias = $"{Constants.PropertyEditors.InternalGenericPropertiesPrefix}email" }, new() { Alias = $"{Constants.PropertyEditors.InternalGenericPropertiesPrefix}password", }, new() { Alias = $"{Constants.PropertyEditors.InternalGenericPropertiesPrefix}membergroup", }, new() { Alias = $"{Constants.PropertyEditors.InternalGenericPropertiesPrefix}failedPasswordAttempts", }, new() { Alias = $"{Constants.PropertyEditors.InternalGenericPropertiesPrefix}approved", }, new() { Alias = $"{Constants.PropertyEditors.InternalGenericPropertiesPrefix}lockedOut", }, new() { Alias = $"{Constants.PropertyEditors.InternalGenericPropertiesPrefix}lastLockoutDate", }, new() { Alias = $"{Constants.PropertyEditors.InternalGenericPropertiesPrefix}lastLoginDate", }, new() { Alias = $"{Constants.PropertyEditors.InternalGenericPropertiesPrefix}lastPasswordChangeDate", }, }, }, }, }; return(member); }
public MemberTest() { _member = MemberBuilder.New().Build(); }
/// <summary> /// Setup all standard member data for test /// </summary> private Member SetupMemberTestData( out MemberSave fakeMemberData, out MemberDisplay memberDisplay, ContentSaveAction contentAction) { // arrange MemberType memberType = MemberTypeBuilder.CreateSimpleMemberType(); Member member = MemberBuilder.CreateSimpleMember(memberType, "Test Member", "*****@*****.**", "123", "test"); var memberId = 123; member.Id = memberId; // TODO: replace with builder for MemberSave and MemberDisplay fakeMemberData = new MemberSave() { Id = memberId, SortOrder = member.SortOrder, ContentTypeId = memberType.Id, Key = member.Key, Password = new ChangingPasswordModel() { Id = 456, NewPassword = member.RawPasswordValue, OldPassword = null }, Name = member.Name, Email = member.Email, Username = member.Username, PersistedContent = member, PropertyCollectionDto = new ContentPropertyCollectionDto() { }, Groups = new List <string>(), //Alias = "fakeAlias", ContentTypeAlias = member.ContentTypeAlias, Action = contentAction, Icon = "icon-document", Path = member.Path }; memberDisplay = new MemberDisplay() { Id = memberId, SortOrder = member.SortOrder, ContentTypeId = memberType.Id, Key = member.Key, Name = member.Name, Email = member.Email, Username = member.Username, //Alias = "fakeAlias", ContentTypeAlias = member.ContentTypeAlias, ContentType = new ContentTypeBasic(), ContentTypeName = member.ContentType.Name, Icon = fakeMemberData.Icon, Path = member.Path, Tabs = new List <Tab <ContentPropertyDisplay> >() { new Tab <ContentPropertyDisplay>() { Alias = "test", Id = 77, Properties = new List <ContentPropertyDisplay>() { new ContentPropertyDisplay() { Alias = "_umb_id", View = "idwithguid", Value = new [] { "123", "guid" } }, new ContentPropertyDisplay() { Alias = "_umb_doctype" }, new ContentPropertyDisplay() { Alias = "_umb_login" }, new ContentPropertyDisplay() { Alias = "_umb_email" }, new ContentPropertyDisplay() { Alias = "_umb_password" }, new ContentPropertyDisplay() { Alias = "_umb_membergroup" } } } } }; return(member); }
private void CreateTestDataForPagingTests(out List <IContent> createdContent, out List <IMember> createdMembers, out List <IMedia> createdMedia) { // Create content createdContent = new List <IContent>(); ContentType contentType = ContentTypeBuilder.CreateBasicContentType("blah"); ContentTypeService.Save(contentType); for (int i = 0; i < 3; i++) { Content c1 = ContentBuilder.CreateBasicContent(contentType); ContentService.Save(c1); createdContent.Add(c1); } // Create related content var relatedContent = new List <IContent>(); for (int i = 0; i < 3; i++) { Content c1 = ContentBuilder.CreateBasicContent(contentType); ContentService.Save(c1); relatedContent.Add(c1); } // Create media createdMedia = new List <IMedia>(); MediaType imageType = MediaTypeBuilder.CreateImageMediaType("myImage"); MediaTypeService.Save(imageType); for (int i = 0; i < 3; i++) { Media c1 = MediaBuilder.CreateMediaImage(imageType, -1); MediaService.Save(c1); createdMedia.Add(c1); } // Create members MemberType memberType = MemberTypeBuilder.CreateSimpleMemberType("simple"); MemberTypeService.Save(memberType); createdMembers = MemberBuilder.CreateSimpleMembers(memberType, 3).ToList(); GetMemberService().Save(createdMembers); IRelationType relatedMediaRelType = RelationService.GetRelationTypeByAlias(Constants.Conventions.RelationTypes.RelatedMediaAlias); IRelationType relatedContentRelType = RelationService.GetRelationTypeByAlias(Constants.Conventions.RelationTypes.RelatedDocumentAlias); // Relate content to media foreach (IContent content in createdContent) { foreach (IMedia media in createdMedia) { RelationService.Relate(content.Id, media.Id, relatedMediaRelType); } } // Relate content to content foreach (IContent relContent in relatedContent) { foreach (IContent content in createdContent) { RelationService.Relate(relContent.Id, content.Id, relatedContentRelType); } } // Relate members to media foreach (IMember member in createdMembers) { foreach (IMedia media in createdMedia) { RelationService.Relate(member.Id, media.Id, relatedMediaRelType); } } // Create copied content var copiedContent = new List <IContent>(); for (int i = 0; i < 3; i++) { Content c1 = ContentBuilder.CreateBasicContent(contentType); ContentService.Save(c1); copiedContent.Add(c1); } IRelationType copiedContentRelType = RelationService.GetRelationTypeByAlias(Constants.Conventions.RelationTypes.RelateDocumentOnCopyAlias); // Relate content to content (mimics copy) foreach (IContent content in createdContent) { foreach (IContent cpContent in copiedContent) { RelationService.Relate(content.Id, cpContent.Id, copiedContentRelType); } } // Create trashed content var trashedContent = new List <IContent>(); for (int i = 0; i < 3; i++) { Content c1 = ContentBuilder.CreateBasicContent(contentType); ContentService.Save(c1); trashedContent.Add(c1); } IRelationType trashedRelType = RelationService.GetRelationTypeByAlias(Constants.Conventions.RelationTypes.RelateParentDocumentOnDeleteAlias); // Relate to trashed content foreach (IContent trContent in trashedContent) { foreach (IContent content in createdContent) { RelationService.Relate(trContent.Id, content.Id, trashedRelType); } } // Create trashed media var trashedMedia = new List <IMedia>(); for (int i = 0; i < 3; i++) { Media m1 = MediaBuilder.CreateMediaImage(imageType, -1); MediaService.Save(m1); trashedMedia.Add(m1); } IRelationType trashedMediaRelType = RelationService.GetRelationTypeByAlias(Constants.Conventions.RelationTypes.RelateParentMediaFolderOnDeleteAlias); // Relate to trashed media foreach (IMedia trMedia in trashedMedia) { foreach (IMedia media in createdMedia) { RelationService.Relate(trMedia.Id, media.Id, trashedMediaRelType); } } }