Exemple #1
0
        public void AbbreviationsHarvester_WithValidParametersInConstructor_ShouldCorrectlyInitializeNewInstance()
        {
            // Arrange
            var contextWrapperMock = new Mock <IXmlContextWrapper>();
            var contextWrapper     = contextWrapperMock.Object;

            var serializerMock          = new Mock <IXmlTransformDeserializer>();
            var transformersFactoryMock = new Mock <IAbbreviationsTransformersFactory>();

            // Act
            var harvester = new AbbreviationsHarvester(contextWrapper, serializerMock.Object, transformersFactoryMock.Object);

            // Assert
            Assert.IsNotNull(harvester);

            var contextWrapperField = PrivateField.GetInstanceField(HarvesterType.BaseType, harvester, ContextWrapperFieldName);

            Assert.IsNotNull(contextWrapperField);
            Assert.IsInstanceOf <IXmlContextWrapper>(contextWrapperField);
            Assert.AreSame(contextWrapper, contextWrapperField);

            var serializerField = PrivateField.GetInstanceField(HarvesterType, harvester, SerializerFieldName);

            Assert.IsNotNull(serializerField);
            Assert.IsInstanceOf <IXmlTransformDeserializer>(serializerField);
            Assert.AreSame(serializerMock.Object, serializerField);

            var transformersFactoryField = PrivateField.GetInstanceField(HarvesterType, harvester, TransformersFactoryFieldName);

            Assert.IsNotNull(transformersFactoryField);
            Assert.IsInstanceOf <IAbbreviationsTransformersFactory>(transformersFactoryField);
            Assert.AreSame(transformersFactoryMock.Object, transformersFactoryField);
        }
Exemple #2
0
        public void ExtractTaxaCommand_WithValidHarvesterAndValidReporter_ShouldCorrectlyInitializeObject()
        {
            // Arrange
            var harvesterMock = new Mock <ITaxonNamesHarvester>();
            var reporterMock  = new Mock <IReporter>();

            // Act
            var command = new ExtractTaxaCommand(harvesterMock.Object, reporterMock.Object);

            // Assert
            Assert.IsNotNull(command, "Initialized Command object should not be null.");

            var harvester = PrivateField.GetInstanceField <ExtractTaxaCommand>(
                command,
                ParameterNames.Harvester);

            Assert.IsNotNull(harvester, "Private harvester field should not be null.");
            Assert.AreSame(harvesterMock.Object, harvester, "Private harvester field should not be set correctly.");

            var reporter = PrivateField.GetInstanceField <ExtractTaxaCommand>(
                command,
                ParameterNames.Reporter);

            Assert.IsNotNull(reporter, "Private reporter field should not be null.");
            Assert.AreSame(reporterMock.Object, reporter, "Private reporter field should not be set correctly.");

            harvesterMock.Verify(r => r.Harvest(It.IsAny <XmlNode>()), Times.Never);
            harvesterMock.Verify(r => r.HarvestLowerTaxa(It.IsAny <XmlNode>()), Times.Never);
            harvesterMock.Verify(r => r.HarvestHigherTaxa(It.IsAny <XmlNode>()), Times.Never);

            reporterMock.Verify(r => r.AppendContent(It.IsAny <string>()), Times.Never);
            reporterMock.Verify(r => r.MakeReport(), Times.Never);
        }
