private static CommonField CreateCommonField(Mock <CommonType> commonType, FakeField fakeField) { if (fakeField == null) { return(null); } var fieldName = fakeField.Name; var fieldFullName = $"{commonType.Object.FullName}.{fieldName}"; var commonAttributes = CreateCommonAttributes(fakeField.Attributes); var monoCecilField = new Mock <MonoCecilField>(null); monoCecilField.Setup(field => field.Name).Returns(() => fieldName); monoCecilField.Setup(field => field.FullName).Returns(() => fieldFullName); monoCecilField.Setup(field => field.Attributes).Returns(() => commonAttributes.Select(attribute => attribute.MonoCecilAttribute)); var reflectionField = new Mock <ReflectionField>(null); reflectionField.Setup(field => field.Name).Returns(() => fieldName); reflectionField.Setup(field => field.FullName).Returns(() => fieldFullName); reflectionField.Setup(field => field.Attributes).Returns(() => commonAttributes.Select(attribute => attribute.ReflectionAttribute)); return(new Mock <CommonField>(commonAttributes, monoCecilField.Object, reflectionField.Object).Object); }
private static ICommonField CreateCommonField(FakeField fakeField, string typeFullName) { var fieldName = fakeField.Name; var fieldFullName = $"{fakeField.FieldType.FullName} {typeFullName}::{fieldName}()"; var commonAttributes = CreateCommonAttributes(fakeField.Attributes); var monoCecilField = CreateMockFor <FieldDefinition>(); monoCecilField.Setup(field => field.Name).Returns(() => fieldName); monoCecilField.Setup(field => field.FullName).Returns(() => fieldFullName); monoCecilField.Setup(field => field.CustomAttributes).Returns(() => new Collection <CustomAttribute>(commonAttributes.Select(attribute => attribute.MonoCecil).ToArray())); var reflectionField = CreateMockFor <FieldInfo>(); reflectionField.Setup(constructor => constructor.GetCustomAttributes(It.IsAny <bool>())) .Returns(() => fakeField.Attributes.Select(attribute => (object)attribute).ToArray()); reflectionField.Setup(constructor => constructor.GetCustomAttributes(It.IsAny <Type>(), It.IsAny <bool>())) .Returns((Type type, bool b) => fakeField.Attributes.Select(attribute => (object)attribute).Where(attribute => attribute.GetType() == type).ToArray()); var commonField = CreateMockFor <ICommonField>(); commonField.Setup(field => field.Name).Returns(() => fieldName); commonField.Setup(field => field.FullName).Returns(() => fieldFullName); commonField.Setup(field => field.MonoCecil).Returns(() => monoCecilField.Object); commonField.Setup(field => field.Reflection).Returns(() => reflectionField.Object); commonField.Setup(field => field.Type).Returns(() => CreateReflectionType(fakeField.FieldType)); commonField.Setup(field => field.Attributes).Returns(() => commonAttributes); commonField.Setup(field => field.Load(It.IsAny <int>())).Returns(() => commonField.Object); commonField.Setup(field => field.TypeTypeToAttributes).Returns(() => commonAttributes.GroupBy(attribute => attribute.Type).ToDictionary(group => group.Key, group => group.ToArray())); commonField.Setup(field => field.TypeFullNameToAttributes).Returns(() => commonAttributes.GroupBy(attribute => attribute.FullName).ToDictionary(group => group.Key, group => group.ToArray())); return(commonField.Object); }
public void TestInitialize_InvalidState_ThrowsException(FieldState state) { var field = new FakeField(1, 1, 1); field.SetState(state); Assert.Throws <InvalidOperationException>(() => field.Initialize()); }
IField ResolveFieldReference(MemberReferenceHandle memberReferenceHandle, GenericContext context) { var memberRef = metadata.GetMemberReference(memberReferenceHandle); var declaringType = ResolveDeclaringType(memberRef.Parent, context); var declaringTypeDefinition = declaringType.GetDefinition(); string name = metadata.GetString(memberRef.Name); // field signature is for the definition, not the generic instance var signature = memberRef.DecodeFieldSignature(TypeProvider, new GenericContext(declaringTypeDefinition?.TypeParameters)); // 'f' in the predicate is also the definition, even if declaringType is a ParameterizedType var field = declaringType.GetFields(f => f.Name == name && CompareTypes(f.ReturnType, signature), GetMemberOptions.IgnoreInheritedMembers).FirstOrDefault(); if (field == null) { // If it's a field in a generic type, we need to substitute the type arguments: if (declaringType.TypeArguments.Count > 0) { signature = signature.AcceptVisitor(declaringType.GetSubstitution()); } field = new FakeField(Compilation) { ReturnType = signature, Name = name, DeclaringType = declaringType, }; } return(field); }
public void FakeField_ShouldSubstitute_InnerItem() { Item item = new FakeItem(); Field field = new FakeField().WithInnerItem(item); field.InnerItem.Should().Be(item); field.Database.GetItem(field.ID, language: null).Should().Be(item); }
public void ItemProperty_WhenRequested_ReturnsFieldOwnerItem() { Item fieldOwnerItem = new FakeItem(); Field field = new FakeField(ID.NewID, owner: fieldOwnerItem); field.Item.Should().Be(fieldOwnerItem); }
public void FakeField_ShouldTakeLanguage_FromItem(string languageName) { var item = new FakeItem().WithLanguage(languageName).ToSitecoreItem(); Field field = new FakeField(owner: item) ; field.Language.Name.Should().Be(languageName); }
public void DatabaseProperty_IsTaken_FromItem() { var database = Substitute.For <Database>(); database.Name.Returns("fake db name"); Field field = new FakeField(ID.NewID, new FakeItem(ID.NewID, database)); field.Database.Name.Should().Be("fake db name"); }
public void FakeField_ShouldSubstitute_Definition1(string sectionName, string fieldName, ID sectionId, ID fieldId) { var template = new FakeTemplate(); var section = new FakeTemplateSection(template, sectionName, sectionId); TemplateField templateField = new FakeTemplateField(section, fieldName, fieldId); Field field = new FakeField().WithDefinition(templateField); field.Definition.Should().Be(templateField); }
public void DefaultConstructor_ShouldInitialize_UsingDefaultData() { Field field = new FakeField(); field.ID.Should() .NotBeNull() .And .NotBe(ID.Null); field.Item.Should().NotBeNull(); field.Database.Should().NotBeNull(); }
public void FakeItemFields_ShouldBeModified(ID fieldId) { var fakeItem = new FakeItem(); var item = fakeItem.ToSitecoreItem(); item.Fields.Should().BeEmpty(); Field field = new FakeField(fieldId, fakeItem); item.Fields.Should().HaveCount(1); item.Fields[field.ID].Should().Be(field); }
public void TestMarkCell_CellsOfField2x2Revealed_CellStateNotChanged() { var field = new FakeField(2, 2, 1); field.Initialize(); field.RevealCell(0, 0); field.SetState(FieldState.SomeCellsMarkedOrRevealed); var previousState = field[0, 0].State; field.MarkCell(0, 0); Assert.AreEqual(previousState, field[0, 0].State); }
public FakeCommonTypeBuilder AddField(FakeField field) { fields.Add(field); return(this); }
public void FakeField_ShouldSubstitute_HasValue() { Field field = new FakeField().WithHasValue(true); field.HasValue.Should().BeTrue(); }
public void Constructor_WhenReceivesFieldValue_SetsFieldValue(string fieldValue) { Field field = new FakeField(ID.NewID, fieldValue, new FakeItem()); field.Value.Should().Be(fieldValue); }
public void HasValue_WhenNullValueSet_ReturnsFalse() { Field field = new FakeField().WithValue(null); field.HasValue.Should().BeFalse(); }
public void FakeField_ShouldSubstitute_Description(string description) { Field field = new FakeField().WithDescription(description); field.Description.Should().Be(description); }
public void FakeField_ShouldSubstitute_InheritedValue(string inheritedValue) { Field field = new FakeField().WithInheritedValue(inheritedValue); field.InheritedValue.Should().Be(inheritedValue); }
public void FieldValue_WhenMocked_ReturnsMockedValue(string fieldValue) { Field field = new FakeField().WithValue(fieldValue); field.Value.Should().Be(fieldValue); }
public void FakeField_ShouldSubstitute_CanRead() { Field field = new FakeField().WithCanRead(true); field.CanRead.Should().BeTrue(); }
public void FakeField_ShouldSubstitute_ContainsStandardValue() { Field field = new FakeField().WithContainsStandardValue(true); field.ContainsStandardValue.Should().BeTrue(); }
public void FakeField_ShouldSubstitute_HasBlobStream() { Field field = new FakeField().WithHasBlobStream(true); field.HasBlobStream.Should().BeTrue(); }
public void FakeField_ShouldSubstitute_SectionDisplayName(string sectionDisplayName) { Field field = new FakeField().WithSectionDisplayName(sectionDisplayName); field.SectionDisplayName.Should().Be(sectionDisplayName); }
public void FakeField_ShouldSubstitute_FallbackValueSource(string source) { Field field = new FakeField().WithFallbackValueSource(source); field.FallbackValueSource.Should().Be(source); }
public void FakeField_ShouldSubstitute_DisplayName(string fieldDisplayName) { Field field = new FakeField().WithDisplayName(fieldDisplayName); field.DisplayName.Should().Be(fieldDisplayName); }
public void FakeField_ShouldSubstitute_HelpLink(string helpLink) { Field field = new FakeField().WithHelpLink(helpLink); field.HelpLink.Should().Be(helpLink); }
public void HasValue_WhenFieldValueSet_ReturnsTrue(string fieldValue) { Field field = new FakeField().WithValue(fieldValue); field.HasValue.Should().BeTrue(); }
public void HasValue_WhenEmptyValueSet_ReturnsTrue() { Field field = new FakeField().WithValue(string.Empty); field.HasValue.Should().BeTrue(); }
public void FakeField_ShouldSubstitute_InheritsValueFromOtherItem() { Field field = new FakeField().WithInheritsValueFromOtherItem(true); field.InheritsValueFromOtherItem.Should().BeTrue(); }
public void FakeField_ShouldSubstitute_Definition() { Field field = new FakeField().WithDefinition(); field.Definition.Should().NotBeNull(); }