Пример #1
0
        public void SetPrimaryLocation_GivenLocationButWithoutAgencyLocations_PrimaryLocationIsNotChanged()
        {
            using (var serviceLocatorFixture = new ServiceLocatorFixture())
            {
                // Setup
                SetupServiceLocatorFixture ( serviceLocatorFixture );

                var staff = new Staff(new Mock<Agency>().Object,
                        new StaffProfileBuilder().WithStaffName(new PersonNameBuilder().WithFirst("first name").WithLast("last name")));

                var location = new Location(
                    new Mock<Agency>().Object,
                    new LocationProfileBuilder().WithLocationName(new LocationNameBuilder().WithName("location name")));

                staff.SetPrimaryLocation(null);

                // Exercise
                staff.SetPrimaryLocation(location);

                // Verify
                Assert.IsTrue ( staff.PrimaryLocation == null );
            }
        }
Пример #2
0
        public void SetPrimaryLocation_GivenLocationButWithoutAgencyLocations_ValidationFailureEventIsRaised()
        {
            using (var serviceLocatorFixture = new ServiceLocatorFixture())
            {
                // Setup
                SetupServiceLocatorFixture(serviceLocatorFixture);
                var staff = new Staff(new Mock<Agency>().Object,
                          new StaffProfileBuilder().WithStaffName(new PersonNameBuilder().WithFirst("first name").WithLast("last name")));

                var location = new Location(
                    new Mock<Agency>().Object,
                    new LocationProfileBuilder().WithLocationName(new LocationNameBuilder().WithName("location name")));

                bool eventRaised = false;
                DomainEvent.Register<RuleViolationEvent>(p => eventRaised = true);

                // Exercise
                staff.SetPrimaryLocation(location);

                // Verify
                Assert.IsTrue(eventRaised);
            }
        }
Пример #3
0
        public void SetPrimaryLocation_GivenNullLocation_Succeeds()
        {
            using (var serviceLocatorFixture = new ServiceLocatorFixture())
            {
                // Setup
                SetupServiceLocatorFixture(serviceLocatorFixture);
                // Setup
                var staff = new Staff(
                    new Mock<Agency>().Object,
                    new StaffProfileBuilder().WithStaffName(new PersonNameBuilder().WithFirst("first name").WithLast("last name")));

                // Exercise
                staff.SetPrimaryLocation(null);

                // Verify
                Assert.IsNull(staff.PrimaryLocation);
            }
        }
Пример #4
0
        public void SetPrimaryLocation_GivenLocationNotInAgencyLocations_ValidationFailureEventIsRaised()
        {
            using (var serviceLocatorFixture = new ServiceLocatorFixture())
            {
                // Setup
                SetupServiceLocatorFixture(serviceLocatorFixture);

                var location1Mock = new Mock<Location>();
                location1Mock.SetupGet(p => p.Key).Returns(1);
                var location2Mock = new Mock<Location>();
                location2Mock.SetupGet(p => p.Key).Returns(2);

                var agencyMock = new Mock<Agency>();
                agencyMock.SetupGet(p => p.Locations).Returns(new[] { location1Mock.Object, location2Mock.Object });

                var staff = new Staff(agencyMock.Object,
                          new StaffProfileBuilder().WithStaffName(new PersonNameBuilder().WithFirst("first name").WithLast("last name")));

                staff.SetPrimaryLocation(null);

                bool eventRaised = false;
                DomainEvent.Register<RuleViolationEvent>(p => eventRaised = true);

                // Exercise
                staff.SetPrimaryLocation(new Mock<Location>().Object);

                // Verify
                Assert.IsTrue(eventRaised);
            }
        }
Пример #5
0
        public void SetPrimaryLocation_GivenLocationNotInAgencyLocations_PrimaryLocationIsNotChanged()
        {
            using (var serviceLocatorFixture = new ServiceLocatorFixture())
            {
                // Setup
                SetupServiceLocatorFixture(serviceLocatorFixture);

                var location1Mock = new Mock<Location>();
                location1Mock.SetupGet(p => p.Key).Returns(1);
                var location2Mock = new Mock<Location>();
                location2Mock.SetupGet(p => p.Key).Returns(2);

                var agencyMock = new Mock<Agency>();
                agencyMock.SetupGet(p => p.Locations).Returns(new[] { location1Mock.Object, location2Mock.Object });

                var staff = new Staff(agencyMock.Object,
                          new StaffProfileBuilder().WithStaffName(new PersonNameBuilder().WithFirst("first name").WithLast("last name")));

                staff.SetPrimaryLocation(null);

                // Exercise
                staff.SetPrimaryLocation(new Mock<Location>().Object);

                // Verify
                Assert.IsTrue(staff.PrimaryLocation == null);
            }
        }