public void WhenItemsIsNull_FormatResult_ReturnsValidResult()
        {
            // Arrange.
            const string ProcessDisplayName = "Test Process";

            var filters = new List<Filter> { new Filter(), new Filter() };
            var layouts = new List<LayoutMetadata> { new LayoutMetadata(), new LayoutMetadata() };
            var relatedProcesses = new List<ProcessMetadata> { new ProcessMetadata(), new ProcessMetadata() };
            var appliedFilter = new Filter();
            var appliedLayout = new LayoutMetadata();

            var searchResult = new SearchCommandResult
                                   {
                                       ProcessDisplayName = ProcessDisplayName,
                                       AppliedFilter = appliedFilter,
                                       FilterParametersRequired = true,
                                       AppliedLayout = appliedLayout,
                                       Items = null,
                                       ResultColumns = { CreateColumnMetadata("Field1"), CreateColumnMetadata("Field3") },
                                       Filters = filters,
                                       Layouts = layouts,
                                       RelatedProcesses = relatedProcesses
                                   };

            var formatter = new PublicSearchResultFormatter();

            // Act.
            var result = formatter.FormatResult(searchResult) as PublicSearchResult;

            // Assert.
            Assert.IsNotNull(result);
            Assert.AreEqual(ProcessDisplayName, result.ProcessDisplayName);
            Assert.AreSame(appliedFilter, result.AppliedFilter);
            Assert.IsTrue(result.FilterParametersRequired);
            Assert.AreSame(appliedLayout, result.AppliedLayout);
            Assert.AreEqual(-1, result.CurrentPage);
            Assert.AreEqual(0, result.TotalRowCount);
            Assert.IsTrue(result.Filters.SequenceEqual(filters));
            Assert.IsTrue(result.Layouts.SequenceEqual(layouts));
            Assert.IsTrue(result.RelatedProcesses.SequenceEqual(relatedProcesses));
            Assert.IsNull(result.Items);
        }
        public void FormatResult_Returns_PublicSearchResult()
        {
            // Arrange.
            const string ProcessDisplayName = "Test Process";
            const int TotalRowCount = 123;
            const int PageNumber = 3;

            var items = new InfoList<IInfoClass>
                            {
                                new InfoItem { Field1 = "Value 1.1", Field2 = "Value 1.2", Field3 = "Value 1.3" },
                                new InfoItem { Field1 = "Value 2.1", Field2 = "Value 2.2", Field3 = "Value 2.3" }
                            };
            items.TotalRowCount = TotalRowCount;
            items.PageNumber = PageNumber;

            var filters = new List<Filter> { new Filter(), new Filter() };
            var layouts = new List<LayoutMetadata> { new LayoutMetadata(), new LayoutMetadata() };
            var relatedProcesses = new List<ProcessMetadata> { new ProcessMetadata(), new ProcessMetadata() };
            var appliedFilter = new Filter();
            var appliedLayout = new LayoutMetadata();

            var searchResult = new SearchCommandResult
                                   {
                                       ProcessDisplayName = ProcessDisplayName,
                                       AppliedFilter = appliedFilter,
                                       FilterParametersRequired = false,
                                       AppliedLayout = appliedLayout,
                                       Items = items,
                                       ResultColumns = { CreateColumnMetadata("Field1"), CreateColumnMetadata("Field3") },
                                       Filters = filters,
                                       Layouts = layouts,
                                       RelatedProcesses = relatedProcesses
                                   };

            var formatter = new PublicSearchResultFormatter();

            // Act.
            var result = formatter.FormatResult(searchResult) as PublicSearchResult;

            // Assert.
            Assert.IsNotNull(result);
            Assert.AreEqual(ProcessDisplayName, result.ProcessDisplayName);
            Assert.AreSame(appliedFilter, result.AppliedFilter);
            Assert.IsFalse(result.FilterParametersRequired);
            Assert.AreSame(appliedLayout, result.AppliedLayout);
            Assert.AreEqual(PageNumber, result.CurrentPage);
            Assert.AreEqual(TotalRowCount, result.TotalRowCount);
            Assert.IsTrue(result.Filters.SequenceEqual(filters));
            Assert.IsTrue(result.Layouts.SequenceEqual(layouts));
            Assert.IsTrue(result.RelatedProcesses.SequenceEqual(relatedProcesses));

            Assert.IsNotNull(result.Items);
            Assert.AreEqual(2, result.Items.Count);

            Assert.AreEqual(2, result.Items[0].Count);
            Assert.AreEqual("Value 1.1", result.Items[0]["Field1"]);
            Assert.AreEqual("Value 1.3", result.Items[0]["Field3"]);

            Assert.AreEqual(2, result.Items[1].Count);
            Assert.AreEqual("Value 2.1", result.Items[1]["Field1"]);
            Assert.AreEqual("Value 2.3", result.Items[1]["Field3"]);
        }