Exemple #3
0
        public void When_Private_Field_And_xBind_Not_OneTime()
        {
            var source = new PrivateField(42);
            var SUT    = new Windows.UI.Xaml.Controls.Grid();

            var binding = new Binding()
            {
                Path           = "MyField",
                Mode           = BindingMode.OneWay,
                CompiledSource = source
            };

            binding.SetBindingXBindProvider(
                source,
                (a) => "Test",
                null,
                new[] { "MyField" });

            SUT.SetBinding(
                Windows.UI.Xaml.Controls.Grid.TagProperty,
                binding
                );

            SUT.ApplyXBind();

            Assert.AreEqual("Test", SUT.Tag);
        }
        public static void projectWindowForTarget(Object target)
        {
            // Get a reference to the `InspectorWindow` type object
            var windowType     = typeof(UnityEditor.Editor).Assembly.GetType("UnityEditor.ProjectBrowser");
            var windowInstance = ScriptableObject.CreateInstance(windowType) as EditorWindow;

            Debug.Assert(windowInstance != null, nameof(windowInstance) + " != null");
            windowInstance.Show();
            PrivateMethod.obtain(windowType, "Init")(windowInstance);

            var getInstanceIDFromGUID = PrivateMethod.obtainStaticFn <string, int>(
                typeof(AssetDatabase), "GetInstanceIDFromGUID"
                );

            var setFolderSelection = PrivateMethod.obtain <int[], bool>(windowType, "SetFolderSelection");

            setFolderSelection(
                windowInstance,
                new[] { getInstanceIDFromGUID(
                            AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(Selection.activeObject))
                            ) },
                true
                );
            var isLockedFieldAccessor = PrivateField.accessor <bool>(windowType, "m_IsLocked");
            var isLockedField         = isLockedFieldAccessor(windowInstance);

            isLockedField.value = true;
        }
Exemple #5
0
        public void When_Private_Field_And_Binding()
        {
            var source = new PrivateField(42);
            var SUT    = new Windows.UI.Xaml.Controls.Grid();

            SUT.SetBinding(
                Windows.UI.Xaml.Controls.Grid.TagProperty,
                new Binding()
            {
                Path = "MyField"
            }
                );

            SUT.DataContext = source;

            Assert.IsNull(SUT.Tag);
        }
        public void ExpandLowerTaxaCommand_WithValidParser_ShouldCorrectlyInitializeObject()
        {
            // Arrange + Act
            var parserMock = new Mock <IExpander>();
            var command    = new ExpandLowerTaxaCommand(parserMock.Object);

            // Assert
            Assert.IsNotNull(command, "Initialized Command object should not be null.");

            var parser = PrivateField.GetInstanceField(
                typeof(ExpandLowerTaxaCommand).BaseType,
                command,
                ParameterNames.Parser);

            Assert.IsNotNull(parser, "Private parser field should not be null.");
            Assert.AreSame(parserMock.Object, parser, "Private parser field should not be set correctly.");
        }
        public void FormatTreatmentsCommand_WithValidFormatter_ShouldCorrectlyInitializeObject()
        {
            // Arrange + Act
            var formatterMock = new Mock <ITreatmentFormatter>();
            var command       = new FormatTreatmentsCommand(formatterMock.Object);

            // Assert
            Assert.IsNotNull(command, "Initialized Command object should not be null.");

            var formatter = PrivateField.GetInstanceField(
                typeof(FormatTreatmentsCommand).BaseType,
                command,
                ParameterNames.Formatter);

            Assert.IsNotNull(formatter, "Private formatter field should not be null.");
            Assert.AreSame(formatterMock.Object, formatter, "Private formatter field should not be set correctly.");
        }
        public void ParseTreatmentMetaWithInternalInformationCommand_WithValidParser_ShouldCorrectlyInitializeObject()
        {
            // Arrange + Act
            var parserMock = new Mock <ITreatmentMetaParserWithInternalInformation>();
            var command    = new ParseTreatmentMetaWithInternalInformationCommand(parserMock.Object);

            // Assert
            Assert.IsNotNull(command, "Initialized Command object should not be null.");

            var parser = PrivateField.GetInstanceField(
                typeof(ParseTreatmentMetaWithInternalInformationCommand).BaseType,
                command,
                ParameterNames.Parser);

            Assert.IsNotNull(parser, "Private parser field should not be null.");
            Assert.AreSame(parserMock.Object, parser, "Private parser field should not be set correctly.");
        }
