public void WithDifferentAttributes( IInterfaceThatWeWillAddAttributesTo1 fake1, IInterfaceThatWeWillAddAttributesTo1 fake2, Action <IFakeOptions <IInterfaceThatWeWillAddAttributesTo1> > optionsBuilder1, Action <IFakeOptions <IInterfaceThatWeWillAddAttributesTo1> > optionsBuilder2) { "Given an explicit options builder that adds an attribute to a fake" .x(() => optionsBuilder1 = options => options.WithAttributes(() => new ForTestAttribute())); "And another explicit options builder that adds another attribute to a fake" .x(() => optionsBuilder2 = options => options.WithAttributes(() => new DebuggerStepThroughAttribute())); "When I create a fake using the first options builder" .x(() => fake1 = this.CreateFake(optionsBuilder1)); "And another fake using the second options builder" .x(() => fake2 = this.CreateFake(optionsBuilder2)); "Then the fakes have different types" .x(() => fake1.GetType().Should().NotBe(fake2.GetType())); "And the first fake should have the first attribute" .x(() => fake1.GetType().GetCustomAttributes(inherit: false) .Select(a => a.GetType()) .Should().Contain(typeof(ForTestAttribute))); "And the second fake should have the second attribute" .x(() => fake2.GetType().GetCustomAttributes(inherit: false) .Select(a => a.GetType()) .Should().Contain(typeof(DebuggerStepThroughAttribute))); }
public void WithSameAttributes( IInterfaceThatWeWillAddAttributesTo1 fake1, IInterfaceThatWeWillAddAttributesTo1 fake2, Action <IFakeOptions <IInterfaceThatWeWillAddAttributesTo1> > optionsBuilder) { "Given an explicit options builder that adds an attribute to a fake" .x(() => optionsBuilder = options => options.WithAttributes(() => new ForTestAttribute())); "When I create a fake using the options builder" .x(() => fake1 = this.CreateFake(optionsBuilder)); "And another fake with the same options builder" .x(() => fake2 = this.CreateFake(optionsBuilder)); "Then the fakes have the same type" .x(() => fake1.GetType().Should().Be(fake2.GetType())); "And the first fake should have the attribute" .x(() => fake1.GetType().GetCustomAttributes(inherit: false) .Select(a => a.GetType()) .Should().Contain(typeof(ForTestAttribute))); "And the second fake should have the attribute" .x(() => fake2.GetType().GetCustomAttributes(inherit: false) .Select(a => a.GetType()) .Should().Contain(typeof(ForTestAttribute))); }
public void WithAttributes( IInterfaceThatWeWillAddAttributesTo1 fake, Action <IFakeOptions <IInterfaceThatWeWillAddAttributesTo1> > optionsBuilder) { "Given an explicit options builder that adds an attribute to a fake" .x(() => { optionsBuilder = options => options .WithAttributes(() => new ForTestAttribute()); }); "When I create a fake using the options builder" .x(() => fake = this.CreateFake(optionsBuilder)); "Then it has the attribute" .x(() => fake.GetType().GetCustomAttributes(inherit: false).Select(a => a.GetType()) .Should().Contain(typeof(ForTestAttribute))); }
public static void WithAdditionalAttributes( IInterfaceThatWeWillAddAttributesTo1 fake) { "When a fake is built with an additional attribute" .x(() => { var constructor = typeof(ForTestAttribute).GetConstructor(new Type[0]); var attribute = new CustomAttributeBuilder(constructor, new object[0]); var customAttributeBuilders = new List <CustomAttributeBuilder> { attribute }; fake = A.Fake <IInterfaceThatWeWillAddAttributesTo1>(options => options .WithAdditionalAttributes(customAttributeBuilders)); }); "Then it should have the attribute" .x(() => fake.GetType().GetCustomAttributes(typeof(ForTestAttribute), false).Should().HaveCount(1)); }
public void WithAdditionalAttributes( IInterfaceThatWeWillAddAttributesTo1 fake, Action <IFakeOptions <IInterfaceThatWeWillAddAttributesTo1> > optionsBuilder) { "Given an explicit options builder that adds an attribute to a fake" .x(() => { var constructor = typeof(ForTestAttribute).GetConstructor(new Type[0]); var attribute = new CustomAttributeBuilder(constructor, new object[0]); var customAttributeBuilders = new List <CustomAttributeBuilder> { attribute }; optionsBuilder = options => options .WithAdditionalAttributes(customAttributeBuilders); }); "When I create a fake using the options builder" .x(() => fake = this.CreateFake(optionsBuilder)); "Then it has the attribute" .x(() => fake.GetType().GetCustomAttributes(inherit: false).Select(a => a.GetType()) .Should().Contain(typeof(ForTestAttribute))); }
public static void WithAdditionalAttributes( IInterfaceThatWeWillAddAttributesTo1 fake) { "When a fake is built with an additional attribute" .x(() => { var constructor = typeof(ForTestAttribute).GetConstructor(new Type[0]); var attribute = new CustomAttributeBuilder(constructor, new object[0]); var customAttributeBuilders = new List<CustomAttributeBuilder> { attribute }; fake = A.Fake<IInterfaceThatWeWillAddAttributesTo1>(options => options .WithAdditionalAttributes(customAttributeBuilders)); }); "Then it should have the attribute" .x(() => fake.GetType().GetCustomAttributes(typeof(ForTestAttribute), false).Should().HaveCount(1)); }
public void WithAdditionalAttributes( IInterfaceThatWeWillAddAttributesTo1 fake) { "when WithAdditionalAttributes is used to configure a fake" .x(() => { var constructor = typeof(ForTestAttribute).GetConstructor(new Type[0]); var attribute = new CustomAttributeBuilder(constructor, new object[0]); var customAttributeBuilders = new List<CustomAttributeBuilder> { attribute }; fake = A.Fake<IInterfaceThatWeWillAddAttributesTo1>(options => options .WithAdditionalAttributes(customAttributeBuilders)); }); "it should produce a fake that has the attribute" .x(() => fake.GetType().GetCustomAttributes(typeof(ForTestAttribute), false).Should().HaveCount(1)); }