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"); }
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); }
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); }
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); }
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)); }
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); }