public void CreateInteractor_Success()
        {
            //arrange
            IEntityGateway    entityGateway = InMemoryEntityGatewayFactory.CreateEntityGateway();
            IAddUserPresenter presenter     = new FakeAddUserPresenter(_output);

            //act
            var interactor = new AddUserInteractor(presenter, entityGateway);

            //assert
            Assert.NotNull(interactor);
        }
        public void CreateInteractor_ThrowsException_NullGateway()
        {
            //arrange
            IEntityGateway    entityGateway = null;
            IAddUserPresenter presenter     = new FakeAddUserPresenter(_output);

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

            //assert
            Assert.Throws <ArgumentNullException>(action);
        }
        public async Task AddUserAsync_ThrowsException_NullInput()
        {
            //arrange
            IEntityGateway     entityGateway = InMemoryEntityGatewayFactory.CreateEntityGateway();
            IAddUserPresenter  presenter     = new FakeAddUserPresenter(_output);
            IAddUserInteractor interactor    = new AddUserInteractor(presenter, entityGateway);
            AddUserInputModel  inputModel    = null;

            //act
            async Task <CommandResult <Application.UseCase.Out.AddUserOutputModel> > function() => await interactor.AddUserAsync(inputModel);

            //assert
            await Assert.ThrowsAsync <ArgumentNullException>(function);
        }
        public async Task AddUserAsync_FailedModelValidation_NullUsername()
        {
            //arrange
            IEntityGateway     entityGateway = InMemoryEntityGatewayFactory.CreateEntityGateway();
            IAddUserPresenter  presenter     = new FakeAddUserPresenter(_output);
            IAddUserInteractor interactor    = new AddUserInteractor(presenter, entityGateway);
            AddUserInputModel  inputModel    = new AddUserInputModel();

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

            //assert
            Assert.NotNull(result);
            Assert.True(result.Status == Application.Common.CommandResultStatusCode.FailedModelValidation);
            Assert.True(result.ModelValidationErrors.ContainsKey(Domain.Common.ModelValidationStatusCode.RequiredInformationMissing));
        }
        public async Task AddUserAsync_CommandResult_Success()
        {
            //arrange
            IEntityGateway     entityGateway = InMemoryEntityGatewayFactory.CreateEntityGateway();
            IAddUserPresenter  presenter     = new FakeAddUserPresenter(_output);
            IAddUserInteractor interactor    = new AddUserInteractor(presenter, entityGateway);
            AddUserInputModel  inputModel    = new AddUserInputModel {
                Username = "******"
            };

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

            //assert
            Assert.NotNull(result);
            Assert.True(result.Status == Application.Common.CommandResultStatusCode.Success);
            Assert.Null(result.ModelValidationErrors);
            Assert.NotNull(result.OutputModel);
            Assert.True(result.OutputModel.Id != Guid.Empty);
        }
        public async Task AddUserAsyncExistingUserUsernameDifferentCase_CommandResult_DuplicateEntry()
        {
            //arrange
            string duplicatedUsername = "******";
            var    users = new User[] { new User {
                                            Username = duplicatedUsername
                                        } };
            IEntityGateway entityGateway = await InMemoryEntityGatewayFactory.CreateEntityGatewayAsync(users);

            IAddUserPresenter  presenter  = new FakeAddUserPresenter(_output);
            IAddUserInteractor interactor = new AddUserInteractor(presenter, entityGateway);
            AddUserInputModel  inputModel = new AddUserInputModel {
                Username = duplicatedUsername.ToUpperInvariant()
            };

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

            //assert
            Assert.NotNull(result);
            Assert.True(result.Status == Application.Common.CommandResultStatusCode.DuplicateEntry);
        }