public Customer(Guid id, Name name, SSN ssn, AccountCollection accounts)
 {
     Id        = id;
     Name      = name;
     SSN       = ssn;
     _accounts = accounts;
 }
Пример #2
0
 //Override GetHashCode()
 public override int GetHashCode() //https://docs.microsoft.com/en-us/dotnet/api/system.object.gethashcode?view=netframework-4.8
 {
     return(FirstName.GetHashCode()
            ^ MiddleName.GetHashCode()
            ^ LastName.GetHashCode()
            ^ SSN.GetHashCode());  //https://www.tutorialspoint.com/csharp/csharp_operators.htm Binary XOR Operator copies the bit if it is set in one operand but not both.	(A ^ B) = 49, which is 0011 0001
 }
 public AddEmployeeForm() : base("AddEmployeeForm")
 {
     EmployeeName           = AddTextInput(nameof(EmployeeName));
     EmployeeName.MaxLength = 100;
     EmployeeName.SetValue("");
     BirthDate  = AddDateInput(nameof(BirthDate));
     Department = AddInt32DropDown
                  (
         nameof(Department),
         new DropDownItem <int?>(1, "HR"),
         new DropDownItem <int?>(2, "IT")
                  );
     Department.ItemCaption = "Select...";
     Department.MustNotBeNull();
     Address         = AddComplex(nameof(Address), (p, n) => new AddressInput(p, n));
     SSN             = AddInt32Input(nameof(SSN));
     SSN.IsProtected = true;
     SSN.AddConstraints(Int32RangeConstraint.FromAbove(0).ToBelow(1000000000));
     HireDate = AddDateDropDown
                (
         nameof(HireDate),
         new DropDownItem <DateTimeOffset?>(DateTimeOffset.Now.Date.AddDays(-1), "Yesterday"),
         new DropDownItem <DateTimeOffset?>(DateTimeOffset.Now.Date, "Today"),
         new DropDownItem <DateTimeOffset?>(DateTimeOffset.Now.Date.AddDays(1), "Tomorrow")
                );
     IsTemp     = AddBooleanDropDown(nameof(IsTemp));
     EmployeeID = AddInt32Hidden(nameof(EmployeeID), 32);
 }
Пример #4
0
        public async Task Register_WritesOutput_InputIsValid(decimal amount)
        {
            var presenter = new RegisterPresenter();
            var ssn       = new SSN("8608178888");
            var name      = new Name("Ivan Paulovich");

            var sut = new Register(
                _fixture.EntityFactory,
                presenter,
                _fixture.CustomerRepository,
                _fixture.AccountRepository,
                _fixture.UnitOfWork
                );

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

            var actual = presenter.Registers.Last();

            Assert.NotNull(actual);
            Assert.Equal(ssn.ToString(), actual.Customer.SSN);
            Assert.Equal(name.ToString(), actual.Customer.Name);
            Assert.Equal(amount, actual.Account.CurrentBalance);
        }
        public async Task <ICustomer> CreateCustomer(SSN ssn, Name name)
        {
            var customer = _customerFactory.NewCustomer(ssn, name);
            await _customerRepository.Add(customer);

            return(customer);
        }
Пример #6
0
    public override int GetHashCode()
    {
        // using prime numbers to multiply

        int hash           = 29;
        int hashMultiplier = 11;

        // overflow is ok for hashing

        unchecked
        {
            // use multyplying and the fields' own hashcode to generate a unique code for the student

            hash = hash * hashMultiplier + string.Format("{0} {1} {2}", FirstName, MiddleName, LastName).GetHashCode();
            hash = hash * hashMultiplier + Adress.GetHashCode();
            hash = hash * hashMultiplier + Course.GetHashCode();
            hash = hash * hashMultiplier + Email.GetHashCode();
            hash = hash * hashMultiplier + Faculty.GetHashCode();
            hash = hash * hashMultiplier + Phone.GetHashCode();
            hash = hash * hashMultiplier + SSN.GetHashCode();
            hash = hash * hashMultiplier + University.GetHashCode();
            hash = hash * hashMultiplier + Specialty.GetHashCode();
        }

        return(hash);
    }