Exemple #9
0
        public void RedisKeyValuePairsRepositoryOfTweet_WithValidClientProviderInConstructor_ShouldBeInitializedCorrectly()
        {
            // Arrange
            var clientProvider = new RedisClientProvider();

            // Act + Assert
            var repository = new RedisKeyValuePairsRepository <ITweet>(clientProvider);

            Assert.IsNotNull(repository);

            var providerField = PrivateField.GetInstanceField(
                typeof(RedisKeyValuePairsRepository <ITweet>).BaseType,
                repository,
                Constants.ClientProviderFieldName);

            Assert.AreSame(clientProvider, providerField);
        }
        public void MemoryKeyCollectionValuePairsRepositoryOfTweet_WithValidDataStoreInConstructor_ShouldBeInitializedCorrectly()
        {
            // Arrange
            var dataStoreMock = new Mock <IMemoryStringKeyCollectionValueDataStore <ITweet> >();
            var dataStore     = dataStoreMock.Object;

            // Act + Assert
            var repository = new MemoryKeyCollectionValuePairsRepository <ITweet>(dataStore);

            Assert.IsNotNull(repository);

            var dataStoreFieldValue = PrivateField.GetInstanceField <MemoryKeyCollectionValuePairsRepository <ITweet> >(
                repository,
                Constants.DataStoreParamName);

            Assert.AreSame(dataStore, dataStoreFieldValue);
        }
Exemple #11
0
        public void ParseTreatmentMetaWithCatalogueOfLifeCommand_WithValidParser_ShouldCorrectlyInitializeObject()
        {
            // Arrange + Act
            var parserMock = new Mock <ITreatmentMetaParserWithDataService <ICatalogueOfLifeTaxaClassificationResolver> >();
            var command    = new ParseTreatmentMetaWithCatalogueOfLifeCommand(parserMock.Object);

            // Assert
            Assert.IsNotNull(command, "Initialized Command object should not be null.");

            var parser = PrivateField.GetInstanceField(
                typeof(ParseTreatmentMetaWithCatalogueOfLifeCommand).BaseType,
                command,
                ParameterNames.Parser);

            Assert.IsNotNull(parser, "Private parser field should not be null.");
            Assert.AreSame(parserMock.Object, parser, "Private parser field should not be set correctly.");
        }
Exemple #12
0
        public void When_Private_Field_And_xBind()
        {
            var source = new PrivateField(42);
            var SUT    = new Windows.UI.Xaml.Controls.Grid();

            SUT.SetBinding(
                Windows.UI.Xaml.Controls.Grid.TagProperty,
                new Binding()
            {
                Path           = "MyField",
                CompiledSource = source
            }
                );

            SUT.ApplyCompiledBindings();

            Assert.AreEqual(42, SUT.Tag);
        }
        public void RedisValidationCacheDataRepository_WithValidClientProviderInConstructor_ShouldBeInitializedCorrectly()
        {
            // Arrange
            var clientProviderMock = new Mock <IRedisClientProvider>();
            var clientProvider     = clientProviderMock.Object;

            // Act + Assert
            var repository = new RedisValidationCacheDataRepository(clientProvider);

            Assert.IsNotNull(repository);

            var providerField = PrivateField.GetInstanceField(
                typeof(RedisValidationCacheDataRepository).BaseType.BaseType,
                repository,
                Constants.ClientProviderFieldName);

            Assert.AreSame(clientProvider, providerField);
        }
        public void ValidationCacheService_WithValidParametersInConstructor_ShouldBeInitializedCorrectly()
        {
            // Arrange
            var repositoryMock = new Mock <IValidationCacheDataRepository>();
            var repository     = repositoryMock.Object;

            var dateTimeProviderMock = new Mock <IDateTimeProvider>();
            var dateTimeProvider     = dateTimeProviderMock.Object;

            // Act
            var service = new ValidationCacheService(repository, dateTimeProvider);

            // Assert
            Assert.IsNotNull(service);

            var repositoryFieldValue = PrivateField.GetInstanceField <ValidationCacheService>(service, Constants.RepositoryParamName);

            Assert.AreSame(repository, repositoryFieldValue, "Repository field should be set correctly.");

            var dateTimeProviderFieldValue = PrivateField.GetInstanceField <ValidationCacheService>(service, Constants.DateTimeProviderParamName);

            Assert.AreEqual(dateTimeProvider, dateTimeProviderFieldValue, "DateTimeProvider field should be set correctly.");
        }
        public void ReferenceEqual()
        {
            var element = new PrivateField("");

            Assert.That(PropComparer.Equal(element, element), Is.True);
        }