public void Dispose_CallsRelease_WhenCalled()
        {
            // Arrange
            var bayOne = Substitute.For <IBay>();

            bayOne.IsEmpty.Returns(true);
            var bayTwo = Substitute.For <IBay>();

            bayTwo.IsEmpty.Returns(true);
            var factory = Substitute.For <IBayFactory>();

            factory.Create(Arg.Any <int>()).Returns(bayOne,
                                                    bayTwo);
            var         vehicleOne = Substitute.For <IVehicle>();
            var         vehicleTwo = Substitute.For <IVehicle>();
            BaysManager sut        = CreateSut(3,
                                               factory);

            sut.AssignBay(vehicleOne);
            sut.AssignBay(vehicleTwo);

            // Act
            sut.Dispose();

            // Assert
            factory.Received().Release(bayOne);
            factory.Received().Release(bayTwo);
        }
        public void AssignBay_ThrowsException_ForNoEmptyBayLeft()
        {
            // Arrange
            var         vehicleOne = Substitute.For <IVehicle>();
            var         vehicleTwo = Substitute.For <IVehicle>();
            BaysManager sut        = CreateSut(1);

            sut.AssignBay(vehicleOne);

            // Act
            // Assert
            Assert.Throws <NoEmptyBayException>(() => sut.AssignBay(vehicleTwo));
        }
        public void AssignBay_AssignsVehiclesToDifferetBays_ForVehicles()
        {
            // Arrange
            var         vehicleOne = Substitute.For <IVehicle>();
            var         vehicleTwo = Substitute.For <IVehicle>();
            BaysManager sut        = CreateSut(3);

            // Act
            sut.AssignBay(vehicleOne);
            sut.AssignBay(vehicleTwo);

            // Assert
            Assert.AreEqual(0,
                            sut.FindVehicleBayId(vehicleOne),
                            "vehicleOne");

            Assert.AreEqual(1,
                            sut.FindVehicleBayId(vehicleTwo),
                            "vehicleTwo");
        }
        public void IsFull_ReturnsTrue_WhenAllBaysAreOccupied()
        {
            // Arrange
            var         vehicleOne = Substitute.For <IVehicle>();
            BaysManager sut        = CreateSut(1);

            sut.AssignBay(vehicleOne);

            // Act
            // Assert
            Assert.True(sut.IsFull);
        }
        public void IsFull_ReturnsFalse_WhenEmptyBaysAreAvailable()
        {
            // Arrange
            var         vehicleOne = Substitute.For <IVehicle>();
            BaysManager sut        = CreateSut(2);

            sut.AssignBay(vehicleOne);

            // Act
            // Assert
            Assert.False(sut.IsFull);
        }
        public void AssignBay_IncreasedNumberOfOccupiedBays_ForVehicle()
        {
            // Arrange
            var         vehicleOne = Substitute.For <IVehicle>();
            BaysManager sut        = CreateSut(3);

            // Act
            sut.AssignBay(vehicleOne);

            // Assert
            Assert.AreEqual(1,
                            sut.NumberOfOccupiedBays);
        }
        public void AssignBay_DecreasesNumberOfEmptyBays_ForVehicle()
        {
            // Arrange
            var         vehicleOne = Substitute.For <IVehicle>();
            BaysManager sut        = CreateSut(3);

            // Act
            sut.AssignBay(vehicleOne);

            // Assert
            Assert.AreEqual(2,
                            sut.NumberOfEmptyBays);
        }
        public void AssignBay_AssignsVehicleToBay_ForVehicle()
        {
            // Arrange
            var         vehicle = Substitute.For <IVehicle>();
            BaysManager sut     = CreateSut(3);

            // Act
            sut.AssignBay(vehicle);

            // Assert
            Assert.AreEqual(0,
                            sut.FindVehicleBayId(vehicle));
        }
        public void ReleaseBay_ReleasesBayFromVehicle_ForVehicle()
        {
            // Arrange
            var         vehicle = Substitute.For <IVehicle>();
            BaysManager sut     = CreateSut(3);

            sut.AssignBay(vehicle);

            // Act
            sut.ReleaseBay(vehicle);

            // Assert
            Assert.Throws <NoVehicleFoundInBaysException>(() => sut.FindVehicleBayId(vehicle));
        }
        public void Vehicles_ReturnsVehiclesInBays_WhenCalled()
        {
            // Arrange
            var         vehicleOne = Substitute.For <IVehicle>();
            var         vehicleTwo = Substitute.For <IVehicle>();
            BaysManager sut        = CreateSut(3);

            sut.AssignBay(vehicleOne);
            sut.AssignBay(vehicleTwo);

            // Act
            IVehicle[] actual = sut.Vehicles.ToArray();

            // Assert
            Assert.AreEqual(2,
                            actual.Length,
                            "Length");
            Assert.AreEqual(vehicleOne,
                            actual.First(),
                            "vehicleOne");
            Assert.AreEqual(vehicleTwo,
                            actual.Last(),
                            "vehicleTwo");
        }
        public void ReleaseBay_MarksBayAsEmpty_ForVehicle()
        {
            // Arrange
            var         vehicle = Substitute.For <IVehicle>();
            BaysManager sut     = CreateSut(3);

            sut.AssignBay(vehicle);

            // Act
            sut.ReleaseBay(vehicle);

            // Assert
            Assert.AreEqual(3,
                            sut.NumberOfEmptyBays);
        }