Пример #1
0
        public async Task Register_WritesOutput_InputIsValid(decimal amount)
        {
            var presenter      = new RegisterPresenter();
            var externalUserId = new ExternalUserId("github/ivanpaulovich");
            var ssn            = new SSN("8608178888");

            var sut = new RegisterUseCase(
                new TestUserService(this._fixture.Context),
                this._fixture.CustomerService,
                this._fixture.AccountService,
                this._fixture.SecurityService,
                presenter,
                this._fixture.UnitOfWork);

            await sut.Execute(new RegisterInput(
                                  ssn,
                                  new PositiveMoney(amount)));

            var actual = presenter.Registers.Last();

            Assert.NotNull(actual);
            Assert.Equal(ssn, actual.Customer.SSN);
            Assert.NotEmpty(actual.Customer.Name.ToString());
            Assert.Equal(amount, actual.Account.CurrentBalance.ToDecimal());
        }
        public async Task Register_ValidValues_ShouldReturnACustomerWithAnAccount()
        {
            //ARRANGE
            string name   = "Customer Name Test";
            string pin    = "0101010000";
            double amount = 10;

            _customerWriteOnlyRepository.Setup(m => m.Add(It.IsAny <Customer>())).Returns(Task.CompletedTask);
            _accountWriteOnlyRepository.Setup(m => m.Add(It.IsAny <Account>(), It.IsAny <Credit>())).Returns(Task.CompletedTask);

            //ACT
            RegisterOutput outPut = await registerUseCase.Execute(pin, name, amount);

            //ASSERT
            _customerWriteOnlyRepository.Verify(v => v.Add(It.IsAny <Customer>()), Times.Once());
            _accountWriteOnlyRepository.Verify(v => v.Add(It.IsAny <Account>(), It.IsAny <Credit>()), Times.Once());
            Assert.Equal(outPut.Customer.Name, name);
            Assert.Equal(outPut.Account.CurrentBalance, amount);
        }
        public async void Register_Valid_User_Account(string personnummer, string name, double amount)
        {
            var registerUseCase = new RegisterUseCase(
                customerWriteOnlyRepository,
                accountWriteOnlyRepository
                );

            RegisterResult result = await registerUseCase.Execute(
                personnummer,
                name,
                amount);

            Assert.Equal(personnummer, result.Customer.Personnummer);
            Assert.Equal(name, result.Customer.Name);
            Assert.True(Guid.Empty != result.Customer.CustomerId);
            Assert.True(Guid.Empty != result.Account.AccountId);
        }
Пример #4
0
        public async void Should_Register_New_User()
        {
            // Arrange
            var valid          = new User((Name)"Alexander Held", (Password)"supersecret");
            var userRepository = new Mock <IUserRepository>();
            var todoRepository = new Mock <ITodoRepository>();

            var register = new RegisterUseCase(userRepository.Object, todoRepository.Object);

            // Act
            var output = await register.Execute("Alexander Held", "supersecret");

            // Assert
            Assert.Equal(valid.Name, output.UserOutput.Name);
            Assert.Equal(valid.GetAssociatedTasks(), output.UserOutput.AssociatedTodos.GetReadOnly());
            Assert.NotNull(valid);
            Assert.IsType <User>(valid);
        }
        public async void Register_Valid_User_Account(decimal amount)
        {
            string personnummer = "8608178888";
            string name         = "Ivan Paulovich";

            var mockCustomerWriteOnlyRepository = new Mock <ICustomerWriteOnlyRepository>();
            var mockAccountWriteOnlyRepository  = new Mock <IAccountWriteOnlyRepository>();

            RegisterUseCase sut = new RegisterUseCase(
                mockCustomerWriteOnlyRepository.Object,
                mockAccountWriteOnlyRepository.Object
                );

            RegisterOutput output = await sut.Execute(
                personnummer,
                name,
                amount);

            Assert.Equal(amount, output.Account.CurrentBalance);
        }
        public async Task Register_WritesOutput_AlreadyRegisterested(decimal amount)
        {
            var    presenter = new RegisterPresenter();
            string ssn       = "8608178888";

            var sut = new RegisterUseCase(
                this._fixture.TestUserService,
                this._fixture.CustomerService,
                this._fixture.AccountService,
                this._fixture.SecurityService,
                presenter,
                this._fixture.UnitOfWork,
                this._fixture.CustomerRepository,
                this._fixture.AccountRepository);

            await sut.Execute(new RegisterInput(
                                  ssn,
                                  amount));

            Assert.NotEmpty(presenter.AlreadyRegistered);
        }
Пример #7
0
        public async Task RegsiterUseCase_ValidInput_ShouldReturnTheUser()
        {
            // Arrange
            var userService = new FakeUserService();
            var presenter   = new FakeRegisterOutputHandler();

            var sut = new RegisterUseCase(presenter, userService);

            var input = new RegistrationInput("username", "password", "*****@*****.**");

            // Act
            await sut.Execute(input);

            // Assert
            presenter.ErrorMessage
            .Should()
            .BeNull();

            presenter.ViewModel
            .Should()
            .BeEquivalentTo(userService.User);
        }
Пример #8
0
        public void GivenNullInput_ThrowsException()
        {
            var register = new RegisterUseCase(null, null, null, null, null, null);

            Assert.ThrowsAsync <Exception>(async() => await register.Execute(null));
        }