Пример #7
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 Register(
                new TestUserService(_fixture.Context),
                _fixture.EntityFactory,
                _fixture.EntityFactory,
                _fixture.EntityFactory,
                presenter,
                _fixture.CustomerRepository,
                _fixture.AccountRepository,
                _fixture.UserRepository,
                _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());
        }
Пример #8
0
 public RegisterInput(
     SSN ssn,
     PositiveMoney initialAmount)
 {
     SSN           = ssn;
     InitialAmount = initialAmount;
 }
        public async Task Register_WritesOutput_InputIsValid(double amount)
        {
            var ssn  = new SSN("8608178888");
            var name = new Name("Ivan Paulovich");

            var entityFactory      = new EntityFactory();
            var presenter          = new Presenter();
            var context            = new MangaContext();
            var customerRepository = new CustomerRepository(context);
            var accountRepository  = new AccountRepository(context);
            var unitOfWork         = new UnitOfWork(context);

            var sut = new Register(
                entityFactory,
                presenter,
                customerRepository,
                accountRepository,
                unitOfWork
                );

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

            var actual = presenter.Registers.First();

            Assert.NotNull(actual);
            Assert.Equal(ssn.ToString(), actual.Customer.SSN);
            Assert.Equal(name.ToString(), actual.Customer.Name);
            Assert.Equal(amount, actual.Account.CurrentBalance);
        }
Пример #10
0
        public async Task ShouldInsert_ExternalAgentAndEmployee()
        {
            Guid id = Guid.NewGuid();

            Employee employee = new Employee
                                (
                new ExternalAgent(id, AgentType.Employee),
                SupervisorId.Create(id),
                PersonName.Create("George", "Orwell", "J"),
                SSN.Create("623789999"),
                PhoneNumber.Create("817-987-1234"),
                MaritalStatus.Create("M"),
                TaxExemption.Create(5),
                PayRate.Create(40.00M),
                StartDate.Create(new DateTime(1998, 12, 2)),
                IsActive.Create(true)
                                );

            await _employeeRepo.AddAsync(employee);

            await _unitOfWork.Commit();

            var employeeResult = await _employeeRepo.Exists(employee.Id);

            Assert.True(employeeResult);
        }
        public async Task Register_WritesOutput_InputIsValid(double amount)
        {
            var ssn      = new SSN("8608178888");
            var name     = new Name("Ivan Paulovich");
            var password = new Password("Sahil@123");

            var entityFactory      = new DefaultEntitiesFactory();
            var presenter          = new Presenter();
            var context            = new MangaContext();
            var customerRepository = new CustomerRepository(context);
            var accountRepository  = new AccountRepository(context);
            var registerUser       = new RegisterUser(new UserManager <IdentityUser>());

            var sut = new Register(
                entityFactory,
                presenter,
                customerRepository,
                accountRepository,
                registerUser
                );

            await sut.Execute(new Input(
                                  ssn,
                                  name,
                                  password,
                                  new PositiveAmount(amount)));

            var actual = presenter.Registers.First();

            Assert.NotNull(actual);
            Assert.Equal(ssn.ToString(), actual.Customer.SSN);
            Assert.Equal(name.ToString(), actual.Customer.Name);
            Assert.Equal(amount, actual.Account.CurrentBalance);
            //Assert.Equal(password, actual.Customer.Password);
        }
 public Customer(SSN ssn, Name name)
 {
     Id        = Guid.NewGuid();
     SSN       = ssn;
     Name      = name;
     _accounts = new AccountCollection();
 }
 public Input(SSN ssn, Name name, Password password, PositiveAmount initialAmount)
 {
     SSN           = ssn;
     Name          = name;
     InitialAmount = initialAmount;
     Password      = password;
 }
