示例#1
0
        public void Nesting_scopes()
        {
            // Scopes can be nested however deep you'd like:

            var factory = new Fake<IWidgetFactory>();

            using (Fake.CreateScope())
            {
                factory.AnyCall().Throws(new Exception());

                using (Fake.CreateScope())
                {
                    // Will throw since it's configured in outer scope.
                    factory.FakedObject.Create();

                    factory.AnyCall().DoesNothing();

                    // Now will not throw since it's overridden in the inner scope.
                    factory.FakedObject.Create();
                }

                // Will throw  since it's configured in this scope.
                factory.FakedObject.Create();
            }

            // Returns null since it's not configured.
            factory.FakedObject.Create();
        }
示例#2
0
        public void Nesting_scopes()
        {
            // Scopes can be nested however deep you'd like:

            var factory = new Fake <IWidgetFactory>();

            using (Fake.CreateScope())
            {
                factory.AnyCall().Throws(new Exception());

                using (Fake.CreateScope())
                {
                    // Will throw since it's configured in outer scope.
                    factory.FakedObject.Create();

                    factory.AnyCall().DoesNothing();

                    // Now will not throw since it's overridden in the inner scope.
                    factory.FakedObject.Create();
                }

                // Will throw  since it's configured in this scope.
                factory.FakedObject.Create();
            }

            // Returns null since it's not configured.
            factory.FakedObject.Create();
        }
        public void GenerateAttributeGeneratesAttributeIfAllAttributesParameterIsSpecified()
        {
            var fakeFilterService = new Fake <ICodeWriterFilterService>();

            fakeFilterService.AnyCall().WithReturnType <bool>().Returns(true);

            var fakeServiceProvider = new Fake <IServiceProvider>();

            Environment.SetEnvironmentVariable("AlbanianXrm.EarlyBound:Entities", "contact");
            Environment.SetEnvironmentVariable("AlbanianXrm.EarlyBound:AllAttributes", "contact");

            var metadata = new AttributeMetadata()
            {
                LogicalName = "lastname"
            };

            typeof(AttributeMetadata).GetField("_entityLogicalName", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(metadata, "contact");

            var filteringService       = new FilteringService(fakeFilterService.FakedObject);
            var shouldGenerateLastName = (filteringService as ICodeWriterFilterService).GenerateAttribute(metadata, fakeServiceProvider.FakedObject);

            Environment.SetEnvironmentVariable("AlbanianXrm.EarlyBound:Entities", null);
            Environment.SetEnvironmentVariable("AlbanianXrm.EarlyBound:AllAttributes", null);

            A.CallTo(() => fakeFilterService.FakedObject.GenerateAttribute(A <AttributeMetadata> ._, A <IServiceProvider> ._)).MustHaveHappenedOnceExactly();
            Assert.True(shouldGenerateLastName);
        }
        public void GenerateN1RelationshipIfAllRelationshipsParameterIsSpecified()
        {
            var fakeFilterService = new Fake <ICodeWriterFilterService>();

            fakeFilterService.AnyCall().WithReturnType <bool>().Returns(true);

            var fakeServiceProvider = new Fake <IServiceProvider>();

            Environment.SetEnvironmentVariable(Constants.ENVIRONMENT_ENTITIES, "account");
            Environment.SetEnvironmentVariable(Constants.ENVIRONMENT_ALL_RELATIONSHIPS, "account");

            var metadata = new OneToManyRelationshipMetadata()
            {
                MetadataId           = Guid.NewGuid(),
                SchemaName           = "account_primary_contact",
                ReferencingEntity    = "account",
                ReferencingAttribute = "primarycontactid",
                ReferencedEntity     = "contact",
                ReferencedAttribute  = "contactid"
            };

            var otherEntity = new EntityMetadata()
            {
                LogicalName = "contact"
            };

            var filteringService           = new FilteringService(fakeFilterService.FakedObject);
            var shouldGenerateRelationship = (filteringService as ICodeWriterFilterService).GenerateRelationship(metadata, otherEntity, fakeServiceProvider.FakedObject);

            Environment.SetEnvironmentVariable(Constants.ENVIRONMENT_ENTITIES, null);
            Environment.SetEnvironmentVariable(Constants.ENVIRONMENT_ALL_RELATIONSHIPS, null);

            A.CallTo(() => fakeFilterService.FakedObject.GenerateRelationship(A <RelationshipMetadataBase> .Ignored, A <EntityMetadata> .Ignored, A <IServiceProvider> .Ignored)).MustHaveHappenedOnceExactly();
            Assert.True(shouldGenerateRelationship);
        }
        public void GenerateAttributeGeneratesAttributeIfAllAttributesParameterIsSpecified()
        {
            var fakeFilterService = new Fake <ICodeWriterFilterService>();

            fakeFilterService.AnyCall().WithReturnType <bool>().Returns(true);

            var fakeServiceProvider = new Fake <IServiceProvider>();

            Environment.SetEnvironmentVariable(Constants.ENVIRONMENT_ENTITIES, "contact");
            Environment.SetEnvironmentVariable(Constants.ENVIRONMENT_ALL_ATTRIBUTES, "contact");

            var metadata = new AttributeMetadata()
            {
                LogicalName = "lastname"
            };

            metadata.SetEntityLogicalName("contact");

            var filteringService       = new FilteringService(fakeFilterService.FakedObject);
            var shouldGenerateLastName = (filteringService as ICodeWriterFilterService).GenerateAttribute(metadata, fakeServiceProvider.FakedObject);

            Environment.SetEnvironmentVariable(Constants.ENVIRONMENT_ENTITIES, null);
            Environment.SetEnvironmentVariable(Constants.ENVIRONMENT_ALL_ATTRIBUTES, null);

            Assert.True(shouldGenerateLastName);
        }
        public void GenerateAttributeSkipsEntityIfItIsNotSpecifiedInTheParameters()
        {
            var fakeFilterService = new Fake <ICodeWriterFilterService>();

            fakeFilterService.AnyCall().WithReturnType <bool>().Returns(true);

            var fakeServiceProvider = new Fake <IServiceProvider>();

            Environment.SetEnvironmentVariable(Constants.ENVIRONMENT_ENTITIES, "contact");
            Environment.SetEnvironmentVariable(string.Format(Constants.ENVIRONMENT_ENTITY_ATTRIBUTES, "contact"), "contactid");

            var metadata = new AttributeMetadata()
            {
                LogicalName = "lastname"
            };

            metadata.SetEntityLogicalName("contact");

            var filteringService       = new FilteringService(fakeFilterService.FakedObject);
            var shouldGenerateLastName = (filteringService as ICodeWriterFilterService).GenerateAttribute(metadata, fakeServiceProvider.FakedObject);

            Environment.SetEnvironmentVariable(Constants.ENVIRONMENT_ENTITIES, null);
            Environment.SetEnvironmentVariable(string.Format(Constants.ENVIRONMENT_ENTITY_ATTRIBUTES, "contact"), null);

            A.CallTo(() => fakeFilterService.FakedObject.GenerateAttribute(A <AttributeMetadata> ._, A <IServiceProvider> ._)).MustNotHaveHappened();
            Assert.False(shouldGenerateLastName);
        }
示例#7
0
        public void AnyCall_returns_fake_configuration_for_the_faked_object()
        {
            var fake = new Fake <IFoo>();

            IVoidConfiguration <IFoo> voidConfiguration = fake.AnyCall();
            var configuration = voidConfiguration as FakeConfiguration <IFoo>;

            Assert.That(configuration.Fake.Object, Is.SameAs(fake.FakedObject));
        }
示例#8
0
        public void AnyCall_returns_fake_configuration_for_the_faked_object()
        {
            var callConfig = A.Fake <IVoidArgumentValidationConfiguration>();
            var config     = A.Fake <IFakeConfiguration <IFoo> >();

            A.CallTo(() => config.AnyCall()).Returns(callConfig);

            var fake = new Fake <IFoo>();

            A.CallTo(() => this.startConfigurationFactory.CreateConfiguration <IFoo>(A <FakeObject> .That.IsThis(fake.FakedObject))).Returns(config);

            var result = fake.AnyCall();

            Assert.That(result, Is.SameAs(callConfig));
        }
        public void AnyCall_returns_fake_configuration_for_the_faked_object()
        {
            // Arrange
            var fake = new Fake <IFoo>();

            var callConfig = A.Fake <IAnyCallConfiguration>();
            var config     = A.Fake <IStartConfiguration <IFoo> >();

            A.CallTo(() => config.AnyCall()).Returns(callConfig);
            A.CallTo(() => this.startConfigurationFactory.CreateConfiguration <IFoo>(A <FakeObject> .That.Fakes(fake.FakedObject))).Returns(config);

            // Act
            var result = fake.AnyCall();

            // Assert
            Assert.That(result, Is.SameAs(callConfig));
        }
示例#10
0
        public void AnyCall_returns_fake_configuration_for_the_faked_object()
        {
            // Arrange
            var fake = new Fake<IFoo>();

            var callConfig = A.Fake<IAnyCallConfigurationWithNoReturnTypeSpecified>();
            var config = A.Fake<IStartConfiguration<IFoo>>();

            A.CallTo(() => config.AnyCall()).Returns(callConfig);
            A.CallTo(() => this.startConfigurationFactory.CreateConfiguration<IFoo>(A<FakeManager>.That.Fakes(fake.FakedObject))).Returns(config);

            // Act
            var result = fake.AnyCall();

            // Assert
            result.Should().BeSameAs(callConfig);
        }
示例#11
0
        public void AnyCall_returns_fake_configuration_for_the_faked_object()
        {
            // Arrange
            var fake = new Fake <IFoo>();

            var callConfig = A.Fake <IAnyCallConfigurationWithNoReturnTypeSpecified>();
            var config     = A.Fake <IStartConfiguration <IFoo> >();

            A.CallTo(() => config.AnyCall()).Returns(callConfig);
            A.CallTo(() => this.startConfigurationFactory.CreateConfiguration <IFoo>(A <FakeManager> .That.Fakes(fake.FakedObject))).Returns(config);

            // Act
            var result = fake.AnyCall();

            // Assert
            result.Should().BeSameAs(callConfig);
        }
        public void GenerateEntityUsesDefaultFilterServiceIfNoParametersAreSpecified()
        {
            var fakeFilterService = new Fake <ICodeWriterFilterService>();

            fakeFilterService.AnyCall().WithReturnType <bool>().Returns(true);

            var fakeServiceProvider = new Fake <IServiceProvider>();
            var metadata            = new EntityMetadata()
            {
                LogicalName = "account"
            };

            var filteringService      = new FilteringService(fakeFilterService.FakedObject);
            var shouldGenerateAccount = (filteringService as ICodeWriterFilterService).GenerateEntity(metadata, fakeServiceProvider.FakedObject);

            A.CallTo(() => fakeFilterService.FakedObject.GenerateEntity(A <EntityMetadata> ._, A <IServiceProvider> ._)).MustHaveHappenedOnceExactly();
            Assert.True(shouldGenerateAccount);
        }
        public void GenerateAtributeUsesDefaultFilterServiceIfNoParametersAreSpecified()
        {
            var fakeFilterService = new Fake <ICodeWriterFilterService>();

            fakeFilterService.AnyCall().WithReturnType <bool>().Returns(true);

            var fakeServiceProvider = new Fake <IServiceProvider>();
            var metadata            = new AttributeMetadata()
            {
                LogicalName = "lastname"
            };

            typeof(AttributeMetadata).GetField("_entityLogicalName", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(metadata, "contact");

            var filteringService       = new FilteringService(fakeFilterService.FakedObject);
            var shouldGenerateLastName = (filteringService as ICodeWriterFilterService).GenerateAttribute(metadata, fakeServiceProvider.FakedObject);

            A.CallTo(() => fakeFilterService.FakedObject.GenerateAttribute(A <AttributeMetadata> ._, A <IServiceProvider> ._)).MustHaveHappenedOnceExactly();
            Assert.True(shouldGenerateLastName);
        }
        public void GenerateEntityGeneratesEntityIfItIsSpecifiedInTheParameters()
        {
            var fakeFilterService = new Fake <ICodeWriterFilterService>();

            fakeFilterService.AnyCall().WithReturnType <bool>().Returns(true);
            var fakeServiceProvider = new Fake <IServiceProvider>();
            var metadata            = new EntityMetadata()
            {
                LogicalName = "account"
            };

            Environment.SetEnvironmentVariable(Constants.ENVIRONMENT_ENTITIES, "account");

            var filteringService      = new FilteringService(fakeFilterService.FakedObject);
            var shouldGenerateAccount = (filteringService as ICodeWriterFilterService).GenerateEntity(metadata, fakeServiceProvider.FakedObject);

            Environment.SetEnvironmentVariable(Constants.ENVIRONMENT_ENTITIES, null);

            Assert.True(shouldGenerateAccount);
        }
        public void GenerateEntityGeneratesEntityIfItIsSpecifiedInTheParameters()
        {
            var fakeFilterService = new Fake <ICodeWriterFilterService>();

            fakeFilterService.AnyCall().WithReturnType <bool>().Returns(true);
            var fakeServiceProvider = new Fake <IServiceProvider>();
            var metadata            = new EntityMetadata()
            {
                LogicalName = "account"
            };

            Environment.SetEnvironmentVariable("AlbanianXrm.EarlyBound:Entities", "account");

            var filteringService      = new FilteringService(fakeFilterService.FakedObject);
            var shouldGenerateAccount = (filteringService as ICodeWriterFilterService).GenerateEntity(metadata, fakeServiceProvider.FakedObject);

            Environment.SetEnvironmentVariable("AlbanianXrm.EarlyBound:Entities", null);

            A.CallTo(() => fakeFilterService.FakedObject.GenerateEntity(A <EntityMetadata> ._, A <IServiceProvider> ._)).MustHaveHappenedOnceExactly();
            Assert.True(shouldGenerateAccount);
        }
        public void GenerateEntitySkipsEntityIfItIsNotSpecifiedInTheParameters()
        {
            var fakeFilterService = new Fake <ICodeWriterFilterService>();

            fakeFilterService.AnyCall().WithReturnType <bool>().Returns(true);
            var fakeServiceProvider = new Fake <IServiceProvider>();
            var metadata            = new EntityMetadata()
            {
                LogicalName = "account"
            };

            Environment.SetEnvironmentVariable(Constants.ENVIRONMENT_ENTITIES, "contact");

            var filteringService      = new FilteringService(fakeFilterService.FakedObject);
            var shouldGenerateAccount = (filteringService as ICodeWriterFilterService).GenerateEntity(metadata, fakeServiceProvider.FakedObject);

            Environment.SetEnvironmentVariable(Constants.ENVIRONMENT_ENTITIES, null);

            A.CallTo(() => fakeFilterService.FakedObject.GenerateEntity(A <EntityMetadata> ._, A <IServiceProvider> ._)).MustNotHaveHappened();
            Assert.False(shouldGenerateAccount);
        }