Esempio n. 1
0
        /// <summary>
        /// Sets the source fields.
        /// </summary>
        /// <param name="fields">The fields.</param>
        /// <exception cref="System.ArgumentNullException">fields</exception>
        public void SetSourceFields(ProviderFieldInfoList fields)
        {
            if (fields == null) throw new ArgumentNullException("fields");

            Model.Clear();

            foreach (var field in fields)
            {
                AddField(field);
            }
        }
        public void GetDataProviderFieldsCommandTest()
        {
            // Arrange.
            const string Message1 = "Test Error 1";
            const string Message2 = "Test Success";
            const string ErrorDetails = "Error Details";

            Mock.Arrange(() => LanguageService.Translate("Msg_LoadLdapAttributesFailed")).Returns(Message1);
            Mock.Arrange(() => LanguageService.Translate("Msg_FieldsRetrieved")).Returns(Message2);

            var popupFactory = Mock.Create<PopupFactory>(Behavior.Loose);
            var sourceViewModel = Mock.Create<ISourceViewModel>(Behavior.Loose);
            var sourceFieldsViewModel = Mock.Create<ISourceFieldsViewModel>(Behavior.Loose);
            Mock.Arrange(sourceViewModel, vm => vm.SourceFieldsViewModel).Returns(sourceFieldsViewModel);

            var model = Mock.Create<LdapDirectoryDataProviderEdit>(Behavior.Loose);
            
            var attribute1 = Mock.Create<LdapAttributeEdit>(Behavior.Loose);
            Mock.Arrange(attribute1, a => a.IsChild).Returns(true);
            Mock.Arrange(attribute1, a => a.Name).Returns("Attribute1");

            var attribute2 = Mock.Create<LdapAttributeEdit>(Behavior.Loose);
            Mock.Arrange(attribute2, a => a.IsChild).Returns(true);
            Mock.Arrange(attribute2, a => a.Name).Returns("Attribute2");

            var attributeList = new LdapAttributeEditList { attribute1, attribute2 };

            Mock.Arrange(() => model.AttributesToLoad).Returns(attributeList);

            var target = new LdapDirectoryDataProviderViewModel { PopupFactory = popupFactory };
            target.Initialize(model, sourceViewModel);

            // DataPortalResult.Error != null.
            var dpException = new Exception();

            Mock.Arrange(
                () =>
                LdapDirectoryFieldsRetriever.GetFields(
                    Arg.IsAny<IEnumerable<string>>(), Arg.IsAny<Action<DataPortalResult<LdapDirectoryFieldsRetriever>>>()))
                .DoInstead<IEnumerable<string>, Action<DataPortalResult<LdapDirectoryFieldsRetriever>>>(
                    (fields, callback) =>
                        {
                            if (!fields.SequenceEqual(new[] { "Attribute1", "Attribute2" }))
                                throw new InvalidOperationException("Invalid fields.");

                            callback(new DataPortalResult<LdapDirectoryFieldsRetriever>(null, dpException, null));
                        });

            // Act.
            target.GetDataProviderFieldsCommand.Execute(null);

            // Assert.
            Mock.Assert(() => popupFactory.NotifyFailure(Message1, dpException), Occurs.Once());

            // LdapDirectoryFieldsRetriever.Error != null.
            Mock.Arrange(
                () =>
                LdapDirectoryFieldsRetriever.GetFields(
                    Arg.IsAny<IEnumerable<string>>(), Arg.IsAny<Action<DataPortalResult<LdapDirectoryFieldsRetriever>>>()))
                .DoInstead<IEnumerable<string>, Action<DataPortalResult<LdapDirectoryFieldsRetriever>>>(
                    (fields, callback) =>
                        {
                            if (!fields.SequenceEqual(new[] { "Attribute1", "Attribute2" }))
                                throw new InvalidOperationException("Invalid fields.");

                            var error = Mock.Create<ErrorInfo>(Behavior.Loose);
                            Mock.Arrange(() => error.Details).Returns(ErrorDetails);
                            var result = Mock.Create<LdapDirectoryFieldsRetriever>(Behavior.Loose);
                            Mock.Arrange(() => result.Error).Returns(error);

                            callback(new DataPortalResult<LdapDirectoryFieldsRetriever>(result, null, null));
                        });

            // Act.
            target.GetDataProviderFieldsCommand.Execute(null);

            // Assert.
            Mock.Assert(() => popupFactory.NotifyFailure(Message1, ErrorDetails), Occurs.Once());

            // Retriever executes successfuly.
            var providerFields = new ProviderFieldInfoList();

            Mock.Arrange(
                () =>
                LdapDirectoryFieldsRetriever.GetFields(
                    Arg.IsAny<IEnumerable<string>>(), Arg.IsAny<Action<DataPortalResult<LdapDirectoryFieldsRetriever>>>()))
                .DoInstead<IEnumerable<string>, Action<DataPortalResult<LdapDirectoryFieldsRetriever>>>(
                    (fields, callback) =>
                        {
                            if (!fields.SequenceEqual(new[] { "Attribute1", "Attribute2" }))
                                throw new InvalidOperationException("Invalid fields.");

                            var result = Mock.Create<LdapDirectoryFieldsRetriever>(Behavior.Loose);
                            Mock.Arrange(() => result.Error).Returns(() => null);
                            Mock.Arrange(() => result.ProviderFields).Returns(providerFields);

                            callback(new DataPortalResult<LdapDirectoryFieldsRetriever>(result, null, null));
                        });

            // Act.
            target.GetDataProviderFieldsCommand.Execute(null);
            
            // Assert.
            Mock.Assert(() => sourceFieldsViewModel.SetSourceFields(providerFields), Occurs.Once());
            Mock.Assert(() => popupFactory.NotifySuccess(Message2, Arg.AnyString), Occurs.Once());
        }
Esempio n. 3
0
        public void DataPortalFetchTest()
        {
            var retriever = new ProviderFieldInfoList();

            Mock.Arrange(() => retriever.AddRange(Arg.IsAny<IEnumerable<ProviderFieldInfo>>())).Occurs(2);

            new PrivateAccessor(retriever).CallMethod("DataPortal_Fetch", new object[] { new List<ProviderFieldInfo>() });
            new PrivateAccessor(retriever).CallMethod("DataPortal_Fetch", new object[] { new List<ProviderFieldDefinition>() });
        }