Пример #14
0
        public void ConvertObjectToStringUsingToString()
        {
            SSN.Reset();
            Assert.Equal("123456789", ConversionService.Convert <string>(new SSN("123456789")));

            Assert.Equal(1, SSN.ConstructorCount);
            Assert.Equal(1, SSN.ToStringCount);
        }
Пример #15
0
 public Customer(CustomerId customerId, SSN ssn, Name name, IEnumerable <AccountId> accounts)
 {
     this.Id       = customerId;
     this.SSN      = ssn;
     this.Name     = name;
     this.Accounts = new AccountCollection();
     this.Accounts.Add(accounts);
 }
Пример #16
0
        public void ConvertObjectToObjectUsingObjectConstructor()
        {
            SSN.Reset();
            Assert.Equal(new SSN("123456789"), ConversionService.Convert <SSN>("123456789"));

            Assert.Equal(2, SSN.ConstructorCount);
            Assert.Equal(0, SSN.ToStringCount);
        }
        private CreatePerson GetCreatePerson(Guid?id = null, SSN ssn = null, Name name = null)
        {
            var idToUse = id.HasValue ? id.Value : IdGenerator.GetId();

            ssn  = ssn ?? new SSN("08088212323");
            name = name ?? new Name("Tomas Jansson");
            return(new CreatePerson(idToUse, ssn, name));
        }
Пример #18
0
 public Customer(
     SSN ssn,
     Name name)
 {
     Id   = new CustomerId(Guid.NewGuid());
     SSN  = ssn;
     Name = name;
 }
 public Customer(SSN ssn, Name name, Gender gender)
 {
     Id        = Guid.NewGuid();
     SSN       = ssn;
     Name      = name;
     Gender    = gender;
     _accounts = new AccountCollection();
 }
 public Customer(CustomerId id, Name firstName, Name lastName, SSN ssn, UserId userId)
 {
     this.CustomerId = id;
     this.FirstName  = firstName;
     this.LastName   = lastName;
     this.SSN        = ssn;
     this.UserId     = userId;
 }
Пример #21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Customer"/> class.
 /// </summary>
 /// <param name="ssn">SSN.</param>
 /// <param name="name">Name.</param>
 public Customer(
     SSN ssn,
     Name name)
 {
     this.Id   = new CustomerId(Guid.NewGuid());
     this.SSN  = ssn;
     this.Name = name;
 }
Пример #22
0
        public void Configure(EntityTypeBuilder <Employee> entity)
        {
            entity.ToTable("Employees", schema: "HumanResources");
            entity.HasKey(e => e.Id);
            entity.Property(p => p.Id).HasColumnType("UNIQUEIDENTIFIER").HasColumnName("EmployeeId");
            entity.Property(p => p.SupervisorId)
            .HasConversion(p => p.Value, p => SupervisorId.Create(p))
            .HasColumnType("UNIQUEIDENTIFIER")
            .HasColumnName("SupervisorId")
            .IsRequired();
            entity.OwnsOne(p => p.EmployeeName, p =>
            {
                p.Property(pp => pp.LastName).HasColumnType("NVARCHAR(25)").HasColumnName("LastName").IsRequired();
                p.Property(pp => pp.FirstName).HasColumnType("NVARCHAR(25)").HasColumnName("FirstName").IsRequired();
                p.Property(pp => pp.MiddleInitial).HasColumnType("NCHAR(1)").HasColumnName("MiddleInitial");
            });

            entity.Property(p => p.SSN)
            .HasConversion(p => p.Value, p => SSN.Create(p))
            .HasColumnType("NVARCHAR(9)")
            .HasColumnName("SSN")
            .IsRequired();
            entity.Property(p => p.Telephone)
            .HasConversion(p => p.Value, p => PhoneNumber.Create(p))
            .HasColumnType("NVARCHAR(14)")
            .HasColumnName("Telephone")
            .IsRequired();
            entity.Property(p => p.MaritalStatus)
            .HasConversion(p => p.Value, p => MaritalStatus.Create(p))
            .HasColumnType("NCHAR(1)")
            .HasColumnName("MaritalStatus")
            .IsRequired();
            entity.Property(p => p.TaxExemption)
            .HasConversion(p => p.Value, p => TaxExemption.Create(p))
            .HasColumnType("int")
            .HasColumnName("Exemptions")
            .IsRequired();
            entity.Property(p => p.PayRate)
            .HasConversion(p => p.Value, p => PayRate.Create(p))
            .HasColumnType("DECIMAL(18,2)")
            .HasColumnName("PayRate")
            .IsRequired();
            entity.Property(p => p.StartDate)
            .HasConversion(p => p.Value, p => StartDate.Create(p))
            .HasColumnType("datetime2(0)")
            .HasColumnName("StartDate")
            .IsRequired();
            entity.Property(p => p.IsActive)
            .HasConversion(p => p.Value, p => IsActive.Create(p))
            .HasColumnType("BIT")
            .HasColumnName("IsActive")
            .IsRequired();
            entity.Property(e => e.CreatedDate)
            .HasColumnType("datetime2(7)")
            .ValueGeneratedOnAdd()
            .HasDefaultValueSql("sysdatetime()");
            entity.Property(e => e.LastModifiedDate).HasColumnType("datetime2(7)");
        }
