public void BuildContext_PublicVisibility() { _mixinBuilder.WithIntroducedMemberVisibility(MemberVisibility.Public); MixinContext mixinContext = _mixinBuilder.BuildMixinContext(); Assert.That(mixinContext.IntroducedMemberVisibility, Is.EqualTo(MemberVisibility.Public)); }
private object[] SerializeMixinContext(MixinContext m) { var serializer = CreateMixinContextSerializer(); m.Serialize(serializer); return(serializer.Values); }
public void BuildContext_WithDependency() { _mixinBuilder.WithDependency <IBT3Mixin4>(); MixinContext context = _mixinBuilder.BuildMixinContext(); Assert.That(context.ExplicitDependencies, Is.EqualTo(new[] { typeof(IBT3Mixin4) })); }
public void BuildContext_UsedKind() { _mixinBuilder.OfKind(MixinKind.Used); MixinContext mixinContext = _mixinBuilder.BuildMixinContext(); Assert.That(mixinContext.MixinKind, Is.EqualTo(MixinKind.Used)); }
private MixinDefinition CreateMixinDefinition(MixinContext mixinContext) { Type mixinType = TargetClass.MixinTypeCloser.GetClosedMixinType(mixinContext.MixinType); bool acceptsAlphabeticOrdering = AcceptsAlphabeticOrdering(mixinType); var mixin = new MixinDefinition(mixinContext.MixinKind, mixinType, TargetClass, acceptsAlphabeticOrdering); TargetClass.Mixins.Add(mixin); return(mixin); }
public void SetUp() { _mcObject = MixinContextObjectMother.Create(mixinType: typeof(object)); _mcString = MixinContextObjectMother.Create(mixinType: typeof(string)); _mcList = MixinContextObjectMother.Create(mixinType: typeof(List <int>)); _mcGeneric = MixinContextObjectMother.Create(mixinType: typeof(DerivedGenericMixin <object>)); _mcDerived = MixinContextObjectMother.Create(mixinType: typeof(DerivedNullMixin)); _collection = new MixinContextCollection(new[] { _mcObject, _mcString, _mcList, _mcDerived }); _genericCollection = new MixinContextCollection(new[] { _mcGeneric }); }
public void GetHashCode_Equal() { var c1a = new MixinContext( MixinKind.Extending, typeof(BT6Mixin1), MemberVisibility.Private, new[] { typeof(BT6Mixin2), typeof(BT6Mixin3 <>) }, MixinContextOriginObjectMother.Create()); var c1b = new MixinContext( MixinKind.Extending, typeof(BT6Mixin1), MemberVisibility.Private, new[] { typeof(BT6Mixin2), typeof(BT6Mixin3 <>) }, MixinContextOriginObjectMother.Create()); var c1WithDifferentDependencyOrder = new MixinContext( MixinKind.Extending, typeof(BT6Mixin1), MemberVisibility.Private, new[] { typeof(BT6Mixin3 <>), typeof(BT6Mixin2) }, MixinContextOriginObjectMother.Create()); var c1WithDifferentOrigin = new MixinContext( MixinKind.Extending, typeof(BT6Mixin1), MemberVisibility.Private, new[] { typeof(BT6Mixin2), typeof(BT6Mixin3 <>) }, MixinContextOriginObjectMother.Create(kind: "some different kind")); var c2a = new MixinContext( MixinKind.Extending, typeof(BT6Mixin1), MemberVisibility.Private, Enumerable.Empty <Type>(), MixinContextOriginObjectMother.Create()); var c2b = new MixinContext( MixinKind.Extending, typeof(BT6Mixin1), MemberVisibility.Private, Enumerable.Empty <Type>(), MixinContextOriginObjectMother.Create()); var c3a = new MixinContext( MixinKind.Used, typeof(BT6Mixin1), MemberVisibility.Public, new[] { typeof(BT6Mixin3 <>), typeof(BT6Mixin2) }, MixinContextOriginObjectMother.Create()); var c3b = new MixinContext( MixinKind.Used, typeof(BT6Mixin1), MemberVisibility.Public, new[] { typeof(BT6Mixin3 <>), typeof(BT6Mixin2) }, MixinContextOriginObjectMother.Create()); Assert.That(c1b.GetHashCode(), Is.EqualTo(c1a.GetHashCode())); Assert.That(c1WithDifferentDependencyOrder.GetHashCode(), Is.EqualTo(c1a.GetHashCode())); Assert.That(c1WithDifferentOrigin.Origin, Is.Not.EqualTo(c1a.Origin)); Assert.That(c1WithDifferentOrigin.GetHashCode(), Is.EqualTo(c1a.GetHashCode())); Assert.That(c2b.GetHashCode(), Is.EqualTo(c2a.GetHashCode())); Assert.That(c3b.GetHashCode(), Is.EqualTo(c3a.GetHashCode())); }
public void Apply(MixinContext mixinContext, int index) { ArgumentUtility.CheckNotNull("mixinContext", mixinContext); ArgumentUtility.CheckNotNull("index", index); MixinDefinition mixin = CreateMixinDefinition(mixinContext); AnalyzeMembers(mixin); AnalyzeAttributes(mixin); AnalyzeInterfaceIntroductions(mixin, mixinContext.IntroducedMemberVisibility); AnalyzeOverrides(mixin); AnalyzeDependencies(mixin, mixinContext.ExplicitDependencies); }
public void SetUp() { _provider = new MixinParticipantTypeIdentifierProvider(); var mixinContext = new MixinContext( MixinKind.Extending, typeof(int), MemberVisibility.Private, new Type[0], new MixinContextOrigin("some kind", GetType().Assembly, "some location")); _classContext = ClassContextObjectMother.Create(typeof(string), mixinContext); }
private MixinContext CheckNotOpenGenericMixin(MixinContext mixin) { if (mixin.MixinType.ContainsGenericParameters) { string message = string.Format("The persistence-relevant mixin {0} applied to class {1} has open generic type parameters. All type " + "parameters of the mixin must be specified when it is applied to a DomainObject.", mixin.MixinType.FullName, Type.FullName); throw new MappingException(message); } else { return(mixin); } }
public void Mixins() { var classContext = ClassContextObjectMother.Create(typeof(BaseType7)); Assert.That(classContext.Mixins.ContainsKey(typeof(BT7Mixin1)), Is.False); MixinContext mixinContext = classContext.Mixins[typeof(BT7Mixin1)]; Assert.That(mixinContext, Is.Null); classContext = ClassContextObjectMother.Create(typeof(BaseType7), typeof(BT7Mixin1)); Assert.That(classContext.Mixins.ContainsKey(typeof(BT7Mixin1)), Is.True); mixinContext = classContext.Mixins[typeof(BT7Mixin1)]; Assert.That(classContext.Mixins[typeof(BT7Mixin1)], Is.SameAs(mixinContext)); }
public void Equals_False() { var origin = MixinContextOriginObjectMother.Create(); var c1 = new MixinContext( MixinKind.Extending, typeof(BT6Mixin1), MemberVisibility.Private, new[] { typeof(BT6Mixin2), typeof(BT6Mixin3 <>) }, origin); var c2 = new MixinContext(MixinKind.Extending, typeof(BT6Mixin1), MemberVisibility.Private, new[] { typeof(BT6Mixin3 <>) }, origin); var c3 = new MixinContext(MixinKind.Extending, typeof(BT6Mixin2), MemberVisibility.Private, new[] { typeof(BT6Mixin3 <>) }, origin); var c4 = new MixinContext(MixinKind.Used, typeof(BT6Mixin2), MemberVisibility.Private, new[] { typeof(BT6Mixin3 <>) }, origin); var c5 = new MixinContext(MixinKind.Used, typeof(BT6Mixin2), MemberVisibility.Public, new[] { typeof(BT6Mixin3 <>) }, origin); Assert.That(c2, Is.Not.EqualTo(c1)); Assert.That(c3, Is.Not.EqualTo(c2)); Assert.That(c4, Is.Not.EqualTo(c3)); Assert.That(c5, Is.Not.EqualTo(c4)); }
private void CheckForSuppressedMixins() { var suppressedMixins = from mixin in ParentClassContext.Mixins where IsPersistenceRelevant(mixin.MixinType) && !MixinConfiguration.Mixins.ContainsAssignableMixin(mixin.MixinType) select mixin; MixinContext suppressedMixin = suppressedMixins.FirstOrDefault(); if (suppressedMixin != null) { string message = string.Format("Class '{0}' suppresses mixin '{1}' inherited from its base class '{2}'. This is not allowed because " + "the mixin adds persistence information to the base class which must also be present in the derived class.", Type.FullName, suppressedMixin.MixinType.Name, ParentClassContext.Type.Name); throw new MappingException(message); } }
public void Deserialize() { var expectedContext = MixinContextObjectMother.Create(); var deserializer = MockRepository.GenerateStrictMock <IMixinContextDeserializer> (); deserializer.Expect(mock => mock.GetMixinType()).Return(expectedContext.MixinType); deserializer.Expect(mock => mock.GetMixinKind()).Return(expectedContext.MixinKind); deserializer.Expect(mock => mock.GetIntroducedMemberVisibility()).Return(expectedContext.IntroducedMemberVisibility); deserializer.Expect(mock => mock.GetExplicitDependencies()).Return(expectedContext.ExplicitDependencies); deserializer.Expect(mock => mock.GetOrigin()).Return(expectedContext.Origin); var context = MixinContext.Deserialize(deserializer); deserializer.VerifyAllExpectations(); Assert.That(context, Is.EqualTo(expectedContext)); }
public void BuildContext_Origin() { MixinContext mixinContext = _mixinBuilder.BuildMixinContext(); Assert.That(mixinContext.Origin, Is.EqualTo(_origin)); }
public void BuildContext_NoDependencies() { MixinContext mixinContext = _mixinBuilder.BuildMixinContext(); Assert.That(mixinContext.ExplicitDependencies, Is.Empty); }
public IEnumerable <MixinContext> GetMixins() { var mixins = GetValue <object[]> (1); return(mixins.Select(oa => MixinContext.Deserialize(CreateMixinContextDeserializer((object[])oa)))); }
public void BuildContext_ExplicitKind() { MixinContext mixinContext = _mixinBuilder.BuildMixinContext(); Assert.That(mixinContext.MixinKind, Is.EqualTo(MixinKind.Extending)); }