예제 #1
0
        public async Task ListUsersByPageAsync_Success_GetLastPageNextPage()
        {
            //arrange
            var Users = new List <User>();

            for (int i = 1; i < 100; i++)
            {
                Users.Add(new User {
                    Username = string.Format("Agent{0}", i)
                });
            }
            IEntityGateway entityGateway = await InMemoryEntityGatewayFactory.CreateEntityGatewayAsync(Users.ToArray());

            IListUserByPagePresenter   presenter  = new FakeListUsersByPagePresenter(_output);
            IListUsersByPageInteractor interactor = new ListUsersByPageInteractor(presenter, entityGateway);
            ListUsersByPageInputModel  inputModel = new ListUsersByPageInputModel {
                PageNumber = 5, UsersPerPage = 25
            };

            //act
            var result = await interactor.ListUsersByPageAsync(inputModel);

            //assert
            Assert.NotNull(result);
            Assert.True(result.Status == Application.Common.CommandResultStatusCode.Success);
            Assert.Null(result.ModelValidationErrors);
            Assert.NotNull(result.OutputModel);
            Assert.NotNull(result.OutputModel.Page);
            Assert.True(result.OutputModel.Page.ItemsCount == 0, "Item Count");
            Assert.True(result.OutputModel.Page.TotalItems == 99, "Total Items");
            Assert.True(result.OutputModel.Page.TotalPages == 4, "Total Pages");
        }
예제 #2
0
        public void CreateInteractor_Success()
        {
            //arrange
            IEntityGateway           entityGateway = InMemoryEntityGatewayFactory.CreateEntityGateway();
            IListUserByPagePresenter presenter     = new FakeListUsersByPagePresenter(_output);

            //act
            IListUsersByPageInteractor interactor = new ListUsersByPageInteractor(presenter, entityGateway);

            //assert
            Assert.NotNull(interactor);
        }
예제 #3
0
        public void CreateInteractor_ThrowsException_NullGateway()
        {
            //arrange
            IEntityGateway           entityGateway = null;
            IListUserByPagePresenter presenter     = new FakeListUsersByPagePresenter(_output);

            //act
            Action action = () => new ListUsersByPageInteractor(presenter, entityGateway);

            //assert
            Assert.Throws <ArgumentNullException>(action);
        }
예제 #4
0
        public async Task ListUsersByPageAsync_ThrowsException_NullInput()
        {
            //arrange
            IEntityGateway             entityGateway = InMemoryEntityGatewayFactory.CreateEntityGateway();
            IListUserByPagePresenter   presenter     = new FakeListUsersByPagePresenter(_output);
            IListUsersByPageInteractor interactor    = new ListUsersByPageInteractor(presenter, entityGateway);
            ListUsersByPageInputModel  inputModel    = null;

            //act
            async Task <CommandResult <ListUsersByPageOutputModel> > function() => await interactor.ListUsersByPageAsync(inputModel);

            //assert
            await Assert.ThrowsAsync <ArgumentNullException>(function);
        }
예제 #5
0
        public async Task ListUsersByPageAsync_FailedModelValidation_ZeroUsersPerPage()
        {
            //arrange
            IEntityGateway             entityGateway = InMemoryEntityGatewayFactory.CreateEntityGateway();
            IListUserByPagePresenter   presenter     = new FakeListUsersByPagePresenter(_output);
            IListUsersByPageInteractor interactor    = new ListUsersByPageInteractor(presenter, entityGateway);
            ListUsersByPageInputModel  inputModel    = new ListUsersByPageInputModel {
                PageNumber = 1, UsersPerPage = 0
            };

            //act
            var result = await interactor.ListUsersByPageAsync(inputModel);

            //assert
            Assert.NotNull(result);
            Assert.True(result.Status == Application.Common.CommandResultStatusCode.FailedModelValidation);
            Assert.True(result.ModelValidationErrors.ContainsKey(Domain.Common.ModelValidationStatusCode.InvalidDataSupplied));
        }
예제 #6
0
        public async Task ListUsersByPageAsync_Success_EmptyPage()
        {
            //arrange
            IEntityGateway             entityGateway = InMemoryEntityGatewayFactory.CreateEntityGateway();
            IListUserByPagePresenter   presenter     = new FakeListUsersByPagePresenter(_output);
            IListUsersByPageInteractor interactor    = new ListUsersByPageInteractor(presenter, entityGateway);
            ListUsersByPageInputModel  inputModel    = new ListUsersByPageInputModel {
                PageNumber = 1, UsersPerPage = 50
            };

            //act
            var result = await interactor.ListUsersByPageAsync(inputModel);

            //assert
            Assert.NotNull(result);
            Assert.True(result.Status == Application.Common.CommandResultStatusCode.Success);
            Assert.Null(result.ModelValidationErrors);
            Assert.NotNull(result.OutputModel);
            Assert.NotNull(result.OutputModel.Page);
            Assert.True(result.OutputModel.Page.ItemsCount == 0);
        }