Пример #23
0
        /// <summary>
        ///     Creates a Customer.
        /// </summary>
        /// <param name="ssn">SSN.</param>
        /// <param name="name">Name.</param>
        /// <returns>Created Customer.</returns>
        public async Task <ICustomer> CreateCustomer(SSN ssn, Name name)
        {
            var customer = this.customerFactory.NewCustomer(ssn, name);

            await this.customerRepository.Add(customer)
            .ConfigureAwait(false);

            return(customer);
        }
Пример #24
0
        public void ShouldReturnValid_SSN()
        {
            string ssn = "587887964";

            var result = SSN.Create(ssn);

            Assert.IsType <SSN>(result);
            Assert.Equal(ssn, result);
        }
Пример #25
0
        public void ToDataTable_ProjectionHasANonBuiltInType_ShouldThrowAnInvalidColumnDataTypException()
        {
            var ssn = new SSN();
            Expression <Func <Person, dynamic> > projector = p => new { p.Id, SSN = ssn };

            Func <DataColumnCollection> getColumns = () => _people.ToDataTable(projector).Columns;

            Assert.Throws <InvalidColumnDataTypeException>(getColumns);
        }
 }                                 //add
 public Input(SSN ssn, Name name, Email email, Mobile mobile, Password password, PositiveAmount initialAmount)
 {
     SSN           = ssn;
     Name          = name;
     Email         = email;
     Mobile        = mobile;
     InitialAmount = initialAmount;
     Password      = password;
 }
        private async Task OnBoardCustomerInternal(Name firstName, Name lastName, SSN ssn, UserId userId)
        {
            Customer customer = this._customerFactory
                                .NewCustomer(ssn, firstName, lastName, userId);

            await this.OnBoardCustomer(customer)
            .ConfigureAwait(false);

            this._outputPort?.Ok(customer);
        }
        public static Customer Load(Guid id, Name name, SSN ssn, AccountCollection accounts)
        {
            Customer customer = new Customer();

            customer.Id        = id;
            customer.Name      = name;
            customer.SSN       = ssn;
            customer._accounts = accounts;
            return(customer);
        }
Пример #29
0
        public override int GetHashCode()
        {
            int    hash = 13;
            Random rand = new Random();

            hash = (hash * 7) + SSN.GetHashCode();
            hash = (hash * rand.Next(1, 1000));
            hash = (hash * counter);
            return(hash);
        }
 public RegisterResponse(
     CustomerId customerId,
     SSN ssn,
     Name name,
     List <AccountDetailsModel> accounts)
 {
     CustomerId = customerId.ToGuid();
     SSN        = ssn.ToString();
     Name       = name.ToString();
     Accounts   = accounts;
 }