protected override void SetupNewDatabase(DbContextOptions <IPOContext> dbContextOptions)
        {
            using (new IPOContext(dbContextOptions, _plantProvider, _eventDispatcher, _currentUserProvider))
            {
                _commPkgApiServiceMock = new Mock <ICommPkgApiService>();
                _mainApiCommPkgs       = new List <ProCoSysCommPkg>
                {
                    new ProCoSysCommPkg
                    {
                        Id = 1, CommPkgNo = "CommPkgNo1", Description = "Desc1", CommStatus = "PB"
                    },
                    new ProCoSysCommPkg
                    {
                        Id = 2, CommPkgNo = "CommPkgNo2", Description = "Desc2", CommStatus = "OK"
                    },
                    new ProCoSysCommPkg
                    {
                        Id = 3, CommPkgNo = "CommPkgNo3", Description = "Desc3", CommStatus = "PA"
                    }
                };

                var result = new ProCoSysCommPkgSearchResult {
                    MaxAvailable = 3, Items = _mainApiCommPkgs
                };

                _commPkgApiServiceMock
                .Setup(x => x.SearchCommPkgsByCommPkgNoAsync(TestPlant, _projectName, _commPkgStartsWith, _defaultPageSize, _defaultCurrentPage))
                .Returns(Task.FromResult(result));

                _query = new GetCommPkgsInProjectQuery(_projectName, _commPkgStartsWith, _defaultPageSize, _defaultCurrentPage);
            }
        }
        public async Task SearchCommPkgsByCommPkgNo_ShouldReturnCommPkgs_WhenSpecifyingNumberOfItems()
        {
            var searchWithOneItem = new ProCoSysCommPkgSearchResult
            {
                MaxAvailable = 3,
                Items        = new List <ProCoSysCommPkg>
                {
                    new ProCoSysCommPkg
                    {
                        Id          = 111111111,
                        CommPkgNo   = "CommNo1",
                        Description = "Description1",
                        CommStatus  = "OK"
                    }
                }
            };

            _foreignApiClient
            .SetupSequence(x => x.QueryAndDeserializeAsync <ProCoSysCommPkgSearchResult>(It.IsAny <string>(), null))
            .Returns(Task.FromResult(searchWithOneItem));

            // Act
            var result = await _dut.SearchCommPkgsByCommPkgNoAsync(
                _plant,
                "ProjectName",
                "C",
                1,
                _defaultCurrentPage);

            // Assert
            Assert.AreEqual(1, result.Items.Count);
            Assert.AreEqual(3, result.MaxAvailable);
        }
        public void Setup()
        {
            _mainApiOptions = new Mock <IOptionsMonitor <MainApiOptions> >();
            _mainApiOptions
            .Setup(x => x.CurrentValue)
            .Returns(new MainApiOptions {
                ApiVersion = "4.0", BaseAddress = "http://example.com"
            });

            _foreignApiClient = new Mock <IBearerTokenApiClient>();

            _searchPageWithThreeItems = new ProCoSysCommPkgSearchResult
            {
                MaxAvailable = 3,
                Items        = new List <ProCoSysCommPkg>
                {
                    new ProCoSysCommPkg
                    {
                        Id          = 111111111,
                        CommPkgNo   = "CommNo1",
                        Description = "Description1",
                        CommStatus  = "OK",
                        System      = "1|2"
                    },
                    new ProCoSysCommPkg
                    {
                        Id          = 222222222,
                        CommPkgNo   = "CommNo2",
                        Description = "Description2",
                        CommStatus  = "PA",
                        System      = "1|2"
                    },
                    new ProCoSysCommPkg
                    {
                        Id          = 333333333,
                        CommPkgNo   = "CommNo3",
                        Description = "Description3",
                        CommStatus  = "PB",
                        System      = "1|2"
                    }
                }
            };

            _foreignApiClient
            .SetupSequence(x => x.QueryAndDeserializeAsync <ProCoSysCommPkgSearchResult>(It.IsAny <string>(), null))
            .Returns(Task.FromResult(_searchPageWithThreeItems));

            _dut = new MainApiCommPkgService(_foreignApiClient.Object, _mainApiOptions.Object);
        }
        public async Task SearchCommPkgsByCommPkgNo_ShouldReturnEmptyList_WhenSearchingEmptyPage()
        {
            var emptyPage = new ProCoSysCommPkgSearchResult
            {
                MaxAvailable = 3,
                Items        = new List <ProCoSysCommPkg>()
            };

            _foreignApiClient
            .SetupSequence(x => x.QueryAndDeserializeAsync <ProCoSysCommPkgSearchResult>(It.IsAny <string>(), null))
            .Returns(Task.FromResult(emptyPage));
            // Act
            var result = await _dut.SearchCommPkgsByCommPkgNoAsync(
                _plant,
                "ProjectName",
                "C",
                _defaultPageSize,
                1);

            // Assert
            Assert.AreEqual(0, result.Items.Count);
            Assert.AreEqual(3, result.MaxAvailable);
        }
Example #5
0
        public void TestInitialize()
        {
            var commPkgs = new List <ProCoSysCommPkg>
            {
                new ProCoSysCommPkg
                {
                    CommPkgNo   = CommPkgNo1,
                    CommStatus  = "OK",
                    Description = "CommPkg1Description",
                    Id          = 1,
                    System      = System
                },
                new ProCoSysCommPkg
                {
                    CommPkgNo   = CommPkgNo2,
                    CommStatus  = "OS",
                    Description = "CommPkg2Description",
                    Id          = 2,
                    System      = System
                }
            };

            _commPkgSearchResult = new ProCoSysCommPkgSearchResult {
                MaxAvailable = 2, Items = commPkgs
            };

            _projects = new List <ProCoSysProject>
            {
                new ProCoSysProject {
                    Id = 1, Name = ProjectName1, Description = "Project1Description"
                },
                new ProCoSysProject {
                    Id = 2, Name = ProjectName2, Description = "Project2Description"
                }
            };

            _mcPkgs = new List <ProCoSysMcPkg>
            {
                new ProCoSysMcPkg
                {
                    Id             = 1,
                    CommPkgNo      = CommPkgNo1,
                    McPkgNo        = McPkgNo1,
                    Description    = "McPkg1Description",
                    DisciplineCode = "A",
                    System         = System
                },
                new ProCoSysMcPkg
                {
                    Id             = 2,
                    CommPkgNo      = CommPkgNo2,
                    McPkgNo        = McPkgNo2,
                    Description    = "McPkg2Description",
                    DisciplineCode = "B",
                    System         = System
                }
            };

            TestFactory.Instance
            .CommPkgApiServiceMock
            .Setup(x => x.SearchCommPkgsByCommPkgNoAsync(
                       TestFactory.PlantWithAccess,
                       TestFactory.ProjectWithAccess,
                       "CommPkgNo",
                       10,
                       0))
            .Returns(Task.FromResult(_commPkgSearchResult));

            TestFactory.Instance
            .ProjectApiServiceMock
            .Setup(x => x.GetProjectsInPlantAsync(
                       TestFactory.PlantWithAccess))
            .Returns(Task.FromResult(_projects));

            TestFactory.Instance
            .McPkgApiServiceMock
            .Setup(x => x.GetMcPkgsByCommPkgNoAndProjectNameAsync(
                       TestFactory.PlantWithAccess,
                       TestFactory.ProjectWithAccess,
                       "CommPkgNo"))
            .Returns(Task.FromResult(_mcPkgs));
        }