コード例 #1
0
        public void WhenHorlyRateNotSpecified_ThrowException()
        {
            // Arrange
            var    employeeId = new EmployeeId("foo");
            var    name       = new Name("bar", null, "hee", null, null);
            var    address    = new FakeAddress();
            Action action     = () => HourlyEmployee.CreateNew(employeeId, name, address, null);

            // Act & Assert
            action.Should().Throw <EmployeeDomainException>().WithMessage("Hourly rate must not be null.");
        }
コード例 #2
0
        public void WhenSalaryNotSpecified_ThrowException()
        {
            // Arrange
            var   employeeId = new EmployeeId("foo");
            var   name       = new Name("f", "m", "l", "s", "t");
            var   address    = new FakeAddress();
            Money salary     = null;

            // Act
            Action action = () => SalaryEmployee.CreateNew(employeeId, name, address, salary);

            // Assert
            action.Should().Throw <EmployeeDomainException>().WithMessage("Employee salary must not be null.");
        }
コード例 #3
0
        public void CreateNew_CreatesHourlyEmployee()
        {
            // Arrange
            var employeeId = new EmployeeId("foo");
            var name       = new Name("bar", null, "hee", null, null);
            var address    = new FakeAddress();
            var rate       = new HourlyRate(new HourlyRateValue(110m));

            // Act
            var employee = HourlyEmployee.CreateNew(employeeId, name, address, rate);

            // Assert
            employee.EmployeeId.Should().Be(employeeId);
            employee.Name.Should().Be(name);
            employee.Address.Should().Be(address);
            employee.Rate.Should().Be(rate);
        }
コード例 #4
0
        public void CreateNew_CreatesSalaryEmployee()
        {
            // Arrange
            var employeeId = new EmployeeId("foo");
            var name       = new Name("bar", null, "bee", null, null);
            var address    = new FakeAddress();
            var salary     = new Money(new FakeCurrency(), new MoneyValue(100000m));

            // Act
            var employee = SalaryEmployee.CreateNew(employeeId, name, address, salary);

            // Assert
            employee.EmployeeId.Should().Be(employeeId);
            employee.Name.Should().Be(name);
            employee.Address.Should().Be(address);
            employee.Salary.Should().Be(salary);
        }
コード例 #5
0
        public void HourlyEmployees_WhenNotEqual_HaveDifferentHashCodes()
        {
            // Arrange
            var employeeId = new EmployeeId("foo");
            var name       = new Name("bar", null, "hee", null, null);
            var address    = new FakeAddress();
            var rate1      = new HourlyRate(new HourlyRateValue(100m));
            var rate2      = new HourlyRate(new HourlyRateValue(110m));

            var employee1 = HourlyEmployee.CreateNew(employeeId, name, address, rate1);
            var employee2 = HourlyEmployee.CreateNew(employeeId, name, address, rate2);

            // Act
            var hashCodesEqual = employee1.GetHashCode() == employee2.GetHashCode();

            // Assert
            hashCodesEqual.Should().BeFalse();
        }
コード例 #6
0
        public void HourlyEmployees_AreNotEqual()
        {
            // Arrange
            var employeeId = new EmployeeId("foo");
            var name       = new Name("bar", null, "hee", null, null);
            var address    = new FakeAddress();
            var rate1      = new HourlyRate(new HourlyRateValue(100m));
            var rate2      = new HourlyRate(new HourlyRateValue(110m));

            var employee1 = HourlyEmployee.CreateNew(employeeId, name, address, rate1);
            var employee2 = HourlyEmployee.CreateNew(employeeId, name, address, rate2);

            // Act
            var areEqual = employee1 == employee2;

            // Assert
            areEqual.Should().BeFalse();
        }
コード例 #7
0
        public void CreateNew_CreatesCommissionEmployee()
        {
            // Arrange
            EmployeeId     employeeId = new EmployeeId("foo");
            Name           name       = new Name("fee", null, "fo", null, null);
            FakeAddress    address    = new FakeAddress(new FakeName(), "l1", "city", "country");
            CommissionRate rate       = new CommissionRate(new CommissionRateValue(0.03m));
            Money          salary     = new Money(new FakeCurrency(), new MoneyValue(100000m));

            // Act
            var employee = CommissionEmployee.CreateNew(employeeId, name, address, rate, salary);

            // Assert
            employee.EmployeeId.Should().Be(employeeId);
            employee.Name.Should().Be(name);
            employee.Address.Should().Be(address);
            employee.Rate.Should().Be(rate);
            employee.Salary.Should().Be(salary);
        }